-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild
executable file
·409 lines (336 loc) · 11.5 KB
/
Build
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#!/usr/bin/make -f
#
# Configuration bootstrap, handy generator script
#
# $Id$
#
# Blame: Jordan Hrycaj <[email protected]>
# ---------------------------------------------------------------------------
# Configure options for compiler targets
# ---------------------------------------------------------------------------
NATIVE_DIST =
NATIVE_DEBUG = --enable-debug
I386_DIST =
I386_DEBUG = --enable-debug
WIN32_DIST =
WIN32_DEBUG = --enable-debug
WIN64_DIST =
WIN64_DEBUG = --enable-debug
MGW64_DIST =
MGW64_DEBUG = --enable-debug
MGW32_DIST =
MGW32_DEBUG = --enable-debug
PROFILE =
VALGRIND =
# ---------------------------------------------------------------------------
# Handy settings
# ---------------------------------------------------------------------------
# Local base for sub-systems
IMPORT = tools/import
BUILD_NIM = /bin/sh tools/sh/build-nim.sh $(IMPORT)
# Dependencies - must be set for non- wrapping/include mode
CONFIGURE = configure
# Dependencies - can be set for wrapping/include mode
# CUSTOM = .custom
BUILD = $(MAKE) -f Build$(CUSTOM)
SHELL = /bin/sh
MKDIR_P = mkdir -p
SED = sed
AWK = awk
NOTROOT = test x0 != "x`id|$(SED) 's/^[a-z]*=0(.*/0/'`"
USEROK = $(NOTROOT) || (echo Cannot be run as root; exit 1)
AUTOVS = .git/hooks/post-checkout
AUTOVS += .git/hooks/post-update
AUTOVS += .git/hooks/post-commit
VERSION = echo \\\#`(git describe --long 2>/dev/null||echo 0)`
# Check for debian installation
CHKDEB = dpkg-architecture
VFYDEB = $(CHKDEB)>/dev/null||(echo "*** Notice: not a Debian system";false)
# Check whether we can try cross compiling
MGW32OK = ( $(CHKDEB) && dpkg -s gcc-mingw-w64-i686|$(AWK) \
'$$1=="Status:"&&$$2=="install"{rc=1}END{exit rc!=1}' \
) >/dev/null 2>&1
MGW64OK = ( $(CHKDEB) && dpkg -s gcc-mingw-w64-x86-64|$(AWK) \
'$$1=="Status:"&&$$2=="install"{rc=1}END{exit rc!=1}' \
) >/dev/null 2>&1
# Applies to target tag "win##"
MGW32HO = --host=i686-w64-mingw32
MGW64HO = --host=x86_64-w64-mingw32
# Applies to mgwXX
MGW64T64 = --host=x86_64-w64-mingw32 \
--build=x86_64-w64-mingw32 --enable-cpu=64
MGW64T32 = --host=x86_64-w64-mingw32 \
--build=x86_64-w64-mingw32 --enable-cpu=32
# Applies to i386/amd64
NATIVE32 = --enable-cpu=32
NATIVE64 = --enable-cpu=64
# Support automake compatibility for older versions
AMKVERS = `automake --version|sed -e 's/.* \([0-9]*\.[0-9]*\).*/\1/' -eq`
# Build will generate a stub file
AUTOADD = NEWS README AUTHORS ChangeLog
# Extra delete with clobber target
CLOBBER = NEWS README INSTALL VERSION ChangeLog
CLOBBER += compile depcomp install-sh missing ltmain.sh libtool
CLOBBER += ar-lib configure config.* *.log *.m4
# manage list of sub-modules and paths
GITBRANCH = `git status|awk '{print $$NF;exit}'`
GITPULL = git pull origin $(GITBRANCH)
GITCHKOUT = git checkout $(GITBRANCH)
GITFETCH = git fetch --all
GITMODCFG = git config -f .gitmodules --get-regexp
GITSUBLST = `$(GITMODCFG) '^submodule\..*path$$'|\
sed -e 's/submodule\.//' -e 's/\.path//' -e 's/ /:/'`
# ---------------------------------------------------------------------------
# Start Makefile
# ---------------------------------------------------------------------------
help::
@echo "Usage: ./Build <target>"
@echo
@echo "with <target>: <admin> | <debugging> | <release>"
@echo
@echo " <admin>: nim[-lang]"
@echo " | conf[ig] -- create Configure script"
@echo " | update -- update VERSION file from git"
@echo " | pull -- pull from git repository"
@echo " | clean | distclean | clobber"
@echo
@echo " <debugging>: prof[ile] | valg[rind]"
@echo
@echo " <release>: <buildsys>"
@echo " | <linkage>"
@echo " | <buildsys>-<linkage>"
@echo
@echo " <buildsys>: native -- default, try your best :)"
@echo " | i386 | amd64 -- native variants"
@echo " | win32 | win64 -- MinGW cross compiling"
@echo " | mgw64 | mgw32 -- MinGW/64 variants on Windows"
@echo
@echo " <linkage>: dist -- set up default configuration"
@echo " | debug -- set up for debugging"
# ---------------------------------------------------------------------------
# General helper targets
# ---------------------------------------------------------------------------
.PHONY: package-configure
package-configure: $(CONFIGURE)
@echo "Target => $@"
@$(USEROK)
-test \! -f Makefile || $(MAKE) distclean
@$(MKDIR_P) m4lib
./configure $(ARGV)
# ---------------------------------------------------------------------------
# Cross compiling helper targets
# ---------------------------------------------------------------------------
.PHONY: native-configure win32-configure win64-configure mgw64-configure
native-configure: $(CONFIGURE)
@echo "Target => $@"
@$(BUILD) package-configure ARGV="$(ARGV)"
i386-configure: $(CONFIGURE)
@echo "Target => $@"
@$(BUILD) package-configure ARGV="$(ARGV) $(NATIVE32)"
amd64-configure: $(CONFIGURE)
@echo "Target => $@"
@$(BUILD) package-configure ARGV="$(ARGV) $(NATIVE64)"
win32-configure: $(CONFIGURE)
@echo "Target => $@"
@$(MGW32OK) && $(BUILD) package-configure ARGV="$(ARGV) $(MGW32HO)"
win64-configure: $(CONFIGURE)
@echo "Target => $@"
@$(MGW64OK) && $(BUILD) package-configure ARGV="$(ARGV) $(MGW64HO)"
mgw32-configure: $(CONFIGURE)
@echo "Target => $@"
@$(BUILD) package-configure ARGV="$(ARGV) $(MGW64T32)"
mgw64-configure: $(CONFIGURE)
@echo "Target => $@"
@$(BUILD) package-configure ARGV="$(ARGV) $(MGW64T64)"
# add more cross compiling recipies here
# ...
# ---------------------------------------------------------------------------
# Cross compiling targets
# ---------------------------------------------------------------------------
.PHONY: native-dist native-debug
.PHONY: i386-dist i386-debug
.PHONY: win32-dist win32-debug win64-dist win64-debug
.PHONY: mgw32-dist mgw32-debug mgw64-dist mgw64-debug
native-dist:
@echo "Target => $@"
@$(BUILD) native-configure ARGV="$(NATIVE_DIST)"
native-debug:
@echo "Target => $@"
@$(BUILD) native-configure ARGV="$(NATIVE_DEBUG)"
i386-dist:
@echo "Target => $@"
@$(BUILD) i386-configure ARGV="$(I386_DIST)"
i386-debug:
@echo "Target => $@"
@$(BUILD) i386-configure ARGV="$(I386_DEBUG)"
amd64-dist:
@echo "Target => $@"
@$(BUILD) amd64-configure ARGV="$(AMD64_DIST)"
amd64-debug:
@echo "Target => $@"
@$(BUILD) amd64-configure ARGV="$(AMD64_DEBUG)"
win32-dist:
@echo "Target => $@"
@$(BUILD) win32-configure ARGV="$(WIN32_DIST)"
win32-debug:
@echo "Target => $@"
@$(BUILD) win32-configure ARGV="$(WIN32_DEBUG)"
win64-dist:
@echo "Target => $@"
@$(BUILD) win64-configure ARGV="$(WIN64_DIST)"
win64-debug:
@echo "Target => $@"
@$(BUILD) win64-configure ARGV="$(WIN64_DEBUG)"
mgw32-dist:
@echo "Target => $@"
@$(BUILD) mgw32-configure ARGV="$(MGW32_DIST)"
mgw32-debug:
@echo "Target => $@"
@$(BUILD) mgw32-configure ARGV="$(MGW32_DEBUG)"
mgw64-dist:
@echo "Target => $@"
@$(BUILD) mgw64-configure ARGV="$(MGW64_DIST)"
mgw64-debug:
@echo "Target => $@"
@$(BUILD) mgw64-configure ARGV="$(MGW64_DEBUG)"
# add cross compiling recipies here
# ...
# ---------------------------------------------------------------------------
# Shortcuts, debugging
# ---------------------------------------------------------------------------
.PHONY: native i386 win32 win64 debug dist profile prof valgrind valg
native: native-dist
i386: i386-dist
amd64: amd64-dist
win32: win32-dist
win64: win64-dist
mgw64: mgw64-dist
mgw32: mgw32-dist
debug: native-debug
dist: native-dist
prof profile:
@echo "Target => $@"
@$(BUILD) package-configure ARGV="$(PROFILE)"
valg valgrind:
@echo "Target => $@"
@$(BUILD) package-configure ARGV="$(VALGRIND)"
# ---------------------------------------------------------------------------
# Configuration bootstrap
# ---------------------------------------------------------------------------
.PHONY: conf config
conf config: update configure
$(AUTOADD):
@echo Creating $@
@echo "# Placeholder file" >> $@
@echo "# $$""Id""$$" >> $@
amcompat.m4:
@echo Generating/updating $@
@f="tools/am/compat-$(AMKVERS)"; rm -f $@; \
if test -f "$$f"; then \
echo "Automake $(AMKVERS) compatibility mode" >&2; \
echo "m4_include([$$f])";\
else echo "# $$f"; fi >> $@
acinclude.m4: amcompat.m4
@echo Generating/updating $@
@rm -f $@
@echo "# date: `date`" >> $@
@echo "m4_include([VERSION])" >> $@
@echo "m4_include([amcompat.m4])" >> $@
@ls tools/ac/ac_*.m4|sed 's!.*!m4_include([&])!' >> $@
@echo "# End" >> $@
.PHONY: configure
configure conf/config.h.in: $(AUTOADD) \
configure.ac VERSION acinclude.m4 amcompat.m4
@$(USEROK)
$(MKDIR_P) conf m4lib
aclocal
autoheader
libtoolize --automake --copy
autoconf
automake --add-missing --copy
.PHONY: nim nim-lang nimlang
nim nim-lang nimlang:
@$(USEROK)
@if test \! -d $(IMPORT)/nim; then \
echo; echo ">>> Installing NIM"; echo; \
$(BUILD) force-nimlang; \
elif test \! -x $(IMPORT)/nim/bin/nim -o \
\! -x $(IMPORT)/nim/bin/nimgrep; then \
echo; echo ">>> Re-installing NIM"; echo; \
$(BUILD) force-nimlang; \
else \
echo; echo ">>> NIM is already installed"; echo; \
fi
.PHONY: update-nimlang
update-nimlang:
@$(USEROK)
$(BUILD_NIM)
.PHONY: force-nimlang
force-nimlang:
@$(USEROK)
@rm -rf $(IMPORT)/nim~ 2>/dev/null ||:
mv $(IMPORT)/nim $(IMPORT)/nim~ 2>/dev/null ||:
$(BUILD_NIM)
VERSION:
@$(USEROK)
@for f in . $(AUTOVS); do \
test $$f = . -o -f $$f && continue; \
test -d `dirname $$f` || continue; \
echo Creating $$f; { \
echo "#! /bin/sh"; \
echo 'rm -f $@'; \
echo '$(VERSION)>$@'; \
} >>$$f; \
chmod +x $$f; \
done
@rm -f $@
@$(VERSION) > $@
@echo "Current VERSION: `$(SED) s/\#// $@`"
.PHONY: update
update:
@$(USEROK)
@rm -f VERSION~
@$(VERSION) > VERSION~
@cmp -s VERSION~ VERSION||(rm -f VERSION;set -x;$(BUILD) VERSION)
@rm -f VERSION~
.PHONY: pull
pull:
@for m in $(GITSUBLST); do \
bra=$(GITBRANCH) ;\
mod=`expr "$$m" : '\([^:]*\)'` ;\
pth=`expr "$$m" : '[^:]*:\(.*\)'`;\
test -d "$$pth/.git" -o -s "$$pth/.git" || ( \
pat="submodule.$$mod.url" ;\
url=`$(GITMODCFG) "^$$pat"|awk '{print $$NF;exit}'` ;\
(set -x; git clone -b $$bra $$url $$pth)) || exit ;\
(cd "$$pth" && \
$(GITCHKOUT) && $(GITPULL) && $(GITFETCH)) || exit ;\
done
@$(GITPULL) && $(GITFETCH)
# ---------------------------------------------------------------------------
# Clean up
# ---------------------------------------------------------------------------
.PHONY: clean distclean
clean distclean:
-test \! -f Makefile || $(MAKE) $@
rm -rf autom4te.cache
.PHONY: clobber
clobber:
@$(USEROK)
-test \! -f Makefile || $(MAKE) distclean
-test \! -f config.status || $(SHELL) config.status
@find . -type f -name Makefile.am -print | while read f; do \
case $$f in */private/*)continue;esac; \
d=`dirname $$f`; \
(set -x;rm -f $$d/Makefile $$d/Makefile.in); \
done
@find . -type f -name \*~ -print | while read f; do \
(set -x;rm -f $$f); \
done
rm -rf m4lib autom4te.cache cache $(IMPORT) conf/pkgs
rm -f conf/* $(CLOBBER) VERSION test-driver */nim.cfg
rmdir conf 2>/dev/null || :
(find . -type d -name nimcache -print | xargs rm -rf) || :
# ---------------------------------------------------------------------------
# End
# ---------------------------------------------------------------------------