From f6881669c26ae0604fa8c87687cb2d1a899ab7ea Mon Sep 17 00:00:00 2001 From: "Cameron Armstrong (Nightfox)" Date: Sat, 22 Aug 2026 14:47:19 +0800 Subject: [PATCH] Specify fbaserel and Motorola CPU target --- CMakeLists.txt | 36 ++++++++++++++++++++++++++++++++++-- README.md | 18 ++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d46a3dc..44b696b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,31 @@ if (AMIGA) else() set(NEWLIB ON) endif() - message(STATUS "Building for Motorola 68k AmigaOS using CRT: ${M68K_CRT}") + if (NOT DEFINED M68K_BASEREL) + set(M68K_BASEREL "baserel") + endif() + set(M68K_BASEREL "${M68K_BASEREL}" CACHE STRING "m68k base-relative addressing: baserel, baserel32, or off") + set_property(CACHE M68K_BASEREL PROPERTY STRINGS baserel baserel32 off) + if (NOT M68K_BASEREL STREQUAL "baserel" AND + NOT M68K_BASEREL STREQUAL "baserel32" AND + NOT M68K_BASEREL STREQUAL "off") + message(FATAL_ERROR "M68K_BASEREL must be baserel, baserel32, or off (got: ${M68K_BASEREL})") + endif() + set(M68K_CPU "${M68K_CPU}" CACHE STRING "m68k CPU target (e.g. 68020, 68040, 68060); empty uses the compiler default") + if (M68K_CPU STREQUAL "" OR M68K_CPU STREQUAL "off") + set(M68K_CPU_FLAG "") + elseif (M68K_CPU MATCHES "^-") + set(M68K_CPU_FLAG "${M68K_CPU}") + elseif (M68K_CPU MATCHES "^m") + set(M68K_CPU_FLAG "-${M68K_CPU}") + else() + set(M68K_CPU_FLAG "-m${M68K_CPU}") + endif() + if (M68K_CPU_FLAG STREQUAL "") + message(STATUS "Building for Motorola 68k AmigaOS using CRT: ${M68K_CRT}, baserel: ${M68K_BASEREL}") + else() + message(STATUS "Building for Motorola 68k AmigaOS using CRT: ${M68K_CRT}, baserel: ${M68K_BASEREL}, cpu: ${M68K_CPU_FLAG}") + endif() elseif ($ENV{CROSS_PFX} STREQUAL "ppc-amigaos") set(AMIGA_PPC ON) message(STATUS "Building for PowerPC AmigaOS") @@ -109,6 +133,7 @@ if (AMIGA) message(STATUS "Building for PowerPC MorphOS without ixemul") set(DISABLE_WERROR ON) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -noixemul") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-incompatible-pointer-types") else() message(STATUS "Building for PowerPC MorphOS with ixemul") endif() @@ -362,7 +387,14 @@ if ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") endif() if (AMIGA_M68K) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fbaserel") + if (M68K_BASEREL STREQUAL "baserel") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fbaserel") + elseif (M68K_BASEREL STREQUAL "baserel32") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fbaserel32") + endif() + if (NOT M68K_CPU_FLAG STREQUAL "") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${M68K_CPU_FLAG}") + endif() endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual") diff --git a/README.md b/README.md index d15fa41..5228960 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,24 @@ libjson-c.a will get created in the build directory. 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. +By default the m68k build uses `-fbaserel`. You can select a different base-relative mode with `-DM68K_BASEREL=`: + +* `baserel` (default) — `-fbaserel` +* `baserel32` — `-fbaserel32` +* `off` — no base-relative flag + +``` +cmake -DM68K_CRT=newlib -DM68K_BASEREL=baserel32 .. +cmake -DM68K_CRT=newlib -DM68K_BASEREL=off .. +``` + +You can also set the target CPU with `-DM68K_CPU=`. This is passed to the compiler as `-m` (for example `68020` becomes `-m68020`). If omitted, the compiler default is used. + +``` +cmake -DM68K_CRT=newlib -DM68K_CPU=68020 .. +cmake -DM68K_CRT=newlib -DM68K_CPU=68040 -DM68K_BASEREL=baserel32 .. +``` + ### To build for PowerPC Amiga: ```