Skip to content

Commit 7b73916

Browse files
authored
Merge pull request json-c#847 from sacredbanana/amiga
Add support for Commodore Amiga
2 parents ee83daa + ca1a6b0 commit 7b73916

File tree

5 files changed

+134
-15
lines changed

5 files changed

+134
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*.save
1111
*.autosav
1212
*.autosave
13+
.DS_Store
1314

1415
# Tests
1516
/tests/Makefile

CMakeLists.txt

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ include(CMakePackageConfigHelpers)
4545
option(BUILD_SHARED_LIBS "Default to building shared libraries" ON)
4646
option(BUILD_STATIC_LIBS "Default to building static libraries" ON)
4747

48-
if (BUILD_SHARED_LIBS)
49-
add_definitions(-D JSON_C_DLL)
50-
endif()
51-
5248
# Generate a release merge and test it to verify the correctness of republishing the package.
5349
ADD_CUSTOM_TARGET(distcheck
5450
COMMAND make package_source
@@ -73,12 +69,57 @@ option(DISABLE_JSON_PATCH "Disable JSON patch (RFC6902) support."
7369
option(NEWLOCALE_NEEDS_FREELOCALE "Work around newlocale bugs in old FreeBSD by calling freelocale" OFF)
7470
option(BUILD_APPS "Default to building apps" ON)
7571

72+
if (AMIGA)
73+
set(DISABLE_THREAD_LOCAL_STORAGE ON)
74+
set(ENABLE_THREADING OFF)
75+
set(BUILD_SHARED_LIBS OFF)
76+
set(BUILD_APPS OFF)
77+
set(DISABLE_STATIC_FPIC ON)
78+
if ($ENV{CROSS_PFX} STREQUAL "m68k-amigaos")
79+
set(AMIGA_M68K ON)
80+
set(BUILD_TESTING OFF)
81+
if (${M68K_CRT} STREQUAL "newlib")
82+
set(NEWLIB ON)
83+
elseif(${M68K_CRT} STREQUAL "clib2")
84+
set(CLIB2 ON)
85+
elseif(${M68K_CRT} STREQUAL "ixemul")
86+
set(IXEMUL ON)
87+
elseif(${M68K_CRT} STREQUAL "nix20")
88+
set(NIX20 ON)
89+
elseif(${M68K_CRT} STREQUAL "nix13")
90+
set(NIX13 ON)
91+
else()
92+
set(NEWLIB ON)
93+
endif()
94+
message(STATUS "Building for Motorola 68k AmigaOS using CRT: ${M68K_CRT}")
95+
elseif ($ENV{CROSS_PFX} STREQUAL "ppc-amigaos")
96+
set(AMIGA_PPC ON)
97+
message(STATUS "Building for PowerPC AmigaOS")
98+
elseif($ENV{CROSS_PFX} STREQUAL "ppc-morphos")
99+
set(MORPHOS ON)
100+
if (NOIXEMUL)
101+
message(STATUS "Building for PowerPC MorphOS without ixemul")
102+
set(DISABLE_WERROR ON)
103+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -noixemul")
104+
else()
105+
message(STATUS "Building for PowerPC MorphOS with ixemul")
106+
endif()
107+
else()
108+
message(FATAL_ERROR "Unsupported AmigaOS target")
109+
endif()
110+
else()
111+
message(STATUS "Building for ${CMAKE_SYSTEM_NAME}")
112+
endif()
76113

77-
if (UNIX OR MINGW OR CYGWIN)
114+
if (UNIX OR MINGW OR CYGWIN OR AMIGA)
78115
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
79116
endif()
80117

81-
if (UNIX)
118+
if (BUILD_SHARED_LIBS)
119+
add_definitions(-D JSON_C_DLL)
120+
endif()
121+
122+
if (UNIX OR AMIGA)
82123
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
83124
endif()
84125

@@ -136,30 +177,31 @@ endif()
136177
check_symbol_exists(_isnan "float.h" HAVE_DECL__ISNAN)
137178
check_symbol_exists(_finite "float.h" HAVE_DECL__FINITE)
138179

139-
if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX)
180+
if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX OR AMIGA)
140181
check_symbol_exists(INFINITY "math.h" HAVE_DECL_INFINITY)
141182
check_symbol_exists(isinf "math.h" HAVE_DECL_ISINF)
142183
check_symbol_exists(isnan "math.h" HAVE_DECL_ISNAN)
143184
check_symbol_exists(nan "math.h" HAVE_DECL_NAN)
144185
endif()
145186

146187
check_symbol_exists(_doprnt "stdio.h" HAVE_DOPRNT)
147-
if (UNIX OR MINGW OR CYGWIN)
188+
if (UNIX OR MINGW OR CYGWIN OR AMIGA)
148189
check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
149190
endif()
150191
check_symbol_exists(vasprintf "stdio.h" HAVE_VASPRINTF)
151192
check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF)
152193
check_symbol_exists(vprintf "stdio.h" HAVE_VPRINTF)
153-
154-
check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM)
194+
if (NOT AMIGA_M68K)
195+
check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM)
196+
endif()
155197
if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF")
156198
check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H)
157199
if (HAVE_BSD_STDLIB_H)
158-
list(APPEND CMAKE_REQUIRED_LIBRARIES "bsd")
159-
unset(HAVE_ARC4RANDOM CACHE)
200+
list(APPEND CMAKE_REQUIRED_LIBRARIES "bsd")
201+
unset(HAVE_ARC4RANDOM CACHE)
160202
check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM)
161203
if (NOT HAVE_ARC4RANDOM)
162-
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "bsd")
204+
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "bsd")
163205
endif()
164206
endif()
165207
endif()
@@ -173,6 +215,10 @@ endif()
173215
if (HAVE_LOCALE_H)
174216
check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE)
175217
check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE)
218+
if (NOT NIX20 AND NOT NIX13)
219+
# libnix does not fully support this yet
220+
check_symbol_exists(duplocale "locale.h" HAVE_DUPLOCALE)
221+
endif()
176222
endif()
177223

