-
-
Notifications
You must be signed in to change notification settings - Fork 658
/
Makefile
270 lines (225 loc) · 9.14 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
# Haxe compiler Makefile
#
# - use 'make' to build all
# - use 'make haxe' to build only the compiler (not the libraries)
# - if you want to build quickly, install 'ocamlopt.opt' and change OCAMLOPT=ocamlopt.opt
#
# Windows users :
# - use 'make -f Makefile.win' to build for Windows
# - use 'make MSVC=1 -f Makefile.win' to build for Windows with OCaml/MSVC
#
.SUFFIXES : .ml .mli .cmo .cmi .cmx .mly
INSTALL_DIR=/usr/local
INSTALL_BIN_DIR=$(INSTALL_DIR)/bin
INSTALL_LIB_DIR=$(INSTALL_DIR)/lib/haxe
INSTALL_STD_DIR=$(INSTALL_DIR)/share/haxe/std
PACKAGE_OUT_DIR=out
INSTALLER_TMP_DIR=installer
PACKAGE_SRC_EXTENSION=.tar.gz
MAKEFILENAME?=Makefile
PLATFORM?=unix
DUNE_COMMAND=dune
HAXE_OUTPUT=haxe
HAXELIB_OUTPUT=haxelib
PREBUILD_OUTPUT=prebuild
EXTENSION=
LFLAGS=
STATICLINK?=0
SYSTEM_NAME=Unknown
ifeq ($(OS),Windows_NT)
SYSTEM_NAME=Windows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
SYSTEM_NAME=Linux
endif
ifeq ($(UNAME_S),Darwin)
SYSTEM_NAME=Mac
endif
endif
# Configuration
ADD_REVISION?=0
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
COMMIT_SHA=$(shell git rev-parse --short HEAD)
COMMIT_DATE=$(shell \
if [ "$$(uname)" = "Darwin" ]; then \
date -u -r $$(git show -s --format=%ct HEAD) +%Y%m%d%H%M%S; \
else \
date -u -d @$$(git show -s --format=%ct HEAD) +%Y%m%d%H%M%S; \
fi \
)
PACKAGE_FILE_NAME=haxe_$(COMMIT_DATE)_$(COMMIT_SHA)
HAXE_VERSION=$(shell $(CURDIR)/$(HAXE_OUTPUT) -version 2>&1 | awk '{print $$1;}')
HAXE_VERSION_SHORT=$(shell echo "$(HAXE_VERSION)" | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+")
NEKO_VERSION=2.4.0-rc.1
NEKO_MAJOR_VERSION=$(shell echo "$(NEKO_VERSION)" | grep -oE "^[0-9]+")
NEKO_VERSION_TAG=v$(shell echo "$(NEKO_VERSION)" | sed "s/\./-/g")
ifneq ($(STATICLINK),0)
LIB_PARAMS= -cclib '-Wl,-Bstatic -lpcre2-8 -lz -lmbedtls -lmbedx509 -lmbedcrypto -Wl,-Bdynamic '
else
LIB_PARAMS?= -cclib -lpcre2-8 -cclib -lz -cclib -lmbedtls -cclib -lmbedx509 -cclib -lmbedcrypto
endif
ifeq ($(SYSTEM_NAME),Mac)
LIB_PARAMS+= -cclib '-framework Security -framework CoreFoundation'
endif
all: haxe tools
haxe:
$(DUNE_COMMAND) build --workspace dune-workspace.dev src-prebuild/prebuild.exe
_build/default/src-prebuild/prebuild.exe libparams $(LIB_PARAMS) > lib.sexp
_build/default/src-prebuild/prebuild.exe version "$(ADD_REVISION)" "$(BRANCH)" "$(COMMIT_SHA)" > src/compiler/version.ml
$(DUNE_COMMAND) build --workspace dune-workspace.dev src/haxe.exe
cp -f _build/default/src/haxe.exe ./"$(HAXE_OUTPUT)"
plugin: haxe
$(DUNE_COMMAND) build --workspace dune-workspace.dev plugins/$(PLUGIN)/$(PLUGIN).cmxs
mkdir -p plugins/$(PLUGIN)/cmxs/$(SYSTEM_NAME)
cp -f _build/default/plugins/$(PLUGIN)/$(PLUGIN).cmxs plugins/$(PLUGIN)/cmxs/$(SYSTEM_NAME)/plugin.cmxs
kill_exe_win:
ifdef SYSTEMROOT
-@taskkill /F /IM haxe.exe 2>/dev/null
endif
# Only use if you have only changed gencpp.ml
quickcpp: build_src build_pass_4 copy_haxetoolkit
CPP_OS := $(shell uname)
ifeq ($(CPP_OS),Linux)
copy_haxetoolkit:
sudo cp haxe /usr/bin/haxe
else
copy_haxetoolkit: /cygdrive/c/HaxeToolkit/haxe/haxe.exe
/cygdrive/c/HaxeToolkit/haxe/haxe.exe:haxe.exe
cp $< $@
endif
ifeq ($(SYSTEM_NAME),Mac)
# This assumes that haxelib and neko will both be installed into INSTALL_DIR,
# which is the case when installing using the mac installer package
HAXELIB_LFLAGS= -Wl,-rpath,$(INSTALL_DIR)/lib
endif
haxelib_unix:
cd $(CURDIR)/extra/haxelib_src && \
HAXE_STD_PATH=$(CURDIR)/std $(CURDIR)/$(HAXE_OUTPUT) client.hxml && \
nekotools boot -c run.n
$(CC) $(CURDIR)/extra/haxelib_src/run.c -o $(HAXELIB_OUTPUT) -lneko $(HAXELIB_LFLAGS)
# haxelib should depends on haxe, but we don't want to do that...
ifeq ($(SYSTEM_NAME),Windows)
haxelib: haxelib_$(PLATFORM)
else
haxelib: haxelib_unix
endif
tools: haxelib
install: uninstall
mkdir -p "$(DESTDIR)$(INSTALL_BIN_DIR)"
cp $(HAXE_OUTPUT) $(HAXELIB_OUTPUT) "$(DESTDIR)$(INSTALL_BIN_DIR)"
mkdir -p "$(DESTDIR)$(INSTALL_STD_DIR)"
cp -r std/* "$(DESTDIR)$(INSTALL_STD_DIR)"
uninstall:
rm -rf $(DESTDIR)$(INSTALL_BIN_DIR)/$(HAXE_OUTPUT) $(DESTDIR)$(INSTALL_BIN_DIR)/$(HAXELIB_OUTPUT)
if [ -d "$(DESTDIR)$(INSTALL_LIB_DIR)/lib" ] && find "$(DESTDIR)$(INSTALL_LIB_DIR)/lib" -mindepth 1 -print -quit | grep -q .; then \
echo "The local haxelib repo at $(DESTDIR)$(INSTALL_LIB_DIR)/lib will not be removed. Remove it manually if you want."; \
find $(DESTDIR)$(INSTALL_LIB_DIR)/ ! -name 'lib' -mindepth 1 -maxdepth 1 -exec rm -rf {} +; \
else \
rm -rf $(DESTDIR)$(INSTALL_LIB_DIR); \
fi
rm -rf $(DESTDIR)$(INSTALL_STD_DIR)
opam_install:
opam install camlp5 ocamlfind dune --yes
haxe_deps:
opam pin add haxe . --no-action
opam install haxe --deps-only --yes
# Package
package_env: opam_install haxe_deps
package_src:
mkdir -p $(PACKAGE_OUT_DIR)
# use git-archive-all since we have submodules
# https://github.com/Kentzo/git-archive-all
curl -s https://raw.githubusercontent.com/Kentzo/git-archive-all/1.15/git_archive_all.py -o extra/git_archive_all.py
python extra/git_archive_all.py $(PACKAGE_OUT_DIR)/$(PACKAGE_FILE_NAME)_src$(PACKAGE_SRC_EXTENSION)
package_unix:
mkdir -p $(PACKAGE_OUT_DIR)
rm -rf $(PACKAGE_FILE_NAME) $(PACKAGE_FILE_NAME).tar.gz
# Copy the package contents to $(PACKAGE_FILE_NAME)
mkdir -p $(PACKAGE_FILE_NAME)
cp -r $(HAXE_OUTPUT) $(HAXELIB_OUTPUT) std extra/LICENSE.txt extra/CONTRIB.txt extra/CHANGES.txt $(PACKAGE_FILE_NAME)
# archive
tar -zcf $(PACKAGE_OUT_DIR)/$(PACKAGE_FILE_NAME)_bin.tar.gz $(PACKAGE_FILE_NAME)
rm -r $(PACKAGE_FILE_NAME)
package_bin: package_$(PLATFORM)
xmldoc:
cd extra && \
$(CURDIR)/$(HAXELIB_OUTPUT) newrepo && \
$(CURDIR)/$(HAXELIB_OUTPUT) git hxcpp https://github.com/HaxeFoundation/hxcpp && \
$(CURDIR)/$(HAXELIB_OUTPUT) git hxjava https://github.com/HaxeFoundation/hxjava && \
PATH="$(CURDIR):$(PATH)" $(CURDIR)/$(HAXE_OUTPUT) doc.hxml
$(INSTALLER_TMP_DIR):
mkdir -p $(INSTALLER_TMP_DIR)
# Can be 'universal', 'arm64', or 'x86_64'
ifndef PACKAGE_INSTALLER_MAC_ARCH
PACKAGE_INSTALLER_MAC_ARCH:=$(shell uname -m)
endif
$(INSTALLER_TMP_DIR)/neko-osx.tar.gz: $(INSTALLER_TMP_DIR)
NEKO_ARCH_SUFFIX=$$(if [ "$(PACKAGE_INSTALLER_MAC_ARCH)" = "x86_64" ]; then \
echo 64; \
else \
echo "-$(PACKAGE_INSTALLER_MAC_ARCH)"; \
fi); \
wget -nv https://github.com/HaxeFoundation/neko/releases/download/$(NEKO_VERSION_TAG)/neko-$(NEKO_VERSION)-osx$$NEKO_ARCH_SUFFIX.tar.gz -O installer/neko-osx.tar.gz
# Installer
package_installer_mac: $(INSTALLER_TMP_DIR)/neko-osx.tar.gz package_unix
$(eval OUTFILE := $(shell pwd)/$(PACKAGE_OUT_DIR)/$(PACKAGE_FILE_NAME)_installer.tar.gz)
$(eval PACKFILE := $(shell pwd)/$(PACKAGE_OUT_DIR)/$(PACKAGE_FILE_NAME)_bin.tar.gz)
$(eval VERSION := $(shell $(CURDIR)/$(HAXE_OUTPUT) -version 2>&1))
bash -c "rm -rf $(INSTALLER_TMP_DIR)/{resources,pkg,tgz,haxe.tar.gz}"
mkdir $(INSTALLER_TMP_DIR)/resources
# neko - unpack to change the dir name
cd $(INSTALLER_TMP_DIR)/resources && tar -zxvf ../neko-osx.tar.gz
mv $(INSTALLER_TMP_DIR)/resources/neko* $(INSTALLER_TMP_DIR)/resources/neko
cd $(INSTALLER_TMP_DIR)/resources && tar -zcvf neko.tar.gz neko
# haxe - unpack to change the dir name
cd $(INSTALLER_TMP_DIR)/resources && tar -zxvf $(PACKFILE)
mv $(INSTALLER_TMP_DIR)/resources/haxe* $(INSTALLER_TMP_DIR)/resources/haxe
cd $(INSTALLER_TMP_DIR)/resources && tar -zcvf haxe.tar.gz haxe
# scripts
cp -rf extra/mac-installer/* $(INSTALLER_TMP_DIR)/resources
sed -i '' 's/%%NEKO_VERSION%%/$(NEKO_VERSION)/g' $(INSTALLER_TMP_DIR)/resources/scripts/neko-postinstall.sh
sed -i '' 's/%%NEKO_MAJOR_VERSION%%/$(NEKO_MAJOR_VERSION)/g' $(INSTALLER_TMP_DIR)/resources/scripts/neko-postinstall.sh
cd $(INSTALLER_TMP_DIR)/resources && tar -zcvf scripts.tar.gz scripts
# installer structure
mkdir -p $(INSTALLER_TMP_DIR)/pkg
cd $(INSTALLER_TMP_DIR)/pkg && xar -xf ../resources/installer-structure.pkg .
mkdir $(INSTALLER_TMP_DIR)/tgz; mv $(INSTALLER_TMP_DIR)/resources/*.tar.gz $(INSTALLER_TMP_DIR)/tgz
cd $(INSTALLER_TMP_DIR)/tgz; find . | cpio -o --format odc | gzip -c > ../pkg/files.pkg/Payload
cd $(INSTALLER_TMP_DIR)/pkg/files.pkg && bash -c "INSTKB=$$(du -sk ../../tgz | awk '{print $$1;}'); \
du -sk ../../tgz; \
echo $$INSTKB ; \
INSTKBH=`expr $$INSTKB - 4`; \
echo $$INSTKBH ;\
sed -i '' 's/%%INSTKB%%/$$INSTKBH/g' PackageInfo ;\
sed -i '' 's/%%VERSION%%/$(VERSION)/g' PackageInfo ;\
sed -i '' 's/%%VERSTRING%%/$(VERSION)/g' PackageInfo ;\
sed -i '' 's/%%VERLONG%%/$(VERSION)/g' PackageInfo ;\
sed -i '' 's/%%NEKOVER%%/$(NEKO_VERSION)/g' PackageInfo ;\
cd .. ;\
sed -i '' 's/%%VERSION%%/$(VERSION)/g' Distribution ;\
sed -i '' 's/%%VERSTRING%%/$(VERSION)/g' Distribution ;\
sed -i '' 's/%%VERLONG%%/$(VERSION)/g' Distribution ;\
sed -i '' 's/%%NEKOVER%%/$(NEKO_VERSION)/g' Distribution ;\
sed -i '' 's/%%INSTKB%%/$$INSTKBH/g' Distribution"
# repackage
cd $(INSTALLER_TMP_DIR)/pkg; xar --compression none -cf ../$(PACKAGE_FILE_NAME).pkg *
# tar
cd $(INSTALLER_TMP_DIR); tar -zcvf $(OUTFILE) $(PACKAGE_FILE_NAME).pkg
# Clean
clean: clean_haxe clean_tools clean_package
clean_haxe:
rm -f -r _build $(HAXE_OUTPUT) $(PREBUILD_OUTPUT)
clean_tools:
rm -f $(HAXE_OUTPUT) $(PREBUILD_OUTPUT) $(HAXELIB_OUTPUT)
clean_package:
rm -rf $(PACKAGE_OUT_DIR)
FORCE:
# SUFFIXES
.ml.cmx:
$(CC_CMD)
.ml.cmo:
$(CC_CMD)
.PHONY: haxe haxelib
# our "all:" target doens't work in parallel mode
.NOTPARALLEL: