-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
189 lines (171 loc) · 6.08 KB
/
Makefile
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# Build configuration
INCLUDE_DIR = include
INCLUDE_FLAGS = -I$(INCLUDE_DIR)
BUILD_DIR = build/clay
SRC_DIR = src
NDK_PATH ?= /opt/android-ndk
SDK_PATH ?= /opt/android-sdk
ANDROID_ABIS ?= armeabi-v7a arm64-v8a x86 x86_64
ifeq ($(BUILD_TYPE),web)
CC = emcc
CFLAGS = -Wall -Werror -Os -DCLAY_WASM -mbulk-memory --target=wasm32
INCLUDE_FLAGS += -Ivendor/clay
LINKER_FLAGS = \
-Wl,--strip-all \
-Wl,--export-dynamic \
-Wl,--export=__heap_base \
-Wl,--export=ACTIVE_RENDERER_INDEX \
-s WASM=1 \
-s USE_PTHREADS=0 \
-s ASSERTIONS=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \
-s EXPORTED_FUNCTIONS='["_main", "_printf"]'
TARGET = $(BUILD_DIR)/index.wasm
SRCS = $(shell find $(SRC_DIR) -name "*.c" ! -path "$(SRC_DIR)/platforms/*")
else ifeq ($(BUILD_TYPE),android)
CFLAGS = -Wall -Werror -O2 -DCLAY_MOBILE -fPIC
INCLUDE_FLAGS += \
-I$(NDK_PATH)/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include \
-Ivendor/cJSON \
-Ivendor/SDL/include \
-Ivendor/SDL_image/include \
-Ivendor/SDL_ttf \
-Ivendor/SDL2_gfx
LINKER_FLAGS = -shared -landroid -llog -lm \
-L$(dir $(TARGET)) \
-lSDL2 -lSDL2_image -lSDL2_ttf \
vendor/SDL2_gfx/build-android-$(TARGET_ABI)/libSDL2_gfx.a
SRCS = $(shell find $(SRC_DIR) -name "*.c")
SRCS += vendor/cJSON/cJSON.c
else ifeq ($(BUILD_TYPE),desktop)
CC = clang
CFLAGS = -Wall -Werror -O2 -DCLAY_DESKTOP
LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_gfx -lm
INCLUDE_FLAGS += -I/usr/include/SDL2 -Ivendor/cJSON
TARGET = $(BUILD_DIR)/game
SRCS = $(shell find $(SRC_DIR) -name "*.c")
SRCS += vendor/cJSON/cJSON.c
endif
OBJS = $(SRCS:%.c=$(BUILD_DIR)/%.o)
all: $(TARGET) copy_assets
$(TARGET): $(OBJS)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LINKER_FLAGS) $(INCLUDE_FLAGS) -o $@ $(OBJS)
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INCLUDE_FLAGS) -c $< -o $@
copy_assets:
ifeq ($(BUILD_TYPE),web)
cp index.html $(BUILD_DIR)/index.html
cp manifest.json $(BUILD_DIR)/manifest.json
cp -r fonts/ $(BUILD_DIR)/fonts
cp -r images/ $(BUILD_DIR)/images
else ifeq ($(BUILD_TYPE),android)
mkdir -p android/app/src/main/assets/fonts
mkdir -p android/app/src/main/assets/images
cp -r fonts/* android/app/src/main/assets/fonts/
cp -r images/* android/app/src/main/assets/images/
else
cp -r fonts/ $(BUILD_DIR)/fonts
cp -r images/ $(BUILD_DIR)/images
endif
clean:
rm -rf $(BUILD_DIR)
build-sdl-android:
@for abi in $(ANDROID_ABIS) ; do \
echo "Building SDL for $$abi" && \
mkdir -p vendor/SDL/build-android-$$abi && \
(cd vendor/SDL/build-android-$$abi && \
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=$(NDK_PATH)/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=$$abi \
-DANDROID_PLATFORM=android-21 \
-DBUILD_SHARED_LIBS=ON && \
make) && \
mkdir -p android/app/src/main/jniLibs/$$abi/ && \
cp vendor/SDL/build-android-$$abi/libSDL2.so android/app/src/main/jniLibs/$$abi/ ; \
done
build-sdl-gfx-android: build-sdl-android
@for abi in $(ANDROID_ABIS) ; do \
echo "Building SDL2_gfx for $$abi" && \
mkdir -p vendor/SDL2_gfx/build-android-$$abi && \
(cd vendor/SDL2_gfx/build-android-$$abi && \
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=$(NDK_PATH)/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=$$abi \
-DANDROID_PLATFORM=android-21 \
-DSDL2_DIR=../../SDL/build-android-$$abi \
-DSDL2_INCLUDE_DIR=../../SDL/include \
-DSDL2_LIBRARY=../../SDL/build-android-$$abi/libSDL2.so && \
make) ; \
done
build-sdl-image-android: build-sdl-gfx-android
@for abi in $(ANDROID_ABIS) ; do \
echo "Building SDL_image for $$abi" && \
mkdir -p vendor/SDL_image/build-android-$$abi && \
(cd vendor/SDL_image/build-android-$$abi && \
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=$(NDK_PATH)/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=$$abi \
-DANDROID_PLATFORM=android-21 \
-DSDL2_DIR=../../SDL/build-android-$$abi \
-DSDL2_INCLUDE_DIR=../../SDL/include \
-DSDL2_LIBRARY=../../SDL/build-android-$$abi/libSDL2.so \
-DSDL2IMAGE_AVIF=OFF \
-DSDL2IMAGE_WEBP=OFF \
-DSDL2IMAGE_TIFF=OFF && \
make) && \
cp vendor/SDL_image/build-android-$$abi/libSDL2_image.so android/app/src/main/jniLibs/$$abi/ ; \
done
build-sdl-ttf-android: build-sdl-image-android
@for abi in $(ANDROID_ABIS) ; do \
echo "Building SDL_ttf for $$abi" && \
mkdir -p vendor/SDL_ttf/build-android-$$abi && \
(cd vendor/SDL_ttf/build-android-$$abi && \
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=$(NDK_PATH)/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=$$abi \
-DANDROID_PLATFORM=android-21 \
-DSDL2_DIR=../../SDL/build-android-$$abi \
-DSDL2_INCLUDE_DIR=../../SDL/include \
-DSDL2_LIBRARY=../../SDL/build-android-$$abi/libSDL2.so \
-DBUILD_SHARED_LIBS=ON \
-DSDL2TTF_SAMPLES=OFF && \
make) && \
cp vendor/SDL_ttf/build-android-$$abi/libSDL2_ttf.so android/app/src/main/jniLibs/$$abi/ ; \
done
build-android-abi:
rm -rf $(BUILD_DIR)
$(eval CC = $(NDK_PATH)/toolchains/llvm/prebuilt/linux-x86_64/bin/$(TARGET_TRIPLE)-clang)
@echo "Building for ABI: $(TARGET_ABI) using compiler: $(CC)"
$(MAKE) all BUILD_TYPE=android CC="$(CC)"
build-android: build-sdl-ttf-android
@for abi in $(ANDROID_ABIS) ; do \
case $$abi in \
"armeabi-v7a") \
TARGET_TRIPLE="armv7a-linux-androideabi21" ;; \
"arm64-v8a") \
TARGET_TRIPLE="aarch64-linux-android21" ;; \
"x86") \
TARGET_TRIPLE="i686-linux-android21" ;; \
"x86_64") \
TARGET_TRIPLE="x86_64-linux-android21" ;; \
esac ; \
$(MAKE) build-android-abi TARGET_TRIPLE=$$TARGET_TRIPLE TARGET_ABI=$$abi TARGET=android/app/src/main/jniLibs/$$abi/libmain.so ; \
done
cd android && ./gradlew assembleDebug
# Update clean target
clean-android:
rm -rf vendor/SDL/build-android-*
rm -rf vendor/SDL_image/build-android-*
rm -rf vendor/SDL_ttf/build-android-*
rm -rf vendor/SDL2_gfx/build-android-* #
rm -rf android/app/build
rm -rf android/app/src/main/jniLibs
help:
@echo "Available targets:"
@echo " make BUILD_TYPE=web - Build web version"
@echo " make BUILD_TYPE=desktop - Build desktop version"
@echo " make clean - Clean build directory"
@echo " make help - Show this help message"