forked from Wilfred/babyc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
54 lines (37 loc) · 1.44 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
CC = clang
CFLAGS = -Wall -Wextra -g -O0 -std=gnu99 -fstack-protector-all -ftrapv
BUILD_DIR = build
all: $(BUILD_DIR)/babyc
$(BUILD_DIR):
@mkdir $(BUILD_DIR)
$(BUILD_DIR)/lex.yy.c: babyc_lex.l $(BUILD_DIR)/y.tab.h
lex -t $< > $@
$(BUILD_DIR)/lex.yy.o: $(BUILD_DIR)/lex.yy.c
$(CC) $(CFLAGS) -Wno-unused-function -c $< -o $@
$(BUILD_DIR)/y.tab.c $(BUILD_DIR)/y.tab.h: babyc_parse.y
yacc -d $< -o $(BUILD_DIR)/y.tab.c
$(BUILD_DIR)/y.tab.o: $(BUILD_DIR)/y.tab.c syntax.c stack.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/stack.o: stack.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/assembly.o: assembly.c syntax.c environment.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/syntax.o: syntax.c list.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/list.o: list.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/environment.o: environment.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/babyc: $(BUILD_DIR) $(BUILD_DIR)/lex.yy.o $(BUILD_DIR)/y.tab.o $(BUILD_DIR)/syntax.o $(BUILD_DIR)/environment.o $(BUILD_DIR)/assembly.o $(BUILD_DIR)/stack.o $(BUILD_DIR)/list.o main.c
$(CC) $(CFLAGS) -o $@ main.c $(BUILD_DIR)/lex.yy.o $(BUILD_DIR)/y.tab.o $(BUILD_DIR)/syntax.o $(BUILD_DIR)/environment.o $(BUILD_DIR)/assembly.o $(BUILD_DIR)/stack.o $(BUILD_DIR)/list.o
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
$(BUILD_DIR)/run_tests: run_tests.c $(BUILD_DIR)/babyc
$(CC) $(CFLAGS) $< -o $@
.PHONY: test
test: $(BUILD_DIR)/run_tests
@./$^
.PHONY: format
format:
clang-format -i *.c *.h