1 ## Copyright (C) 2010,2013,2016,2018 Matthew Fluet.
2 # Copyright (C) 1999-2009 Henry Cejtin, Matthew Fluet, Suresh
3 # Jagannathan, and Stephen Weeks.
4 # Copyright (C) 1997-2000 NEC Research Institute.
6 # MLton is released under a BSD-style license.
7 # See the file MLton-LICENSE for details.
13 BOOTSTRAP_MLTON_RUNTIME_ARGS
:=
14 BOOTSTRAP_MLTON_COMPILE_ARGS
:=
20 ######################################################################
21 ######################################################################
23 SRC
:= $(shell cd ..
&& pwd
)
27 PATH
:= $(BIN
):$(shell echo
$$PATH)
29 MLTON_VERSION
:= 20180207
31 HOST_ARCH
:= $(shell ..
/bin
/host-arch
)
32 HOST_OS
:= $(shell ..
/bin
/host-os
)
34 TARGET_ARCH
:= $(HOST_ARCH
)
35 TARGET_OS
:= $(HOST_OS
)
37 ######################################################################
39 ifeq (other
, $(shell if
[ ! -x
"$(BIN)/mlton" ]; then echo other
; fi
))
46 BOOTSTRAP_MLTON
:= mlton
48 MLTON_COMPILE_TYPECHECK_ARGS
:=
49 ifeq (false
, $(BOOTSTRAP
))
50 # Older versions of `mlton` may not support `sequenceNonUnit` or `warnUnused`.
51 MLTON_COMPILE_TYPECHECK_ARGS
+= -default-ann
'sequenceNonUnit warn'
52 MLTON_COMPILE_TYPECHECK_ARGS
+= -default-ann
'warnUnused true'
53 # MLTON_COMPILE_TYPECHECK_ARGS += -type-check true
56 ifeq (false
, $(BOOTSTRAP
))
57 MLTON_ACTUAL
:= $(MLTON
)
58 MLTON_RUNTIME_ARGS_ACTUAL
:= ram-slop
0.7 $(MLTON_RUNTIME_ARGS
)
59 MLTON_COMPILE_ARGS_ACTUAL
:= $(MLTON_COMPILE_TYPECHECK_ARGS
) $(MLTON_COMPILE_ARGS
)
61 MLTON_ACTUAL
:= $(BOOTSTRAP_MLTON
)
62 MLTON_RUNTIME_ARGS_ACTUAL
:= ram-slop
0.7 $(BOOTSTRAP_MLTON_RUNTIME_ARGS
)
63 MLTON_COMPILE_ARGS_ACTUAL
:= $(MLTON_COMPILE_TYPECHECK_ARGS
) $(BOOTSTRAP_MLTON_COMPILE_ARGS
)
66 ifeq (false
, $(BOOTSTRAP
))
67 # We're self-compiling, so don't use any stubs.
70 ifneq (, $(findstring $(HOST_OS
),cygwin mingw
))
71 # We're bootstrapping on Cygwin or MinGW; stubs define `spawn` in terms of
72 # `fork` and `fork` doesn't work on Cygwin or MinGW, so don't use any stubs.
75 # We're bootstrapping, so use stubs.
76 FILE
:= mlton-stubs.mlb
80 FRONT_END_SOURCES
:= \
81 front-end
/ml.
lex.sml \
82 front-end
/ml.grm.sig \
83 front-end
/ml.grm.sml \
84 front-end
/mlb.
lex.sml \
85 front-end
/mlb.grm.sig \
90 $(FRONT_END_SOURCES
) \
91 $(filter-out control
/version.sml
,$(shell if
[ -r
$(FILE
) ]; then mlton
-stop f
$(FILE
) |
$(GREP
) -v
" "; fi
))
96 control
/version.sml
: control
/version_sml.src
97 $(SED
) "s/MLTON_VERSION/$(MLTON_VERSION)/" \
98 < control
/version_sml.src \
101 front-end
/%.
lex.sml
: front-end
/%.
lex
102 $(MAKE
) -C front-end
$(<F
).sml
103 front-end
/%.grm.sig front-end
/%.grm.sml
: front-end
/%.grm
104 $(MAKE
) -C front-end
$(<F
).sig
$(<F
).sml
106 mlton-stubs.mlb
: $(shell mlton
-stop f ..
/lib
/stubs
/mlton-stubs
/sources.mlb
) $(shell mlton
-stop f mlton.mlb
)
108 echo
'$$(SML_LIB)/basis/unsafe.mlb'; \
109 echo
'$$(SML_LIB)/basis/sml-nj.mlb'; \
110 echo
'$$(SML_LIB)/basis/mlton.mlb'; \
111 echo
'$$(SML_LIB)/basis/basis.mlb'; \
112 mlton
-stop f mlton.mlb |
$(GREP
) -v
'mlb$$' |
$(GREP
) 'mlyacc'; \
113 mlton
-stop f ..
/lib
/stubs
/mlton-stubs
/sources.mlb | \
114 $(GREP
) -v
'mlb$$' | \
115 $(GREP
) 'mlton-stubs'; \
116 mlton
-stop f mlton.mlb | \
117 $(GREP
) -v
'mlb$$' | \
118 $(GREP
) -v
'sml/basis' | \
119 $(GREP
) -v
'targets' | \
120 $(GREP
) -v
'mlyacc'; \
123 MLTON_OUTPUT
:= mlton
124 $(MLTON_OUTPUT
): $(SOURCES
)
125 rm -f control
/version.sml
126 $(MAKE
) control
/version.sml
127 @echo
'Compiling mlton'
128 "$(MLTON_ACTUAL)" @MLton gc-summary
$(MLTON_RUNTIME_ARGS_ACTUAL
) -- \
129 -verbose
2 $(MLTON_COMPILE_ARGS_ACTUAL
) \
130 -target
$(TARGET
) -output
$(MLTON_OUTPUT
) $(FILE
)
133 def-use
: mlton.def-use
135 mlton.def-use
: $(SOURCES
)
136 "$(MLTON_ACTUAL)" @MLton
$(MLTON_RUNTIME_ARGS_ACTUAL
) -- \
137 -verbose
0 $(MLTON_COMPILE_ARGS_ACTUAL
) \
138 -stop tc
-prefer-abs-paths true
-show-def-use mlton.def-use \
146 # The following rebuilds the heap file for the SML/NJ compiled version of MLton.
149 SMLNJ_CM_SERVERS_NUM
:= 0
152 smlnj-mlton
: $(FRONT_END_SOURCES
)
153 rm -f control
/version.sml
154 $(MAKE
) control
/version.sml
156 echo
'SMLofNJ.Internals.GC.messages false;'; \
157 echo
'#set CM.Control.verbose false;'; \
158 echo
'#set CM.Control.warn_obsolete false;'; \
159 echo
'Control.polyEqWarn := false;'; \
161 echo
'fun loop 0 = () | loop n = (CM.Server.start {cmd = (CommandLine.name (), ["@CMslave"]), name = "server" ^ (Int.toString n), pathtrans = NONE, pref = 0}; loop (n - 1));'; \
163 echo
'val _ = loop $(SMLNJ_CM_SERVERS_NUM);'; \
165 echo
'if (CM.make "mlton-smlnj.cm") handle _ => false'; \
167 echo
' else OS.Process.exit OS.Process.failure;'; \
168 echo
'SMLofNJ.exportFn("mlton-smlnj",Main.main);' \
172 # The following rebuilds the executable file for the Poly/ML compiled version of
178 polyml-mlton
: mlton-polyml.use
$(FRONT_END_SOURCES
)
179 rm -f control
/version.sml
180 $(MAKE
) control
/version.sml
182 echo
'use "mlton-polyml.use";'; \
183 echo
'PolyML.export("mlton-polyml", Main.mainWrapped);'; \
185 $(CC
) -o mlton-polyml mlton-polyml.o
-lpolymain
-lpolyml
188 mlton-polyml.use
: ..
/lib
/stubs
/basis-stubs-for-polyml
/sources.use ..
/lib
/stubs
/mlton-stubs-for-polyml
/sources.use
$(shell mlton
-stop f ..
/lib
/stubs
/mlton-stubs
/sources.mlb
) $(filter-out control
/version.sml
,$(shell mlton
-stop f mlton.mlb
))
190 cat ..
/lib
/stubs
/basis-stubs-for-polyml
/sources.use | \
191 $(SED
) 's|use "\(.*\)";|../lib/stubs/basis-stubs-for-polyml/\1|'; \
192 mlton
-stop f mlton.mlb |
$(GREP
) -v
'mlb$$' |
$(GREP
) 'mlyacc'; \
193 cat ..
/lib
/stubs
/mlton-stubs-for-polyml
/sources.use | \
194 $(SED
) 's|use "\(.*\)";|../lib/stubs/mlton-stubs-for-polyml/\1|'; \
195 mlton
-stop f ..
/lib
/stubs
/mlton-stubs
/sources.mlb | \
196 $(GREP
) -v
'mlb$$' | \
197 $(GREP
) 'mlton-stubs'; \
198 mlton
-stop f mlton.mlb | \
199 $(GREP
) -v
'mlb$$' | \
200 $(GREP
) -v
'sml/basis' | \
201 $(GREP
) -v
'targets' | \
202 $(GREP
) -v
'mlton-stubs' | \
203 $(GREP
) -v
'mlyacc' | \
204 $(GREP
) -v
'call-main.sml'; \
205 ) |
$(SED
) 's|\(.*\)|use "\1";|' > mlton-polyml.use