This repository was archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
100 lines (82 loc) · 3 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
# config.mk contains the paths to antlr4 etc.
# Each student should have a config.mk corresponding to her system.
# Examples are ubuntu.mk, DI.mk, fedora.mk
# Then config.mk should be in the .gitignore of your project
ifeq ($(wildcard makefiles/config.mk),)
include makefiles/DI.mk
else
include makefiles/config.mk
endif
CC=g++
CCFLAGS=-g -c -std=c++17 -I$(ANTLRINC) -Wno-attributes # -Wno-defaulted-function-deleted -Wno-unknown-warning-option
LDFLAGS=-g
SRC_DIR = src
BUILD_DIR = build
GENERATED_DIR = $(SRC_DIR)/generated
TEST_OUTPUT = tests-output
DOC_DIR = doc
EXE = ifcc
default: all
all: $(EXE)
##########################################
# automatically find source files
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
# form object file names
OBJECTS := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRCS))
# generated objects
GENERATED_OBJECTS=\
$(BUILD_DIR)/ifccBaseVisitor.o \
$(BUILD_DIR)/ifccLexer.o \
$(BUILD_DIR)/ifccVisitor.o \
$(BUILD_DIR)/ifccParser.o \
##########################################
# link together all pieces of our compiler
$(EXE): $(OBJECTS)
@mkdir -p $(BUILD_DIR)
$(CC) $(LDFLAGS) $(OBJECTS) $(GENERATED_OBJECTS) $(ANTLRLIB) -o $(EXE)
##########################################
# compile our hand-written C++ code: main(), Visitors, etc.
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(GENERATED_OBJECTS)
@mkdir -p $(BUILD_DIR)
$(CC) $(CCFLAGS) -MMD -o $@ $<
##########################################
# compile all the antlr-generated C++
$(BUILD_DIR)/%.o: $(GENERATED_DIR)/%.cpp
@mkdir -p $(BUILD_DIR)
$(CC) $(CCFLAGS) -MMD -o $@ $<
# automagic dependency management: `gcc -MMD` generates all the .d files for us
-include $(BUILD_DIR)/*.d
$(BUILD_DIR)/%.d:
##########################################
# generate the C++ implementation of our Lexer/Parser/Visitor
$(GENERATED_DIR)/ifccLexer.cpp: $(GENERATED_DIR)/ifccParser.cpp
$(GENERATED_DIR)/ifccVisitor.cpp: $(GENERATED_DIR)/ifccParser.cpp
$(GENERATED_DIR)/ifccBaseVisitor.cpp: $(GENERATED_DIR)/ifccParser.cpp
$(GENERATED_DIR)/ifccParser.cpp: ifcc.g4
@mkdir -p $(GENERATED_DIR)
$(ANTLR) -visitor -no-listener -Dlanguage=Cpp -o $(GENERATED_DIR) ifcc.g4
# prevent automatic cleanup of "intermediate" files like ifccLexer.cpp etc
.PRECIOUS: $(GENERATED_DIR)/ifcc%.cpp $(GENERATED_OBJECTS)
##########################################
# view the parse tree in a graphical window
# Usage: `make gui FILE=path/to/your/file.c`
FILE ?= tests/testfiles/1_return42.c
gui:
@mkdir -p $(GENERATED_DIR) $(BUILD_DIR)
$(ANTLR) -Dlanguage=Java -o $(GENERATED_DIR) ifcc.g4
javac -cp $(ANTLRJAR) -d $(BUILD_DIR) $(GENERATED_DIR)/*.java
java -cp $(ANTLRJAR):$(BUILD_DIR) org.antlr.v4.gui.TestRig $(EXE) axiom -gui $(FILE)
##########################################
# run tests
test: $(EXE)
python3 ifcc-test.py tests
##########################################
# delete all machine-generated files
clean:
rm -rf $(BUILD_DIR) $(GENERATED_DIR) $(TEST_OUTPUT) $(DOC_DIR)
rm -f $(EXE)
##########################################
# documentation
doc:
doxygen
xdg-open $(DOC_DIR)/index.html