From 4feebc1cd61507c236705aa4e3a3b3b98696fd73 Mon Sep 17 00:00:00 2001 From: Cameron Armstrong Date: Sat, 23 Dec 2023 19:47:38 +0800 Subject: [PATCH 1/7] Add support for Commodore Amiga --- CMakeLists.txt | 55 ++++++++++++++++++++++++++++++++------------- README.md | 43 +++++++++++++++++++++++++++++++++-- apps/CMakeLists.txt | 2 +- 3 files changed, 81 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55c6e56..bba3b7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,24 @@ if (UNIX OR MINGW OR CYGWIN) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) endif() -if (UNIX) +if (${CMAKE_SYSTEM_NAME} STREQUAL "AmigaOS") + set(AMIGA 1) + set(DISABLE_THREAD_LOCAL_STORAGE ON) + set(ENABLE_THREADING OFF) + if ($ENV{CROSS_PFX} STREQUAL "m68k-amigaos") + set(AMIGA_M68K 1) + message(STATUS "Building for Motorola 68k AmigaOS") + elseif ($ENV{CROSS_PFX} STREQUAL "ppc-amigaos") + set(AMIGA_PPC 1) + message(STATUS "Building for PowerPC AmigaOS") + else() + message(FATAL_ERROR "Unsupported AmigaOS target") + endif() +else() + message(STATUS "Building for ${CMAKE_SYSTEM_NAME}") +endif() + +if (UNIX OR AMIGA) list(APPEND CMAKE_REQUIRED_LIBRARIES m) endif() @@ -87,7 +104,7 @@ if (MSVC) list(APPEND CMAKE_REQUIRED_FLAGS /wd4996) endif() -if (NOT DISABLE_STATIC_FPIC) +if (NOT DISABLE_STATIC_FPIC AND NOT AMIGA) # Use '-fPIC'/'-fPIE' option. # This will allow other libraries to statically link in libjson-c.a # which in turn prevents crashes in downstream apps that may use @@ -112,7 +129,9 @@ check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) # for getrusage check_include_file("dlfcn.h" HAVE_DLFCN_H) check_include_file("endian.h" HAVE_ENDIAN_H) check_include_file("limits.h" HAVE_LIMITS_H) -check_include_file("locale.h" HAVE_LOCALE_H) +if (NOT AMIGA) + check_include_file("locale.h" HAVE_LOCALE_H) +endif() check_include_file("memory.h" HAVE_MEMORY_H) check_include_file(stdint.h HAVE_STDINT_H) @@ -136,7 +155,7 @@ endif() check_symbol_exists(_isnan "float.h" HAVE_DECL__ISNAN) check_symbol_exists(_finite "float.h" HAVE_DECL__FINITE) -if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX) +if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX OR AMIGA) check_symbol_exists(INFINITY "math.h" HAVE_DECL_INFINITY) check_symbol_exists(isinf "math.h" HAVE_DECL_ISINF) check_symbol_exists(isnan "math.h" HAVE_DECL_ISNAN) @@ -144,22 +163,23 @@ if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX) endif() check_symbol_exists(_doprnt "stdio.h" HAVE_DOPRNT) -if (UNIX OR MINGW OR CYGWIN) +if (UNIX OR MINGW OR CYGWIN OR AMIGA) check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF) endif() check_symbol_exists(vasprintf "stdio.h" HAVE_VASPRINTF) check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF) check_symbol_exists(vprintf "stdio.h" HAVE_VPRINTF) - -check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM) -if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF") - check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H) - if (HAVE_BSD_STDLIB_H) - list(APPEND CMAKE_REQUIRED_LIBRARIES "bsd") - unset(HAVE_ARC4RANDOM CACHE) - check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM) - if (NOT HAVE_ARC4RANDOM) - list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "bsd") +if (NOT AMIGA) + check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM) + if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF") + check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H) + if (HAVE_BSD_STDLIB_H) + list(APPEND CMAKE_REQUIRED_LIBRARIES "bsd") + unset(HAVE_ARC4RANDOM CACHE) + check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM) + if (NOT HAVE_ARC4RANDOM) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "bsd") + endif() endif() endif() endif() @@ -201,7 +221,7 @@ endif() if (HAVE_SYS_RANDOM_H) check_symbol_exists(getrandom "sys/random.h" HAVE_GETRANDOM) endif() -if (HAVE_SYS_RESOURCE_H) +if (HAVE_SYS_RESOURCE_H AND NOT AMIGA) check_symbol_exists(getrusage "sys/resource.h" HAVE_GETRUSAGE) endif() @@ -298,6 +318,9 @@ if ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER if ("${DISABLE_WERROR}" STREQUAL "OFF") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") endif() + if (AMIGA_M68K) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fbaserel") + endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=deprecated-declarations") diff --git a/README.md b/README.md index 38e8fb5..b974bd4 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ json-c 5. [Testing](#testing) 6. [Building with `vcpkg`](#buildvcpkg) 7. [Building for Android](#android) -7. [Linking to libjson-c](#linking) -8. [Using json-c](#using) +8. [Building for Commodore Amiga](#amiga) +9. [Linking to libjson-c](#linking) +10. [Using json-c](#using) JSON-C - A JSON implementation in C @@ -270,6 +271,44 @@ cmake \ make install ``` + +Building for Commodore Amiga +---------------------- + +Building for Commodore Amiga is supported for both Motorola 68k (AmigaOS 3) and PowerPC (AmigaOS 4) architectures. 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. + +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/). + +To build for Motorola 68k Amiga: + +``` +mkdir json-c-build +docker run --rm \ + -v ${PWD}:/work \ + -e USER=$( id -u ) -e GROUP=$( id -g ) \ + -it sacredbanana/amiga-compiler:m68k-amigaos bash +cd json-c-build +cmake .. +make +``` + +libjson-c.a will get created in the json-c-build directory. + +To build for PowerPC Amiga: + +``` +mkdir json-c-build +docker run --rm \ + -v ${PWD}:/work \ + -e USER=$( id -u ) -e GROUP=$( id -g ) \ + -it sacredbanana/amiga-compiler:ppc-amigaos bash +cd json-c-build +cmake .. +make +``` + +libjson-c.a will get created in the json-c-build directory. + Linking to `libjson-c` ---------------------- diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index f7c9dec..c278b02 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -95,7 +95,7 @@ endif() # end "standalone mode" block # --------------------------------- check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) # for getrusage -if (HAVE_SYS_RESOURCE_H) +if (HAVE_SYS_RESOURCE_H AND NOT AMIGA) check_symbol_exists(getrusage "sys/resource.h" HAVE_GETRUSAGE) endif() From f928e7c0fab2703d5e857cb61cc07ccd78dbfc9d Mon Sep 17 00:00:00 2001 From: Cameron Armstrong Date: Thu, 28 Dec 2023 07:53:32 +0800 Subject: [PATCH 2/7] Get working ror libnix and clib2 --- CMakeLists.txt | 56 ++++++++++++++++++++++++++++----------------- README.md | 4 +++- apps/CMakeLists.txt | 2 +- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bba3b7b..41c0d89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,10 +45,6 @@ include(CMakePackageConfigHelpers) option(BUILD_SHARED_LIBS "Default to building shared libraries" ON) option(BUILD_STATIC_LIBS "Default to building static libraries" ON) -if (BUILD_SHARED_LIBS) - add_definitions(-D JSON_C_DLL) -endif() - # Generate a release merge and test it to verify the correctness of republishing the package. ADD_CUSTOM_TARGET(distcheck COMMAND make package_source @@ -73,20 +69,34 @@ option(DISABLE_JSON_PATCH "Disable JSON patch (RFC6902) support." option(NEWLOCALE_NEEDS_FREELOCALE "Work around newlocale bugs in old FreeBSD by calling freelocale" OFF) option(BUILD_APPS "Default to building apps" ON) - -if (UNIX OR MINGW OR CYGWIN) +if (UNIX OR MINGW OR CYGWIN OR AMIGA) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) endif() if (${CMAKE_SYSTEM_NAME} STREQUAL "AmigaOS") - set(AMIGA 1) + set(AMIGA ON) set(DISABLE_THREAD_LOCAL_STORAGE ON) set(ENABLE_THREADING OFF) + set(BUILD_SHARED_LIBS OFF) + set(BUILD_APPS OFF) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) if ($ENV{CROSS_PFX} STREQUAL "m68k-amigaos") - set(AMIGA_M68K 1) + set(AMIGA_M68K ON) + set(BUILD_TESTING OFF) message(STATUS "Building for Motorola 68k AmigaOS") + if (${M68K_CRT} STREQUAL "newlib") + set(NEWLIB ON) + elseif(${M68K_CRT} STREQUAL "clib2") + set(CLIB2 ON) + elseif(${M68K_CRT} STREQUAL "nix20") + set(NIX20 ON) + elseif(${M68K_CRT} STREQUAL "nix13") + set(NIX13 ON) + else() + set(NEWLIB ON) + endif() elseif ($ENV{CROSS_PFX} STREQUAL "ppc-amigaos") - set(AMIGA_PPC 1) + set(AMIGA_PPC ON) message(STATUS "Building for PowerPC AmigaOS") else() message(FATAL_ERROR "Unsupported AmigaOS target") @@ -95,6 +105,10 @@ else() message(STATUS "Building for ${CMAKE_SYSTEM_NAME}") endif() +if (BUILD_SHARED_LIBS) + add_definitions(-D JSON_C_DLL) +endif() + if (UNIX OR AMIGA) list(APPEND CMAKE_REQUIRED_LIBRARIES m) endif() @@ -129,7 +143,7 @@ check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) # for getrusage check_include_file("dlfcn.h" HAVE_DLFCN_H) check_include_file("endian.h" HAVE_ENDIAN_H) check_include_file("limits.h" HAVE_LIMITS_H) -if (NOT AMIGA) +if (NOT AMIGA_M68K) check_include_file("locale.h" HAVE_LOCALE_H) endif() check_include_file("memory.h" HAVE_MEMORY_H) @@ -169,17 +183,17 @@ endif() check_symbol_exists(vasprintf "stdio.h" HAVE_VASPRINTF) check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF) check_symbol_exists(vprintf "stdio.h" HAVE_VPRINTF) -if (NOT AMIGA) +if (NOT AMIGA_M68K) check_symbol_exists(arc4random "stdlib.h" HAVE_ARC4RANDOM) - if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF") - check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H) - if (HAVE_BSD_STDLIB_H) - list(APPEND CMAKE_REQUIRED_LIBRARIES "bsd") - unset(HAVE_ARC4RANDOM CACHE) - check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM) - if (NOT HAVE_ARC4RANDOM) - list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "bsd") - endif() +endif() +if (NOT HAVE_ARC4RANDOM AND DISABLE_EXTRA_LIBS STREQUAL "OFF") + check_include_file(bsd/stdlib.h HAVE_BSD_STDLIB_H) + if (HAVE_BSD_STDLIB_H) + list(APPEND CMAKE_REQUIRED_LIBRARIES "bsd") + unset(HAVE_ARC4RANDOM CACHE) + check_symbol_exists(arc4random "bsd/stdlib.h" HAVE_ARC4RANDOM) + if (NOT HAVE_ARC4RANDOM) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "bsd") endif() endif() endif() @@ -221,7 +235,7 @@ endif() if (HAVE_SYS_RANDOM_H) check_symbol_exists(getrandom "sys/random.h" HAVE_GETRANDOM) endif() -if (HAVE_SYS_RESOURCE_H AND NOT AMIGA) +if (HAVE_SYS_RESOURCE_H) check_symbol_exists(getrusage "sys/resource.h" HAVE_GETRUSAGE) endif() diff --git a/README.md b/README.md index b974bd4..60f3b93 100644 --- a/README.md +++ b/README.md @@ -288,12 +288,14 @@ docker run --rm \ -e USER=$( id -u ) -e GROUP=$( id -g ) \ -it sacredbanana/amiga-compiler:m68k-amigaos bash cd json-c-build -cmake .. +cmake -DM68K_CRT=newlib .. make ``` libjson-c.a will get created in the json-c-build directory. +You can change newlib to nix20, nix13 or clib2 if you would like to build the library suited for libnix or clib2 instead. Newlib is default. + To build for PowerPC Amiga: ``` diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index c278b02..f7c9dec 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -95,7 +95,7 @@ endif() # end "standalone mode" block # --------------------------------- check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) # for getrusage -if (HAVE_SYS_RESOURCE_H AND NOT AMIGA) +if (HAVE_SYS_RESOURCE_H) check_symbol_exists(getrusage "sys/resource.h" HAVE_GETRUSAGE) endif() From 743ebf53e5eac0442fd871f6568c937653fd072b Mon Sep 17 00:00:00 2001 From: "Cameron Armstrong (Nightfox)" Date: Sat, 22 Jun 2024 13:45:15 +0800 Subject: [PATCH 3/7] Fix Readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 60f3b93..f4a889c 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ Building for Commodore Amiga is supported for both Motorola 68k (AmigaOS 3) and 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/). -To build for Motorola 68k Amiga: +### To build for Motorola 68k Amiga: ``` mkdir json-c-build @@ -296,7 +296,7 @@ libjson-c.a will get created in the json-c-build directory. You can change newlib to nix20, nix13 or clib2 if you would like to build the library suited for libnix or clib2 instead. Newlib is default. -To build for PowerPC Amiga: +### To build for PowerPC Amiga: ``` mkdir json-c-build From d31d635af1bdaafcc5d5b27ea6374c5a2952e490 Mon Sep 17 00:00:00 2001 From: "Cameron Armstrong (Nightfox)" Date: Sat, 22 Jun 2024 18:49:50 +0800 Subject: [PATCH 4/7] Clean up CMakeLists.txt and remove Amiga specific locale.h guard --- .gitignore | 1 + CMakeLists.txt | 16 +++++++--------- README.md | 12 ++++++------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 4b7da9f..e50a283 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.save *.autosav *.autosave +.DS_Store # Tests /tests/Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 41c0d89..ed877e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,17 +69,13 @@ option(DISABLE_JSON_PATCH "Disable JSON patch (RFC6902) support." option(NEWLOCALE_NEEDS_FREELOCALE "Work around newlocale bugs in old FreeBSD by calling freelocale" OFF) option(BUILD_APPS "Default to building apps" ON) -if (UNIX OR MINGW OR CYGWIN OR AMIGA) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) -endif() - if (${CMAKE_SYSTEM_NAME} STREQUAL "AmigaOS") set(AMIGA ON) set(DISABLE_THREAD_LOCAL_STORAGE ON) set(ENABLE_THREADING OFF) set(BUILD_SHARED_LIBS OFF) set(BUILD_APPS OFF) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) + set(DISABLE_STATIC_FPIC ON) if ($ENV{CROSS_PFX} STREQUAL "m68k-amigaos") set(AMIGA_M68K ON) set(BUILD_TESTING OFF) @@ -105,6 +101,10 @@ else() message(STATUS "Building for ${CMAKE_SYSTEM_NAME}") endif() +if (UNIX OR MINGW OR CYGWIN OR AMIGA) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) +endif() + if (BUILD_SHARED_LIBS) add_definitions(-D JSON_C_DLL) endif() @@ -118,7 +118,7 @@ if (MSVC) list(APPEND CMAKE_REQUIRED_FLAGS /wd4996) endif() -if (NOT DISABLE_STATIC_FPIC AND NOT AMIGA) +if (NOT DISABLE_STATIC_FPIC) # Use '-fPIC'/'-fPIE' option. # This will allow other libraries to statically link in libjson-c.a # which in turn prevents crashes in downstream apps that may use @@ -143,9 +143,7 @@ check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) # for getrusage check_include_file("dlfcn.h" HAVE_DLFCN_H) check_include_file("endian.h" HAVE_ENDIAN_H) check_include_file("limits.h" HAVE_LIMITS_H) -if (NOT AMIGA_M68K) - check_include_file("locale.h" HAVE_LOCALE_H) -endif() +check_include_file("locale.h" HAVE_LOCALE_H) check_include_file("memory.h" HAVE_MEMORY_H) check_include_file(stdint.h HAVE_STDINT_H) diff --git a/README.md b/README.md index f4a889c..1327f3a 100644 --- a/README.md +++ b/README.md @@ -282,34 +282,34 @@ Install Docker on your machine if you don't already have it. You can download Do ### To build for Motorola 68k Amiga: ``` -mkdir json-c-build +mkdir build docker run --rm \ -v ${PWD}:/work \ -e USER=$( id -u ) -e GROUP=$( id -g ) \ -it sacredbanana/amiga-compiler:m68k-amigaos bash -cd json-c-build +cd build cmake -DM68K_CRT=newlib .. make ``` -libjson-c.a will get created in the json-c-build directory. +libjson-c.a will get created in the build directory. You can change newlib to nix20, nix13 or clib2 if you would like to build the library suited for libnix or clib2 instead. Newlib is default. ### To build for PowerPC Amiga: ``` -mkdir json-c-build +mkdir build docker run --rm \ -v ${PWD}:/work \ -e USER=$( id -u ) -e GROUP=$( id -g ) \ -it sacredbanana/amiga-compiler:ppc-amigaos bash -cd json-c-build +cd build cmake .. make ``` -libjson-c.a will get created in the json-c-build directory. +libjson-c.a will get created in the build directory. Linking to `libjson-c` From 254b5abef8217a92032f9ad971b8477966f72bbd Mon Sep 17 00:00:00 2001 From: "Cameron Armstrong (Nightfox)" Date: Mon, 15 Jul 2024 11:30:44 +0800 Subject: [PATCH 5/7] Do not use duplocale if building for libnix because it isnt supported yet --- CMakeLists.txt | 8 +++++++- README.md | 2 +- cmake/config.h.in | 3 +++ json_tokener.c | 8 ++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed877e3..11bfa43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,8 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "AmigaOS") set(NEWLIB ON) elseif(${M68K_CRT} STREQUAL "clib2") set(CLIB2 ON) + elseif(${M68K_CRT} STREQUAL "ixemul") + set(IXEMUL ON) elseif(${M68K_CRT} STREQUAL "nix20") set(NIX20 ON) elseif(${M68K_CRT} STREQUAL "nix13") @@ -205,6 +207,10 @@ endif() if (HAVE_LOCALE_H) check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE) check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE) + if (NOT NIX20 AND NOT NIX13) + # libnix does not fully support this yet + check_symbol_exists(duplocale "locale.h" HAVE_DUPLOCALE) + endif() endif() # uClibc *intentionally* crashes in duplocale(), at least as of: @@ -379,7 +385,7 @@ if (NOT ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")) # OSX Mach-O doesn't support linking with '-Bsymbolic-functions'. # Others may not support it, too. - list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions") + list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions,-lamiga,-lc") check_c_source_compiles( " int main (void) diff --git a/README.md b/README.md index 1327f3a..4b972d6 100644 --- a/README.md +++ b/README.md @@ -294,7 +294,7 @@ make libjson-c.a will get created in the build directory. -You can change newlib to nix20, nix13 or clib2 if you would like to build the library suited for libnix or clib2 instead. Newlib is default. +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. ### To build for PowerPC Amiga: diff --git a/cmake/config.h.in b/cmake/config.h.in index 1e6359d..6517340 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -137,6 +137,9 @@ /* Define to 1 if you have the `uselocale' function. */ #cmakedefine HAVE_USELOCALE +/* Define to 1 if you have the `duplocale' function. */ +#cmakedefine HAVE_DUPLOCALE + /* Define to 1 if newlocale() needs freelocale() called on it's `base` argument */ #cmakedefine NEWLOCALE_NEEDS_FREELOCALE diff --git a/json_tokener.c b/json_tokener.c index 20bad14..53ef209 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -345,6 +345,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char * #ifdef HAVE_USELOCALE { +#ifdef HAVE_DUPLOCALE locale_t duploc = duplocale(oldlocale); if (duploc == NULL && errno == ENOMEM) { @@ -352,16 +353,23 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char * return NULL; } newloc = newlocale(LC_NUMERIC_MASK, "C", duploc); +#else + newloc = newlocale(LC_NUMERIC_MASK, "C", oldlocale); +#endif if (newloc == NULL) { tok->err = json_tokener_error_memory; +#ifdef HAVE_DUPLOCALE freelocale(duploc); +#endif return NULL; } #ifdef NEWLOCALE_NEEDS_FREELOCALE +#ifdef HAVE_DUPLOCALE // Older versions of FreeBSD (<12.4) don't free the locale // passed to newlocale(), so do it here freelocale(duploc); +#endif #endif uselocale(newloc); } From daff6eb7460632ec7da2b121437b2a7c92c349d4 Mon Sep 17 00:00:00 2001 From: "Cameron Armstrong (Nightfox)" Date: Mon, 5 Aug 2024 12:50:47 +0800 Subject: [PATCH 6/7] Remove linking to libamiga and libc --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11bfa43..5266def 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -385,7 +385,7 @@ if (NOT ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")) # OSX Mach-O doesn't support linking with '-Bsymbolic-functions'. # Others may not support it, too. - list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions,-lamiga,-lc") + list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions") check_c_source_compiles( " int main (void) From ca1a6b0cc9603b34d375d27073f01384f968eef2 Mon Sep 17 00:00:00 2001 From: "Cameron Armstrong (Nightfox)" Date: Sat, 31 Aug 2024 03:57:46 +0800 Subject: [PATCH 7/7] Add support for MorphOS --- CMakeLists.txt | 14 +++++++++++--- README.md | 23 ++++++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5266def..e599244 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,8 +69,7 @@ option(DISABLE_JSON_PATCH "Disable JSON patch (RFC6902) support." option(NEWLOCALE_NEEDS_FREELOCALE "Work around newlocale bugs in old FreeBSD by calling freelocale" OFF) option(BUILD_APPS "Default to building apps" ON) -if (${CMAKE_SYSTEM_NAME} STREQUAL "AmigaOS") - set(AMIGA ON) +if (AMIGA) set(DISABLE_THREAD_LOCAL_STORAGE ON) set(ENABLE_THREADING OFF) set(BUILD_SHARED_LIBS OFF) @@ -79,7 +78,6 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "AmigaOS") if ($ENV{CROSS_PFX} STREQUAL "m68k-amigaos") set(AMIGA_M68K ON) set(BUILD_TESTING OFF) - message(STATUS "Building for Motorola 68k AmigaOS") if (${M68K_CRT} STREQUAL "newlib") set(NEWLIB ON) elseif(${M68K_CRT} STREQUAL "clib2") @@ -93,9 +91,19 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "AmigaOS") else() set(NEWLIB ON) endif() + message(STATUS "Building for Motorola 68k AmigaOS using CRT: ${M68K_CRT}") elseif ($ENV{CROSS_PFX} STREQUAL "ppc-amigaos") set(AMIGA_PPC ON) message(STATUS "Building for PowerPC AmigaOS") + elseif($ENV{CROSS_PFX} STREQUAL "ppc-morphos") + set(MORPHOS ON) + if (NOIXEMUL) + message(STATUS "Building for PowerPC MorphOS without ixemul") + set(DISABLE_WERROR ON) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -noixemul") + else() + message(STATUS "Building for PowerPC MorphOS with ixemul") + endif() else() message(FATAL_ERROR "Unsupported AmigaOS target") endif() diff --git a/README.md b/README.md index 4b972d6..d15fa41 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ json-c 5. [Testing](#testing) 6. [Building with `vcpkg`](#buildvcpkg) 7. [Building for Android](#android) -8. [Building for Commodore Amiga](#amiga) +8. [Building for Commodore Amiga or MorphOS](#amiga) 9. [Linking to libjson-c](#linking) 10. [Using json-c](#using) @@ -272,10 +272,10 @@ make install ``` -Building for Commodore Amiga +Building for Commodore Amiga or MorphOS ---------------------- -Building for Commodore Amiga is supported for both Motorola 68k (AmigaOS 3) and PowerPC (AmigaOS 4) architectures. 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. +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. 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/). @@ -311,6 +311,23 @@ make libjson-c.a will get created in the build directory. +### To build for PowerPC MorphOS: + +``` +mkdir build +docker run --rm \ + -v ${PWD}:/work \ + -e USER=$( id -u ) -e GROUP=$( id -g ) \ + -it sacredbanana/amiga-compiler:ppc-morphos bash +cd build +cmake -DNOIXEMUL=1 .. +make +``` + +If you are making an application that absolutely requires ixemul, then remove the `-DNOIXEMUL=1`. + +libjson-c.a will get created in the build directory. + Linking to `libjson-c` ----------------------