Skip to content

Commit a2e5b41

Browse files
committed
Implement Podman-based Windows cross-compilation testing environment
- Added build-windows-cross.sh script using maxrd2/arch-mingw Docker image - Enhanced CMakeLists.txt to detect and handle cross-compilation builds - Improved create-minimal-makefile.sh with file existence checking - Added platform function stubs for Windows compatibility - Added missing headers (inttypes.h, dirent.h) to config.h Successfully builds libatari800.a cross-compilation, now debugging remaining linker issues and platform function declarations.
1 parent 6ca2425 commit a2e5b41

File tree

3 files changed

+150
-12
lines changed

3 files changed

+150
-12
lines changed

CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ set(ATARI800_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/atari800-build")
5555
set(ATARI800_LIBRARY "${ATARI800_SOURCE_DIR}/src/libatari800.a")
5656

5757
# Configure platform-specific build commands for atari800
58-
if(WIN32)
58+
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
59+
# Native Windows build with MSYS2
5960
# Windows: Use MSYS2 environment for building atari800
6061
# GitHub Actions uses setup-msys2 which sets up environment differently
6162
# Look for MSYS2 bash in GitHub Actions setup-msys2 location
@@ -89,6 +90,11 @@ if(WIN32)
8990
set(ATARI800_CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env MSYSTEM=MSYS OS=Windows_NT RUNNER_OS=Windows CI=true ${MSYS2_BASH} --login -c "export PATH='/mingw64/bin:/usr/bin:$PATH' && cd '<SOURCE_DIR>' && echo 'FORCING MINIMAL BUILD FOR WINDOWS' && '${CMAKE_CURRENT_SOURCE_DIR}/scripts/create-minimal-makefile.sh' '<SOURCE_DIR>'")
9091
set(ATARI800_BUILD_COMMAND ${CMAKE_COMMAND} -E env MSYSTEM=MSYS ${MSYS2_BASH} --login -c "export PATH='/mingw64/bin:/usr/bin:$PATH' && cd '<SOURCE_DIR>' && echo '=== Starting make build ===' && make -j4 VERBOSE=1 || (echo '=== Make failed, trying single-threaded build ===' && make VERBOSE=1)")
9192
endif()
93+
elseif(CMAKE_CROSSCOMPILING AND WIN32)
94+
# Cross-compilation for Windows (using MinGW on Linux)
95+
message(STATUS "Configuring for Windows cross-compilation")
96+
set(ATARI800_CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/create-minimal-makefile.sh <SOURCE_DIR>)
97+
set(ATARI800_BUILD_COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR> make -j4 CC=${CMAKE_C_COMPILER} AR=x86_64-w64-mingw32-ar)
9298
else()
9399
# Unix/macOS: Use native tools
94100
set(ATARI800_CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/configure-atari800.sh <SOURCE_DIR>)
@@ -132,7 +138,7 @@ ExternalProject_Add(atari800_external
132138
)
133139

134140
# Verify that the library was created successfully
135-
if(WIN32)
141+
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
136142
# Add custom command to verify library creation on Windows
137143
add_custom_command(TARGET atari800_external POST_BUILD
138144
COMMAND ${CMAKE_COMMAND} -E echo "=== Verifying libatari800 build on Windows ==="
@@ -141,6 +147,14 @@ if(WIN32)
141147
COMMAND ${CMAKE_COMMAND} -E env MSYSTEM=MSYS ${MSYS2_BASH} -c "export PATH='/mingw64/bin:/usr/bin:$PATH' && if [ -f '${ATARI800_LIBRARY}' ]; then echo 'SUCCESS: libatari800.a exists'; ls -la '${ATARI800_LIBRARY}'; if [ -f '${ATARI800_SOURCE_DIR}/.minimal-build-marker' ]; then echo 'INFO: Built using minimal Makefile approach'; cat '${ATARI800_SOURCE_DIR}/.minimal-build-marker'; fi; else echo 'ERROR: libatari800.a missing'; ls -la '${ATARI800_SOURCE_DIR}/src/'; if [ -f '${ATARI800_SOURCE_DIR}/.minimal-build-marker' ]; then echo 'DEBUG: Minimal build was attempted'; cat '${ATARI800_SOURCE_DIR}/.minimal-build-marker'; fi; fi"
142148
COMMENT "Verifying libatari800 library creation"
143149
)
150+
elseif(CMAKE_CROSSCOMPILING AND WIN32)
151+
# Add custom command to verify library creation during cross-compilation
152+
add_custom_command(TARGET atari800_external POST_BUILD
153+
COMMAND ${CMAKE_COMMAND} -E echo "=== Verifying libatari800 cross-compilation build ==="
154+
COMMAND ${CMAKE_COMMAND} -E echo "Expected library: ${ATARI800_LIBRARY}"
155+
COMMAND test -f "${ATARI800_LIBRARY}" && echo "SUCCESS: libatari800.a exists" || echo "ERROR: libatari800.a missing"
156+
COMMENT "Verifying cross-compiled libatari800 library creation"
157+
)
144158
endif()
145159

146160
# Create imported target for libatari800

scripts/build-windows-cross.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
# build-windows-cross.sh - Cross-compile Fujisan for Windows using Podman
3+
4+
set -e
5+
6+
echo "=== Fujisan Windows Cross-compilation Build Script ==="
7+
8+
# Configuration
9+
CONTAINER_IMAGE="maxrd2/arch-mingw"
10+
BUILD_DIR="build-cross-windows"
11+
CURRENT_DIR=$(pwd)
12+
13+
# Clean previous build
14+
if [ -d "$BUILD_DIR" ]; then
15+
echo "Cleaning previous build directory..."
16+
rm -rf "$BUILD_DIR"
17+
fi
18+
19+
mkdir -p "$BUILD_DIR"
20+
21+
echo "Using container image: $CONTAINER_IMAGE"
22+
echo "Build directory: $BUILD_DIR"
23+
echo "Source directory: $CURRENT_DIR"
24+
25+
# Create CMake toolchain file for cross-compilation
26+
cat > "$BUILD_DIR/mingw-toolchain.cmake" << 'EOF'
27+
set(CMAKE_SYSTEM_NAME Windows)
28+
set(CMAKE_SYSTEM_PROCESSOR x86_64)
29+
30+
# Cross-compilation tools
31+
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
32+
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
33+
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
34+
35+
# Where to find libraries and headers
36+
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
37+
38+
# Search for programs in the build host directories
39+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
40+
# Search for libraries and headers in the target directories
41+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
42+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
43+
44+
# Qt5 configuration for cross-compilation
45+
set(CMAKE_PREFIX_PATH /usr/x86_64-w64-mingw32)
46+
set(Qt5_DIR /usr/x86_64-w64-mingw32/lib/cmake/Qt5)
47+
48+
# Windows-specific settings
49+
set(CMAKE_CXX_STANDARD 14)
50+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
51+
EOF
52+
53+
echo "Created CMake toolchain file"
54+
55+
# Run cross-compilation build inside container
56+
echo "Starting cross-compilation build..."
57+
58+
podman run --rm \
59+
-v "$CURRENT_DIR:/work" \
60+
--userns=keep-id \
61+
--workdir="/work" \
62+
"$CONTAINER_IMAGE" \
63+
bash -c "
64+
set -e
65+
echo '=== Cross-compilation Environment ==='
66+
x86_64-w64-mingw32-gcc --version
67+
x86_64-w64-mingw32-cmake --version
68+
69+
echo '=== Configuring CMake ==='
70+
cd $BUILD_DIR
71+
x86_64-w64-mingw32-cmake \
72+
-DCMAKE_TOOLCHAIN_FILE=mingw-toolchain.cmake \
73+
-DCMAKE_BUILD_TYPE=Release \
74+
-DFUJISAN_VERSION=dev-cross \
75+
..
76+
77+
echo '=== Building ==='
78+
make -j4 VERBOSE=1
79+
80+
echo '=== Build Complete ==='
81+
ls -la
82+
file *.exe 2>/dev/null || echo 'No .exe files found'
83+
"
84+
85+
echo "Cross-compilation build completed!"
86+
echo "Check $BUILD_DIR/ for results"

scripts/create-minimal-makefile.sh

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ DESIRED_SOURCES="
4545
afile antic atari cartridge cpu esc gtia memory monitor pbi pia pokey pokeysnd
4646
sio sound statesav pbi_mio pbi_bb pbi_xld mzpokeysnd votraxsnd votrax pbi_scsi
4747
rtime cassette compfile cfg log util colours screen input binload devices
48-
img_tape remez lib
48+
img_tape remez lib artifact ide rdevice sysrom videomode
4949
"
5050

5151
# Check which files actually exist and build the object list
@@ -59,11 +59,47 @@ for src in $DESIRED_SOURCES; do
5959
fi
6060
done
6161

62-
# Always include libatari800 API files
63-
EXISTING_OBJS="$EXISTING_OBJS src/libatari800/api.o src/libatari800/main.o src/libatari800/init.o src/libatari800/input.o src/libatari800/statesav.o"
62+
# Always include libatari800 API files and platform stubs
63+
EXISTING_OBJS="$EXISTING_OBJS src/libatari800/api.o src/libatari800/main.o src/libatari800/init.o src/libatari800/input.o src/libatari800/statesav.o src/platform_stubs.o"
6464

6565
echo "Will compile these object files: $EXISTING_OBJS"
6666

67+
# Create platform stubs for missing functions
68+
cat > src/platform_stubs.c << 'PLATFORM_EOF'
69+
/* Platform function stubs for minimal libatari800 build */
70+
71+
#include "videomode.h"
72+
#include "platform.h"
73+
74+
/* Platform video mode stubs */
75+
int PLATFORM_SupportsVideomode(VIDEOMODE_MODE_t mode, int windowed, VIDEOMODE_ROTATE_t rotate) {
76+
return 1; /* Assume all modes supported */
77+
}
78+
79+
void PLATFORM_SetVideoMode(VIDEOMODE_resolution_t *res, int windowed, VIDEOMODE_MODE_t mode, VIDEOMODE_ROTATE_t rotate) {
80+
/* Stub - no actual video mode setting */
81+
}
82+
83+
VIDEOMODE_resolution_t* PLATFORM_DesktopResolution(void) {
84+
static VIDEOMODE_resolution_t res = {640, 480};
85+
return &res;
86+
}
87+
88+
int PLATFORM_WindowMaximised(void) {
89+
return 0; /* Never maximized */
90+
}
91+
92+
VIDEOMODE_resolution_t* PLATFORM_AvailableResolutions(int *size) {
93+
static VIDEOMODE_resolution_t resolutions[] = {{640, 480}, {800, 600}, {1024, 768}};
94+
*size = 3;
95+
return resolutions;
96+
}
97+
98+
void PLATFORM_Exit(int code) {
99+
/* Stub - no platform-specific exit handling */
100+
}
101+
PLATFORM_EOF
102+
67103
# Create a basic Makefile that compiles the essential files for libatari800
68104
cat > Makefile << EOF
69105
# Minimal Makefile for libatari800
@@ -74,19 +110,19 @@ AR = ar
74110
CFLAGS = -O2 -DHAVE_CONFIG_H -I. -Isrc -DTARGET_LIBATARI800
75111
ARFLAGS = rcs
76112
77-
LIBATARI800_OBJS = $EXISTING_OBJS
113+
LIBATARI800_OBJS =$EXISTING_OBJS
78114
79115
all: src/libatari800.a
80116
81-
src/libatari800.a: $(LIBATARI800_OBJS)
82-
@echo "=== Creating libatari800.a from $(words $(LIBATARI800_OBJS)) object files ==="
83-
$(AR) $(ARFLAGS) $@ $^
117+
src/libatari800.a: \$(LIBATARI800_OBJS)
118+
@echo "=== Creating libatari800.a from \$(words \$(LIBATARI800_OBJS)) object files ==="
119+
\$(AR) \$(ARFLAGS) \$@ \$^
84120
@echo "=== libatari800.a created successfully ==="
85-
@ls -la $@
121+
@ls -la \$@
86122
87123
%.o: %.c
88-
@echo "Compiling $< ..."
89-
$(CC) $(CFLAGS) -c $< -o $@
124+
@echo "Compiling \$< ..."
125+
\$(CC) \$(CFLAGS) -c \$< -o \$@
90126
91127
clean:
92128
rm -f \$(LIBATARI800_OBJS) src/libatari800.a
@@ -108,6 +144,8 @@ cat > src/config.h << 'EOF'
108144
#define HAVE_STDLIB_H 1
109145
#define HAVE_STRING_H 1
110146
#define HAVE_UNISTD_H 1
147+
#define HAVE_INTTYPES_H 1
148+
#define HAVE_DIRENT_H 1
111149
112150
#ifdef _WIN32
113151
#define HAVE_WINDOWS_H 1

0 commit comments

Comments
 (0)