aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 71dbd3d87858f1155a4178f1c00015a90af9e6ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
CXX = g++
CC = gcc


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
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)/dist/$(APP_NAME).app/Contents/MacOS
    TARGET = $(TARGET_DIR)/$(APP_NAME)
    INFO_PLIST = $(BUILD_DIR)/dist/$(APP_NAME).app/Contents/Info.plist
    MAKE_APP = true
else
    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)
	mkdir -p $(TARGET_DIR)
	$(CXX) $(OBJ_CPP) $(LUA_OBJ) -o $(TARGET) $(LDFLAGS)
ifeq ($(MAKE_APP),true)
	mkdir -p $(dir $(INFO_PLIST))
	cp Info.plist $(INFO_PLIST)
	mkdir -p $(TARGET_DIR)
	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_DIR)/main.o: src/main.cpp
	mkdir -p $(BUILD_DIR)
	$(CXX) $(CXXFLAGS) -c src/main.cpp -o $(BUILD_DIR)/main.o

$(BUILD_DIR)/lua/%.o: src/lua/%.c
	mkdir -p $(BUILD_DIR)/lua
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -rf $(ROOT_BUILD_DIR)