-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
54 lines (39 loc) · 1.37 KB
/
Copy pathMakefile
File metadata and controls
54 lines (39 loc) · 1.37 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
CC = gcc
CFLAGS = -Wall -g -Wno-unused-function -Wno-format-truncation
FLEX = flex
BISON = bison
SRC_DIR = src
BUILD_DIR = build
OBJS = $(BUILD_DIR)/lex.yy.o $(BUILD_DIR)/minilang.tab.o \
$(BUILD_DIR)/symbol_table.o $(BUILD_DIR)/ast.o \
$(BUILD_DIR)/code_gen.o $(BUILD_DIR)/main.o
TARGET = minilang
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ -lm
$(BUILD_DIR)/lex.yy.o: $(SRC_DIR)/lex.yy.c $(SRC_DIR)/minilang.tab.h
mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/minilang.tab.o: $(SRC_DIR)/minilang.tab.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/symbol_table.o: $(SRC_DIR)/symbol_table.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/ast.o: $(SRC_DIR)/ast.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/code_gen.o: $(SRC_DIR)/code_gen.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/main.o: $(SRC_DIR)/main.c
$(CC) $(CFLAGS) -c $< -o $@
$(SRC_DIR)/lex.yy.c: $(SRC_DIR)/minilang.l
$(FLEX) -o $@ $<
$(SRC_DIR)/minilang.tab.c $(SRC_DIR)/minilang.tab.h: $(SRC_DIR)/minilang.y
$(BISON) -d -o $@ $< 2>/dev/null || $(BISON) -d -o $@ $<
clean:
rm -rf $(BUILD_DIR) $(TARGET) $(SRC_DIR)/lex.yy.c $(SRC_DIR)/minilang.tab.c $(SRC_DIR)/minilang.tab.h
rm -f *.c *.txt compile_error.log
rm -f tests/*.c tests/*.txt tests/compile_error.log
for f in tests/*.min; do \
rm -f "$${f%.min}"; \
done
chmod +x tests/run_tests.sh 2>/dev/null || true
.PHONY: all clean