-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
113 lines (76 loc) · 2.22 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
include Make.defaults
include Make.rules
SRC := $(shell find src -name *.sign)
VERSION := $(shell git describe --broken --dirty)
CCFLAGS += -DSIGNCVERSION=$(VERSION)
STAGE1_LEX := $(BUILD_DIR)/stage1.lex
STAGE2_LEX := $(BUILD_DIR)/stage2.lex
STAGE3_LEX := $(BUILD_DIR)/stage3.lex
STAGE1_PARSE := $(BUILD_DIR)/stage1.parse
STAGE2_PARSE := $(BUILD_DIR)/stage2.parse
STAGE3_PARSE := $(BUILD_DIR)/stage3.parse
STAGE1_GEN := $(BUILD_DIR)/stage1.c
STAGE2_GEN := $(BUILD_DIR)/stage2.c
STAGE3_GEN := $(BUILD_DIR)/stage3.c
STAGE_1 := $(BUILD_DIR)/stage1
STAGE_2 := $(BUILD_DIR)/stage2
STAGE_3 := $(BUILD_DIR)/stage3
SIGNC := $(BIN_DIR)/signc
.PHONY: all
all: $(STAGE_3)
@
.PHONY: install
install: .$(SIGNC)
@
# Only delete $(BIN_DIR) if we know it is safe (not set by user)
ifeq ($(origin SIGN_INSTALL_PATH),file)
.PHONY: clean-bin
clean-bin: clean
@$(RM) -r $(BIN_DIR)
endif
.PHONY: clean
clean::
@$(RM) -r $(BUILD_DIR)
.PHONY: signc
signc: .$(SIGNC)
@
.PHONY: stage1
stage1: $(STAGE_1)
@
.PHONY: stage2
stage2: $(STAGE_2)
@
.PHONY: stage3
stage3: $(STAGE_3)
@
$(STAGE1_LEX): $(SRC) | $(BUILD_DIR)
@$(SIGNC) -l $(SRC) > $@
$(STAGE1_PARSE): $(SRC) | $(BUILD_DIR)
@$(SIGNC) -p $(SRC) > $@
$(STAGE1_GEN): $(SRC) | $(BUILD_DIR)
@$(SIGNC) -g $(SRC) > $@
$(STAGE_1): $(STAGE1_LEX) $(STAGE1_PARSE) $(STAGE1_GEN)
@$(CC) $(CCFLAGS) -o $@ $(STAGE1_GEN)
$(STAGE2_LEX): $(STAGE_1) $(SRC)
@$< -l $(SRC) > $@
$(STAGE2_PARSE): $(STAGE_1) $(SRC)
@$< -p $(SRC) > $@
$(STAGE2_GEN): $(STAGE_1) $(SRC)
@$< -g $(SRC) > $@
$(STAGE_2): $(STAGE2_LEX) $(STAGE2_PARSE) $(STAGE2_GEN)
@$(CC) $(CCFLAGS) -o $@ $(STAGE2_GEN)
$(STAGE3_LEX): $(STAGE_2) $(SRC)
@$< -l $(SRC) > $@
$(STAGE3_PARSE): $(STAGE_2) $(SRC)
@$< -p $(SRC) > $@
$(STAGE3_GEN): $(STAGE_2) $(SRC)
@$< -g $(SRC) > $@
$(STAGE_3): $(STAGE3_LEX) $(STAGE3_PARSE) $(STAGE3_GEN)
@$(CC) $(CCFLAGS) -o $@ $(STAGE3_GEN)
.$(SIGNC): $(STAGE_3) | .$(BIN_DIR)
@diff -q $(STAGE2_LEX) $(STAGE3_LEX) >/dev/null || (echo "Stage 3 lexer failed" && exit 1)
@diff -q $(STAGE2_PARSE) $(STAGE3_PARSE) >/dev/null || (echo "Stage 3 parser failed" && exit 1)
@diff -q $(STAGE2_GEN) $(STAGE3_GEN) >/dev/null || (echo "Stage 3 c codegen failed" && exit 1)
@cp $< $(SIGNC)
include Make.test
include Make.docker