-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMasterMakefile
More file actions
447 lines (337 loc) · 12.5 KB
/
MasterMakefile
File metadata and controls
447 lines (337 loc) · 12.5 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
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
442
443
444
445
446
447
#------------------------------------------------------------------------------
#$Author$
#$Revision$
#$Date$
#$URL$
#------------------------------------------------------------------------------
MAKECONF_EXAMPLES = ${filter-out %~, ${wildcard Makeconf*.example}}
MAKECONF_FILES = $(sort \
${filter-out %~, ${wildcard Makeconf*}} \
${MAKECONF_EXAMPLES:%.example=%})
ifneq ("${MAKECONF_FILES}","")
include ${MAKECONF_FILES}
endif
#
# ${SRC_DIR} contains C sources to be compiled into the
# local library ${LOCAL_LIB}
#
ifeq ("${SRC_DIR}","")
SRC_DIR = .
endif
#
# ${OBJDIR} is where the compiled object files should be stored
#
OBJDIR = ./obj
#
# GEN_DIR will contain any .c and .h files that are automatically
# generated by scripts or makefiles
#
GEN_DIR = ./generated
#
# Each .c file in the ./programs/ directory is considered to be a source
# for some main program (i.e. contains main() function). It will be
# compiled and linked with all .c files in directories specified by
# the OTHER_DIRS variable. OTHER_DIRS should be defined in the
# Makeconf file in each directory.
#
PROGDIR = ${SRC_DIR}/programs
PRG_FILES = ${wildcard ${PROGDIR}/*.c}
EXE_FILES = ${patsubst %.c, %, ${notdir ${PRG_FILES}}}
PRG_SOURCE = ${notdir ${PRG_FILES}}
PRG_DIRS = ${dir ${PRG_FILES}}
PRG_DEPEND = ${join ${PRG_DIRS}, ${PRG_SOURCE:%.c=.%.d}}
#
# The first program (alphabetically) in the ./programs directory is a
# main executable (target). It will be run for every file in ./inputs
# when 'make test' is invoked.
#
TARGET = ${firstword ${EXE_FILES}}
#
# All .c files in the current directory will be compiled and the object
# files put into the local library; the library in the directory
# 'dir' will be called 'libdir.a'
#
LOCAL_CFILES := ${notdir ${wildcard ${SRC_DIR}/*.c}}
LOCAL_CFILES := ${filter-out %.tab.c lex.yy.c %.lex.c, ${LOCAL_CFILES}}
LOCAL_OBJS = ${LOCAL_CFILES:%.c=${OBJDIR}/%.o}
LOCAL_DEPENDS = ${LOCAL_CFILES:%.c=.%.d}
SO_MAJOR = 0
SO_MINOR = 01
SO_VERSION = ${SO_MAJOR}.${SO_MINOR}
LOCAL_LIB := ${addprefix lib, ${addsuffix .a, ${notdir ${shell pwd}} }}
LOCAL_SO := ${addprefix lib, ${addsuffix .so, ${subst -O3,,${notdir ${shell pwd}}} }}
LOCAL_SOV := ${LOCAL_SO}.${SO_VERSION}
#
# ./testprogs directory contains test drivers, each of them containing
# main() program that must be linked with all .o files from all .c
# sources from ${OTHER_DIRS}.
#
# Each test driver will then be run without arguments, and its output
# will be compared with the sample output in ./testout directory
#
TST_PRG_DIR = ./testprogs
TST_EXE_DIR = ./testbin
TST_SOURCES = $(sort ${wildcard ${TST_PRG_DIR}/*.c})
TST_DRIVERS = ${patsubst %.c, ${TST_EXE_DIR}/%, ${notdir ${TST_SOURCES}}}
TST_BASENAMES = ${notdir ${TST_SOURCES}}
TST_DIRS = ${dir ${TST_SOURCES}}
TST_DEPEND = ${join ${TST_DIRS}, ${TST_BASENAMES:%.c=.%.d}}
#
# All other .c files will be compiled to objects in the current
# directory, and used for linking
#
vpath %.c ${SRC_DIR} ${OTHER_DIRS}
vpath %.h ${SRC_DIR} ${OTHER_DIRS}
#VPATH = ${OTHER_DIRS}
OTHER_CFILES := ${notdir $(sort ${wildcard ${addsuffix /*.c, ${OTHER_DIRS}}})}
OTHER_CFILES := ${filter-out %.tab.c lex.yy.c %.lex.c, ${OTHER_CFILES}}
OTHER_OBJS = ${OTHER_CFILES:%.c=${OBJDIR}/%.o}
OTHER_DEPENDS = ${OTHER_CFILES:%.c=.%.d}
DEPEND_FILES = ${LOCAL_DEPENDS} ${OTHER_DEPENDS} ${PRG_DEPEND} ${TST_DEPEND}
DEL_OBJS = ${LOCAL_OBJS} ${OTHER_OBJS}
# ${LIB_DIRS} variable contains a list of directories, each of them
# containin a library that must be linked with programs in the
# curent directory. The library in the directory 'dir' must be called
# 'dir/libdir.a'. We assume that the 'dir' directory contains a Makefile
# to build a corresponding library, and simply do 'make -C dir libdir.a'
# if the library does not exist. If the library exists, we will use
# whatever it contains, without checking its dependencies. To build the
# up-to-date libraries in ${LIB_DIRS} directories use 'make libs' command.
# We omit the check of library dependencies just for speed; if the library
# is actively changed and must be constantly recompiled, one should use
# ${OTHER_DIRS} variable to include the the *.c files of that directory
# into the compilation list.
LIB_NAMES := ${notdir ${LIB_DIRS}}
LIB_FILES := ${addprefix /lib, ${addsuffix .a, ${LIB_NAMES} }}
LIB_FILES := ${join ${LIB_DIRS}, ${LIB_FILES} }
%.a:
cd $(dir $@); ${MAKE} $(notdir $@)
#------------------------------------------------------------------------------
#
# Executables:
#
CC = gcc
CCVER = ${CC} --version
GCC = gcc
YACC = bison
FLEX = flex
INCLUDES = -I. ${addprefix -I, ${sort ${SRC_DIR} ${OTHER_DIRS} ${LIB_DIRS}}}
## LDFLAGS = ${addprefix -L, ${sort ${LIB_DIRS}}}
## LIBFLAGS = ${addprefix -l, ${LIB_NAMES}}
## LDFLAGS = -L/usr/local/lib
## LIBFLAGS = -lm
SVN_VERSION := $(shell svnversion)
SVN_MESSAGE := SVN revision ${SVN_VERSION}
ifeq (${SVN_VERSION},Unversioned directory)
SVN_VERSION := $(shell git log --format='%h' -1)
SVN_MESSAGE := GIT commit ${SVN_VERSION}
endif
ifeq (${CC},tcc)
CFLAGS = ${OPTFLAGS} -DYYDEBUG=1 -D_YACC_ ${INCLUDES} \
-DSVN_VERSION="\"${SVN_MESSAGE}\""
else
CFLAGS = -Wall -g -fPIC ${OPTFLAGS} -DYYDEBUG=1 -D_YACC_ ${INCLUDES} \
-DSVN_VERSION="\"${SVN_MESSAGE}\""
endif
#------------------------------------------------------------------------------
FLEXFILES = ${wildcard *.flex}
FLEXOBJ = ${FLEXFILES:%.flex=%.lex.o}
YYFILES = ${wildcard *.y}
YYOBJ = ${YYFILES:%.y=%.tab.o}
LINK_OBJ_FILES = ${YYOBJ} ${FLEXOBJ} ${OTHER_OBJS}
#------------------------------------------------------------------------------
.PRECIOUS: %.o %.c %.lex.c %.tab.c %.a
.PHONY: all lib libs clean distclean cleanAll FORCE
all: ${LOCAL_LIB} ${LOCAL_SO} ${EXE_FILES} ${TST_DRIVERS}
lib libs: ${LIB_DIRS}
${LIB_DIRS}: FORCE
cd $@; ${MAKE} OPTFLAGS="${OPTFLAGS}" \
INTERPRETER_DIR="${INTERPRETER_DIR}"
FORCE:;
# A file can be create from a repository-committed example; used for
# Makeconfig files:
%: %.example
sed 's/\?=/=/g; s/^## LD_LIBRARY_PATH :=/LD_LIBRARY_PATH :=/' $< > $@
#------------------------------------------------------------------------------
#
# How to build library in the current directory
#
${LOCAL_LIB}: ${LOCAL_OBJS}
ar cr ${LOCAL_LIB} ${LOCAL_OBJS}
${LOCAL_SOV}: ${LOCAL_OBJS} ${LINK_OBJ_FILES}
${LD} -shared -soname ${LOCAL_SO}.${SO_MAJOR} -o $@ $^ ${LIBFLAGS} -lc_nonshared
${LOCAL_SO}: ${LOCAL_SO}.${SO_MAJOR}
ln -sf $< $@
${LOCAL_SO}.${SO_MAJOR}: ${LOCAL_SOV}
ln -sf $< $@
#------------------------------------------------------------------------------
MAKELOCAL_FILES = ${filter-out %~, ${wildcard Makelocal*}}
ifneq ("${MAKELOCAL_FILES}","")
include ${MAKELOCAL_FILES}
endif
include ${DEPEND_FILES}
.%.d: %.c
${GCC} ${CFLAGS} -M -MG \
$< | sed -e 's,^${notdir $*}.o:,${OBJDIR}/$*.o:,' > $@
#------------------------------------------------------------------------------
${OBJDIR}/%.o: %.c
${CC} ${CFLAGS} -c $< -o $@
%: ${PROGDIR}/%.c ${LINK_OBJ_FILES} ${LOCAL_LIB} ${LIB_FILES}
${CC} ${CFLAGS} ${LDFLAGS} -o $@ $^ ${LIBFLAGS}
## %: ${PROGDIR}/%.c ${LOCAL_SO}
## ${CC} ${CFLAGS} ${LDFLAGS} -o $@ $^ ${LIBFLAGS}
${TST_EXE_DIR}/%: ${TST_PRG_DIR}/%.c ${LINK_OBJ_FILES} \
${LOCAL_LIB} ${LIB_FILES}
${CC} ${CFLAGS} ${LDFLAGS} -o $@ $^ ${LIBFLAGS}
%.lex.c: %.flex
${FLEX} -d $<
mv lex.yy.c $*.lex.c
%.tab.c %.tab.h: %.y
${YACC} -v -d $<
test -f y.tab.c && mv y.tab.c $*.tab.c ; true
test -f y.tab.h && mv y.tab.h $*.tab.h ; true
test -f y.output && mv y.output $*.output ; true
#------------------------------------------------------------------------------
# When 'make test' is invoked, a TARGET executable will be run for
# every file in inputs that has extension ${EXT}. The outputs will be
# compared with the sample outputs files in ./outputs/*.out, and any
# differences will be recorded in ./outputs/*.diff #
ARCH := $(shell uname -p)
TEST_DIR = ./inputs
OUTPUT_DIR = ./outputs/out
DIFFIL_DIR = ./outputs/diff
TEST_FILES = $(sort ${wildcard ${TEST_DIR}/*${EXT}} \
${wildcard ${TEST_DIR}/${ARCH}/*${EXT}} \
${wildcard ${TEST_DIR}/$(notdir ${INTERPRETER_DIR})/${ARCH}/*${EXT}} \
${wildcard ${TEST_DIR}/$(notdir ${INTERPRETER_DIR})/*${EXT}})
RES_FILES = ${patsubst ${TEST_DIR}/%${EXT},${OUTPUT_DIR}/%.out,${TEST_FILES}}
DIFF_FILES = ${patsubst ${TEST_DIR}/%${EXT},${DIFFIL_DIR}/%.diff,${TEST_FILES}}
#
# Outputs and diffs from the standalone test drivers
#
TST_OUT_DIR = ./testout/out
TST_DIF_DIR = ./testout/diff
TST_OUTPUTS = ${addprefix ${TST_OUT_DIR}/, ${TST_BASENAMES:%.c=%.out}}
TST_DIFFS = ${addprefix ${TST_DIF_DIR}/, ${TST_BASENAMES:%.c=%.diff}}
#
# Outputs and tests from the shell-driven tests
#
SHELL_TSTDIR = ./shtests
SHELL_OUTDIR = ./shoutputs/out
SHELL_DIFDIR = ./shoutputs/diff
SHELL_TESTS = $(sort ${wildcard ${SHELL_TSTDIR}/*.sh})
SHELL_BASES = ${notdir ${SHELL_TESTS}}
SHELL_OUTPUTS = ${addprefix ${SHELL_OUTDIR}/, ${SHELL_BASES:%.sh=%.out}}
SHELL_DIFFS = ${addprefix ${SHELL_DIFDIR}/, ${SHELL_BASES:%.sh=%.diff}}
#------------------------------------------------------------------------------
.PHONY: outputs test
outputs: ${RES_FILES} ${TST_OUTPUTS}
test: ${DIFF_FILES} ${TST_DIFFS}
${DIFF_FILES}: ${TARGET}
${DIFFIL_DIR}/%.diff: ${TARGET} ${TEST_DIR}/%${EXT}
-@printf "%-30s " "$*:" ; \
if [ ! -f ${TEST_DIR}/$*.chk ] || ${TEST_DIR}/$*.chk; then \
unset SL_INCLUDE_PATHS; \
./$^ ${TEST_OPTIONS} 2>&1 \
| diff -u ${OUTPUT_DIR}/$*.out - > $@ ; \
if [ $$? = 0 ]; \
then echo "OK"; \
else echo "FAILED:"; cat $@; \
fi; \
else \
echo " -- SKIPPED"; \
touch $@; \
fi
${OUTPUT_DIR}/%.out: ${TARGET} ${TEST_DIR}/%${EXT}
-@test -f $@ || echo "$@:"
-@unset SL_INCLUDE_PATHS; \
test -f $@ || ./$^ ${TEST_OPTIONS} 2>&1 | tee $@
-@touch $@
${TST_OUT_DIR}/%.out: ${TST_EXE_DIR}/%
-@test -f $@ || echo "$@:"
-@unset SL_INCLUDE_PATHS; \
test -f $@ || $< 2>&1 | tee $@
-@touch $@
${TST_DIF_DIR}/%.diff: ${TST_EXE_DIR}/%
-@printf "%-30s " "$*:" ; \
unset SL_INCLUDE_PATHS; \
./$< 2>&1 | diff -u ${TST_OUT_DIR}/$*.out - > $@ ; \
if [ $$? = 0 ]; then echo "OK"; else echo "FAILED:"; cat $@; fi
.PHONY: shoutpus shout shtests shtest
shoutputs shout: ${SHELL_OUTPUTS}
shtest shtests: ${SHELL_DIFFS}
${SHELL_OUTDIR}/%.out: ${SHELL_TSTDIR}/%.sh ${TARGET}
-@test -f $@ || echo "$@:"
-@unset SL_INCLUDE_PATHS; \
test -f $@ || $< 2>&1 | tee $@
-@touch $@
${SHELL_DIFDIR}/%.diff: ${SHELL_TSTDIR}/%.sh ${TARGET}
-@printf "%-30s " "$*:" ; \
unset SL_INCLUDE_PATHS; \
$< 2>&1 | diff -u ${SHELL_OUTDIR}/$*.out - > $@ ; \
if [ $$? = 0 ]; then echo "OK"; else echo "FAILED:"; cat $@; fi
.PHONY: tests alltests
tests alltests: test shtests
.PHONY: listdiff failed
listdiff failed: # test
@- ( \
if [ -d ${DIFFIL_DIR} ]; then \
find ${DIFFIL_DIR} -name '*.diff' -size +0; \
fi; \
if [ -d ${TST_DIF_DIR} ]; then \
find ${TST_DIF_DIR} -name '*.diff' -size +0; \
fi; \
if [ -d ${SHELL_DIFDIR} ]; then \
find ${SHELL_DIFDIR} -name '*.diff' -size +0; \
fi \
) | sort -u
#------------------------------------------------------------------------------
.PHONY: benchmark benchmarks bench
BENCH_DIR = ./benchmarks
ARCH_TYPE = ${shell uname -m}
BENCH_FILE = ${BENCH_DIR}/times-${ARCH_TYPE}.dat
SIZE_FILE = ${BENCH_DIR}/sizes-${ARCH_TYPE}.dat
BENCH_INPUTS = $(sort ${wildcard ${BENCH_DIR}/*${EXT}})
benchmarks benchmark bench: ${BENCH_FILE} ${SIZE_FILE}
${BENCH_FILE}: ${TARGET} ${BENCH_INPUTS}
date | tee $@
uname -srm | tee -a $@
if [ -f /proc/cpuinfo ]; then \
awk -F: '/^model name/{print $$2}' /proc/cpuinfo \
| sed -e 's/^ *//g; s/ *$$//g' \
| tee -a $@; \
fi
${CCVER} --version | head -n 1 | tee -a $@
for i in ${BENCH_DIR}/*${EXT}; \
do \
printf "%-20s " `basename $$i` ; \
printf "%s %-11s " \
`bash -c "time ./$< ${TEST_OPTIONS} $$i > /dev/null" 2>&1` \
| awk '{print $$1, $$2}' ; \
done | tee -a $@
${SIZE_FILE}: ${TARGET} ${BENCH_INPUTS}
date | tee $@
uname -srm | tee -a $@
${CCVER} --version | head -n 1 | tee -a $@
for i in ${BENCH_DIR}/*${EXT}; \
do \
printf "%-20s " `basename $$i` ; \
printf "%4d\n" `./$< ${SIZE_OPTIONS} $$i 2> /dev/null | wc -l` ; \
done | tee -a $@
#------------------------------------------------------------------------------
clean:
rm -f *~
rm -f ${DEL_OBJS} ${FLEXOBJ} ${YYOBJ}
rm -f *.tab.c lex.yy.c *.lex.c *.tab.h *.output
rm -f ${DIFF_FILES} ${TST_DIFFS}
rm -f ${SHELL_DIFFS}
cleanAll distclean: clean ${LOCAL_CLEAN_TARGETS}
rm -f ${EXE_FILES} ${TST_DRIVERS}
rm -f ${DEPEND_FILES}
rm -f ${LOCAL_LIB}
rm -f ${LOCAL_SO} ${LOCAL_SO}.${SO_MAJOR} ${LOCAL_SOV}
#------------------------------------------------------------------------------
.PHONY: alltests testall
alltests testall:
./tools/testall 2>&1 | tee testall.log
${MAKE}