-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakefile
78 lines (58 loc) · 1.85 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
MAKE_CHILD_OPTIONS=--no-print-directory
CXX=g++
CXXFLAGS=-Wall -D_DEBUG -g -pthread
BIN_FILE=parser
BIN_DIR=bin
OBJ_DIR=obj
DEP_DIR=$(OBJ_DIR)
SRC_DIR=src/cpp
SRC_PATTERN=\( -name "*.c" -o -name "*.cpp" \)
SRCS=$(shell find $(SRC_DIR) $(SRC_PATTERN))
OBJS=$(patsubst $(SRC_DIR)%,$(OBJ_DIR)%.o,$(basename $(SRCS)))
DEPS=$(patsubst $(SRC_DIR)%,$(DEP_DIR)%.d,$(basename $(SRCS)))
BIN_FILE:=$(BIN_DIR)/$(BIN_FILE)
-include $(DEPS)
PARSER_SRC=src/gsc.ypp
LEXER_SRC=src/gsc.l
PARSER_SRC_OUT=parser/gsc.tab
LEXER_SRC_OUT=parser/gsc.yy
YACC=bison
LEX=flex
YFLAGS=-d
LFLAGS=-d -Cfa --header-file="$(SRC_DIR)/$(LEXER_SRC_OUT).h"
$(SRC_DIR)/$(LEXER_SRC_OUT).cpp $(SRC_DIR)/$(LEXER_SRC_OUT).h: $(LEXER_SRC)
@echo "[COMPILE] $@"
@$(LEX) -o "$(SRC_DIR)/$(LEXER_SRC_OUT).cpp" $(LFLAGS) "$(LEXER_SRC)"
$(SRC_DIR)/$(PARSER_SRC_OUT).cpp $(SRC_DIR)/$(PARSER_SRC_OUT).hpp: $(PARSER_SRC)
@echo "[COMPILE] $@"
@$(YACC) -v -o "$(SRC_DIR)/$(PARSER_SRC_OUT).cpp" $(YFLAGS) "$(PARSER_SRC)"
$(DEP_DIR)/%.d: $(SRC_DIR)/%.cpp $(SRC_DIR)/$(PARSER_SRC_OUT).hpp $(SRC_DIR)/$(LEXER_SRC_OUT).h
@echo "[DEPS] $@"
@mkdir --parents $(dir $@)
@$(CXX) -MM $(word 1,$^) -MT $(OBJ_DIR)/$*.o -MF $@
$(OBJ_DIR)/%.o: $(DEP_DIR)/%.d
@echo "[COMPILE] $*.o"
@mkdir --parents $(dir $@)
@$(CXX) $(CXXFLAGS) -c -o $@ $(filter $(SRCS),$^)
$(BIN_FILE): $(OBJ_DIR)/$(PARSER_SRC_OUT).o $(OBJ_DIR)/$(LEXER_SRC_OUT).o $(OBJS)
@echo "[LINK] $(BIN_FILE)"
@mkdir --parents $(dir $(BIN_FILE))
@$(CXX) $(CXXFLAGS) $^ -o $(BIN_FILE)
# Make the executable binary by default
.DEFAULT_GOAL:=$(BIN_FILE)
.PHONY: build
build: $(BIN_FILE)
.PHONY: clean
clean:
@rm -rf $(BIN_FILE)
@rm -rf $(DEP_DIR)
@rm -rf $(OBJ_DIR)
@mkdir -p src/cpp/parser && rm -f -r src/cpp/parser/*
.PHONY: test
test:
@$(MAKE) $(MAKE_CHILD_OPTIONS)
$(BIN_FILE)
.PHONY: test-file
test-file:
@$(MAKE) $(MAKE_CHILD_OPTIONS)
@$(BIN_FILE) tree ./bin/test.gsc