-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
224 lines (184 loc) · 4.73 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
# Build for Linux, Windows & WASM
#
# This Makefile is intended for use on a linux system
# linux, wasm, win
PLATFORM ?= linux
APP_NAME = lu5
VERSION = 0.1.7
LUA_VERSION=5.4.7
SRCDIR = src
BINDIR = bin
MACROS=-D'LU5_VERSION="$(VERSION)"'
LUA_SRC=include/lua
LUA_A = $(LUA_SRC)/liblua.a
AGNOSTIC_SRC =\
$(wildcard $(SRCDIR)/*.c)\
$(wildcard $(SRCDIR)/bindings/*.c)
ALL_SRC = $(AGNOSTIC_SRC)\
$(wildcard $(SRCDIR)/platform/*.c)\
$(wildcard $(SRCDIR)/platform/geometry/2D/*.c)\
$(wildcard $(SRCDIR)/platform/geometry/3D/*.c)
HEADERS = $(wildcard $(SRCDIR)/*.h)
ifeq ($(PLATFORM), linux)
OBJ_EXT = .o
LIB_EXT = .a
BIN_EXT =
CC := gcc
BIN = $(BINDIR)/$(PLATFORM)/$(APP_NAME)
OBJDIR = $(BINDIR)/$(PLATFORM)/obj
CFLAGS = -Wall\
-I$(LUA_SRC)\
$(shell pkg-config --cflags glfw3)\
$(shell pkg-config --cflags glew)\
$(shell pkg-config --cflags gl)\
$(shell pkg-config --cflags freetype2)
LDFLAGS :=\
-L$(LUA_SRC)\
$(shell pkg-config --static --libs glfw3)\
$(shell pkg-config --static --libs glew)\
$(shell pkg-config --static --libs gl)\
$(shell pkg-config --libs freetype2)\
-lm
SOURCES=$(ALL_SRC)
else ifeq ($(PLATFORM), wasm)
OBJ_EXT = .o.wasm
LIB_EXT = .a.wasm
BIN_EXT = .wasm
# WASM setup
WASI_SDK_PATH ?= /opt/wasi-sdk-24
CC := $(WASI_SDK_PATH)/bin/clang
AR := $(WASI_SDK_PATH)/bin/llvm-ar
RANLIB := $(WASI_SDK_PATH)/bin/llvm-ranlib
BIN = $(BINDIR)/$(PLATFORM)/$(APP_NAME)$(BIN_EXT)
OBJDIR = $(BINDIR)/$(PLATFORM)/obj
CFLAGS = \
-mllvm -wasm-enable-sjlj\
--target=wasm32-wasi\
--sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot\
-I$(WASI_SDK_PATH)/share/wasi-sysroot/include\
-I$(LUA_SRC)\
-DLU5_WASM\
-D_WASI_EMULATED_SIGNAL\
-D_WASI_EMULATED_PROCESS_CLOCKS\
-DLUA_USE_C89
LDFLAGS = \
--sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot\
--target=wasm32-wasi\
-Wl,-u__wasm_longjmp\
-lsetjmp\
-lwasi-emulated-process-clocks\
-Wl,-mllvm,-wasm-enable-sjlj\
-Wl,--export=malloc,\
-Wl,--export=free,\
-Wl,--no-entry,
SOURCES=$(AGNOSTIC_SRC)
LUA_A := $(LUA_A:.a=$(LIB_EXT))
else ifeq ($(PLATFORM), win)
OBJ_EXT = .o
LIB_EXT = .a
BIN_EXT = .exe
ARCH=x86_64-w64-mingw32
CC := $(ARCH)-gcc
MINGW = /usr/x86_64-w64-mingw32/
NSIS_PATH := ~/.wine/drive_c/Program\ Files\ \(x86\)/NSIS/makensis.exe
INSTALLER_NAME := lu5_installer-$(VERSION).exe
INSTALLER_SCRIPT := installer/lu5_installer.nsi
INSTALLER_EXEC := $(BINDIR)/$(PLATFORM)/$(INSTALLER_NAME)
BIN = $(BINDIR)/$(PLATFORM)/$(APP_NAME)$(BIN_EXT)
OBJDIR = $(BINDIR)/$(PLATFORM)/obj
CFLAGS = -Wall\
-I/usr/$(ARCH)/include\
-I/usr/$(ARCH)/include/freetype2\
-L/usr/$(ARCH)/lib
LDFLAGS :=\
-lfreetype\
-lglfw3\
-lglu32\
-lgdi32\
-lopengl32\
-llua
DLL_FILES = \
zlib1.dll \
libssp-0.dll \
libbrotlicommon.dll \
libbrotlidec.dll \
libbz2-1.dll \
lua54.dll \
libfreetype-6.dll \
libwinpthread-1.dll
SOURCES=$(ALL_SRC)
endif
OBJECTS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%$(OBJ_EXT),$(SOURCES))
all: $(BIN)
# Build lua static library
$(LUA_A):
cd $(LUA_SRC) && make PLATFORM=$(PLATFORM)
# Build object files
$(OBJDIR)/%$(OBJ_EXT): src/%.c $(LUA_A) $(HEADERS)
@mkdir -p $(dir $@)
$(CC) -MMD -c $< -o $@ $(CFLAGS) $(MACROS)
# Rule to build .wat files from .wasm files
$(OBJDIR)/%.wat: $(OBJDIR)/%$(OBJ_EXT)
wasm2wat $< -o $@ --enable-all
debug: $(OBJECTS:$(OBJ_EXT)=.wat)
# Link all togheter
$(BIN): $(OBJECTS) $(LUA_A)
@mkdir -p $(dir $@)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
# ---
# Build the documentation using lu5 and lua scripts
#
# `make docs`
#
# See `site/config.lua`
# ---
DOC_BUILD_TASK = site/tasks/build_docs.lua
docs: $(BIN) $(SOURCES)
$(BIN) $(DOC_BUILD_TASK)
# ---
# Run a lu5 script with the latest build
#
# `make run` will run `./test.lua`
# `make run SCRIPT=foo.lua` will run `foo.lua`
#
# ---
SCRIPT ?= ./test.lua
run: $(BIN) $(SCRIPT)
$(BIN) $(SCRIPT)
examples:
cd examples && make
# ---
# Run non-graphical unit tests
#
# `make tests`
# ---
TESTS = $(wildcard tests/*.lua)
tests: $(all) $(TESTS:=.run)
tests/%.lua.run: tests/%.lua
$(BIN) --log 2 $<
rm -f $@
ifeq ($(PLATFORM), win)
# Copy all DLLs from mingw to build destination
$(BINDIR)/$(PLATFORM)/%.dll: /usr/x86_64-w64-mingw32/bin/%.dll
cp $< $@
# Build windows installer
$(INSTALLER_EXEC): $(INSTALLER_SCRIPT) $(BIN) $(DLL_FILES:%=$(BINDIR)/$(PLATFORM)/%)
wine $(NSIS_PATH) $<
# Command to build the installer
installer: $(INSTALLER_EXEC)
else
# Zip binary
zip: $(BIN)
zip $(BINDIR)/$(PLATFORM)/lu5-x86_64-$(PLATFORM)-$(VERSION).zip $(BIN)
endif
clean:
cd include/lua && make clean
rm -fr $(BINDIR)/wasm
rm -fr $(BINDIR)/win
rm -fr $(BINDIR)/linux
rm -fr $(INSTALLER_EXEC)
rm -fr docs/assets/*.svg
rm -fr docs/assets/*.css
rm -fr docs/assets/*.js
rm -fr examples/*.lua.run
.PHONY: all clean docs zip examples tests installer