From 184c14c0460b9d107762babfc3caefb72cf5f7aa Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Fri, 20 Feb 2026 20:54:01 -0800 Subject: [PATCH 01/11] builds working on macos --- external/lekkit/{sha256.cc => sha256.c} | 0 macos/makefile | 61 +++++++++++++++---------- shared/{audio.cc => audio.c} | 0 shared/audio.h | 8 ++++ shared/{chip8.cc => chip8.c} | 4 +- shared/chip8.h | 45 +++++++++++------- shared/{display.cc => display.c} | 0 shared/display.h | 9 ++++ shared/gui.cc | 1 - shared/gui.h | 10 ++++ shared/{input.cc => input.c} | 4 +- shared/input.h | 9 ++++ shared/main.cc | 1 + shared/opcodes.h | 18 ++++++-- shared/open_file_dialog.h | 8 ++++ shared/{profiles.cc => profiles.c} | 0 shared/profiles.h | 8 ++++ shared/quirks.h | 10 ++++ shared/{toast.cc => toast.c} | 0 shared/toast.h | 8 ++++ tools/generate_bootrom_header.py | 28 ++++++++---- tools/generate_license_header.py | 10 +++- 22 files changed, 179 insertions(+), 63 deletions(-) rename external/lekkit/{sha256.cc => sha256.c} (100%) rename shared/{audio.cc => audio.c} (100%) rename shared/{chip8.cc => chip8.c} (99%) rename shared/{display.cc => display.c} (100%) rename shared/{input.cc => input.c} (95%) rename shared/{profiles.cc => profiles.c} (100%) rename shared/{toast.cc => toast.c} (100%) diff --git a/external/lekkit/sha256.cc b/external/lekkit/sha256.c similarity index 100% rename from external/lekkit/sha256.cc rename to external/lekkit/sha256.c diff --git a/macos/makefile b/macos/makefile index ecc27457..0c653f37 100644 --- a/macos/makefile +++ b/macos/makefile @@ -15,11 +15,14 @@ APP_MANIFEST = src/Info.plist APP_BUNDLE = $(APP_NAME).app APP_EXE = $(APP_NAME) -CC = clang++ -CFLAGS = -std=c++11 -Wall -mmacosx-version-min=11.0 -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"' -LFLAGS = -mmacosx-version-min=11.0 -INCS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ -LIBS = -L../external/sdl/build/lib/ -lSDL2-2.0.0 -framework Cocoa -framework OpenGL + +CC = clang +CXX = clang++ +CFLAGS = -std=c11 +CPPFLAGS = -Wall -mmacosx-version-min=11.0 -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"' +CXXFLAGS = -std=c++11 +INCLUDE_DIRS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ +LDFLAGS = -mmacosx-version-min=11.0 -L../external/sdl/build/lib/ -lSDL2-2.0.0 -framework Cocoa -framework OpenGL # SDL dependency files SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.0.dylib @@ -29,19 +32,21 @@ LICENSE_HEADER = ../shared/license.h BOOTROM_HEADER = ../shared/bootrom.h BOOTROM_SOURCE = ../roms/Kiwi8_logo_2.ch8 -# Source files -CORE_SRCS = ../shared/audio.cc ../shared/chip8.cc ../shared/display.cc ../shared/gui.cc \ - ../shared/input.cc ../shared/main.cc \ - ../shared/toast.cc ../shared/open_file_dialog.cc ../shared/profiles.cc -IMGUI_SRCS = ../external/imgui/imgui.cpp ../external/imgui/imgui_draw.cpp ../external/imgui/imgui_impl_sdl.cpp -SHA256_SRC = ../external/lekkit/sha256.cc -MACOS_SRCS = src/file_dialog.mm - -# Object files (convert source paths to .o in current directory) -OBJS = $(notdir $(CORE_SRCS:.cc=.o)) \ - $(notdir $(IMGUI_SRCS:.cpp=.o)) \ - $(notdir $(MACOS_SRCS:.mm=.o)) \ - $(notdir $(SHA256_SRC:.cc=.o)) +OBJS = audio.o \ + chip8.o \ + display.o \ + gui.o \ + input.o \ + main.o \ + toast.o \ + open_file_dialog.o \ + profiles.o \ + imgui.o \ + imgui_draw.o \ + imgui_impl_sdl.o \ + sha256.o \ + file_dialog.o + DEPS = $(OBJS:.o=.d) PROFILES_INI = ../shared/profiles.ini @@ -75,16 +80,19 @@ $(APP_MANIFEST): $(APP_MANIFEST).in # Pattern rules for incremental compilation %.o: src/%.mm - $(CC) $(CFLAGS) $(INCS) -c $< -o $@ + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ %.o: ../external/imgui/%.cpp - $(CC) $(CFLAGS) $(INCS) -c $< -o $@ + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ -%.o: ../external/lekkit/%.cc - $(CC) $(CFLAGS) $(INCS) -c $< -o $@ +%.o: ../external/lekkit/%.c + $(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ + +%.o: ../shared/%.c $(LICENSE_HEADER) $(BOOTROM_HEADER) + $(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ %.o: ../shared/%.cc $(LICENSE_HEADER) $(BOOTROM_HEADER) - $(CC) $(CFLAGS) $(INCS) -c $< -o $@ + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ debug/profiles.ini: $(PROFILES_INI) mkdir -p debug @@ -98,7 +106,7 @@ release/$(APP_BUNDLE)/Contents/Resources/profiles.ini: $(PROFILES_INI) debug/$(APP_EXE): $(SDL_LIB) $(OBJS) mkdir -p debug cp $(SDL_LIB) debug/libSDL2-2.0.0.dylib - $(CC) $(CFLAGS) -g $(LIBS) $(INCS) $(OBJS) -o $@ $(LFLAGS) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -g $(INCLUDE_DIRS) $(LDFLAGS) $(OBJS) -o $@ # Set the dylib's install name to be relative to the bundle install_name_tool -id @executable_path/libSDL2-2.0.0.dylib debug/libSDL2-2.0.0.dylib @@ -109,7 +117,7 @@ debug/$(APP_EXE): $(SDL_LIB) $(OBJS) # release executable (inside .app bundle) release/$(APP_BUNDLE)/Contents/MacOS/$(APP_EXE): $(SDL_LIB) $(OBJS) mkdir -p release/$(APP_BUNDLE)/Contents/MacOS - $(CC) $(CFLAGS) $(LIBS) $(INCS) $(OBJS) -o $@ $(LFLAGS) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(LDFLAGS) $(OBJS) -o $@ # Fix executable's reference to SDL (from @rpath to bundle-relative path) install_name_tool -change @rpath/libSDL2-2.0.0.dylib @executable_path/../Frameworks/libSDL2-2.0.0.dylib release/$(APP_BUNDLE)/Contents/MacOS/$(APP_EXE) @@ -155,4 +163,7 @@ clean: distclean: clean $(RM) -r ../external/sdl +debug-vars: + @echo "OBJS content: $(OBJS)" + .PHONY: all sdl clean distclean run-release run-debug diff --git a/shared/audio.cc b/shared/audio.c similarity index 100% rename from shared/audio.cc rename to shared/audio.c diff --git a/shared/audio.h b/shared/audio.h index 78088a0b..edb7bd1e 100644 --- a/shared/audio.h +++ b/shared/audio.h @@ -1,6 +1,10 @@ #ifndef AUDIO_H #define AUDIO_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -25,4 +29,8 @@ extern struct audio audio; void audio_destroy(void); int audio_init(void); +#ifdef __cplusplus +} +#endif + #endif // AUDIO_H diff --git a/shared/chip8.cc b/shared/chip8.c similarity index 99% rename from shared/chip8.cc rename to shared/chip8.c index 98a1bb5f..76af933e 100644 --- a/shared/chip8.cc +++ b/shared/chip8.c @@ -92,7 +92,7 @@ int chip8_init( /* load fontset */ for(int i = 0; i < FONTS_SIZE; ++i) { - chip8.memory[i] = chip8.chip8_fontset[i]; + chip8.memory[i] = chip8_fontset[i]; } /* Initialize ROM profile database */ @@ -222,7 +222,7 @@ void chip8_soft_reset() { /* load fontset */ for(int i = 0; i < FONTS_SIZE; ++i) { - chip8.memory[i] = chip8.chip8_fontset[i]; + chip8.memory[i] = chip8_fontset[i]; } /* copy the entire rom to memory starting from 0x200 */ diff --git a/shared/chip8.h b/shared/chip8.h index b1414e3c..d6e438db 100644 --- a/shared/chip8.h +++ b/shared/chip8.h @@ -1,9 +1,14 @@ #ifndef CHIP8_H #define CHIP8_H +#ifdef __cplusplus +extern "C" { +#endif + #include "bootrom.h" // Generated at build time from roms/Kiwi8_logo_2.ch8 #include "quirks.h" #include +#include #define MEM_SIZE 4096 #define NUM_REGISTERS 16 @@ -15,6 +20,24 @@ #define MAX_CYCLES_PER_STEP 50 #define TICKS 60 /* hz - Timer count down rate */ +static const unsigned char chip8_fontset[FONTS_SIZE] = { + 0xF0, 0x90, 0x90, 0x90, 0xF0, // 0 + 0x20, 0x60, 0x20, 0x20, 0x70, // 1 + 0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2 + 0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3 + 0x90, 0x90, 0xF0, 0x10, 0x10, // 4 + 0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5 + 0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6 + 0xF0, 0x10, 0x20, 0x40, 0x40, // 7 + 0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8 + 0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9 + 0xF0, 0x90, 0xF0, 0x90, 0x90, // A + 0x20, 0x60, 0x20, 0x20, 0x70, // B + 0xF0, 0x80, 0xF0, 0x80, 0xF0, // C + 0xF0, 0x80, 0xF0, 0x80, 0x80, // D + 0xF0, 0x90, 0x90, 0xF0, 0x90 // F + }; + struct chip8 { /* number of cycles per step */ int cycles; @@ -63,23 +86,7 @@ struct chip8 { /* 1-bit encoded screen pixels (64x32) */ unsigned char **vram; - const unsigned char chip8_fontset[FONTS_SIZE] = { - 0xF0, 0x90, 0x90, 0x90, 0xF0, // 0 - 0x20, 0x60, 0x20, 0x20, 0x70, // 1 - 0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2 - 0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3 - 0x90, 0x90, 0xF0, 0x10, 0x10, // 4 - 0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5 - 0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6 - 0xF0, 0x10, 0x20, 0x40, 0x40, // 7 - 0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8 - 0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9 - 0xF0, 0x90, 0xF0, 0x90, 0x90, // A - 0x20, 0x60, 0x20, 0x20, 0x70, // B - 0xF0, 0x80, 0xF0, 0x80, 0xF0, // C - 0xF0, 0x80, 0xF0, 0x80, 0x80, // D - 0xF0, 0x90, 0x90, 0xF0, 0x90 // F - }; + }; /* Global chip8 instance */ @@ -138,4 +145,8 @@ void execFX55(void); void execFX65(void); void execUnknown(void); +#ifdef __cplusplus +} #endif + +#endif // CHIP8_H diff --git a/shared/display.cc b/shared/display.c similarity index 100% rename from shared/display.cc rename to shared/display.c diff --git a/shared/display.h b/shared/display.h index 3f0e04cd..e57e8d80 100644 --- a/shared/display.h +++ b/shared/display.h @@ -1,8 +1,13 @@ #ifndef DISPLAY_H #define DISPLAY_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include +#include #define WIDTH 64 #define HEIGHT 32 @@ -51,4 +56,8 @@ void display_toggle_vsync(void); void display_raise_window(void); void display_render_frame(unsigned char **frame); +#ifdef __cplusplus +} +#endif + #endif diff --git a/shared/gui.cc b/shared/gui.cc index 098b6dfa..635e3224 100644 --- a/shared/gui.cc +++ b/shared/gui.cc @@ -1,5 +1,4 @@ #include "gui.h" -#include "chip8.h" #include "display.h" #include "imgui.h" #include "imgui_impl_sdl.h" diff --git a/shared/gui.h b/shared/gui.h index 15c8cc1a..b3619c7d 100644 --- a/shared/gui.h +++ b/shared/gui.h @@ -1,7 +1,13 @@ #ifndef GUI_H #define GUI_H +#ifdef __cplusplus +extern "C" { +#endif + #include +#include +#include "chip8.h" #define MENU_HEIGHT 38 @@ -34,4 +40,8 @@ void gui_process_events(SDL_Event *event); void gui_new_frame(void); void gui_render(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/shared/input.cc b/shared/input.c similarity index 95% rename from shared/input.cc rename to shared/input.c index 7951ea47..9684c064 100644 --- a/shared/input.cc +++ b/shared/input.c @@ -60,8 +60,8 @@ static int input_process_events(void) { if (input.state[SDL_SCANCODE_RALT]) gui.show_fps_flag = !gui.show_fps_flag; /* slow/raise emulation speed */ - if (input.state[SDL_SCANCODE_PAGEDOWN]) (chip8.cycles -1 < MIN_CYCLES_PER_STEP ) ? chip8.cycles = MIN_CYCLES_PER_STEP : chip8.cycles -= 1; - if (input.state[SDL_SCANCODE_PAGEUP]) (chip8.cycles +1 > MAX_CYCLES_PER_STEP ) ? chip8.cycles = MAX_CYCLES_PER_STEP : chip8.cycles += 1; + if (input.state[SDL_SCANCODE_PAGEDOWN]) (chip8.cycles -1 < MIN_CYCLES_PER_STEP ) ? (chip8.cycles = MIN_CYCLES_PER_STEP) : (chip8.cycles -= 1); + if (input.state[SDL_SCANCODE_PAGEUP]) (chip8.cycles +1 > MAX_CYCLES_PER_STEP ) ? (chip8.cycles = MAX_CYCLES_PER_STEP) : (chip8.cycles += 1); } /* window events */ diff --git a/shared/input.h b/shared/input.h index 9aeb87b2..f635f966 100644 --- a/shared/input.h +++ b/shared/input.h @@ -1,6 +1,11 @@ #ifndef INPUT_H #define INPUT_H +#ifdef __cplusplus +extern "C" { +#endif + +#include #include #define NUM_KEYS 16 @@ -32,4 +37,8 @@ extern struct input input; void input_reset(void); int input_poll(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/shared/main.cc b/shared/main.cc index ae89475f..0ecbad53 100644 --- a/shared/main.cc +++ b/shared/main.cc @@ -2,6 +2,7 @@ #include "usage.h" #include #include +#include int main(int argc, char **argv){ diff --git a/shared/opcodes.h b/shared/opcodes.h index 7cb13181..e10c1d7d 100644 --- a/shared/opcodes.h +++ b/shared/opcodes.h @@ -2,6 +2,10 @@ #ifndef OPCODES_H #define OPCODES_H +#ifdef __cplusplus +extern "C" { +#endif + #include "chip8.h" #include "display.h" /* for WIDTH and HEIGHT */ #include "input.h" @@ -103,7 +107,7 @@ inline void exec8XY4() { carry, and to 0 when there isn't */ unsigned short sum; sum = chip8.V[OP_Y] + chip8.V[OP_X]; - (sum > 0xFF) ? chip8.V[0xF] = 1 : chip8.V[0xF] = 0; + (sum > 0xFF) ? (chip8.V[0xF] = 1) : (chip8.V[0xF] = 0); /* only the lowest 8 bits are kept */ chip8.V[OP_X] = (unsigned char) sum; @@ -112,7 +116,7 @@ inline void exec8XY4() { inline void exec8XY5() { /* 0x8XY5: VY is subtracted from VX. VF is set to 0 when there's a borrow, and 1 when there isn't */ - (chip8.V[OP_Y] > chip8.V[OP_X]) ? chip8.V[0xF] = 0 : chip8.V[0xF] = 1; + (chip8.V[OP_Y] > chip8.V[OP_X]) ? (chip8.V[0xF] = 0) : (chip8.V[0xF] = 1); chip8.V[OP_X] -= chip8.V[OP_Y]; } @@ -120,19 +124,19 @@ inline void exec8XY6() { /* 0x8XY6: shifts VX right by one. VF is set to the value of the least significant bit of VX before the shift. */ chip8.V[0xF] = chip8.V[OP_X] & 0x01; - chip8.quirks.shift_quirk ? chip8.V[OP_X] >>= 1 : chip8.V[OP_X] = chip8.V[OP_Y] >> 1; + chip8.quirks.shift_quirk ? (chip8.V[OP_X] >>= 1) : (chip8.V[OP_X] = chip8.V[OP_Y] >> 1); } inline void exec8XY7() { /* 0x8XY7: sets VX to VY minus VX. VF is set to 0 when there's a borrow, and 1 when there isn't. */ - (chip8.V[OP_X] > chip8.V[OP_Y]) ? chip8.V[0xF] = 0 : chip8.V[0xF] = 1; + (chip8.V[OP_X] > chip8.V[OP_Y]) ? (chip8.V[0xF] = 0) : (chip8.V[0xF] = 1); chip8.V[OP_X] = chip8.V[OP_Y] - chip8.V[OP_X]; } inline void exec8XYE() { /* 0x8XYE: shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift. */ chip8.V[0xF] = (chip8.V[OP_X] & 0x80) >> 7; - chip8.quirks.shift_quirk ? chip8.V[OP_X] <<= 1 : chip8.V[OP_X] = chip8.V[OP_Y] << 1; + chip8.quirks.shift_quirk ? (chip8.V[OP_X] <<= 1) : (chip8.V[OP_X] = chip8.V[OP_Y] << 1); } inline void exec9XY0() { @@ -273,4 +277,8 @@ inline void execUnknown() { fprintf (stderr, "Unknown opcode: 0x%X\n", chip8.opcode); } +#ifdef __cplusplus +} +#endif + #endif // OPCODES_H diff --git a/shared/open_file_dialog.h b/shared/open_file_dialog.h index 042c722f..a0837b3b 100644 --- a/shared/open_file_dialog.h +++ b/shared/open_file_dialog.h @@ -1,6 +1,10 @@ #ifndef OPEN_FILE_DIALOG_H #define OPEN_FILE_DIALOG_H +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __APPLE__ #include /* PATH_MAX */ #endif @@ -16,4 +20,8 @@ int open_file_dialog(char *rom_name); +#ifdef __cplusplus +} +#endif + #endif diff --git a/shared/profiles.cc b/shared/profiles.c similarity index 100% rename from shared/profiles.cc rename to shared/profiles.c diff --git a/shared/profiles.h b/shared/profiles.h index c621baac..59d66026 100644 --- a/shared/profiles.h +++ b/shared/profiles.h @@ -1,6 +1,10 @@ #ifndef PROFILES_H #define PROFILES_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include "quirks.h" #include "sha256.h" @@ -25,4 +29,8 @@ const struct profile* profile_lookup(const sha256_hash_t *sha256); * Also adds profile to runtime hashmap immediately */ void profiles_save_current(void); +#ifdef __cplusplus +} +#endif + #endif /* PROFILES_H */ diff --git a/shared/quirks.h b/shared/quirks.h index eb8501de..bd620dba 100644 --- a/shared/quirks.h +++ b/shared/quirks.h @@ -1,6 +1,12 @@ #ifndef QUIRKS_H #define QUIRKS_H +#ifdef __cplusplus +extern "C" { +#endif + +#include + /* * X-macro list of all quirk fields. * Format: X(field_name, default_value) @@ -33,4 +39,8 @@ static inline struct quirks quirks_get_defaults(void) { return defaults; } +#ifdef __cplusplus +} +#endif + #endif // QUIRKS_H diff --git a/shared/toast.cc b/shared/toast.c similarity index 100% rename from shared/toast.cc rename to shared/toast.c diff --git a/shared/toast.h b/shared/toast.h index 87241e6f..9816700b 100644 --- a/shared/toast.h +++ b/shared/toast.h @@ -1,6 +1,10 @@ #ifndef TOAST_H #define TOAST_H +#ifdef __cplusplus +extern "C" { +#endif + /* Toast struct definition */ struct toast { char message[256]; @@ -31,4 +35,8 @@ const struct toast* toast_get_toasts(int *count); int toast_is_active(const struct toast *t); void toast_get_info(const struct toast *t, const char **message, int *type, double *time); +#ifdef __cplusplus +} #endif + +#endif // TOAST_H diff --git a/tools/generate_bootrom_header.py b/tools/generate_bootrom_header.py index 3d717fa2..bfa742c5 100644 --- a/tools/generate_bootrom_header.py +++ b/tools/generate_bootrom_header.py @@ -9,28 +9,28 @@ def generate_header(rom_file, output_file): """Generate C++ header with ROM data as byte array.""" - + if not os.path.exists(rom_file): print(f"Error: ROM file '{rom_file}' not found", file=sys.stderr) sys.exit(1) - + # Read binary data with open(rom_file, 'rb') as f: rom_data = f.read() - + rom_size = len(rom_data) rom_name = os.path.splitext(os.path.basename(rom_file))[0] - + # Format bytes as hex, 8 per line hex_lines = [] for i in range(0, rom_size, 8): chunk = rom_data[i:i+8] hex_bytes = ', '.join(f'0x{b:02x}' for b in chunk) hex_lines.append(f' {hex_bytes}') - + # Join with commas and newlines formatted_data = ',\n'.join(hex_lines) - + # Generate header content header_content = f"""// Auto-generated file - DO NOT EDIT // Generated from {os.path.basename(rom_file)} @@ -38,27 +38,35 @@ def generate_header(rom_file, output_file): #ifndef BOOTROM_H #define BOOTROM_H +#ifdef __cplusplus +extern "C" {{ +#endif + #define BOOTROM_SIZE {rom_size} /* {os.path.basename(rom_file)} */ -const unsigned char bootrom[BOOTROM_SIZE] = {{ +static const unsigned char bootrom[BOOTROM_SIZE] = {{ {formatted_data} }}; +#ifdef __cplusplus +}} +#endif + #endif // BOOTROM_H """ - + # Write header file with open(output_file, 'w', encoding='utf-8') as f: f.write(header_content) - + print(f"Generated {output_file} from {rom_file} ({rom_size} bytes)") if __name__ == '__main__': if len(sys.argv) != 3: print("Usage: python3 generate_bootrom_header.py ") sys.exit(1) - + rom_file = sys.argv[1] output_file = sys.argv[2] generate_header(rom_file, output_file) diff --git a/tools/generate_license_header.py b/tools/generate_license_header.py index e9ec1ffb..d44d7b22 100644 --- a/tools/generate_license_header.py +++ b/tools/generate_license_header.py @@ -59,9 +59,17 @@ def generate_header(license_file, output_file): #ifndef LICENSE_H #define LICENSE_H -const char* LICENSE_TEXT = +#ifdef __cplusplus +extern "C" {{ +#endif + +static const char* LICENSE_TEXT = {chr(10).join(cpp_lines)}; +#ifdef __cplusplus +}} +#endif + #endif // LICENSE_H """ From e427eaa3da783833ec2267ae403e4f6289b080bc Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Fri, 20 Feb 2026 20:54:14 -0800 Subject: [PATCH 02/11] remove debug-vars target --- macos/makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/macos/makefile b/macos/makefile index 0c653f37..4c8d2076 100644 --- a/macos/makefile +++ b/macos/makefile @@ -163,7 +163,4 @@ clean: distclean: clean $(RM) -r ../external/sdl -debug-vars: - @echo "OBJS content: $(OBJS)" - .PHONY: all sdl clean distclean run-release run-debug From 76b712278a85c2c6fd3d4fda44f3d5eb544c26b1 Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Fri, 20 Feb 2026 21:17:18 -0800 Subject: [PATCH 03/11] attempt linux build --- linux/makefile | 67 +++++++++++++++++++++++++++----------------------- macos/makefile | 2 -- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/linux/makefile b/linux/makefile index 05103860..c96e43fa 100644 --- a/linux/makefile +++ b/linux/makefile @@ -13,9 +13,15 @@ endif APP_EXE = $(APP_NAME) -CC = g++ -CFLAGS = -std=c++11 -Wall -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"' -LFLAGS = -Wl,-rpath,'$$ORIGIN' +CC = gcc +CXX = g++ +CFLAGS = -std=c11 +CPPFLAGS = -Wall -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"' +CXXFLAGS = -std=c++11 + +INCLUDE_DIRS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ + +LDFLAGS = -L../external/sdl/build/lib -lSDL2-2.0 -lGL -lm -ldl -lpthread -Wl,-rpath,'$$ORIGIN' # Use pkg-config to get GTK3 and audio backend flags GTK3_CFLAGS = $(shell pkg-config --cflags gtk+-3.0) @@ -31,12 +37,9 @@ PIPEWIRE_LIBS = $(shell pkg-config --libs libpipewire-0.3) JACK_CFLAGS = $(shell pkg-config --cflags jack) JACK_LIBS = $(shell pkg-config --libs jack) -CFLAGS += $(GTK3_CFLAGS) $(ALSA_CFLAGS) $(PULSE_CFLAGS) $(PIPEWIRE_CFLAGS) $(JACK_CFLAGS) - -INCS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ -LIBS = -L../external/sdl/build/lib -lSDL2-2.0 -lGL $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS) $(ESD_LIBS) $(SNDIO_LIBS) -lm -ldl -lpthread +CPPFLAGS += $(GTK3_CFLAGS) $(ALSA_CFLAGS) $(PULSE_CFLAGS) $(PIPEWIRE_CFLAGS) $(JACK_CFLAGS) +LDFLAGS += $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS) -# SDL dependency files SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.so.0 # Generated headers @@ -44,19 +47,21 @@ LICENSE_HEADER = ../shared/license.h BOOTROM_HEADER = ../shared/bootrom.h BOOTROM_SOURCE = ../roms/Kiwi8_logo_2.ch8 -# Source files -CORE_SRCS = ../shared/audio.cc ../shared/chip8.cc ../shared/display.cc ../shared/gui.cc \ - ../shared/input.cc ../shared/main.cc \ - ../shared/toast.cc ../shared/open_file_dialog.cc ../shared/profiles.cc -IMGUI_SRCS = ../external/imgui/imgui.cpp ../external/imgui/imgui_draw.cpp ../external/imgui/imgui_impl_sdl.cpp -LINUX_SRCS = src/file_dialog.cc -SHA256_SRC = ../external/lekkit/sha256.cc - -# Object files (convert source paths to .o in current directory) -OBJS = $(notdir $(CORE_SRCS:.cc=.o)) \ - $(notdir $(IMGUI_SRCS:.cpp=.o)) \ - $(notdir $(LINUX_SRCS:.cc=.o)) \ - $(notdir $(SHA256_SRC:.cc=.o)) +OBJS = audio.o \ + chip8.o \ + display.o \ + gui.o \ + input.o \ + main.o \ + toast.o \ + open_file_dialog.o \ + profiles.o \ + imgui.o \ + imgui_draw.o \ + imgui_impl_sdl.o \ + sha256.o \ + file_dialog.o + DEPS = $(OBJS:.o=.d) PROFILES_INI = ../shared/profiles.ini @@ -66,7 +71,7 @@ PROFILES_INI = ../shared/profiles.ini .DEFAULT_GOAL := all -all: debug/profiles.ini debug/$(APP_EXE) release/profiles. release/$(APP_EXE) +all: debug/profiles.ini debug/$(APP_EXE) release/profiles.ini release/$(APP_EXE) # Build SDL (force rebuild with: make sdl) sdl: @@ -85,17 +90,17 @@ $(BOOTROM_HEADER): $(BOOTROM_SOURCE) python3 ../tools/generate_bootrom_header.py $(BOOTROM_SOURCE) $(BOOTROM_HEADER) # Pattern rules for incremental compilation -%.o: src/%.cc - $(CC) $(CFLAGS) $(INCS) -c $< -o $@ - %.o: ../external/imgui/%.cpp - $(CC) $(CFLAGS) $(INCS) -c $< -o $@ + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ + +%.o: ../external/lekkit/%.c + $(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ -%.o: ../external/lekkit/%.cc - $(CC) $(CFLAGS) $(INCS) -c $< -o $@ +%.o: ../shared/%.c $(LICENSE_HEADER) $(BOOTROM_HEADER) + $(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ %.o: ../shared/%.cc $(LICENSE_HEADER) $(BOOTROM_HEADER) - $(CC) $(CFLAGS) $(INCS) -c $< -o $@ + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ debug/profiles.ini: $(PROFILES_INI) mkdir -p debug @@ -109,13 +114,13 @@ release/profiles.ini: $(PROFILES_INI) debug/$(APP_EXE): $(SDL_LIB) $(OBJS) mkdir -p debug cp $(SDL_LIB) debug/libSDL2-2.0.so.0 - $(CC) $(CFLAGS) -g $(INCS) $(LIBDIRS) $(OBJS) -o $@ $(LIBS) $(LFLAGS) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -g $(INCLUDE_DIRS) $(LDFLAGS) $(OBJS) -o $@ # release executable release/$(APP_EXE): $(SDL_LIB) $(OBJS) mkdir -p release cp $(SDL_LIB) release/libSDL2-2.0.so.0 - $(CC) $(CFLAGS) $(INCS) $(LIBDIRS) $(OBJS) -o $@ $(LIBS) $(LFLAGS) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(LDFLAGS) $(OBJS) -o $@ run-debug: debug/$(APP_EXE) ./debug/$(APP_EXE) diff --git a/macos/makefile b/macos/makefile index 4c8d2076..52da7aca 100644 --- a/macos/makefile +++ b/macos/makefile @@ -15,7 +15,6 @@ APP_MANIFEST = src/Info.plist APP_BUNDLE = $(APP_NAME).app APP_EXE = $(APP_NAME) - CC = clang CXX = clang++ CFLAGS = -std=c11 @@ -24,7 +23,6 @@ CXXFLAGS = -std=c++11 INCLUDE_DIRS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ LDFLAGS = -mmacosx-version-min=11.0 -L../external/sdl/build/lib/ -lSDL2-2.0.0 -framework Cocoa -framework OpenGL -# SDL dependency files SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.0.dylib # Generated headers From c419b17f38f4c54891a22a56f0da4c853ffb527c Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Fri, 20 Feb 2026 21:42:01 -0800 Subject: [PATCH 04/11] define M_PI manually --- shared/audio.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shared/audio.h b/shared/audio.h index edb7bd1e..00a71665 100644 --- a/shared/audio.h +++ b/shared/audio.h @@ -8,6 +8,10 @@ extern "C" { #include #include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + #define TAU (2.0 * M_PI) #define AMPLITUDE 28000 // Max amplitude for signed 16-bit #define SAMPLE_RATE 48000 From d9f948a09b4fb64a5faf69a2cf0bb0d2b92ed450 Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Sat, 21 Feb 2026 12:06:18 -0800 Subject: [PATCH 05/11] let's try using gnu standard? --- linux/makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/makefile b/linux/makefile index c96e43fa..34ec0b6d 100644 --- a/linux/makefile +++ b/linux/makefile @@ -15,9 +15,9 @@ APP_EXE = $(APP_NAME) CC = gcc CXX = g++ -CFLAGS = -std=c11 +CFLAGS = -std=gnu11 CPPFLAGS = -Wall -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"' -CXXFLAGS = -std=c++11 +CXXFLAGS = -std=gnu++11 INCLUDE_DIRS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ From 9e5ee0ad881a5904cccd0a9d3005376e1498f42e Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Sat, 21 Feb 2026 12:12:03 -0800 Subject: [PATCH 06/11] add missing rule for linux/src dir --- linux/makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linux/makefile b/linux/makefile index 34ec0b6d..13b07817 100644 --- a/linux/makefile +++ b/linux/makefile @@ -90,6 +90,9 @@ $(BOOTROM_HEADER): $(BOOTROM_SOURCE) python3 ../tools/generate_bootrom_header.py $(BOOTROM_SOURCE) $(BOOTROM_HEADER) # Pattern rules for incremental compilation +%.o: src/%.cc + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ + %.o: ../external/imgui/%.cpp $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@ From 34d1b16f4a72c8916d5a57e1b8f58a1ec49aff28 Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Sat, 21 Feb 2026 12:56:49 -0800 Subject: [PATCH 07/11] does order matter? --- linux/makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/makefile b/linux/makefile index 13b07817..831ca9e5 100644 --- a/linux/makefile +++ b/linux/makefile @@ -21,7 +21,7 @@ CXXFLAGS = -std=gnu++11 INCLUDE_DIRS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ -LDFLAGS = -L../external/sdl/build/lib -lSDL2-2.0 -lGL -lm -ldl -lpthread -Wl,-rpath,'$$ORIGIN' +LDFLAGS = -L../external/sdl/build/lib -lSDL2-2.0 -lGL $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS) -lm -ldl -lpthread -Wl,-rpath,'$$ORIGIN' # Use pkg-config to get GTK3 and audio backend flags GTK3_CFLAGS = $(shell pkg-config --cflags gtk+-3.0) @@ -38,7 +38,7 @@ JACK_CFLAGS = $(shell pkg-config --cflags jack) JACK_LIBS = $(shell pkg-config --libs jack) CPPFLAGS += $(GTK3_CFLAGS) $(ALSA_CFLAGS) $(PULSE_CFLAGS) $(PIPEWIRE_CFLAGS) $(JACK_CFLAGS) -LDFLAGS += $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS) +#LDFLAGS += $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS) SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.so.0 From 7b73111a4a2ad0084c0d90bcc74733a8bf1a041d Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Sat, 21 Feb 2026 13:09:31 -0800 Subject: [PATCH 08/11] put linker flags at the end, where they were before --- linux/makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/linux/makefile b/linux/makefile index 831ca9e5..4a0f23df 100644 --- a/linux/makefile +++ b/linux/makefile @@ -21,7 +21,7 @@ CXXFLAGS = -std=gnu++11 INCLUDE_DIRS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ -LDFLAGS = -L../external/sdl/build/lib -lSDL2-2.0 -lGL $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS) -lm -ldl -lpthread -Wl,-rpath,'$$ORIGIN' +LDFLAGS = -L../external/sdl/build/lib -lSDL2-2.0 -lGL -lm -ldl -lpthread -Wl,-rpath,'$$ORIGIN' # Use pkg-config to get GTK3 and audio backend flags GTK3_CFLAGS = $(shell pkg-config --cflags gtk+-3.0) @@ -38,7 +38,7 @@ JACK_CFLAGS = $(shell pkg-config --cflags jack) JACK_LIBS = $(shell pkg-config --libs jack) CPPFLAGS += $(GTK3_CFLAGS) $(ALSA_CFLAGS) $(PULSE_CFLAGS) $(PIPEWIRE_CFLAGS) $(JACK_CFLAGS) -#LDFLAGS += $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS) +LDFLAGS += $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS) SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.so.0 @@ -117,13 +117,13 @@ release/profiles.ini: $(PROFILES_INI) debug/$(APP_EXE): $(SDL_LIB) $(OBJS) mkdir -p debug cp $(SDL_LIB) debug/libSDL2-2.0.so.0 - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -g $(INCLUDE_DIRS) $(LDFLAGS) $(OBJS) -o $@ + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -g $(INCLUDE_DIRS) $(OBJS) -o $@ $(LDFLAGS) # release executable release/$(APP_EXE): $(SDL_LIB) $(OBJS) mkdir -p release cp $(SDL_LIB) release/libSDL2-2.0.so.0 - $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(LDFLAGS) $(OBJS) -o $@ + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(OBJS) -o $@ $(LDFLAGS) run-debug: debug/$(APP_EXE) ./debug/$(APP_EXE) From 57219a2e87f1733f6acdf5c3866fa52a88e088aa Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Sat, 21 Feb 2026 13:09:38 -0800 Subject: [PATCH 09/11] make macos consistent --- macos/makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/macos/makefile b/macos/makefile index 52da7aca..67d17e01 100644 --- a/macos/makefile +++ b/macos/makefile @@ -104,7 +104,7 @@ release/$(APP_BUNDLE)/Contents/Resources/profiles.ini: $(PROFILES_INI) debug/$(APP_EXE): $(SDL_LIB) $(OBJS) mkdir -p debug cp $(SDL_LIB) debug/libSDL2-2.0.0.dylib - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -g $(INCLUDE_DIRS) $(LDFLAGS) $(OBJS) -o $@ + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -g $(INCLUDE_DIRS) $(OBJS) -o $@ $(LDFLAGS) # Set the dylib's install name to be relative to the bundle install_name_tool -id @executable_path/libSDL2-2.0.0.dylib debug/libSDL2-2.0.0.dylib @@ -115,7 +115,7 @@ debug/$(APP_EXE): $(SDL_LIB) $(OBJS) # release executable (inside .app bundle) release/$(APP_BUNDLE)/Contents/MacOS/$(APP_EXE): $(SDL_LIB) $(OBJS) mkdir -p release/$(APP_BUNDLE)/Contents/MacOS - $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(LDFLAGS) $(OBJS) -o $@ + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(OBJS) -o $@ $(LDFLAGS) # Fix executable's reference to SDL (from @rpath to bundle-relative path) install_name_tool -change @rpath/libSDL2-2.0.0.dylib @executable_path/../Frameworks/libSDL2-2.0.0.dylib release/$(APP_BUNDLE)/Contents/MacOS/$(APP_EXE) From ed474e7433e00160778c2493f5c9c0cba804ecb4 Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Sat, 21 Feb 2026 13:53:05 -0800 Subject: [PATCH 10/11] convert long lines to multiline --- linux/makefile | 26 +++++++++++++++++++++----- macos/makefile | 22 ++++++++++++++++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/linux/makefile b/linux/makefile index 4a0f23df..f6550f9c 100644 --- a/linux/makefile +++ b/linux/makefile @@ -1,11 +1,12 @@ APP_NAME = Kiwi8 -# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to unknown +# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to develop VERSION ?= $(GITHUB_REF_NAME) ifeq ($(VERSION),) VERSION = develop endif +# Use SUB_VERSION if set, otherwise fall back to GITHUB_SHA, then default to unknown SUB_VERSION ?= $(GITHUB_SHA) ifeq ($(SUB_VERSION),) SUB_VERSION = unknown @@ -16,12 +17,27 @@ APP_EXE = $(APP_NAME) CC = gcc CXX = g++ CFLAGS = -std=gnu11 -CPPFLAGS = -Wall -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"' -CXXFLAGS = -std=gnu++11 +CPPFLAGS = -Wall \ + -MMD \ + -MP \ + -DAPP_NAME='"$(APP_NAME)"' \ + -DVERSION='"$(VERSION)"' \ + -DSUB_VERSION='"$(SUB_VERSION)"' -INCLUDE_DIRS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ +CXXFLAGS = -std=gnu++11 -LDFLAGS = -L../external/sdl/build/lib -lSDL2-2.0 -lGL -lm -ldl -lpthread -Wl,-rpath,'$$ORIGIN' +INCLUDE_DIRS = -I../external/sdl/build/include/ \ + -I../external/imgui/ \ + -I../external/stb/ \ + -I../external/lekkit/ + +LDFLAGS = -L../external/sdl/build/lib \ + -lSDL2-2.0 \ + -lGL \ + -lm \ + -ldl \ + -lpthread \ + -Wl,-rpath,'$$ORIGIN' # Use pkg-config to get GTK3 and audio backend flags GTK3_CFLAGS = $(shell pkg-config --cflags gtk+-3.0) diff --git a/macos/makefile b/macos/makefile index 67d17e01..d3bb845d 100644 --- a/macos/makefile +++ b/macos/makefile @@ -1,11 +1,12 @@ APP_NAME = Kiwi8 -# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to unknown +# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to develop VERSION ?= $(GITHUB_REF_NAME) ifeq ($(VERSION),) VERSION = develop endif +# Use SUB_VERSION if set, otherwise fall back to GITHUB_SHA, then default to unknown SUB_VERSION ?= $(GITHUB_SHA) ifeq ($(SUB_VERSION),) SUB_VERSION = unknown @@ -18,10 +19,23 @@ APP_EXE = $(APP_NAME) CC = clang CXX = clang++ CFLAGS = -std=c11 -CPPFLAGS = -Wall -mmacosx-version-min=11.0 -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"' +CPPFLAGS = -Wall \ + -mmacosx-version-min=11.0 \ + -MMD -MP -DAPP_NAME='"$(APP_NAME)"' \ + -DVERSION='"$(VERSION)"' \ + -DSUB_VERSION='"$(SUB_VERSION)"' + CXXFLAGS = -std=c++11 -INCLUDE_DIRS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/ -LDFLAGS = -mmacosx-version-min=11.0 -L../external/sdl/build/lib/ -lSDL2-2.0.0 -framework Cocoa -framework OpenGL +INCLUDE_DIRS = -I../external/sdl/build/include/ \ + -I../external/imgui/ \ + -I../external/stb/ \ + -I../external/lekkit/ + +LDFLAGS = -mmacosx-version-min=11.0 \ + -L../external/sdl/build/lib/ \ + -lSDL2-2.0.0 \ + -framework Cocoa \ + -framework OpenGL SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.0.dylib From a3f0a4725c8056a0b59cfa2717a67df29044a437 Mon Sep 17 00:00:00 2001 From: Thomas Daley Date: Sat, 21 Feb 2026 13:53:14 -0800 Subject: [PATCH 11/11] try windows builds here we go... --- windows/makefile | 113 ++++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 51 deletions(-) diff --git a/windows/makefile b/windows/makefile index 343d4b2f..c262232e 100644 --- a/windows/makefile +++ b/windows/makefile @@ -1,6 +1,6 @@ APP_NAME = Kiwi8 -# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to unknown +# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to develop !IFNDEF VERSION !IFDEF GITHUB_REF_NAME VERSION = $(GITHUB_REF_NAME) @@ -9,6 +9,7 @@ VERSION = develop !ENDIF !ENDIF +# Use SUB_VERSION if set, otherwise fall back to GITHUB_SHA, then default to unknown !IFNDEF SUB_VERSION !IFDEF GITHUB_SHA SUB_VERSION = $(GITHUB_SHA) @@ -17,66 +18,76 @@ SUB_VERSION = unknown !ENDIF !ENDIF +# Detect architecture from environment (set by MSVC vcvarsall.bat) +# VSCMD_ARG_TGT_ARCH is set to x64, x86, arm64, or arm +!IFNDEF SDL_ARCH +!IFDEF VSCMD_ARG_TGT_ARCH +SDL_ARCH = $(VSCMD_ARG_TGT_ARCH) +!ELSE +SDL_ARCH = x64 +!ENDIF +!ENDIF + APP_EXE = $(APP_NAME).exe APP_PDB = $(APP_NAME).pdb APP_RES = $(APP_NAME).res CC = CL -CFLAGS = /std:c++11 /W4 /MD /nologo /w44996 "/DAPP_NAME=\"$(APP_NAME)\"" "/DVERSION=\"$(VERSION)\"" "/DSUB_VERSION=\"$(SUB_VERSION)\"" - -LFLAGS = /link \ - /LIBPATH:..\external\sdl\build\lib \ - /ENTRY:mainCRTStartup - -INCS = /I..\.shared \ +CXX = CL +CFLAGS = /std:c11 +CPPFLAGS = /W4 \ + /MD \ + /nologo \ + /w44996 \ + "/DAPP_NAME=\"$(APP_NAME)\"" \ + "/DVERSION=\"$(VERSION)\"" \ + "/DSUB_VERSION=\"$(SUB_VERSION)\"" + +CXXFLAGS = /std:c++11 +INCLUDE_DIRS = /I..\shared \ /I..\external\sdl\build\include \ /I..\external\imgui \ /I..\external\stb \ /I..\external\lekkit -LIBS = user32.lib \ +LDFLAGS = /link \ + /LIBPATH:..\external\sdl\build\lib \ + /ENTRY:mainCRTStartup \ + user32.lib \ SDL2.lib \ SDL2main.lib \ opengl32.lib \ Comdlg32.lib \ Shell32.lib -# SDL dependency files +# SDL2.dll is built in the same step as the static libs SDL_LIB = ..\external\sdl\build\lib\SDL2.lib -SDL_DLL = ..\external\sdl\build\bin\SDL2.dll # Generated headers LICENSE_HEADER = ..\shared\license.h BOOTROM_HEADER = ..\shared\bootrom.h BOOTROM_SOURCE = ..\roms\Kiwi8_logo_2.ch8 -# Source files -CORE_SRCS = ..\shared\audio.cc ..\shared\chip8.cc ..\shared\display.cc ..\shared\gui.cc \ - ..\shared\input.cc ..\shared\main.cc \ - ..\shared\toast.cc ..\shared\open_file_dialog.cc ..\shared\profiles.cc -IMGUI_SRCS = ..\external\imgui\imgui.cpp ..\external\imgui\imgui_draw.cpp ..\external\imgui\imgui_impl_sdl.cpp -WINDOWS_SRCS = src\file_dialog.cc -SHA256_SRC = ..\external\lekkit\sha256.cc - -# Object files (all built in current directory) -OBJS = audio.obj chip8.obj display.obj gui.obj imgui_impl_sdl.obj input.obj \ - main.obj toast.obj profiles.obj open_file_dialog.obj imgui.obj imgui_draw.obj \ - file_dialog.obj sha256.obj +OBJS = audio.obj \ + chip8.obj \ + display.obj \ + gui.obj \ + imgui_impl_sdl.obj \ + input.obj \ + main.obj \ + toast.obj \ + profiles.obj \ + open_file_dialog.obj \ + imgui.obj \ + imgui_draw.obj \ + file_dialog.obj \ + sha256.obj PROFILES_INI = ..\shared\profiles.ini # Default target all: debug\profiles.ini debug\$(APP_EXE) release\profiles.ini release\$(APP_EXE) -# Detect architecture from environment (set by MSVC vcvarsall.bat) -# VSCMD_ARG_TGT_ARCH is set to x64, x86, arm64, or arm -!IFNDEF SDL_ARCH -!IFDEF VSCMD_ARG_TGT_ARCH -SDL_ARCH = $(VSCMD_ARG_TGT_ARCH) -!ELSE -SDL_ARCH = x64 -!ENDIF -!ENDIF # Build SDL (force rebuild with: nmake sdl) sdl: @@ -86,9 +97,6 @@ sdl: $(SDL_LIB): powershell -ExecutionPolicy Bypass -File build_sdl.ps1 -ARCH $(SDL_ARCH) -$(SDL_DLL): $(SDL_LIB) - @REM DLL is created by same script that creates LIB - # Generate license header from LICENSE file $(LICENSE_HEADER): ..\LICENSE python3 ..\tools\generate_license_header.py ..\LICENSE $(LICENSE_HEADER) @@ -98,24 +106,27 @@ $(BOOTROM_HEADER): $(BOOTROM_SOURCE) python3 ..\tools\generate_bootrom_header.py $(BOOTROM_SOURCE) $(BOOTROM_HEADER) # Inference rules for incremental compilation -{..\shared}.cc{}.obj: - $(CC) $(CFLAGS) /c $(INCS) $< - {src}.cc{}.obj: - $(CC) $(CFLAGS) /c $(INCS) $< + $(CXX) $(CXXFLAGS) $(CPPFLAGS) /c $(INCLUDE_DIRS) $< {..\external\imgui}.cpp{}.obj: - $(CC) $(CFLAGS) /c $(INCS) $< + $(CXX) $(CXXFLAGS) $(CPPFLAGS) /c $(INCLUDE_DIRS) $< -{..\external\lekkit}.cc{}.obj: - $(CC) $(CFLAGS) /c $(INCS) $< +{..\external\lekkit}.c{}.obj: + $(CC) $(CFLAGS) $(CPPFLAGS) /c $(INCLUDE_DIRS) $< + +{..\shared}.c{}.obj: + $(CC) $(CFLAGS) $(CPPFLAGS) /c $(INCLUDE_DIRS) $< + +{..\shared}.cc{}.obj: + $(CXX) $(CXXFLAGS) $(CPPFLAGS) /c $(INCLUDE_DIRS) $< # Explicit rules for files depending on generated headers gui.obj: ..\shared\gui.cc $(LICENSE_HEADER) - $(CC) $(CFLAGS) /c $(INCS) ..\shared\gui.cc + $(CC) $(CFLAGS) $(CPPFLAGS) /c $(INCLUDE_DIRS) ..\shared\gui.cc -chip8.obj: ..\shared\chip8.cc $(BOOTROM_HEADER) - $(CC) $(CFLAGS) /c $(INCS) ..\shared\chip8.cc +chip8.obj: ..\shared\chip8.c $(BOOTROM_HEADER) + $(CC) $(CFLAGS) $(CPPFLAGS) /c $(INCLUDE_DIRS) ..\shared\chip8.c $(APP_RES): src\Kiwi8.rc resources\Kiwi8.ico RC src\Kiwi8.rc @@ -129,16 +140,16 @@ release\profiles.ini: $(PROFILES_INI) IF NOT EXIST release MKDIR release COPY $(PROFILES_INI) release\profiles.ini -debug\$(APP_EXE): $(SDL_LIB) $(SDL_DLL) $(OBJS) $(APP_RES) - $(CC) $(CFLAGS) /Zi /Fe$(APP_NAME) $(INCS) $(OBJS) $(APP_RES) $(LIBS) $(LFLAGS) /SUBSYSTEM:CONSOLE +debug\$(APP_EXE): $(SDL_LIB) $(OBJS) $(APP_RES) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) /Zi /Fe$(APP_NAME) $(INCLUDE_DIRS) $(OBJS) $(APP_RES) $(LDFLAGS) /SUBSYSTEM:CONSOLE IF NOT EXIST debug MKDIR debug - COPY $(SDL_DLL) debug\SDL2.dll + COPY ..\external\sdl\build\bin\SDL2.dll debug\SDL2.dll MOVE $(APP_EXE) $@ -release\$(APP_EXE): $(SDL_LIB) $(SDL_DLL) $(OBJS) $(APP_RES) - $(CC) $(CFLAGS) /Fe$(APP_NAME) $(INCS) $(OBJS) $(APP_RES) $(LIBS) $(LFLAGS) /SUBSYSTEM:WINDOWS +release\$(APP_EXE): $(SDL_LIB) $(OBJS) $(APP_RES) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) /Fe$(APP_NAME) $(INCLUDE_DIRS) $(OBJS) $(APP_RES) $(LDFLAGS) /SUBSYSTEM:WINDOWS IF NOT EXIST release MKDIR release - COPY $(SDL_DLL) release\SDL2.dll + COPY ..\external\sdl\build\bin\SDL2.dll release\SDL2.dll MOVE $(APP_EXE) $@ run-debug: