-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
240 lines (203 loc) · 5.05 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
# finding host and default targets
ifeq ($(OS),Windows_NT)
HOST := windows
endif
ifeq ($(shell uname -s),Darwin)
HOST := macos
endif
ifeq ($(shell uname -s),Linux)
HOST := linux
endif
TARGET := $(HOST)
# programs / paths
CC := cc
ifeq ($(TARGET),web)
CC := emcc
endif
ifeq ($(TARGET),ios)
CC := xcrun -sdk iphoneos clang
endif
ifeq ($(TARGET),iossim)
CC := xcrun -sdk iphonesimulator clang
endif
ifeq ($(TARGET),windows)
CC := x86_64-w64-mingw32-gcc
endif
DEMO := hi
BIN_PATH := build/$(TARGET)
DEMO_PATH := demo
# flags
CFLAGS += -Wall
CFLAGS += -Werror
CFLAGS += -pedantic
CFLAGS += -std=c99
CFLAGS += -I.
CFLAGS += -Iext
CFLAGS += -Iext/lua/src
CFLAGS += -Wno-unused-function
CFLAGS += -Wno-unused-variable
CFLAGS += -Wno-unused-but-set-variable
CFLAGS += -Wno-gnu-label-as-value
CFLAGS += -Wno-incompatible-pointer-types-discards-qualifiers
ifdef DEBUG
CFLAGS += -O0 -g
else
CFLAGS += -O2
endif
ifeq ($(TARGET),macos)
CFLAGS += -ObjC
endif
ifeq ($(TARGET),ios)
CFLAGS += -ObjC
CFLAGS += -arch armv7
CFLAGS += -arch arm64
endif
ifeq ($(TARGET),iossim)
CFLAGS += -ObjC
endif
ifeq ($(TARGET),web)
CFLAGS += -s "ALLOW_MEMORY_GROWTH=1"
CFLAGS += -s "EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']"
endif
ifeq ($(TARGET),macos)
LDFLAGS += -framework Cocoa
LDFLAGS += -framework OpenGL
LDFLAGS += -framework Metal
LDFLAGS += -framework MetalKit
LDFLAGS += -framework AudioToolbox
endif
ifeq ($(TARGET),ios)
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework CoreGraphics
LDFLAGS += -framework OpenGLES
LDFLAGS += -framework GLKit
LDFLAGS += -framework Metal
LDFLAGS += -framework MetalKit
LDFLAGS += -framework AudioToolbox
endif
ifeq ($(TARGET),iossim)
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework CoreGraphics
LDFLAGS += -framework OpenGLES
LDFLAGS += -framework GLKit
LDFLAGS += -framework Metal
LDFLAGS += -framework MetalKit
LDFLAGS += -framework AudioToolbox
endif
ifeq ($(TARGET),windows)
LDFLAGS += -mwindows
LDFLAGS += -lole32
LDFLAGS += -lavrt
LDFLAGS += -lwinmm
endif
ifeq ($(TARGET),linux)
LDFLAGS += -lx11
LDFLAGS += -lGL
endif
ifeq ($(TARGET),web)
LDFLAGS += --preload-file demo/res@res
endif
ifndef DEBUG
LDFLAGS += -flto
endif
# files
DEMO_FILES := $(wildcard $(DEMO_PATH)/*.c)
DEMO_TARGETS := $(patsubst $(DEMO_PATH)/%.c, $(BIN_PATH)/%, $(DEMO_FILES))
PREFIX := /usr/local
LUA_PATH := ext/lua
LUA_LIB := lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c lcorolib.c ldblib.c liolib.c lmathlib.c loadlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c linit.c
LUA_SRC := $(addprefix $(LUA_PATH)/src/, $(LUA_LIB))
.PHONY: run
run: $(BIN_PATH)/$(DEMO)
ifeq ($(TARGET),web)
cd $(BIN_PATH); \
python3 -m http.server 8000
else ifeq ($(TARGET),iossim)
@if [ -z "$(SIMULATOR)" ]; then \
echo "SIMULATOR not set"; \
exit 1; \
fi
$(MAKE) bundle
xcrun simctl boot $(SIMULATOR)
xcrun simctl install booted $<.app
open -a Simulator --args -CurrentDeviceUDID $(SIMULATOR)
xcrun simctl launch --console-pty booted xyz.space55.$(DEMO)
else ifeq ($(TARGET),ios)
$(MAKE) bundle
ios-deploy --debug --bundle $<.app
else ifeq ($(TARGET),windows)
ifeq ($(HOST), windows)
cd $(BIN_PATH); \
$(DEMO).exe $(ARGS)
else
cd $(BIN_PATH); \
wine $(DEMO).exe $(ARGS)
endif
else
cd $(BIN_PATH); \
./$(DEMO) $(ARGS)
endif
.PHONY: debug
debug: $(BIN_PATH)/$(DEMO)
lldb -- $< $(ARGS)
.PHONY: demo
demo: $(BIN_PATH)/$(DEMO)
.PHONY: demos
demos: $(DEMO_TARGETS)
.PHONY: bundle
bundle: $(BIN_PATH)/$(DEMO)
ifeq ($(TARGET),macos)
mkdir -p $<.app/Contents/MacOS
mkdir -p $<.app/Contents/Resources
cp $< $<.app/Contents/MacOS
cp -R $(DEMO_PATH)/res $<.app/Contents/Resources
sed 's/{{name}}/$(DEMO)/' misc/macos.plist > $<.app/Contents/Info.plist
else ifeq ($(TARGET),iossim)
mkdir -p $<.app
cp $< $<.app/
cp -r $(BIN_PATH)/res $<.app/
sed 's/{{name}}/$(DEMO)/' misc/ios.plist > $<.app/Info.plist
else ifeq ($(TARGET),ios)
mkdir -p $<.app
cp $< $<.app/
cp -r $(BIN_PATH)/res $<.app/
sed 's/{{name}}/$(DEMO)/' misc/ios.plist > $<.app/Info.plist
@if [ -z "$(PROVISION)" ] || [ -z "$(CODESIGN)" ]; then \
echo "PROVISION and CODESIGN required"; \
exit 1; \
fi
cp $(PROVISION) $<.app/embedded.mobileprovision
codesign -s "$(CODESIGN)" $<.app
endif
$(BIN_PATH)/%: $(DEMO_PATH)/%.c *.h
@mkdir -p $(BIN_PATH)
ifeq ($(TARGET),web)
$(CC) $(CFLAGS) -o [email protected] $< $(LDFLAGS)
sed 's/{{name}}/$*/' misc/web.html > $(BIN_PATH)/index.html
else
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
endif
rsync -a --delete $(DEMO_PATH)/res $(BIN_PATH)/
$(BIN_PATH)/dlua: $(LUA_SRC) d_lua.c *.h
@mkdir -p $(BIN_PATH)
$(CC) $(CFLAGS) $(LDFLAGS) $(LUA_SRC) d_lua.c -o $@
$(BIN_PATH)/dirty: dirty.c *.h
@mkdir -p $(BIN_PATH)
$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
.PHONY: runlua
runlua: $(BIN_PATH)/dlua
$< $(ARGS)
.PHONY: runscript
runscript: $(BIN_PATH)/dirty
$< $(ARGS)
.PHONY: debugscript
debugscript: $(BIN_PATH)/dirty
lldb -- $< $(ARGS)
.PHONY: install
install: $(BIN_PATH)/dirty
install $< $(PREFIX)/bin/dirty
.PHONY: clean
clean:
rm -rf build