-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
441 lines (396 loc) · 12.8 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
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
## Copyright (C) 2009,2011,2013 Matthew Fluet.
# Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
# Jagannathan, and Stephen Weeks.
# Copyright (C) 1997-2000 NEC Research Institute.
#
# MLton is released under a BSD-style license.
# See the file MLton-LICENSE for details.
##
export TARGET := self
export TARGET_ARCH := $(shell bin/host-arch)
export TARGET_OS := $(shell bin/host-os)
ROOT := $(shell pwd)
BUILD := $(ROOT)/build
SRC := $(ROOT)
BIN := $(BUILD)/bin
LIB := $(BUILD)/lib
INC := $(LIB)/include
COMP := $(SRC)/mlton
RUN := $(SRC)/runtime
MLTON := $(BIN)/mlton
AOUT := mlton-compile
ifeq (mingw, $(TARGET_OS))
EXE := .exe
else
EXE :=
endif
MLBPATHMAP := $(LIB)/mlb-path-map
SPEC := package/rpm/mlton.spec
LEX := mllex
PROF := mlprof
YACC := mlyacc
NLFFIGEN := mlnlffigen
PATH := $(BIN):$(SRC)/bin:$(shell echo $$PATH)
CP := /bin/cp -fpR
GZIP := gzip --force --best
RANLIB := ranlib
# If we're compiling with another version of MLton, then we want to do
# another round of compilation so that we get a MLton built without
# stubs.
ifeq (other, $(shell if [ ! -x "$(BIN)/mlton" ]; then echo other; fi))
BOOTSTRAP_OTHER:=true
else
BOOTSTRAP_OTHER:=false
endif
ifeq ($(origin VERSION), undefined)
VERSION := $(shell date +%Y%m%d)
endif
ifeq ($(origin RELEASE), undefined)
RELEASE := 1
endif
.PHONY: all
all:
$(MAKE) docs all-no-docs
.PHONY: all-no-docs
all-no-docs:
$(MAKE) dirs runtime compiler basis-no-check script mlbpathmap constants libraries tools
# Remove $(AOUT) so that the $(MAKE) compiler below will remake MLton.
# We also want to re-run the just-built tools (mllex and mlyacc)
# because they may be better than those that were used for the first
# round of compilation. So, we clean out the front end.
ifeq (true, $(BOOTSTRAP_OTHER))
rm -f "$(COMP)/$(AOUT)$(EXE)"
$(MAKE) -C "$(COMP)/front-end" clean
endif
$(MAKE) compiler basis
@echo 'Build of MLton succeeded.'
.PHONY: basis-no-check
basis-no-check:
mkdir -p "$(LIB)/sml"
rm -rf "$(LIB)/sml/basis"
$(CP) "$(SRC)/basis-library/." "$(LIB)/sml/basis"
find "$(LIB)/sml/basis" -name .gitignore | xargs rm -rf
.PHONY: basis
basis:
$(MAKE) basis-no-check
@echo 'Type checking basis.'
"$(MLTON)" -disable-ann deadCode \
-stop tc \
'$$(SML_LIB)/basis/libs/all.mlb' \
>/dev/null
.PHONY: bootstrap-nj
bootstrap-nj:
$(MAKE) smlnj-mlton
$(MAKE) all
.PHONY: clean
clean:
bin/clean
.PHONY: clean-git
clean-git:
find . -type d -name .git | xargs rm -rf
.PHONY: compiler
compiler:
$(MAKE) -C "$(COMP)"
$(CP) "$(COMP)/$(AOUT)$(EXE)" "$(LIB)/"
.PHONY: constants
constants:
@echo 'Creating constants file.'
"$(BIN)/mlton" -target "$(TARGET)" -build-constants true >tmp.c
"$(BIN)/mlton" -target "$(TARGET)" -output tmp tmp.c
./tmp >"$(LIB)/targets/$(TARGET)/constants"
rm -f tmp tmp.exe tmp.c
.PHONY: debugged
debugged:
$(MAKE) -C "$(COMP)" "AOUT=$(AOUT).debug" COMPILE_ARGS="-debug true -const 'Exn.keepHistory true' -profile-val true -const 'MLton.debug true' -drop-pass 'deepFlatten'"
$(CP) "$(COMP)/$(AOUT).debug" "$(LIB)/"
sed 's/mlton-compile/mlton-compile.debug/' < "$(MLTON)" > "$(MLTON).debug"
chmod a+x "$(MLTON).debug"
.PHONY: dirs
dirs:
mkdir -p "$(BIN)" "$(INC)"
mkdir -p "$(LIB)/targets/$(TARGET)/include"
mkdir -p "$(LIB)/targets/$(TARGET)/sml"
.PHONY: docs
docs: dirs
$(MAKE) -C "$(LEX)" docs
$(MAKE) -C "$(YACC)" docs
$(MAKE) -C doc/guide
LIBRARIES := ckit-lib cml mllpt-lib mlnlffi-lib mlrisc-lib mlyacc-lib smlnj-lib
TYPE_CHECK_LIBRARIES := ckit-lib cml mllpt-lib mlnlffi-lib mlrisc-lib mlyacc-lib
.PHONY: libraries-no-check
libraries-no-check:
mkdir -p "$(LIB)/sml"
cd "$(LIB)/sml" && rm -rf $(LIBRARIES)
$(MAKE) -C "$(SRC)/lib/ckit-lib"
$(MAKE) -C "$(SRC)/lib/mllpt-lib"
$(MAKE) -C "$(SRC)/lib/mlnlffi-lib"
$(MAKE) -C "$(SRC)/lib/mlrisc-lib"
$(MAKE) -C "$(SRC)/lib/smlnj-lib"
$(CP) "$(SRC)/lib/cml/." "$(LIB)/sml/cml"
$(CP) "$(SRC)/lib/ckit-lib/ckit/." "$(LIB)/sml/ckit-lib"
$(CP) "$(SRC)/lib/mlnlffi-lib/." "$(LIB)/sml/mlnlffi-lib"
$(CP) "$(SRC)/lib/mlrisc-lib/MLRISC/." "$(LIB)/sml/mlrisc-lib"
$(CP) "$(SRC)/lib/mllpt-lib/ml-lpt/lib/." "$(LIB)/sml/mllpt-lib"
$(CP) "$(SRC)/lib/mlyacc-lib/." "$(LIB)/sml/mlyacc-lib"
$(CP) "$(SRC)/lib/smlnj-lib/smlnj-lib/." "$(LIB)/sml/smlnj-lib"
find "$(LIB)/sml" -type d -name .cm | xargs rm -rf
find "$(LIB)/sml" -name .gitignore | xargs rm -rf
.PHONY: libraries
libraries:
$(MAKE) libraries-no-check
for f in $(TYPE_CHECK_LIBRARIES); do \
echo "Type checking $$f library."; \
"$(MLTON)" -disable-ann deadCode \
-stop tc \
'$$(SML_LIB)/'"$$f/$$f.mlb" \
>/dev/null; \
done
.PHONY: mlbpathmap
mlbpathmap:
touch "$(MLBPATHMAP)"
( echo 'MLTON_ROOT $$(LIB_MLTON_DIR)/sml'; \
echo 'SML_LIB $$(LIB_MLTON_DIR)/sml'; ) \
>>"$(MLBPATHMAP).tmp"
mv "$(MLBPATHMAP).tmp" "$(MLBPATHMAP)"
.PHONY: polyml-mlton
polyml-mlton:
$(MAKE) dirs runtime
$(MAKE) -C "$(COMP)" polyml-mlton
$(CP) "$(COMP)/mlton-polyml$(EXE)" "$(LIB)/"
$(MAKE) script basis-no-check mlbpathmap constants libraries-no-check
@echo 'Build of MLton succeeded.'
.PHONY: profiled
profiled:
for t in alloc count time; do \
$(MAKE) -C "$(COMP)" "AOUT=$(AOUT).$$t" \
COMPILE_ARGS="-profile $$t"; \
$(CP) "$(COMP)/$(AOUT).$$t" "$(LIB)/"; \
sed "s/mlton-compile/mlton-compile.$$t/" \
<"$(MLTON)" \
>"$(MLTON).$$t"; \
chmod a+x "$(MLTON).$$t"; \
done
.PHONY: runtime
runtime:
@echo 'Compiling MLton runtime system for $(TARGET).'
@echo Translate ./build/lib/targets/self/constants to include/gcstate-offsets.h
$(MAKE) -C runtime
$(CP) include/*.h "$(INC)/"
$(CP) runtime/*.a "$(LIB)/targets/$(TARGET)/"
$(CP) runtime/gen/sizes "$(LIB)/targets/$(TARGET)/"
$(CP) runtime/gen/c-types.sml "$(LIB)/targets/$(TARGET)/sml/"
echo "$(TARGET_OS)" > "$(LIB)/targets/$(TARGET)/os"
echo "$(TARGET_ARCH)" > "$(LIB)/targets/$(TARGET)/arch"
$(CP) runtime/gen/basis-ffi.sml \
basis-library/primitive/basis-ffi.sml
$(CP) runtime/*.h "$(INC)/"
mv "$(INC)/c-types.h" "$(LIB)/targets/$(TARGET)/include"
for d in basis basis/Real basis/Word gc platform util; do \
mkdir -p "$(INC)/$$d"; \
$(CP) runtime/$$d/*.h "$(INC)/$$d"; \
done
for x in "$(LIB)/targets/$(TARGET)"/*.a; do $(RANLIB) "$$x"; done
.PHONY: script
script:
$(CP) bin/mlton-script "$(MLTON)"
chmod a+x "$(MLTON)"
$(CP) "$(SRC)/bin/platform" "$(LIB)"
$(CP) "$(SRC)/bin/static-library" "$(LIB)"
ifeq (mingw, $(TARGET_OS))
$(CP) "$(SRC)/bin/static-library.bat" "$(LIB)"
endif
.PHONY: smlnj-mlton
smlnj-mlton:
$(MAKE) dirs runtime
$(MAKE) -C "$(COMP)" smlnj-mlton
smlnj_heap_suffix=`echo 'TextIO.output (TextIO.stdErr, SMLofNJ.SysInfo.getHeapSuffix ());' | sml 2>&1 1> /dev/null` && $(CP) "$(COMP)/mlton-smlnj.$$smlnj_heap_suffix" "$(LIB)/"
$(MAKE) script basis-no-check mlbpathmap constants libraries-no-check
@echo 'Build of MLton succeeded.'
.PHONY: smlnj-mlton-dual
smlnj-mlton-dual:
$(MAKE) SMLNJ_CM_SERVERS_NUM=2 smlnj-mlton
.PHONY: smlnj-mlton-quad
smlnj-mlton-quad:
$(MAKE) SMLNJ_CM_SERVERS_NUM=4 smlnj-mlton
.PHONY: traced
traced:
$(MAKE) -C "$(COMP)" "AOUT=$(AOUT).trace" COMPILE_ARGS="-const 'Exn.keepHistory true' -profile-val true -const 'MLton.debug true' -drop-pass 'deepFlatten'"
$(CP) "$(COMP)/$(AOUT).trace" "$(LIB)/"
sed 's/mlton-compile/mlton-compile.trace/' < "$(MLTON)" > "$(MLTON).trace"
chmod a+x "$(MLTON).trace"
.PHONY: tools
tools:
$(MAKE) -C "$(LEX)"
$(MAKE) -C "$(NLFFIGEN)"
$(MAKE) -C "$(PROF)"
$(MAKE) -C "$(YACC)"
$(CP) "$(LEX)/$(LEX)$(EXE)" \
"$(NLFFIGEN)/$(NLFFIGEN)$(EXE)" \
"$(PROF)/$(PROF)$(EXE)" \
"$(YACC)/$(YACC)$(EXE)" \
"$(BIN)/"
.PHONY: version
version:
@echo 'Instantiating version numbers.'
for f in \
"$(SPEC)" \
package/freebsd/Makefile \
mlton/control/version_sml.src \
doc/guide/conf/asciidoc-mlton.flags \
; do \
if grep -q 'MLTONVERSION' "$$f"; then \
sed "s/\(.*\)MLTONVERSION\(.*\)/\1$(VERSION)\2/" <"$$f" >z && \
mv z "$$f"; \
fi; \
done
if grep -q '^Release:$$' "$(SPEC)"; then \
sed <"$(SPEC)" >z "/^Release:/s;.*;Release: $(RELEASE);"; \
mv z "$(SPEC)"; \
fi
.PHONY: check
check:
./bin/regression -p part-1 -no-stop-onfail
./bin/regression -p part-2 -no-stop-onfail
./bin/regression -p part-3 -no-stop-onfail
./bin/regression -p part-4 -no-stop-onfail
./bin/regression -skip-parts -benchmark
# The TBIN and TLIB are where the files are going to be after installing.
# The DESTDIR and is added onto them to indicate where the Makefile actually
# puts them.
DESTDIR := $(CURDIR)/install
PREFIX := /usr
ifeq ($(findstring $(TARGET_OS), darwin freebsd solaris), $(TARGET_OS))
PREFIX := /usr/local
endif
ifeq ($(TARGET_OS), mingw)
PREFIX := /mingw
endif
prefix := $(PREFIX)
MAN_PREFIX_EXTRA :=
TBIN := $(DESTDIR)$(prefix)/bin
ULIB := lib/mlton
TLIB := $(DESTDIR)$(prefix)/$(ULIB)
TMAN := $(DESTDIR)$(prefix)$(MAN_PREFIX_EXTRA)/man/man1
TDOC := $(DESTDIR)$(prefix)/share/doc/mlton
ifeq ($(findstring $(TARGET_OS), solaris mingw), $(TARGET_OS))
TDOC := $(DESTDIR)$(prefix)/doc/mlton
endif
TEXM := $(TDOC)/examples
GZIP_MAN := true
ifeq ($(TARGET_OS), solaris)
GZIP_MAN := false
endif
.PHONY: install
install: install-no-strip install-strip
.PHONY: install-no-strip
install-no-strip: install-docs install-no-docs move-docs
MAN_PAGES := \
mllex.1 \
mlnlffigen.1 \
mlprof.1 \
mlton.1 \
mlyacc.1
.PHONY: install-no-docs
install-no-docs:
mkdir -p "$(TLIB)" "$(TBIN)" "$(TMAN)"
$(CP) "$(LIB)/." "$(TLIB)/"
sed "/^lib=/s;.*;lib='$(prefix)/$(ULIB)';" \
<"$(BIN)/mlton" >"$(TBIN)/mlton"
chmod a+x "$(TBIN)/mlton"
if [ -x "$(BIN)/mlton.trace" ]; then \
sed "/^lib=/s;.*;lib='$(prefix)/$(ULIB)';" \
<"$(BIN)/mlton.trace" >"$(TBIN)/mlton.trace"; \
chmod a+x "$(TBIN)/mlton.trace"; \
fi
if [ -x "$(BIN)/mlton.debug" ]; then \
sed "/^lib=/s;.*;lib='$(prefix)/$(ULIB)';" \
<"$(BIN)/mlton.debug" >"$(TBIN)/mlton.debug"; \
chmod a+x "$(TBIN)/mlton.debug"; \
fi
cd "$(BIN)" && $(CP) "$(LEX)$(EXE)" "$(NLFFIGEN)$(EXE)" \
"$(PROF)$(EXE)" "$(YACC)$(EXE)" "$(TBIN)/"
( cd "$(SRC)/man" && tar cf - $(MAN_PAGES)) | \
( cd "$(TMAN)/" && tar xf - )
if $(GZIP_MAN); then \
cd "$(TMAN)" && $(GZIP) $(MAN_PAGES); \
fi
.PHONY: install-strip
install-strip:
case "$(TARGET_OS)" in \
aix|cygwin|darwin|solaris) \
;; \
*) \
for f in "$(TLIB)/$(AOUT)$(EXE)" "$(TBIN)/$(LEX)$(EXE)" \
"$(TBIN)/$(NLFFIGEN)$(EXE)" "$(TBIN)/$(PROF)$(EXE)" \
"$(TBIN)/$(YACC)$(EXE)"; do \
strip --remove-section=.comment \
--remove-section=.note "$$f"; \
done \
esac
.PHONY: install-docs
install-docs:
mkdir -p "$(TDOC)"
( \
cd "$(SRC)/doc" && \
$(CP) changelog examples license README "$(TDOC)/" \
)
if [ -d "$(SRC)/doc/guide/localhost" ]; then \
$(CP) "$(SRC)/doc/guide/localhost" "$(TDOC)/guide"; \
fi
if [ -r "$(SRC)/doc/guide/mlton-guide.pdf" ]; then \
$(CP) "$(SRC)/doc/guide/mlton-guide.pdf" "$(TDOC)/"; \
fi
( \
cd "$(SRC)/util" && \
$(CP) cmcat cm2mlb "$(TDOC)/" \
)
for f in callcc command-line hello-world same-fringe signals \
size taut thread1 thread2 thread-switch timeout \
; do \
$(CP) "$(SRC)/regression/$$f.sml" "$(TEXM)/"; \
done
if [ -r "$(LEX)/$(LEX).pdf" ]; then \
$(CP) "$(LEX)/$(LEX).pdf" "$(TDOC)/"; \
fi
if [ -r "$(YACC)/$(YACC).pdf" ]; then \
$(CP) "$(YACC)/$(YACC).pdf" "$(TDOC)/"; \
fi
find "$(TDOC)/" -name .gitignore | xargs rm -rf
find "$(TEXM)/" -name .gitignore | xargs rm -rf
.PHONY: move-docs
move-docs: install-docs install-no-docs
cd "$(TLIB)/sml"; for i in *; do test -d "$(TDOC)/$$i" || mkdir -p "$(TDOC)/$$i"; done
cd "$(TLIB)/sml"; for i in */[Dd]oc; do mv "$$i" "$(TDOC)/$$i"; done
cd "$(TLIB)/sml"; for i in */README*; do mv "$$i" "$(TDOC)/$$i"; done
.PHONY: release
release: version
tar cvzf ../mlton-$(VERSION).src.tgz \
--exclude .git --exclude package \
--transform "s@^@mlton-$(VERSION)/@S" \
*
BSDSRC := /tmp/mlton-$(VERSION)
.PHONY: freebsd
freebsd:
$(MAKE) clean clean-git version
rm -rf "$(BSDSRC)"
mkdir -p "$(BSDSRC)"
( cd $(SRC) && tar -cpf - . ) | ( cd "$(BSDSRC)" && tar -xpf - )
cd /tmp && tar -cpf - mlton-$(VERSION) | \
$(GZIP) >/usr/ports/distfiles/mlton-$(VERSION)-$(RELEASE).freebsd.src.tgz
# do not change "make" to "$(MAKE)" in the following line
cd "$(BSDSRC)/package/freebsd" && MAINTAINER_MODE=yes make build-package
TOPDIR := 'TOPDIR-unset'
SOURCEDIR := $(TOPDIR)/SOURCES/mlton-$(VERSION)
.PHONY: rpms
rpms:
$(MAKE) clean clean-git version
mkdir -p "$(TOPDIR)"
cd "$(TOPDIR)" && mkdir -p BUILD RPMS/i386 SOURCES SPECS SRPMS
rm -rf "$(SOURCEDIR)"
mkdir -p "$(SOURCEDIR)"
( cd "$(SRC)" && tar -cpf - . ) | ( cd "$(SOURCEDIR)" && tar -xpf - )
$(CP) "$(SOURCEDIR)/$(SPEC)" "$(TOPDIR)/SPECS/mlton.spec"
( cd "$(TOPDIR)/SOURCES" && tar -cpf - mlton-$(VERSION) ) \
| $(GZIP) >"$(SOURCEDIR).tgz"
rm -rf "$(SOURCEDIR)"
rpm -ba --quiet --clean "$(TOPDIR)/SPECS/mlton.spec"