-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
78 lines (65 loc) · 2.36 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
CFLAGS=-std=c11 -g -static
SRCS=$(wildcard src/*.c)
OBJS=$(SRCS:.c=.o)
$(OBJS): src/ccc.h
ccc: $(OBJS)
@$(CC) -o $@ $(OBJS) $(CFLAGS)
lint:
clang-format -i src/*.c
clang-format -i src/*.h
test: ccc
./ccc test/test.c > tmp.s
cat test/helper.c | gcc -xc -c -o tmp2.o -
gcc -static -o tmp tmp.s tmp2.o
./tmp
clean:
rm -f ccc src/*.o *~ tmp* stage*/*
help:
@echo "Usage: make [lint|test|clean|self-host]"
@echo " lint: run c and shell checker"
@echo " test: run tests"
@echo " clean: remove object files"
@echo " self-host: check self-hosted compiler"
# stage0: gcc
# stage1: ccc on host machine generated by stage0 (gcc)
# stage2: ccc on X86-64 machine generated by stage1
# stage3: ccc on X86-64 machine generated by stage2
ccc-stage1: $(OBJS)
@rm -rf stage1
@mkdir stage1
$(CC) -o stage1/$@ $(OBJS) $(CFLAGS)
ccc-stage2: ccc-stage1 $(SRCS)
@rm -rf stage2
@mkdir stage2
@echo "`-D__ccc_self__` is to avoid `#include \"ccc.h\"`"
$(CC) -D__ccc_self__ -E -P src/codegen.c -o stage2/codegen.c
$(CC) -D__ccc_self__ -E -P src/main.c -o stage2/main.c
$(CC) -D__ccc_self__ -E -P src/parse.c -o stage2/parse.c
$(CC) -D__ccc_self__ -E -P src/tokenize.c -o stage2/tokenize.c
$(CC) -D__ccc_self__ -E -P src/type.c -o stage2/type.c
stage1/ccc-stage1 stage2/codegen.c > stage2/codegen.s
stage1/ccc-stage1 stage2/main.c > stage2/main.s
stage1/ccc-stage1 stage2/parse.c > stage2/parse.s
stage1/ccc-stage1 stage2/tokenize.c > stage2/tokenize.s
stage1/ccc-stage1 stage2/type.c > stage2/type.s
$(CC) -o stage2/$@
ccc-stage3: ccc-stage2 $(SRCS)
@rm -rf stage3
@mkdir stage3
@echo "`-D__ccc_self__` is to avoid `#include \"ccc.h\"`"
$(CC) -D__ccc_self__ -E -P src/type.c -o stage3/type.c
$(CC) -D__ccc_self__ -E -P src/codegen.c -o stage3/codegen.c
$(CC) -D__ccc_self__ -E -P src/main.c -o stage3/main.c
$(CC) -D__ccc_self__ -E -P src/parse.c -o stage3/parse.c
$(CC) -D__ccc_self__ -E -P src/tokenize.c -o stage3/tokenize.c
stage2/ccc-stage2 stage3/codegen.c > stage3/codegen.s
stage2/ccc-stage2 stage3/main.c > stage3/main.s
stage2/ccc-stage2 stage3/parse.c > stage3/parse.s
stage2/ccc-stage2 stage3/tokenize.c > stage3/tokenize.s
stage2/ccc-stage2 stage3/type.c > stage3/type.s
$(CC) -o stage3/$@
self-host: ccc-stage1 ccc-stage2 ccc-stage3
strip stage2/ccc-stage2
strip stage3/ccc-stage3
diff -s stage2/ccc-stage2 stage3/ccc-stage3
.PHONY: all help lint test clean self-host