forked from kometbomb/klystrack
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
305 lines (256 loc) · 11 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
TARGET := klystrack
KLYSTRON=klystron
ECHO := echo
CFG := debug
EXE := bin.$(CFG)/$(TARGET)
MACHINE :=
NSIS := C:/program\ files\ \(x86\)/nsis/makensis.exe -V2 -NOCD
CURL := curl
MAKEBUNDLE := $(KLYSTRON)/tools/bin/makebundle.exe
UPLOAD := cmd.exe /c upload.bat
DLLS := zip/data/SDL2_image.dll zip/data/SDL2.dll
EXT := .c
CC := gcc
CDEP := $(CC) -E -MM
ARCHIVE := klystrack
INSTALLER := klystrack.exe
SDL_VER := 2.0.10
SDL_IMAGEVER := 2.0.5
THEMES :=
REV := cp -f
PREFIX ?= /usr
BINDIR = $(PREFIX)/bin
CFLAGS := $(MACHINE) -ftree-vectorize -std=gnu99 -Wno-strict-aliasing
ifdef COMSPEC
# Compiling for Windows
RES_PATH := .
CFLAGS += -DRESOURCES_IN_BINARY_DIR
CONFIG_PATH := ~/.klystrack
else
# Not compiling for Windows
RES_PATH = $(PREFIX)/lib/klystrack
CONFIG_PATH := ~/.klystrack
CFLAGS += -DCONFIG_DEFAULT_DISABLE_RENDER_TO_TEXTURE
endif
include klystron/common.mk
ifdef COMSPEC
TARGET := $(TARGET).exe
ARCHIVE := $(ARCHIVE).zip
CFLAGS += -mthreads
ZIP := zip -r ../$(ARCHIVE) .
ZIPEXT := unzip
else
ZIP := tar czf
DLLS =
ARCHIVE := $(ARCHIVE).tar.gz
endif
RESOURCES = $(subst themes,res,$(sort $(wildcard themes/*)))
KEYS = $(sort $(wildcard key/*))
EXTFLAGS := -DNOSDL_MIXER -DUSESDLMUTEXES -DENABLEAUDIODUMP -DSTEREOOUTPUT -DUSESDL_IMAGE -DMIDI -DUSESDL_RWOPS $(EXTFLAGS) $(CFLAGS)
LDFLAGS := -L $(KLYSTRON)/bin.$(CFG) -lengine_gfx -lengine_util -lengine_snd -lengine_gui -lm -lz $(SDLLIBS)
INCLUDEFLAGS := -I src $(SDLFLAGS) -I $(KLYSTRON)/src -L$(KLYSTRON)/bin.$(CFG) -DRES_PATH="$(RES_PATH)" -DCONFIG_PATH="$(CONFIG_PATH)" $(EXTFLAGS) -DKLYSTRON=$(KLYSTRON)
ifdef COMSPEC
LDFLAGS := -lmingw32 $(LDFLAGS)
else
LDFLAGS := -lasound $(LDFLAGS)
endif
DIRS := $(notdir $(wildcard src/*))
SUBDIRS := $(notdir $(wildcard src/import/*))
THEMEDIRS := $(notdir $(wildcard themes/*))
ifeq ($(CFG),debug)
CFLAGS += -g -Wall -DDEBUG -fno-inline
else
ifeq ($(CFG),profile)
CFLAGS += -O3 -pg -Wall
else
ifeq ($(CFG),release)
CFLAGS += -O3 -Wall -s
ifdef COMSPEC
CFLAGS += -mwindows
endif
else
@$(ECHO) "Invalid configuration "$(CFG)" specified."
@$(ECHO) "Possible choices for configuration are "
@$(ECHO) "'release', 'profile' and 'debug'"
@exit 1
endif
endif
endif
CFLAGS += -Wno-strict-aliasing
# $(1) = subdir, $(2) = filename prefix (i.e. subdir without a slash)
define directory_defs
SRC := $$(notdir $$(wildcard src/$(value 1)/*$(EXT)))
DEP := $$(patsubst %$(EXT),deps/$(CFG)_$(2)%.d,$$(SRC))
OBJ := $$(patsubst %$(EXT),objs.$(CFG)/$(2)%.o,$$(SRC))
OBJS := $(OBJS) $$(OBJ)
DEPS := $(DEPS) $$(DEP)
objs.$(CFG)/$(2)%.o: src/$(1)%$(EXT) src/version.h src/version_number.h
$(MSG) "Compiling $$(notdir $$<)..."
$(Q)mkdir -p objs.$(CFG)
$(Q)$(CC) $(INCLUDEFLAGS) -c $(CFLAGS) -o $$@ $$<
deps/$(CFG)_$(2)%.d: src/$(1)%$(EXT) src/version.h src/version_number.h
$(Q)mkdir -p deps
$(MSG) "Generating dependencies for $$(notdir $$<)..."
$(Q)set -e; $(CDEP) $(INCLUDEFLAGS) $$< > $$@.$$$$$$$$; \
sed 's,\($$*\)\.o[ :]*,objs.$(CFG)\/$(2)\1.o $$@ : ,g' \
< $$@.$$$$$$$$ > $$@; \
rm -f $$@.$$$$$$$$
endef
define subdirectory_defs
SRC := $$(notdir $$(wildcard src/import/$(value 1)/*$(EXT)))
DEP := $$(patsubst %$(EXT),deps/$(CFG)_$(2)%.d,$$(SRC))
OBJ := $$(patsubst %$(EXT),objs.$(CFG)/$(2)%.o,$$(SRC))
OBJS := $(OBJS) $$(OBJ)
DEPS := $(DEPS) $$(DEP)
objs.$(CFG)/$(2)%.o: src/import/$(1)%$(EXT) src/version.h src/version_number.h
$(MSG) "Compiling $$(notdir $$<)..."
$(Q)mkdir -p objs.$(CFG)
$(Q)$(CC) $(INCLUDEFLAGS) -c $(CFLAGS) -o $$@ $$<
deps/$(CFG)_$(2)%.d: src/import/$(1)%$(EXT) src/version.h src/version_number.h
$(Q)mkdir -p deps
$(MSG) "Generating dependencies for $$(notdir $$<)..."
$(Q)set -e; $(CDEP) $(INCLUDEFLAGS) $$< > $$@.$$$$$$$$; \
sed 's,\($$*\)\.o[ :]*,objs.$(CFG)\/$(2)\1.o $$@ : ,g' \
< $$@.$$$$$$$$ > $$@; \
rm -f $$@.$$$$$$$$
endef
define theme_defs
THEMES := $$(THEMES) res/$(1)
res/$(1): themes/$(1)/* #themes/$(1)/font/* themes/$(1)/font7x6/* themes/$(1)/tiny/*
@$(ECHO) "Building theme $(1)..."
$(Q)mkdir -p res
$(Q)mkdir -p themetemp.$(1)
-$(Q)if test -e themes/$(1)/colors.txt; then cp -f themes/$(1)/colors.txt themetemp.$(1); fi
-$(Q)if test -e themes/$(1)/bevel.*; then cp -f themes/$(1)/bevel.* themetemp.$(1); fi
-$(Q)if test -e themes/$(1)/vu.*; then cp -f themes/$(1)/vu.* themetemp.$(1); fi
-$(Q)if test -e themes/$(1)/analyzor.*; then cp -f themes/$(1)/analyzor.* themetemp.$(1); fi
-$(Q)if test -e themes/$(1)/logo.*; then cp -f themes/$(1)/logo.* themetemp.$(1); fi
-$(Q)if test -e themes/$(1)/catometer.*; then cp -f themes/$(1)/catometer.* themetemp.$(1); fi
-$(Q)if test -e themes/$(1)/cursor.*; then cp -f themes/$(1)/cursor.* themetemp.$(1); fi
-$(Q)if test -e themes/$(1)/icon.*; then cp -f themes/$(1)/icon.* themetemp.$(1); fi
-$(Q)if test -d themes/$(1)/font; then $(MAKEBUNDLE) themetemp.$(1)/8x8.fnt themes/$(1)/font; fi
-$(Q)if test -d themes/$(1)/font7x6; then $(MAKEBUNDLE) themetemp.$(1)/7x6.fnt themes/$(1)/font7x6; fi
-$(Q)if test -d themes/$(1)/tiny; then $(MAKEBUNDLE) themetemp.$(1)/4x6.fnt themes/$(1)/tiny; fi
$(Q)-$(MAKEBUNDLE) $$@ themetemp.$(1)
$(Q)rm -rf themetemp.$(1)
$(Q)mkdir -p res/Fonts
$(Q)cp -f Fonts/font16x16.* res/Fonts
$(Q)cp -f Fonts/font24x24.* res/Fonts
endef
build: Makefile src/version.h src/version_number.h
$(Q)touch src/version
$(Q)$(MAKE) -C $(KLYSTRON) CFG=$(CFG) EXTFLAGS="$(EXTFLAGS)"
$(Q)$(MAKE) all CFG=$(CFG) EXTFLAGS="$(EXTFLAGS)"
src/version.h: src/version
$(Q)echo '#ifndef VERSION_H' > ./src/version.h
$(Q)echo '#define VERSION_H' >> ./src/version.h
$(Q)echo '#include "version_number.h"' >> ./src/version.h
$(Q)echo '#define REVISION "' | tr -d '\n' >> ./src/version.h
$(Q)date +"%Y%m%d" | tr -d '\n' >> ./src/version.h
$(Q)echo '"' >> ./src/version.h
$(Q)echo '#define VERSION_STRING "klystrack-plus " VERSION " " REVISION' >> ./src/version.h
$(Q)echo '#endif' >> ./src/version.h
src/version_number.h: src/version
$(Q)echo '#ifndef VERSION_NUMBER' > src/version_number.h
$(Q)echo '#define VERSION_NUMBER' >> src/version_number.h
$(Q)echo '#define VERSION "' | tr -d '\n' >> src/version_number.h
$(Q)cat src/version | tr -d '\r\n' | tr -d '\n' >> src/version_number.h
$(Q)echo '"' >> src/version_number.h
$(Q)echo '#endif' >> src/version_number.h
# root (i.e. src/*.c)
$(eval $(call directory_defs,,))
# subdirs (src/*/*.c)
$(foreach dir,$(DIRS),$(eval $(call directory_defs,$(dir)/,$(dir)_)))
# subsubdirs (src/*/*/*.c) (yes, hacky and hard-coded to src/import/*/*.c now)
$(foreach dir,$(SUBDIRS),$(eval $(call subdirectory_defs,$(dir)/,$(dir)_)))
# themes
$(foreach dir,$(THEMEDIRS),$(eval $(call theme_defs,$(dir))))
ifdef COMSPEC
OBJS += objs.$(CFG)/windres.o
endif
.PHONY: zip all build nightly installer
all: $(EXE) $(THEMES)
zip: doc/* $(THEMES) $(DLLS) examples/instruments/* examples/songs/* $(DLLS)
$(Q)$(MAKE) -C $(KLYSTRON) CFG=release EXTFLAGS="$(EXTFLAGS)"
$(Q)$(MAKE) build CFG=release
$(Q)mkdir -p zip/data/res
$(Q)mkdir -p zip/data/res/Fonts
$(Q)mkdir -p zip/data/examples/songs
$(Q)mkdir -p zip/data/examples/songs/Imported-XMs
$(Q)mkdir -p zip/data/examples/songs/LTVA-examples
$(Q)mkdir -p zip/data/examples/songs/n00bstar-examples
$(Q)mkdir -p zip/data/examples/songs/System64-examples
$(Q)mkdir -p zip/data/examples/instruments
$(Q)mkdir -p zip/data/examples/instruments/n00bstar-instruments
$(Q)mkdir -p zip/data/examples/instruments/LTVA-instruments
$(Q)mkdir -p zip/data/examples/wavegen-patches
$(Q)mkdir -p zip/data/examples/wavegen-patches/LTVA-examples
$(Q)cp examples/songs/*.kt zip/data/examples/songs
$(Q)cp examples/songs/n00bstar-examples/*.kt zip/data/examples/songs/n00bstar-examples
$(Q)cp examples/songs/Imported-XMs/*.kt zip/data/examples/songs/Imported-XMs
$(Q)cp examples/songs/LTVA-examples/*.kt zip/data/examples/songs/LTVA-examples
$(Q)cp examples/songs/System64-examples/*.kt zip/data/examples/songs/System64-examples
$(Q)cp examples/instruments/*.ki zip/data/examples/instruments
$(Q)cp examples/instruments/n00bstar-instruments/*.ki zip/data/examples/instruments/n00bstar-instruments
$(Q)cp examples/instruments/LTVA-instruments/*.ki zip/data/examples/instruments/LTVA-instruments
$(Q)cp examples/wavegen-patches/*.kw zip/data/examples/wavegen-patches
$(Q)cp examples/wavegen-patches/LTVA-examples/*.kw zip/data/examples/wavegen-patches/LTVA-examples
$(Q)cp res/* zip/data/res
$(Q)cp res/Fonts/* zip/data/res/Fonts
$(Q)mkdir -p zip/data/key
$(Q)cp key/* zip/data/key
$(Q)cp LICENSE zip/data/LICENSE
$(Q)cp doc/SDL.txt zip/data/SDL.txt
$(Q)cp doc/SDL_image.txt zip/data/SDL_image.txt
$(Q)cp doc/Default.kt zip/data/Default.kt
$(Q)cp bin.release/$(TARGET) zip/data/$(TARGET)
ifdef COMSPEC
cd zip/data; rm -f ../$(ARCHIVE); $(ZIP) zip
$(Q)cp -f zip/klystrack.zip zip/klystrack-`cat src/version | tr -d '\r\n'`-win32.zip
else
-$(Q)rm -f zip/data/Makefile
cd zip; cp -r data klystrack-`cat ../src/version | tr -d '\r\n'`; rm -f $(ARCHIVE); $(ZIP) klystrack-`cat ../src/version`.tar.gz klystrack-`cat ../src/version`; rm -rf klystrack-`cat ../src/version`
endif
installer: zip installer/klystrack.nsi
ifdef COMSPEC
$(NSIS) -DVERSION=`cat src/version | tr -d '\r\n'` installer/klystrack.nsi
endif
nightly: zip
$(Q)cp zip/$(ARCHIVE) zip/klystrack-nightly-`date +"%Y%m%d" | tr -d '\n'`-win32.zip
clean:
$(MAKE) -C klystron clean
$(Q)rm -rf deps objs.debug objs.release objs.profile bin.release bin.debug bin.profile zip temp res
$(EXE): $(OBJS)
@$(ECHO) "Linking $(TARGET)..."
$(Q)mkdir -p bin.$(CFG)
$(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
release: bin.release/$(TARGET)
@$(ECHO) "Building release -->"
$(DESTDIR)$(BINDIR)/$(TARGET): $(EXE)
install -D -m 755 $< $@
$(DESTDIR)$(RES_PATH)/res/%: res/%
install -D -m 644 $< $@
$(DESTDIR)$(RES_PATH)/key/%: key/%
install -D -m 644 $< $@
install: $(EXE:bin.$(CFG)/%=$(DESTDIR)$(BINDIR)/%) $(RESOURCES:res/%=$(DESTDIR)$(RES_PATH)/res/%) $(KEYS:key/%=$(DESTDIR)$(RES_PATH)/key/%)
#bin.release/$(TARGET):
# $(Q)make CFG=release
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif
zip/data/SDL2_image.dll:
@$(ECHO) "Downloading "$@"..."
$(Q)mkdir -p temp
$(Q)cd temp; $(CURL) -O http://www.libsdl.org/projects/SDL_image/release/SDL2_image-$(SDL_IMAGEVER)-win32-x86.zip; $(ZIPEXT) SDL2_image-$(SDL_IMAGEVER)-win32-x86.zip SDL2_image.dll libpng16-16.dll zlib1.dll; rm SDL2_image-$(SDL_IMAGEVER)-win32-x86.zip
$(Q)mkdir -p zip/data
$(Q)mv temp/SDL2_image.dll zip/data/SDL2_image.dll
$(Q)mv temp/libpng16-16.dll zip/data/libpng16-16.dll
$(Q)mv temp/zlib1.dll zip/data/zlib1.dll
zip/data/SDL2.dll:
@$(ECHO) "Downloading "$@"..."
$(Q)mkdir -p temp
$(Q)cd temp; $(CURL) -O https://www.libsdl.org/release/SDL2-$(SDL_VER)-win32-x86.zip; $(ZIPEXT) SDL2-$(SDL_VER)-win32-x86.zip SDL2.dll; rm SDL2-$(SDL_VER)-win32-x86.zip
$(Q)mkdir -p zip/data
$(Q)mv temp/SDL2.dll zip/data/SDL2.dll
objs.$(CFG)/windres.o: windres/* icon/*
windres -i windres/resource.rc -o $@