-
Notifications
You must be signed in to change notification settings - Fork 747
/
Makefile
74 lines (57 loc) · 1.55 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
CFLAGS=-Wall -Wno-strict-aliasing -std=gnu11 -g -I. -O0
OBJS=cpp.o debug.o dict.o gen.o lex.o vector.o parse.o buffer.o map.o \
error.o path.o file.o set.o encoding.o
TESTS := $(patsubst %.c,%.bin,$(filter-out test/testmain.c,$(wildcard test/*.c)))
ECC=./8cc
override CFLAGS += -DBUILD_DIR='"$(shell pwd)"'
8cc: 8cc.h main.o $(OBJS)
cc -o $@ main.o $(OBJS) $(LDFLAGS)
$(OBJS) utiltest.o main.o: 8cc.h keyword.inc
utiltest: 8cc.h utiltest.o $(OBJS)
cc -o $@ utiltest.o $(OBJS) $(LDFLAGS)
test/%.o: test/%.c $(ECC)
$(ECC) -w -o $@ -c $<
test/%.bin: test/%.o test/testmain.o
cc -o $@ $< test/testmain.o $(LDFLAGS)
self: 8cc cleanobj
$(MAKE) CC=$(ECC) CFLAGS= 8cc
test: 8cc $(TESTS)
$(MAKE) CC=$(ECC) CFLAGS= utiltest
./utiltest
./test/ast.sh
./test/negative.py
$(MAKE) runtests
runtests:
@for test in $(TESTS); do \
./$$test || exit; \
done
stage1:
$(MAKE) cleanobj
[ -f 8cc ] || $(MAKE) 8cc
mv 8cc stage1
stage2: stage1
$(MAKE) cleanobj
$(MAKE) CC=./stage1 ECC=./stage1 CFLAGS= 8cc
mv 8cc stage2
stage3: stage2
$(MAKE) cleanobj
$(MAKE) CC=./stage2 ECC=./stage2 CFLAGS= 8cc
mv 8cc stage3
# Compile and run the tests with the default compiler.
testtest:
$(MAKE) clean
$(MAKE) $(TESTS)
$(MAKE) runtests
fulltest: testtest
$(MAKE) stage1
$(MAKE) CC=./stage1 ECC=./stage1 CFLAGS= test
$(MAKE) stage2
$(MAKE) CC=./stage2 ECC=./stage2 CFLAGS= test
$(MAKE) stage3
cmp stage2 stage3
clean: cleanobj
rm -f 8cc stage?
cleanobj:
rm -f *.o *.s test/*.o test/*.bin utiltest
all: 8cc
.PHONY: clean cleanobj test runtests fulltest self all