-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
295 lines (229 loc) · 6.98 KB
/
Copy pathMakefile
File metadata and controls
295 lines (229 loc) · 6.98 KB
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
# -*- makefile -*-
# Copyright (c) 1993-2012 David Gay and Gustav Hållberg
# All rights reserved.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose, without fee, and without written agreement is hereby granted,
# provided that the above copyright notice and the following two paragraphs
# appear in all copies of this software.
#
# IN NO EVENT SHALL DAVID GAY OR GUSTAV HALLBERG BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF DAVID GAY OR
# GUSTAV HALLBERG HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# DAVID GAY AND GUSTAV HALLBERG SPECIFICALLY DISCLAIM ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
# "AS IS" BASIS, AND DAVID GAY AND GUSTAV HALLBERG HAVE NO OBLIGATION TO
# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
# disable built-in rules
.SUFFIXES:
USE_XML := yes
USE_GMP := yes
USE_READLINE := yes
# USE_PCRE := yes
# PCRE_HEADER := PCRE_H # for <pcre.h>
# PCRE_HEADER := PCRE_PCRE_H # for <pcre/pcre.h>
# USE_LPSOLVE := yes
# LPSOLVE_HEADER := LPKIT_LPKIT_H # for <lpkit/lpkit.h>
# LPSOLVE_HEADER := LP_SOLVE_LPKIT_H # for <lp_solve/lpkit.h>
# USE_VALGRIND := yes
# USE_CPP_STEP := t
ifeq ($(verbose),yes)
Q :=
else
Q := @
endif
ifeq ($(optimize),no)
NO_OPT := t
endif
ARCH := i386
ifneq ($(filter x86 i386 i686,$(ARCH)),)
override ARCH := i386
endif
ifneq ($(filter x64-64 x86_64 x64,$(ARCH)),)
override ARCH := amd64
endif
ifeq ($(filter i386 amd64,$(ARCH)),)
$(error Unsupported ARCH=$(ARCH); expected i386 or amd64)
endif
ifeq ($(ARCH),i386)
PRIMITIVE_CFLAGS := -mstackrealign
BUILTINS := x86builtins.o
BUILTINDEPS := x86consts.h
ARCHFLAG := -m32
else
ifeq ($(ARCH),amd64)
BUILTINS := x64builtins.o
BUILTINDEPS := x64consts.h
ARCHFLAG := -m64
endif
endif
INDENT=indent
ARCHDEP:=.mudlle-arch
OLD_ARCH:=$(shell [ -f $(ARCHDEP) ] && cat $(ARCHDEP))
ifneq ($(OLD_ARCH),$(ARCH))
ifneq ($(OLD_ARCH),)
$(info Architecture changed. Recompiling.)
endif
.PHONY: $(ARCHDEP)
endif
$(ARCHDEP):
@echo "$(ARCH)" > $@
OBJDEP:=$(ARCHDEP) mudlle-macro-n.h
SRC := alloc.c assoc.c call.c calloc.c charset.c compile.c context.c \
dwarf.c elf.c env.c error.c global.c hash.c ins.c interpret.c \
lexer.c mcompile.c module.c mudlle-main.c mudlle.c objenv.c \
parser.tab.c ports.c print.c random.c stack.c strbuf.c \
table.c tree.c types.c utils.c
OBJS := $(BUILTINS) $(SRC:%.c=%.o)
alloc.o error.o: CFLAGS+=$(PRIMITIVE_CFLAGS)
warnings := all missing-declarations missing-prototypes nested-externs \
shadow unused-macros write-strings
CC := gcc -std=gnu11
CFLAGS := -g3 $(if $(NO_OPT),-O0,-O2) $(addprefix -W,$(warnings))
CPPFLAGS := $(ARCHFLAG) -I.
LDFLAGS := $(ARCHFLAG) -fno-pie
LIBS := -lm
MAKEDEPEND = $(CC) -MM
PERL := perl
LIBCURSES := -lcurses
ifeq ($(shell uname -s),Darwin)
CPPFLAGS += -isystem /opt/local/include
LDFLAGS += -L/opt/local/lib
LIBS += -liconv
endif # Darwin
export CC CFLAGS CPPFLAGS LDFLAGS MAKEDEPEND PERL
ifneq ($(USE_XML),)
CPPFLAGS += -DUSE_XML
LIBS += -lxml2
endif
ifneq ($(USE_GMP),)
CPPFLAGS += -DUSE_GMP
LIBS += -lgmp
endif
ifneq ($(USE_READLINE),)
CPPFLAGS += -DUSE_READLINE
LIBS += -lreadline $(LIBCURSES)
endif
ifneq ($(USE_PCRE),)
CPPFLAGS += -DUSE_PCRE -DHAVE_$(PCRE_HEADER)
LIBS += -lpcre
endif
ifneq ($(USE_LPSOLVE),)
CPPFLAGS += -DHAVE_LIB_LPK -DHAVE_$(LPSOLVE_HEADER)
LIBS += -llpk -lfl -lm
endif
ifneq ($(USE_VALGRIND),)
CPPFLAGS += -DHAVE_VALGRIND_MEMCHECK_H
endif
clang:=$(shell : | $(CC) $(CPPFLAGS) $(CFLAGS) -E -dM - \
| grep '^\#define __clang__\b')
NO_UNUSED_MACROS:=x86builtins.o x64builtins.o
charset.o: CFLAGS:=-Wno-invalid-source-encoding $(CFLAGS)
LIBRUN := runtime/librun.a
.PHONY: all
all: mudlle
mudlle: $(OBJS)
@echo "Link $@"
$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
.PHONY: clean depclean
depclean:
rm -f .depend
clean:
rm -f *.o *.obj lexer.c tokens.h parser.tab.c parser.tab.h \
.depend genconst genconstdefs.h mudlle mudlle-macro-n.h \
parser.output x86consts.h x64consts.h
ifeq (,$(USE_CPP_STEP))
%.o: %.c $(OBJDEP)
@echo "Compile $<"
$(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
else
%.o: %-mpp.c
@echo "Compile $<"
$(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
.PRECIOUS: %-mpp.c
%-mpp.c: %.c $(OBJDEP)
@echo "Create $@"
$(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -E $< | grep -v '^#' | $(INDENT) > $@
endif
.depend parser.tab.o lexer.o $(NO_UNUSED_MACROS): \
CFLAGS:=$(filter-out -Wunused-macros,$(CFLAGS))
lexer.o: parser.tab.h
lexer.c: lexer.l
@echo "Flex $<"
$(Q)flex -CFe -8 -o $@ $<
%.tab.c %.tab.h: %.y
@echo "Bison $<"
$(Q)bison -dtv $<
$(BUILTINS): $(BUILTINS:%.o=%.S) $(BUILTINDEPS) $(OBJDEP)
@echo "Compile $<"
$(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
x64consts.h x86consts.h: genconst Makefile
@echo "Create $<"
$(Q)./genconst > $@
genconst: genconst.o Makefile
@echo "Link $@"
$(Q)$(CC) $(LDFLAGS) -o $@ $<
genconst.o: genconstdefs.h
CONSTH := types.h mvalues.h context.h error.h
genconstdefs.h: runtime/consts.pl $(CONSTH) Makefile
@echo "Create $@"
$(Q)LC_ALL=C $(PERL) $< -d -o $@ -- $(CONSTH)
mudlle-macro-n.h: make-macro-n.pl
@echo "Create $@"
$(Q)LC_ALL=C $(PERL) $< > $@
.PHONY: dep depend
dep depend: .depend
$(Q)$(MAKE) -C runtime -f Makefile depend
.depend: $(SRC) genconst.c genconstdefs.h $(BUILTINS:%.o=%.S) $(BUILTINDEPS) \
$(OBJDEP)
@echo "Create $@"
$(Q)$(MAKEDEPEND) $(CPPFLAGS) $(CFLAGS) \
$(filter-out %.h $(ARCHDEP),$^) \
> $@
# Currently 22 files, split into at most 8 groups for parallel builds
GROUPS=0 1 2 3 4 5 6 7
define BUILDER
.PHONY: comp_$(1)_$(3)
comp_$(1)_$(3): build-slice.sh $(4)
@echo "Compiling $(2) compiler files $(3)/$(words $(GROUPS))"
@/bin/sh $$< $(2) $(3) $(words $(GROUPS))
endef
define PASS
$$(foreach g,$$(GROUPS),$$(eval $$(call BUILDER,$(1),$(2),$$(g),$(3))))
.PHONY: comp_$(1)
comp_$(1): $$(foreach g,$$(GROUPS),comp_$(1)_$$(g))
endef
$(eval $(call PASS,xc,xc,mudlle))
$(eval $(call PASS,icxc,icxc,comp_xc))
$(eval $(call PASS,icxc2,icxc,comp_icxc))
.PHONY: compiler
compiler: comp_icxc2
.PHONY: help
help:
@echo 'Available make targets:' ; \
echo ' mudlle the mudlle binary (default)' ; \
echo ' compiler the mudlle compiler' ; \
echo ' clean remove build files' ; \
echo ' depclean remove dependency files' ; \
echo ; \
echo 'Useful make variables:' ; \
echo ' ARCH set to "i386" (default) or "amd64"' ; \
echo ' optimize set to "no" for -O0 builds' ; \
echo ' verbose set to "yes" for verbose builds'
depfile:=.depend
# include dependency files unless we are only running cleaning targets
NO_DEP_TGT:=clean depclean help
ifneq (,$(MAKECMDGOALS))
ifeq ($(MAKECMDGOALS),$(filter $(NO_DEP_TGT),$(MAKECMDGOALS)))
depfile:=
endif
endif
include runtime/Makefile
ifeq (,$(wildcard $(depfile)))
-include $(depfile)
else
include $(depfile)
endif