178224
# uClibc *intentionally* crashes in duplocale(), at least as of:
@@ -298,6 +344,9 @@ if ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER
298344
if ("${DISABLE_WERROR}" STREQUAL "OFF")
299345
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
300346
endif()
347+
if (AMIGA_M68K)
348+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fbaserel")
349+
endif()
301350
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
302351
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual")
303352
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=deprecated-declarations")

README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ json-c
1212
5. [Testing](#testing)
1313
6. [Building with `vcpkg`](#buildvcpkg)
1414
7. [Building for Android](#android)
15-
7. [Linking to libjson-c](#linking)
16-
8. [Using json-c](#using)
15+
8. [Building for Commodore Amiga or MorphOS](#amiga)
16+
9. [Linking to libjson-c](#linking)
17+
10. [Using json-c](#using)
1718

1819
<a name="overview"></a>
1920
JSON-C - A JSON implementation in C
@@ -270,6 +271,63 @@ cmake \
270271
make install
271272
```
272273

274+
<a name="amiga"></a>
275+
Building for Commodore Amiga or MorphOS
276+
----------------------
277+
278+
Building for Commodore Amiga is supported for both Motorola 68k (AmigaOS 3) and PowerPC (AmigaOS 4) architectures. MorphOS on compatible PowerPC hardware is also supported. You can set up a cross compiler locally, however it is much easier to use the already preconfigured Amiga development environment wtthin a Docker container.
279+
280+
Install Docker on your machine if you don't already have it. You can download Docker Desktop for Windows/macOS/Linux [here](https://www.docker.com/products/docker-desktop/).
281+
282+
### To build for Motorola 68k Amiga:
283+
284+
```
285+
mkdir build
286+
docker run --rm \
287+
-v ${PWD}:/work \
288+
-e USER=$( id -u ) -e GROUP=$( id -g ) \
289+
-it sacredbanana/amiga-compiler:m68k-amigaos bash
290+
cd build
291+
cmake -DM68K_CRT=newlib ..
292+
make
293+
```
294+
295+
libjson-c.a will get created in the build directory.
296+
297+
You can change newlib to nix20, nix13, ixemul or clib2 if you would like to build the library suited for libnix or clib2 instead. Newlib is default.
298+
299+
### To build for PowerPC Amiga:
300+
301+
```
302+
mkdir build
303+
docker run --rm \
304+
-v ${PWD}:/work \
305+
-e USER=$( id -u ) -e GROUP=$( id -g ) \
306+
-it sacredbanana/amiga-compiler:ppc-amigaos bash
307+
cd build
308+
cmake ..
309+
make
310+
```
311+
312+
libjson-c.a will get created in the build directory.
313+
314+
### To build for PowerPC MorphOS:
315+
316+
```
317+
mkdir build
318+
docker run --rm \
319+
-v ${PWD}:/work \
320+
-e USER=$( id -u ) -e GROUP=$( id -g ) \
321+
-it sacredbanana/amiga-compiler:ppc-morphos bash
322+
cd build
323+
cmake -DNOIXEMUL=1 ..
324+
make
325+
```
326+
327+
If you are making an application that absolutely requires ixemul, then remove the `-DNOIXEMUL=1`.
328+
329+
libjson-c.a will get created in the build directory.
330+
273331
<a name="linking"></a>
274332
Linking to `libjson-c`
275333
----------------------

cmake/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@
137137
/* Define to 1 if you have the `uselocale' function. */
138138
#cmakedefine HAVE_USELOCALE
139139

140+
/* Define to 1 if you have the `duplocale' function. */
141+
#cmakedefine HAVE_DUPLOCALE
142+
140143
/* Define to 1 if newlocale() needs freelocale() called on it's `base` argument */
141144
#cmakedefine NEWLOCALE_NEEDS_FREELOCALE
142145

json_tokener.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,23 +345,31 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
345345

346346
#ifdef HAVE_USELOCALE
347347
{
348+
#ifdef HAVE_DUPLOCALE
348349
locale_t duploc = duplocale(oldlocale);
349350
if (duploc == NULL && errno == ENOMEM)
350351
{
351352
tok->err = json_tokener_error_memory;
352353
return NULL;
353354
}
354355
newloc = newlocale(LC_NUMERIC_MASK, "C", duploc);
356+
#else
357+
newloc = newlocale(LC_NUMERIC_MASK, "C", oldlocale);
358+
#endif
355359
if (newloc == NULL)
356360
{
357361
tok->err = json_tokener_error_memory;
362+
#ifdef HAVE_DUPLOCALE
358363
freelocale(duploc);
364+
#endif
359365
return NULL;
360366
}
361367
#ifdef NEWLOCALE_NEEDS_FREELOCALE
368+
#ifdef HAVE_DUPLOCALE
362369
// Older versions of FreeBSD (<12.4) don't free the locale
363370
// passed to newlocale(), so do it here
364371
freelocale(duploc);
372+
#endif
365373
#endif
366374
uselocale(newloc);
367375
}

0 commit comments

Comments
 (0)