forked from compsl/compsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
331 lines (267 loc) · 9.89 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
#################################
# Build compsl #
#################################
#Created: 17Mar06
#
#Links
# http://www.adp-gmbh.ch/cpp/gcc/create_lib.html
# http://www.cs.berkeley.edu/~smcpeak/autodepend/autodepend.html
# http://www.gnu.org/software/make/manual/make.html
# http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html
#TODO: figure out how to make the test link against version of the lib with debug
# symbols but also have optimizations in the release worthy stuff ie: end up with two
# versions of the static lib, one with debug stuff and not optimization, and the other
# with no debug info and -O2
COMPSL_VERSION := 0.2.3
.SUFFIXES:
HAVE_CONFIG_OPTS=$(shell if [ -f config.opts ]; then echo yes; else echo no; fi)
ifeq ($(HAVE_CONFIG_OPTS),yes)
CONFIG_OPTS = $(shell if [ -f config.opts ]; then cat config.opts; fi)
endif
include setup.mk
################################
# FILES #
################################
CMPATH=src/compiler
SHORTLIB=compsl
LIBNAME := lib$(SHORTLIB)
GEN_HEADERS:=src/include/intern/bcstrings.h \
src/interp/jumptbl.h src/include/compiler/bc_info.h \
src/include/intern/bytecode.h $(CMPATH)/compsl.tab.h
REG_SRCS:=src/api/compartment.c src/api/error.c src/api/gen.c src/interp/run.c \
src/api/vars.c src/api/vm.c src/api/mt.c src/api/userspace.c \
$(CMPATH)/binops.c $(CMPATH)/function.c $(CMPATH)/interncomp.c $(CMPATH)/err.c \
$(CMPATH)/var.c $(CMPATH)/comp.c $(CMPATH)/control.c $(CMPATH)/compglobals.c \
$(CMPATH)/stackcheck.c $(CMPATH)/optimize.c $(CMPATH)/ast.c
DERIVED_SRCS=$(CMPATH)/lex.yy.c $(CMPATH)/compsl.tab.c
DERIVED_FILES=$(DERIVED_SRCS) $(CMPATH)/compsl.tab.h
SOURCES := $(REG_SRCS)
OBJECTS := $(SOURCES:.c=.o) $(DERIVED_SRCS:.c=.o)
TESTSRCS := $(addprefix src/test/test-,interp-base.c interp-jumps.c \
interp-arith.c interp-comp.c interp-builtins.c interp.c intern.c api.c \
comp.c torture.c ast.c so.c)
TESTOBJS := $(TESTSRCS:.c=.o)
OTHERSRC := src/dumper.c src/perf-test.c src/runner.c
OTHEROBJ := $(OTHERSRC:.c=.o)
DEPS := $(SOURCES:.c=.dep) $(OTHERSRC:.c=.dep) $(TESTSRCS:.c=.dep)
DDEPS := $(DERIVED_SRCS:.c=.ddp)
TEST_EXES := $(addprefix bin/,$(notdir $(basename $(TESTSRCS))))
STATIC_LIB_OUT := bin/$(LIBNAME).a
ifeq ($(TARGET_WIN32),yes)
DYN_LIB_OUT := bin/$(SHORTLIB).dll
DEFFILE := bin/$(SHORTLIB).def
IMPLIB := bin/$(SHORTLIB).a
LIBFILE := bin/$(SHORTLIB).lib
else
DYN_LIB_OUT := bin/$(LIBNAME).so.$(COMPSL_VERSION)
endif
DOXYFILE = compsl.doxyfile
.PHONY: test cleantest all clean docs install install-strip help package
.PHONY: test-valgrind statmsg testmsg test-exes distclean autoconfig
.INTERMEDIATE: compsl.tab.h
.SECONDARY: $(OBJECTS) $(DERIVED_FILES) $(CMPATH)/compsl.output
.SECONDARY: $(TESTOBJS) $(OTHEROBJ)
################################
#TARGETS #
################################
all: statmsg $(STATIC_LIB_OUT) $(DYN_LIB_OUT) ;
install: all docs
$(INSTALL) -d $(libdir)
$(INSTALL) -d $(includedir)
$(INSTALL) -m 755 $(STATIC_LIB_OUT) $(libdir)/$(notdir $(STATIC_LIB_OUT))
$(INSTALL) -m 755 $(DYN_LIB_OUT) $(libdir)/$(notdir $(DYN_LIB_OUT))
$(INSTALL) src/extern/compsl.h $(includedir)/compsl.h
$(LDCONFIG) -n $(libdir)
$(RANLIB) $(libdir)/$(notdir $(STATIC_LIB_OUT))
install-strip:
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
strip: all
strip --strip-unneeded $(STATIC_LIB_OUT) $(DYN_LIB_OUT)
distclean: clean
-rm -f config.mak src/intern/config.h
clean:
-rm -f -- $(OBJECTS) $(TESTOBJS) $(OTHEROBJ) $(DEPS) $(DDEPS)
-rm -f -- $(DYN_LIB_OUT) $(STATIC_LIB_OUT) $(TEST_EXES:=*)
-rm -f -- $(CMPATH)/compsl.output $(CMPATH)/compsl.tab.h
-rm -f -- bin/perf-test* bin/dumper* bin/runner*
-rm -f -- $(DEFFILE) $(LIBFILE) $(IMPLIB)
-rm -rf doc/html doc/latex doc/man
-rm -f compsl.tab.h
@echo
docs: $(DOXYFILE)
$(DOXYGEN) $(DOXYFILE)
make -C doc/latex
mv doc/latex/refman.pdf doc/compsl.pdf
headers: $(GEN_HEADERS)
clean-headers:
rm -f $(GEN_HEADERS)
help:
@printf "\nMakefile for CompSL\n"
@printf "***************************************************\n"
@printf " Targets: all, clean, test, test-valgrind, static, dynamic, package,\n"
@printf " docs, test-exes\n"
@printf ""
@printf " Variables: DEBUG, TRACE_INTERP, DEBUG_COMP, STACK_CHECK(=1 by default)\n"
@printf "\n"
@printf " Please run ./configure to set up compilation, for help with configure\n"
@printf " run ./configure --help\n"
@echo
static: statmsg $(STATIC_LIB_OUT) ;
dynamic: statmsg $(DYN_LIB_OUT) ;
package: distclean headers
rm -f compsl-${COMPSL_VERSION}.tar.bz2
tar --exclude "*/.svn*" --exclude "*/.settings*" \
--exclude "*/.cvsignore" --exclude "*/.*project*" \
--exclude "*~" --exclude "*/latex*" --exclude "*/config.*" \
--exclude "*/compsl-${COMPSL_VERSION}/compsl-${COMPSL_VERSION}" \
--exclude "config.opts" \
--transform 's,^,compsl-${COMPSL_VERSION}/,' \
-cjvf compsl-${COMPSL_VERSION}.tar.bz2 *
bin/dumper: src/dumper.o $(OBJECTS)
@echo LINK $@
@$(CC) $(ALL_CFLAGS) -MD $< $(OBJECTS) $(PLATLIBS) -o $@
bin/runner: src/runner.o $(OBJECTS)
@echo LINK $@
@$(CC) $(ALL_CFLAGS) -MD $< $(OBJECTS) $(PLATLIBS) -o $@
bin/perf-test: src/perf-test.o $(OBJECTS)
@echo LINK $@
@$(CC) $(ALL_CFLAGS) -MD $< $(OBJECTS) $(PLATLIBS) -o $@
cleantest: clean test ;
test: test-exes testmsg $(addprefix run-,$(notdir $(basename $(TESTSRCS)))) ;
test-exes: statmsg $(TEST_EXES) ;
test-valgrind: $(TEST_EXES)
@for test in $^; do \
echo Running $$test; \
valgrind -v $$test ; \
echo DONE; \
done
################################
# Message targets #
################################
testmsg:
@printf "\n\nRUNNING TESTS\n"
@printf "***************************************************\n"
statmsg:
@printf "\nSETTINGS\n"
@printf "***************************************************\n"
@printf "$(STATMSG)\n"
@printf "CFLAGS\n$(ALL_CFLAGS)\n\n" | fold -s
@printf "PLATLIBS\n$(PLATLIBS)\n" | fold -s
@sleep 5
@printf "\nSTARTING OPERATION\n"
@printf "***************************************************\n"
################################
# INTERNAL TARGETS #
################################
#Dash makes it not error if not found
-include $(DEPS)
-include $(DDEPS)
src/include/intern/bcstrings.h: src/interp/bytecodes gen-bcstrings.sh Makefile
@echo GEN $@
@./gen-bcstrings.sh $< > $@
src/interp/jumptbl.h: src/interp/bytecodes gen-jumptbl.sh Makefile
@echo GEN $@
@./gen-jumptbl.sh $< > $@
src/include/compiler/bc_info.h: src/interp/bytecodes gen-bc-info.sh Makefile
@echo GEN $@
@./gen-bc-info.sh $< > $@
src/include/intern/bytecode.h: src/interp/bytecodes gen-bytecodeh.sh Makefile
@echo GEN $@
@./gen-bytecodeh.sh $< > $@
$(CMPATH)/compsl.tab.o: $(CMPATH)/compsl.tab.c $(GEN_HEADERS)
@echo CC $<
@$(CC) -MM -MQ $@ $(ALL_CFLAGS) $< > $(CMPATH)/compsl.tab.ddp
@$(CC) -c $(ALL_CFLAGS) -fno-gcse -Wno-unused-label $< -o $@
$(CMPATH)/lex.yy.o: $(CMPATH)/lex.yy.c $(GEN_HEADERS)
@echo CC $<
@$(CC) -MM -MQ $@ $(ALL_CFLAGS) $< > $(CMPATH)/lex.yy.ddp
@$(CC) -c $(ALL_CFLAGS) -fno-gcse -Wno-unused-label $< -o $@
#gcc manual says computed goto's may perform better with -fno-gcse
src/interp/run.o: src/interp/run.c config.mak Makefile $(GEN_HEADERS)
@echo CC $<
@$(CC) -MM -MG -MQ $@ $(ALL_CFLAGS) -Wno-unused-label $< -MF src/interp/run.dep
@$(CC) -c $(ALL_CFLAGS) -fno-gcse -falign-labels -Wno-unused-label $< -o $@
%.o: %.c config.mak Makefile $(GEN_HEADERS)
@echo CC $<
@$(CC) -MM -MG -MQ $@ $(ALL_CFLAGS) $< -MF $*.dep
@$(CC) -c $(ALL_CFLAGS) $< -o $@
#%.dep: %.c config.mak Makefile $(GEN_HEADERS)
# @echo DEP $<
#
ifeq ($(TARGET_WIN32),yes)
$(DYN_LIB_OUT) $(DEFFILE) $(IMPLIB): $(OBJECTS)
@echo LINK $@
@$(CC) $(ALL_CFLAGS) $(OBJECTS) -shared \
-Wl,--out-implib,$(IMPLIB) \
-Wl,--output-def,$(DEFFILE) \
-Wl,-soname,$(DYN_LIB_OUT) \
-Wl,--add-stdcall-alias \
-o $(DYN_LIB_OUT)
else
$(DYN_LIB_OUT): $(OBJECTS)
@echo LINK $@
@$(CC) $(LDFLAGS) $(OBJECTS) $(PLATLIBS) -o $(DYN_LIB_OUT) $(ALL_CFLAGS)
endif
$(STATIC_LIB_OUT): $(OBJECTS)
@echo AR $@
@ar rcs $(STATIC_LIB_OUT) $(OBJECTS)
################################
# FLEX/BISON TARGETS #
################################
$(CMPATH)/compsl.tab.h $(CMPATH)/compsl.tab.c: $(CMPATH)/compsl.y config.mak Makefile
@rm -f $(CMPATH)/compsl.tab.c $(CMPATH)/compsl.tab.h
@echo BISON $<
@$(BISON) --report all -d $(CMPATH)/compsl.y -o $(CMPATH)/compsl.tab.c
$(CMPATH)/lex.yy.c: $(CMPATH)/compsl.l $(CMPATH)/compsl.tab.h config.mak Makefile $(GEN_HEADERS)
@rm -f $(CMPATH)/lex.yy.c
@echo FLEX $<
@$(FLEX) -o$@ $<
####################################################
# Testers - assume each test is one sourcefile
####################################################
run-test-%: bin/test-%
@echo
@$<
@echo
bin/test-%: src/test/test-%.o $(STATIC_LIB_OUT)
@echo LINK $@
@$(CC) $(ALL_CFLAGS) -MD $< $(OBJECTS) $(PLATLIBS) -o $@
run-test-so: bin/test-so
@echo
@LD_LIBRARY_PATH="bin" $<
@echo
bin/test-so: src/test/test-so.o $(DYN_LIB_OUT)
@echo LINK $@
@$(CC) $(ALL_CFLAGS) -MD $< $(PLATLIBS) -Lbin/ -lcompsl -o $@
####################################################
Makefile: setup.mk
ifeq ($(HAVE_CONFIG_OPTS),yes)
config.mak: configure config.opts
@sh configure $(CONFIG_OPTS)
@$(MAKE) clean
@sleep 5
src/intern/config.h: config.mak
else
src/intern/config.h: configure
@if [ -f config.mak ]; then \
echo "############################################################";\
echo "################## Please run ./configure ##################";\
echo "############################################################";\
exit 1;\
else \
echo "############################################################";\
echo "####### Please run ./configure again - it's changed! #######";\
echo "############################################################";\
fi
endif
ifeq ($(HAVE_CONFIG_OPTS),yes)
autoconfig: configure config.opts
@sh configure $(CONFIG_OPTS)
@$(MAKE) clean
@sleep 5
else
autoconfig: configure
@sh configure $(CONFIG_OPTS)
@$(MAKE) clean
@sleep 5
endif