From dc0f9628b262b47f37ca7cdf15657f576ab71a45 Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Wed, 11 Jun 2025 20:21:29 +1200 Subject: Add windows cross-compile build support, this was a piece of SHIT to do! --- Makefile | 66 ++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 16 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 05fdbd8..71dbd3d 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,62 @@ CXX = g++ CC = gcc -LUA_SRC = $(wildcard src/lua/*.c) -LUA_OBJ = $(patsubst src/lua/%.c, build/lua/%.o, $(LUA_SRC)) -SRC_CPP = src/main.cpp -OBJ_CPP = build/main.o +NT_SDL_DLL_LOCATION = SDL2-2.24.0/x86_64-w64-mingw32/bin/SDL2.dll +NT_LIBWINPTHREAD_LOCATION = WindowsShit/libwinpthread-1.dll +MACOS_SDL_DYLIB_LOCATION = /opt/homebrew/opt/sdl2/lib/libSDL2-2.0.0.dylib APP_NAME = ShowdownOfTheSticks -BUILD_DIR = build UNAME_S := $(shell uname -s) +PLATFORM_TAG = unknown +ifeq ($(UNAME_S),Darwin) + PLATFORM_TAG = MacOS +endif +ifeq ($(OS),Windows_NT) + PLATFORM_TAG = Windows_NT +endif +ifeq ($(UNAME_S),Linux) +$(error Linux build is not supported yet, attempting to build may cause issues.) +endif + +ROOT_BUILD_DIR = build +BUILD_DIR = $(ROOT_BUILD_DIR)/$(PLATFORM_TAG) + +SRC_CPP = src/main.cpp +OBJ_CPP = $(BUILD_DIR)/main.o + +LUA_SRC = $(wildcard src/lua/*.c) +LUA_OBJ = $(patsubst src/lua/%.c, $(BUILD_DIR)/lua/%.o, $(LUA_SRC)) + ifeq ($(UNAME_S),Darwin) - TARGET_DIR = $(BUILD_DIR)/$(APP_NAME).app/Contents/MacOS + TARGET_DIR = $(BUILD_DIR)/dist/$(APP_NAME).app/Contents/MacOS TARGET = $(TARGET_DIR)/$(APP_NAME) - INFO_PLIST = $(BUILD_DIR)/$(APP_NAME).app/Contents/Info.plist + INFO_PLIST = $(BUILD_DIR)/dist/$(APP_NAME).app/Contents/Info.plist MAKE_APP = true else - TARGET_DIR = $(BUILD_DIR) + TARGET_DIR = $(BUILD_DIR)/dist TARGET = $(TARGET_DIR)/$(APP_NAME) MAKE_APP = false endif +# Default flags for MacOS - these are changed if Windows is detected CXXFLAGS = -I/opt/homebrew/include -D_THREAD_SAFE -std=c++17 CFLAGS = -I/opt/homebrew/include -D_THREAD_SAFE LDFLAGS = -L/opt/homebrew/lib -lSDL2 +ifeq ($(OS),Windows_NT) + CC = x86_64-w64-mingw32-gcc + CXX = x86_64-w64-mingw32-g++ + TARGET_DIR = $(BUILD_DIR)/dist + TARGET = $(TARGET_DIR)/$(APP_NAME).exe + MAKE_APP = false + CXXFLAGS = -ISDL2-2.24.0/x86_64-w64-mingw32/include -D_THREAD_SAFE -std=c++17 -static-libgcc -static-libstdc++ + CFLAGS = -ISDL2-2.24.0/x86_64-w64-mingw32/include -D_THREAD_SAFE + LDFLAGS = -LSDL2-2.24.0/x86_64-w64-mingw32/lib -lSDL2 -static-libgcc -static-libstdc++ +endif + all: $(TARGET) $(TARGET): $(OBJ_CPP) $(LUA_OBJ) @@ -36,18 +66,22 @@ ifeq ($(MAKE_APP),true) mkdir -p $(dir $(INFO_PLIST)) cp Info.plist $(INFO_PLIST) mkdir -p $(TARGET_DIR) - cp /opt/homebrew/opt/sdl2/lib/libSDL2-2.0.0.dylib $(TARGET_DIR)/libSDL2.dylib - install_name_tool -change /opt/homebrew/opt/sdl2/lib/libSDL2-2.0.0.dylib @executable_path/libSDL2.dylib $(TARGET) + cp $(MACOS_SDL_DYLIB_LOCATION) $(TARGET_DIR)/libSDL2.dylib + install_name_tool -change $(MACOS_SDL_DYLIB_LOCATION) @executable_path/libSDL2.dylib $(TARGET) otool -l $(TARGET) endif +ifeq ($(OS),Windows_NT) + cp $(NT_SDL_DLL_LOCATION) $(TARGET_DIR)/SDL2.dll + cp $(NT_LIBWINPTHREAD_LOCATION) $(TARGET_DIR)/libwinpthread-1.dll +endif -build/main.o: src/main.cpp - mkdir -p build - $(CXX) $(CXXFLAGS) -c src/main.cpp -o build/main.o +$(BUILD_DIR)/main.o: src/main.cpp + mkdir -p $(BUILD_DIR) + $(CXX) $(CXXFLAGS) -c src/main.cpp -o $(BUILD_DIR)/main.o -build/lua/%.o: src/lua/%.c - mkdir -p build/lua +$(BUILD_DIR)/lua/%.o: src/lua/%.c + mkdir -p $(BUILD_DIR)/lua $(CC) $(CFLAGS) -c $< -o $@ clean: - rm -rf $(BUILD_DIR) + rm -rf $(ROOT_BUILD_DIR) -- cgit v1.2.3