-
Notifications
You must be signed in to change notification settings - Fork 158
/
Makefile
371 lines (293 loc) · 14.1 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
LBITS := $(shell getconf LONG_BIT)
MARCH ?= $(LBITS)
PREFIX ?= /usr/local
INSTALL_DIR ?= $(PREFIX)
INSTALL_BIN_DIR ?= $(PREFIX)/bin
INSTALL_LIB_DIR ?= $(PREFIX)/lib
INSTALL_INCLUDE_DIR ?= $(PREFIX)/include
LIBS=fmt sdl ssl openal ui uv mysql sqlite
ARCH ?= $(shell uname -m)
CFLAGS = -Wall -O3 -I src -std=c11 -D LIBHL_EXPORTS
LFLAGS = -L. -lhl
EXTRA_LFLAGS ?=
LIBFLAGS =
HLFLAGS = -ldl
LIBEXT = so
LIBTURBOJPEG = -lturbojpeg
LHL_LINK_FLAGS =
PCRE_FLAGS = -I include/pcre -D HAVE_CONFIG_H -D PCRE2_CODE_UNIT_WIDTH=16
PCRE = include/pcre/pcre2_auto_possess.o include/pcre/pcre2_chartables.o include/pcre/pcre2_compile.o \
include/pcre/pcre2_config.o include/pcre/pcre2_context.o include/pcre/pcre2_convert.o \
include/pcre/pcre2_dfa_match.o include/pcre/pcre2_error.o include/pcre/pcre2_extuni.o \
include/pcre/pcre2_find_bracket.o include/pcre/pcre2_jit_compile.o include/pcre/pcre2_maketables.o \
include/pcre/pcre2_match_data.o include/pcre/pcre2_match.o include/pcre/pcre2_newline.o \
include/pcre/pcre2_ord2utf.o include/pcre/pcre2_pattern_info.o include/pcre/pcre2_script_run.o \
include/pcre/pcre2_serialize.o include/pcre/pcre2_string_utils.o include/pcre/pcre2_study.o \
include/pcre/pcre2_substitute.o include/pcre/pcre2_substring.o include/pcre/pcre2_tables.o \
include/pcre/pcre2_ucd.o include/pcre/pcre2_valid_utf.o include/pcre/pcre2_xclass.o
RUNTIME = src/gc.o
STD = src/std/array.o src/std/buffer.o src/std/bytes.o src/std/cast.o src/std/date.o src/std/error.o src/std/debug.o \
src/std/file.o src/std/fun.o src/std/maps.o src/std/math.o src/std/obj.o src/std/random.o src/std/regexp.o \
src/std/socket.o src/std/string.o src/std/sys.o src/std/types.o src/std/ucs2.o src/std/thread.o src/std/process.o \
src/std/track.o
HL = src/code.o src/jit.o src/main.o src/module.o src/debugger.o src/profile.o
FMT_INCLUDE = -I include/mikktspace -I include/minimp3
FMT = libs/fmt/fmt.o libs/fmt/sha1.o include/mikktspace/mikktspace.o libs/fmt/mikkt.o libs/fmt/dxt.o
SDL = libs/sdl/sdl.o libs/sdl/gl.o
OPENAL = libs/openal/openal.o
SSL = libs/ssl/ssl.o
ifdef SSL_STATIC
SSL += include/mbedtls/library/aes.o include/mbedtls/library/aesce.o include/mbedtls/library/aesni.o \
include/mbedtls/library/aria.o include/mbedtls/library/asn1parse.o include/mbedtls/library/asn1write.o \
include/mbedtls/library/base64.o include/mbedtls/library/bignum.o include/mbedtls/library/bignum_core.o \
include/mbedtls/library/bignum_mod.o include/mbedtls/library/bignum_mod_raw.o \
include/mbedtls/library/block_cipher.o include/mbedtls/library/camellia.o include/mbedtls/library/ccm.o \
include/mbedtls/library/chacha20.o include/mbedtls/library/chachapoly.o include/mbedtls/library/cipher.o \
include/mbedtls/library/cipher_wrap.o include/mbedtls/library/cmac.o include/mbedtls/library/constant_time.o \
include/mbedtls/library/ctr_drbg.o include/mbedtls/library/debug.o include/mbedtls/library/des.o \
include/mbedtls/library/dhm.o include/mbedtls/library/ecdh.o include/mbedtls/library/ecdsa.o \
include/mbedtls/library/ecjpake.o include/mbedtls/library/ecp.o include/mbedtls/library/ecp_curves.o \
include/mbedtls/library/ecp_curves_new.o include/mbedtls/library/entropy.o include/mbedtls/library/entropy_poll.o \
include/mbedtls/library/error.o include/mbedtls/library/gcm.o include/mbedtls/library/hkdf.o \
include/mbedtls/library/hmac_drbg.o include/mbedtls/library/lmots.o include/mbedtls/library/lms.o \
include/mbedtls/library/md.o include/mbedtls/library/md5.o include/mbedtls/library/memory_buffer_alloc.o \
include/mbedtls/library/mps_reader.o include/mbedtls/library/mps_trace.o include/mbedtls/library/net_sockets.o \
include/mbedtls/library/nist_kw.o include/mbedtls/library/oid.o include/mbedtls/library/padlock.o \
include/mbedtls/library/pem.o include/mbedtls/library/pk.o include/mbedtls/library/pk_ecc.o \
include/mbedtls/library/pk_wrap.o include/mbedtls/library/pkcs12.o include/mbedtls/library/pkcs5.o \
include/mbedtls/library/pkcs7.o include/mbedtls/library/pkparse.o include/mbedtls/library/pkwrite.o \
include/mbedtls/library/platform.o include/mbedtls/library/platform_util.o include/mbedtls/library/poly1305.o \
include/mbedtls/library/psa_crypto.o include/mbedtls/library/psa_crypto_aead.o include/mbedtls/library/psa_crypto_cipher.o \
include/mbedtls/library/psa_crypto_client.o include/mbedtls/library/psa_crypto_driver_wrappers_no_static.o \
include/mbedtls/library/psa_crypto_ecp.o include/mbedtls/library/psa_crypto_ffdh.o \
include/mbedtls/library/psa_crypto_hash.o include/mbedtls/library/psa_crypto_mac.o \
include/mbedtls/library/psa_crypto_pake.o include/mbedtls/library/psa_crypto_rsa.o \
include/mbedtls/library/psa_crypto_se.o include/mbedtls/library/psa_crypto_slot_management.o \
include/mbedtls/library/psa_crypto_storage.o include/mbedtls/library/psa_its_file.o \
include/mbedtls/library/psa_util.o include/mbedtls/library/ripemd160.o include/mbedtls/library/rsa.o \
include/mbedtls/library/rsa_alt_helpers.o include/mbedtls/library/sha1.o include/mbedtls/library/sha256.o \
include/mbedtls/library/sha3.o include/mbedtls/library/sha512.o include/mbedtls/library/ssl_cache.o \
include/mbedtls/library/ssl_ciphersuites.o include/mbedtls/library/ssl_client.o include/mbedtls/library/ssl_cookie.o \
include/mbedtls/library/ssl_debug_helpers_generated.o include/mbedtls/library/ssl_msg.o \
include/mbedtls/library/ssl_ticket.o include/mbedtls/library/ssl_tls.o include/mbedtls/library/ssl_tls12_client.o \
include/mbedtls/library/ssl_tls12_server.o include/mbedtls/library/ssl_tls13_client.o \
include/mbedtls/library/ssl_tls13_generic.o include/mbedtls/library/ssl_tls13_keys.o \
include/mbedtls/library/ssl_tls13_server.o include/mbedtls/library/threading.o include/mbedtls/library/timing.o \
include/mbedtls/library/version.o include/mbedtls/library/version_features.o include/mbedtls/library/x509.o \
include/mbedtls/library/x509_create.o include/mbedtls/library/x509_crl.o include/mbedtls/library/x509_crt.o \
include/mbedtls/library/x509_csr.o include/mbedtls/library/x509write.o include/mbedtls/library/x509write_crt.o \
include/mbedtls/library/x509write_csr.o
SSL_CFLAGS = -fvisibility=hidden -I libs/ssl -I include/mbedtls/include -D MBEDTLS_USER_CONFIG_FILE=\"mbedtls_user_config.h\"
else
SSL_LDLIBS = -lmbedtls -lmbedx509 -lmbedcrypto
endif
UV = libs/uv/uv.o
UI = libs/ui/ui_stub.o
MYSQL = libs/mysql/socket.o libs/mysql/sha1.o libs/mysql/my_proto.o libs/mysql/my_api.o libs/mysql/mysql.o
SQLITE = libs/sqlite/sqlite.o
LIB = ${PCRE} ${RUNTIME} ${STD}
BOOT = src/_main.o
UNAME := $(shell uname)
# Cygwin
ifeq ($(OS),Windows_NT)
LIBFLAGS += -Wl,--export-all-symbols
LIBEXT = dll
RELEASE_NAME=win
# VS variables are for packaging Visual Studio builds
VS_RUNTIME_LIBRARY ?= c:/windows/system32/vcruntime140.dll
ifeq ($(MARCH),32)
CFLAGS += -msse2 -mfpmath=sse
CC=i686-pc-cygwin-gcc
BUILD_DIR = Release
VS_SDL_LIBRARY ?= include/sdl/lib/x86/SDL2.dll
VS_OPENAL_LIBRARY ?= include/openal/bin/Win32/soft_oal.dll
else
BUILD_DIR = x64/Release
VS_SDL_LIBRARY ?= include/sdl/lib/x64/SDL2.dll
VS_OPENAL_LIBRARY ?= include/openal/bin/Win64/soft_oal.dll
endif
else ifeq ($(UNAME),Darwin)
# Mac
LIBEXT=dylib
BPREFIX := $(shell brew --prefix)
BREW_LIBJPEG := $(shell brew --prefix libjpeg-turbo)
BREW_SDL2 := $(shell brew --prefix sdl2)
BREW_JPEGTURBO := $(shell brew --prefix jpeg-turbo)
BREW_VORBIS := $(shell brew --prefix libvorbis)
BREW_OPENAL := $(shell brew --prefix openal-soft)
BREW_MBEDTLS := $(shell brew --prefix mbedtls)
BREW_LIBPNG := $(shell brew --prefix libpng)
BREW_LIBOGG := $(shell brew --prefix libogg)
BREW_LIBUV := $(shell brew --prefix libuv)
CFLAGS += -m$(MARCH) -I include -I $(BREW_LIBJPEG)/include \
-I $(BREW_JPEGTURBO)/include -I $(BREW_SDL2)/include -I $(BREW_VORBIS)/include \
-I $(BREW_MBEDTLS)/include -I $(BREW_LIBPNG)/include -I $(BREW_LIBOGG)/include \
-I $(BREW_LIBUV)/include \
-I $(BREW_OPENAL)/include -Dopenal_soft -DGL_SILENCE_DEPRECATION
LFLAGS += -Wl,-export_dynamic
CFLAGS += -m$(MARCH) -I include -I /usr/local/include -I /usr/local/opt/libjpeg-turbo/include \
-I /usr/local/opt/jpeg-turbo/include -I /usr/local/opt/sdl2/include -I /usr/local/opt/libvorbis/include \
-I /usr/local/opt/openal-soft/include -Dopenal_soft -DGL_SILENCE_DEPRECATION
LFLAGS += -Wl,-export_dynamic -L/usr/local/lib
ifdef OSX_SDK
ISYSROOT = $(shell xcrun --sdk macosx$(OSX_SDK) --show-sdk-path)
CFLAGS += -isysroot $(ISYSROOT)
LFLAGS += -isysroot $(ISYSROOT)
endif
LIBFLAGS += -L$(BREW_LIBJPEG)/lib -L$(BREW_SDL2)/lib -L$(BREW_JPEGTURBO)/lib \
-L$(BREW_VORBIS)/lib -L$(BREW_OPENAL)/lib -L$(BREW_MBEDTLS)/lib \
-L$(BREW_LIBPNG)/lib -L$(BREW_LIBOGG)/lib -L$(BREW_LIBUV)/lib
LIBOPENGL = -framework OpenGL
LIBOPENAL = -lopenal
LIBSSL = -framework Security -framework CoreFoundation
RELEASE_NAME = osx
# Mac native debug
ifneq ($(ARCH),arm64)
HL_DEBUG = include/mdbg/mdbg.o include/mdbg/mach_excServer.o include/mdbg/mach_excUser.o
LIB += ${HL_DEBUG}
endif
CFLAGS += -arch $(ARCH)
LFLAGS += -arch $(ARCH)
LFLAGS += -rpath @executable_path -rpath $(INSTALL_LIB_DIR)
LIBFLAGS += -rpath @executable_path -rpath $(INSTALL_LIB_DIR)
LHL_LINK_FLAGS += -install_name @rpath/libhl.dylib
else
# Linux
CFLAGS += -m$(MARCH) -fPIC -pthread -fno-omit-frame-pointer
LFLAGS += -lm -Wl,-rpath,.:'$$ORIGIN':$(INSTALL_LIB_DIR) -Wl,--export-dynamic -Wl,--no-undefined
ifeq ($(MARCH),32)
CFLAGS += -I /usr/include/i386-linux-gnu -msse2 -mfpmath=sse
LIBFLAGS += -L/opt/libjpeg-turbo/lib
else
LIBFLAGS += -L/opt/libjpeg-turbo/lib64
endif
LIBOPENAL = -lopenal
LIBOPENGL = -lGL
RELEASE_NAME = linux
endif
ifdef MESA
LIBS += mesa
endif
ifdef DEBUG
CFLAGS += -g
endif
all: libhl libs
ifeq ($(ARCH),arm64)
$(warning HashLink vm is not supported on arm64, skipping)
else
all: hl
endif
install:
$(UNAME)==Darwin && ${MAKE} uninstall
ifneq ($(ARCH),arm64)
mkdir -p $(INSTALL_BIN_DIR)
cp hl $(INSTALL_BIN_DIR)
endif
mkdir -p $(INSTALL_LIB_DIR)
cp *.hdll $(INSTALL_LIB_DIR)
cp libhl.${LIBEXT} $(INSTALL_LIB_DIR)
mkdir -p $(INSTALL_INCLUDE_DIR)
cp src/hl.h src/hlc.h src/hlc_main.c $(INSTALL_INCLUDE_DIR)
uninstall:
rm -f $(INSTALL_BIN_DIR)/hl $(INSTALL_LIB_DIR)/libhl.${LIBEXT} $(INSTALL_LIB_DIR)/*.hdll
rm -f $(INSTALL_INCLUDE_DIR)/hl.h $(INSTALL_INCLUDE_DIR)/hlc.h $(INSTALL_INCLUDE_DIR)/hlc_main.c
libs: $(LIBS)
./include/pcre/%.o: include/pcre/%.c
${CC} ${CFLAGS} -o $@ -c $< ${PCRE_FLAGS}
src/std/regexp.o: src/std/regexp.c
${CC} ${CFLAGS} -o $@ -c $< ${PCRE_FLAGS}
libhl: ${LIB}
${CC} ${CFLAGS} -o libhl.$(LIBEXT) -m${MARCH} ${LIBFLAGS} ${LHL_LINK_FLAGS} -shared ${LIB} -lpthread -lm
hlc: ${BOOT}
${CC} ${CFLAGS} -o hlc ${BOOT} ${LFLAGS} ${EXTRA_LFLAGS}
hl: ${HL} libhl
${CC} ${CFLAGS} -o hl ${HL} ${LFLAGS} ${EXTRA_LFLAGS} ${HLFLAGS}
libs/fmt/%.o: libs/fmt/%.c
${CC} ${CFLAGS} -o $@ -c $< ${FMT_INCLUDE}
fmt: ${FMT} libhl
${CC} ${CFLAGS} -shared -o fmt.hdll ${FMT} ${LIBFLAGS} -L. -lhl -lpng $(LIBTURBOJPEG) -lz -lvorbisfile
sdl: ${SDL} libhl
${CC} ${CFLAGS} -shared -o sdl.hdll ${SDL} ${LIBFLAGS} -L. -lhl -lSDL2 $(LIBOPENGL)
openal: ${OPENAL} libhl
${CC} ${CFLAGS} -shared -o openal.hdll ${OPENAL} ${LIBFLAGS} -L. -lhl $(LIBOPENAL)
./include/mbedtls/%.o: ./include/mbedtls/%.c
${CC} ${CFLAGS} -o $@ -c $< ${SSL_CFLAGS}
# force rebuild ssl.o in case we mix SSL_STATIC with normal build
.PHONY: libs/ssl/ssl.o
libs/ssl/ssl.o: libs/ssl/ssl.c
${CC} ${CFLAGS} -o $@ -c $< ${SSL_CFLAGS}
ssl: ${SSL} libhl
${CC} ${CFLAGS} ${SSL_CFLAGS} -shared -o ssl.hdll ${SSL} ${LIBFLAGS} -L. -lhl ${SSL_LDLIBS} $(LIBSSL)
ui: ${UI} libhl
${CC} ${CFLAGS} -shared -o ui.hdll ${UI} ${LIBFLAGS} -L. -lhl
uv: ${UV} libhl
${CC} ${CFLAGS} -shared -o uv.hdll ${UV} ${LIBFLAGS} -L. -lhl -luv
mysql: ${MYSQL} libhl
${CC} ${CFLAGS} -shared -o mysql.hdll ${MYSQL} ${LIBFLAGS} -L. -lhl
sqlite: ${SQLITE} libhl
${CC} ${CFLAGS} -shared -o sqlite.hdll ${SQLITE} ${LIBFLAGS} -L. -lhl -lsqlite3
mesa:
(cd libs/mesa && ${MAKE})
release: release_prepare release_$(RELEASE_NAME)
release_haxelib:
${MAKE} HLIB=hashlink release_haxelib_package
${MAKE} HLIB=directx release_haxelib_package
${MAKE} HLIB=sdl release_haxelib_package
${MAKE} HLIB=openal release_haxelib_package
ifeq ($(HLIB),hashlink)
HLDIR=other/haxelib
HLPACK=templates hlmem memory.hxml Run.hx
else
HLDIR=libs/$(HLIB)
ifeq ($(HLIB),directx)
HLPACK=dx *.h *.c *.cpp
else
HLPACK=$(HLIB) *.h *.c
endif
endif
release_haxelib_package:
rm -rf $(HLIB)_release
mkdir $(HLIB)_release
(cd $(HLDIR) && cp -R $(HLPACK) haxelib.json $(CURDIR)/$(HLIB)_release | true)
zip -r $(HLIB).zip $(HLIB)_release
haxelib submit $(HLIB).zip
rm -rf $(HLIB)_release
BUILD_DIR ?= .
PACKAGE_NAME = $(eval PACKAGE_NAME := hashlink-$(shell $(BUILD_DIR)/hl --version)-$(RELEASE_NAME))$(PACKAGE_NAME)
release_prepare:
rm -rf $(PACKAGE_NAME)
mkdir $(PACKAGE_NAME)
mkdir $(PACKAGE_NAME)/include
cp src/hl.h src/hlc.h src/hlc_main.c $(PACKAGE_NAME)/include
release_win:
cp $(BUILD_DIR)/{hl.exe,libhl.dll,*.hdll,*.lib} $(PACKAGE_NAME)
cp $(VS_RUNTIME_LIBRARY) $(PACKAGE_NAME)
cp $(VS_SDL_LIBRARY) $(PACKAGE_NAME)
cp $(VS_OPENAL_LIBRARY) $(PACKAGE_NAME)/OpenAL32.dll
# 7z switches: https://sevenzip.osdn.jp/chm/cmdline/switches/
7z a -spf -y -mx9 -bt $(PACKAGE_NAME).zip $(PACKAGE_NAME)
rm -rf $(PACKAGE_NAME)
release_linux release_osx:
ifeq ($(ARCH),arm64)
cp libhl.$(LIBEXT) *.hdll $(PACKAGE_NAME)
else
cp hl libhl.$(LIBEXT) *.hdll $(PACKAGE_NAME)
endif
tar -cvzf $(PACKAGE_NAME).tar.gz $(PACKAGE_NAME)
rm -rf $(PACKAGE_NAME)
codesign_osx:
sudo security delete-identity -c hl-cert || echo
echo "[req]\ndistinguished_name=codesign_dn\n[codesign_dn]\ncommonName=hl-cert\n[v3_req]\nkeyUsage=critical,digitalSignature\nextendedKeyUsage=critical,codeSigning" > openssl.cnf
openssl req -x509 -newkey rsa:4096 -keyout key.pem -nodes -days 365 -subj '/CN=hl-cert' -outform der -out cert.cer -extensions v3_req -config openssl.cnf
sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain cert.cer
sudo security import key.pem -k /Library/Keychains/System.keychain -A
codesign --entitlements other/osx/entitlements.xml -fs hl-cert hl
rm key.pem cert.cer openssl.cnf
.SUFFIXES : .c .o
.c.o :
${CC} ${CFLAGS} -o $@ -c $<
clean_o:
rm -f ${STD} ${BOOT} ${RUNTIME} ${PCRE} ${HL} ${FMT} ${SDL} ${SSL} ${OPENAL} ${UI} ${UV} ${MYSQL} ${SQLITE} ${HL_DEBUG}
clean: clean_o
rm -f hl hl.exe libhl.$(LIBEXT) *.hdll
.PHONY: libhl hl hlc fmt sdl libs release