-
Notifications
You must be signed in to change notification settings - Fork 126
/
Makefile.config
255 lines (212 loc) · 7.1 KB
/
Makefile.config
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
## Copyright (C) 2009,2011,2013,2017-2023 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 HPND-style license.
# See the file MLton-LICENSE for details.
##
# Specify C compiler and binutils.
# Can be used for alternative tools (e.g., `CC=clang` or `CC=gcc-7`).
CC := cc
AR := ar
RANLIB := ranlib
STRIP := strip
# Specify GMP include and library paths, if not on default search paths.
WITH_GMP_DIR :=
ifneq ($(WITH_GMP_DIR),)
WITH_GMP_INC_DIR := $(WITH_GMP_DIR)/include
WITH_GMP_LIB_DIR := $(WITH_GMP_DIR)/lib
endif
# Specify installation prefix and staged install destination.
PREFIX := /usr/local
DESTDIR :=
# Specify runtime and compile arguments given to (the to-be-built) `mlton`
# when compiling distributed executables ((self-compiled) `mlton`, `mllex`,
# `mlyacc`, `mlprof`, and `mlnlffigen`).
# Can be used for testing (e.g., `MLTON_COMPILE_ARGS="-codegen c"`) or for
# downstream packaging.
MLTON_RUNTIME_ARGS :=
MLTON_COMPILE_ARGS :=
# Specify runtime and compile arguments given to "old" `mlton` when
# compiling "new" `mlton`.
# Can be used to work around bugs in "old" `mlton` when compiling "new"
# `mlton` (e.g., `OLD_MLTON_COMPILE_ARGS="-drop-pass 'deepFlatten'"`).
OLD_MLTON := mlton
OLD_MLTON_RUNTIME_ARGS :=
OLD_MLTON_COMPILE_ARGS :=
OLD_MLTON_DIR :=
ifneq (,$(OLD_MLTON_DIR))
OLD_MLTON := $(OLD_MLTON_DIR)/$(OLD_MLTON)
endif
# Specify standard tools.
# Can be used for alternative tools (e.g., `SED=gsed`).
DIFF := diff
FIND := find
GIT := git
GREP := grep
GZIP := gzip
PATCH := patch
RSYNC := rsync
SED := sed
TAR := tar
SHA1SUM := sha1sum
SHA1 := sha1
OPENSSL := openssl
SHASUM := shasum
CAT := cat
CHMOD := chmod
CP := cp -fpR
MKDIR := mkdir -p
MV := mv -f
RM := rm -rf
export MAKE
######################################################################
RELEASE := false
MLTON_FORK :=
ifeq (,$(MLTON_FORK))
MLTON := mlton
MLTON_NAME := MLton
else
MLTON := mlton-$(MLTON_FORK)
MLTON_NAME := MLton [$(MLTON_FORK)]
endif
MLTON_OUTPUT := $(MLTON)-compile
MLTON_VERSION := $(shell TZ=UTC $(GIT) log -n1 --date=format-local:"%Y%m%d.%H%M%S" --pretty=format:"%cd-g%h$$([ "$$($(GIT) status --porcelain 2> /dev/null)" ] && echo '-dirty')" 2> /dev/null || echo '????????')
######################################################################
######################################################################
define HAVE_CMD
$(shell if [ -x "$$(command -v "$(1)")" ]; then echo true; else echo false; fi)
endef
SHA1DGST :=
ifeq (,$(SHA1DGST))
ifeq (true, $(call HAVE_CMD,$(SHA1SUM)))
SHA1DGST := $(SHA1SUM) | $(SED) 's/.*\([a-z0-9]\{40\}\).*/\1/'
else ifeq (true, $(call HAVE_CMD,$(SHA1)))
SHA1DGST := $(SHA1) | $(SED) 's/.*\([a-z0-9]\{40\}\).*/\1/'
else ifeq (true, $(call HAVE_CMD,$(OPENSSL)))
SHA1DGST := $(OPENSSL) sha1 | $(SED) 's/.*\([a-z0-9]\{40\}\).*/\1/'
else ifeq (true, $(call HAVE_CMD,$(SHASUM)))
SHA1DGST := $(SHASUM) -a | $(SED) 's/.*\([a-z0-9]\{40\}\).*/\1/'
else
$(error Could not determine suitable SHA-1 digest command)
endif
endif
######################################################################
######################################################################
TGT_REL_SRC = ref="$(1)" pos="$(2)" down=; ref="$${ref%%/}" pos="$${pos%%/}"; while :; do test "$$pos" = '/' && break ; case "$$ref" in "$$pos"/*) break;; esac; down="../$$down"; pos="$${pos%/*}"; done; echo "$$down$${ref\#\#$$pos/}"
SRC := $(shell cd $(ROOT) && pwd)
BUILD := $(SRC)/build
BIN := $(BUILD)/bin
LIB := $(BUILD)/lib/mlton
INC := $(LIB)/include
LIB_REL_BIN := $(shell $(call TGT_REL_SRC,$(LIB),$(BIN)))
HOST_ARCH := $(shell "$(SRC)/bin/host-arch")
HOST_OS := $(shell "$(SRC)/bin/host-os")
ifeq (0, $(MAKELEVEL))
define CHECK_HOST
ifeq ($$($(1)),)
$$(error Could not determine '$(1)')
endif
endef
$(eval $(call CHECK_HOST,HOST_ARCH))
$(eval $(call CHECK_HOST,HOST_OS))
endif
TARGET := self
TARGET_ARCH := $(HOST_ARCH)
TARGET_OS := $(HOST_OS)
ifeq (mingw, $(TARGET_OS))
EXE := .exe
else
EXE :=
endif
######################################################################
## BOOTSTRAP_STYLE
## 0 -- Use $(OLD_MLTON) for round1 (and stop)
## 1 -- Use $(BIN)/$(MLTON) for round1 (and stop);
## default if $(BIN)/$(MLTON) exists
## 2 -- Use $(OLD_MLTON) for round1; use $(BIN)/$(MLTON) for round2;
## default if $(BIN)/$(MLTON) does not exist
## 3 -- Use $(OLD_MLTON) or use $(BIN)/$(MLTON) for round1;
## use $(BIN)/$(MLTON) for round2;
## use $(BIN)/$(MLTON) for round3 (and check fixpoint)
ifeq (true, $(call HAVE_CMD,"$(BIN)/$(MLTON)"))
BOOTSTRAP_STYLE := 1
else
BOOTSTRAP_STYLE := 2
endif
ifeq (0, $(BOOTSTRAP_STYLE))
SELF_COMPILE := false
else ifeq (1, $(BOOTSTRAP_STYLE))
SELF_COMPILE := true
else ifeq (2, $(BOOTSTRAP_STYLE))
SELF_COMPILE := false
else ifeq (3, $(BOOTSTRAP_STYLE))
SELF_COMPILE := false
endif
ifeq (true, $(SELF_COMPILE))
RUN_MLTON := $(BIN)/$(MLTON)
RUN_MLTON_RUNTIME_ARGS := $(MLTON_RUNTIME_ARGS)
RUN_MLTON_COMPILE_ARGS := $(MLTON_COMPILE_ARGS)
ifeq (true, $(call HAVE_CMD,"$(BIN)/mllex"))
RUN_MLLEX := $(BIN)/mllex
endif
ifeq (true, $(call HAVE_CMD,"$(BIN)/mlyacc"))
RUN_MLYACC := $(BIN)/mlyacc
endif
else
RUN_MLTON := $(OLD_MLTON)
RUN_MLTON_RUNTIME_ARGS := $(OLD_MLTON_RUNTIME_ARGS)
RUN_MLTON_COMPILE_ARGS := $(OLD_MLTON_COMPILE_ARGS)
endif
ifeq (0, $(MAKELEVEL))
define CHECK_MLCMD
ifeq (false, $$(call HAVE_CMD,$$($(2))))
$$(warning '$(1)' command not found: $$($(2)))
endif
endef
$(eval $(call CHECK_MLCMD,mlton,RUN_MLTON))
endif
ifeq (true, $(call HAVE_CMD,$(RUN_MLTON)))
RUN_MLTON_VERSION := $(shell "$(RUN_MLTON)" | $(SED) -n 's/MLton.*\([0-9]\{8\}\).*/\1/p')
MLBDEPS := mlbdeps() { if [ -e "$$1" ]; then $(RUN_MLTON) -stop f "$$1"; else echo "$$1"; fi; } && mlbdeps
else
RUN_MLTON_VERSION := "????????"
MLBDEPS := "$(SRC)/bin/mlbdeps"
endif
######################################################################
SMLNJ := sml
SMLNJ_MAKEDEPEND := ml-makedepend
SMLNJ_DIR :=
ifneq (,$(SMLNJ_DIR))
SMLNJ := $(SMLNJ_DIR)/$(SMLNJ)
SMLNJ_MAKEDEPEND := $(SMLNJ_DIR)/$(SMLNJ_MAKEDEPEND)
endif
ifeq (true, $(call HAVE_CMD,$(SMLNJ)))
SMLNJ_HEAP_SUFFIX := $(shell "$(SMLNJ)" @SMLsuffix)
else
SMLNJ_HEAP_SUFFIX := unkwn-unkwn
endif
MLTON_OUTPUT_SMLNJ_HEAP := $(MLTON_OUTPUT)-smlnj.$(SMLNJ_HEAP_SUFFIX)
######################################################################
POLYC := polyc
######################################################################
MLKIT := mlkit
MLKIT_FLAGS :=
######################################################################
SHOW_VARS := MLTON_NAME MLTON_VERSION SRC BUILD BIN LIB INC LIB_REL_BIN HOST_ARCH HOST_OS TARGET TARGET_ARCH TARGET_OS BOOTSTRAP_STYLE SELF_COMPILE RUN_MLTON RUN_MLTON_VERSION RUN_MLLEX RUN_MLYACC
SHOW_VAR = echo "$(1) = $(strip $($(1)))";
define MK_COMMON_GOALS
.PHONY: show-config
show-config:
@$$(foreach VAR,$$(SHOW_VARS),$$(call SHOW_VAR,$$(VAR)))
.PHONY: clean
clean:
"$$(SRC)/bin/clean" $$(foreach EXCL,$$(CLEAN_EXCLS),--exclude $$(EXCL))
ifneq (,$$(CLEAN_EXTS))
$$(foreach EXT,$$(CLEAN_EXTS),$$(RM) *.$$(EXT);)
endif
ifeq (true,$$(CLEAN_EXES))
for f in *; do if [ -x "$$$$f" -a ! -d "$$$$f" ]; then $$(RM) "$$$$f"; fi; done
endif
endef