-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
67 lines (54 loc) · 1.38 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
# default target
all:
# dirs
OUTPUT = output
$(OUTPUT):
mkdir -p $@
# files
LEX_INPUT = pascal.l
LEX_OUTPUT = $(OUTPUT)/lex.yy.cpp
LEX_OBJECT = $(LEX_OUTPUT).o
$(LEX_OUTPUT): | $(OUTPUT)
YACC_INPUT = pascal.y
YACC_OUTPUT = $(OUTPUT)/y.tab.cpp
$(YACC_OUTPUT): | $(OUTPUT)
YACC_OBJECT = $(YACC_OUTPUT).o
BINARY = opc
SOURCES := $(wildcard *.cpp)
OBJECTS = $(addprefix $(OUTPUT)/,$(addsuffix .o,$(SOURCES)))
ALL_OBJECTS = $(OBJECTS) $(LEX_OBJECT) $(YACC_OBJECT)
$(ALL_OBJECTS): $(LEX_OUTPUT) $(YACC_OUTPUT)
DEPEND_FILES = $(addsuffix .d,$(ALL_OBJECTS))
-include $(DEPEND_FILES)
# tools
LEX = flex
LEX_FLAGS =
YACC = bison
YACC_FLAGS = -d -y
CC = g++
CC_FLAGS = -ggdb -Wall -I. -I$(OUTPUT)
CC_COMPILE = $(CC) $(CC_FLAGS) -c -o $@ -MMD -MP -MF $@.d
LINK = g++
LINK_FLAGS =
TEST = python test.py
# rulz
$(OBJECTS):
$(CC_COMPILE) $(notdir $(basename $@))
$(LEX_OUTPUT): $(LEX_INPUT)
$(LEX) $(LEX_FLAGS) -o$(LEX_OUTPUT) $(LEX_INPUT)
$(LEX_OBJECT):
$(CC_COMPILE) $(LEX_OUTPUT)
$(YACC_OUTPUT): $(YACC_INPUT)
$(YACC) $(YACC_FLAGS) $(YACC_INPUT) -o $(YACC_OUTPUT)
sed -i 1i'#include "parser.h"' $(basename $(YACC_OUTPUT)).hpp
$(YACC_OBJECT):
$(CC_COMPILE) $(YACC_OUTPUT)
all: $(BINARY)
$(BINARY): $(ALL_OBJECTS)
$(LINK) $(LINK_FLAGS) $(ALL_OBJECTS) -o $(BINARY)
test: all
$(TEST)
clean:
rm -rf $(OUTPUT) $(BINARY)
# the | in this list is because old make doesn't have order-only rules
.PHONY: all clean |