]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Add support for Commodore Amiga
authorCameron Armstrong <cameronscottarmstrong@gmail.com>
Sat, 23 Dec 2023 11:47:38 +0000 (19:47 +0800)
committerCameron Armstrong (Nightfox) <cameronscottarmstrong@gmail.com>
Tue, 24 Dec 2024 02:09:50 +0000 (10:09 +0800)
CMakeLists.txt
README.md
apps/CMakeLists.txt

index 55c6e561b25b9fb18df3046cda63fe141e183ef5..bba3b7b08635278af86358f7d60bed3082f15e11 100644 (file)
@@ -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")
index 38e8fb5c68093f9809a43dd6622e22568ecdbbb4..b974bd4ce3bddb7ce014783a0b9d90039efc4742 100644 (file)
--- 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)
 
 <a name="overview"></a>
 JSON-C - A JSON implementation in C
@@ -270,6 +271,44 @@ cmake \
 make install
 ```
 
+<a name="amiga"></a>
+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.
+
 <a name="linking"></a>
 Linking to `libjson-c`
 ----------------------
index f7c9dec633918c320afaf1fa8f56143b4ba51156..c278b025ed4d48c500884e538efaaced54f4cf59 100644 (file)
@@ -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()