aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2025-06-11 20:21:29 +1200
committerArslaan Pathan <[email protected]>2025-06-11 20:21:29 +1200
commitdc0f9628b262b47f37ca7cdf15657f576ab71a45 (patch)
tree9a06c44bb510d90d74c225fb543bfce04b1303a2 /Makefile
parent5dfe69e4580073c9bdeaed605a46cf0ec3e24ad2 (diff)
downloadshowdownofthesticks-dc0f9628b262b47f37ca7cdf15657f576ab71a45.tar.xz
showdownofthesticks-dc0f9628b262b47f37ca7cdf15657f576ab71a45.zip
Add windows cross-compile build support, this was a piece of SHIT to do!
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile66
1 files changed, 50 insertions, 16 deletions
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)