-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
91 lines (75 loc) · 2.21 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
COMPILER = jay
TEST_EXEC = jay.test
CXXFLAGS = -Wall -std=c++17
LDFLAGS = -lfl
DFLAGS :=
CXX = g++
SRC_PATH = ./src
BUILD_PATH = ./build
# INCLUDE := -I $(SRC)/include/ -I parser.tab.hh
INCLUDE := -I $(SRC_PATH)/include
TESTINCLUDE := -I lib/catch2
SOURCES = lex.yy.cc parser.tab.cc src/string_builder.c src/SymTable.cpp src/SemanticAnalyzer.cpp src/JayCompiler.cpp
CPP_SOURCES = $(shell find $(SRC_PATH) \( -name '*.cpp' \) -printf '%T@\t%p\n' | sort -k 1nr | cut -f2-)
CPP_HEADERS = $(shell find $(SRC_PATH) -name '*.h*' -printf '%T@\t%p\n' | sort -k 1nr | cut -f2-)
OBJECTS = $(CPP_SOURCES:$(SRC_PATH)/%.cpp=$(BUILD_PATH)/%.o)
OBJECTS_NO_MAIN := $(shell find $(BUILD_PATH)/ ! -name 'main.o' -name '*.o')
export V := false
export CMD_PREFIX := @
ifeq ($(V),true)
CMD_PREFIX :=
endif
.PHONY: all
all:
@ $(MAKE) -s scanner
@ $(MAKE) -s parser
@ $(MAKE) -s $(COMPILER)
scanner: $(SRC_PATH)/scanner.l
@ echo "flex: generating scanner"
$(CMD_PREFIX)flex -o $(SRC_PATH)/lex.yy.cpp src/scanner.l
parser: $(SRC_PATH)/parser.yy
@ echo "bison: generating parser"
$(CMD_PREFIX)bison -t -d $(SRC_PATH)/parser.yy -o $(SRC_PATH)/parser.tab.cpp
@ mv $(SRC_PATH)/*.h* $(SRC_PATH)/include/
$(COMPILER): $(OBJECTS)
@ echo "compiling executable: \`$@\`..."
$(CMD_PREFIX)$(CXX) $(CXXFLAGS) $(DFLAGS) $(OBJECTS) -o $@
@ echo "compiled. executable is \`$@\`."
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.c*
@ echo " > compiling $< -> $@"
$(CMD_PREFIX)$(CXX) $(CXXFLAGS) $(DFLAGS) $(INCLUDE) -c $< -o $@
.PHONY: build
build: clear
build: all
.PHONY: debug
debug: DFLAGS=-g -DYYTRACE
debug: clear
debug: all
.PHONY: run
run: clear
run: $(COMPILER)
run:
./$(COMPILER) $(FILE)
.PHONY: run
run_debug: debug
run_debug:
./$(COMPILER) $(FILE)
.PHONY: test
test: test_runner
.PHONY: test_runner
test_runner: build
test_runner:
@ chmod +x ./test.sh
./test.sh
.PHONY: export
export: clear
export: ARCHIVE_NAME := artem-golovin-$(MSPART)
export:
git archive -o $(ARCHIVE_NAME).zip HEAD
.PHONY: clear
clear:
@ echo "> cleaning build & misc files..."
@ -rm -rf src/include/stack.hh src/*.tab.cpp src/include/*.tab.hpp src/*.yy.cpp $(COMPILER) $(TEST_EXEC) *.totallynotzip 2> /dev/null
@ -rm -rf build/*.o 2> /dev/null
@ -rm *.wat *.wasm 2> /dev/null
@ echo "> done"