-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
69 lines (58 loc) · 1.63 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
# compilers
CC := clang
CFLAGS := -Wall -Wno-strict-aliasing -Wno-deprecated-register -Iinclude -std=c++11 -g
LFLAGS := -lstdc++
# directories
INCLUDES_DIR := include
BUILD_DIR := build
EXEC_DIR := bin
vpath %.cpp src
vpath %.cpp src/parser
vpath %.cpp src/nodes
vpath %.cpp src/dictionary
# files
MAIN := src/main.cpp
PARSER := src/parser/parser.ypp
PARSER_GEN := $(addsuffix .gen.cpp, $(basename $(PARSER)))
PARSER_H := $(addsuffix .h, include/parser/$(basename $(notdir $(PARSER))))
LEXER := src/parser/lexer.l
LEXER_GEN := $(addsuffix .gen.cpp, $(basename $(LEXER)))
LEXER_H := $(addsuffix .h, include/parser/$(basename $(notdir $(LEXER))))
EXEC_NAME := prolog
SOURCES := $(shell find src -name *.cpp)
OBJS := $(addprefix $(BUILD_DIR)/,$(addsuffix .o, $(notdir $(basename $(SOURCES)))))
# Sort out sad platform discrepencies
ifeq ($(shell uname -s), Darwin)
LFLAGS += -ll
CFLAGS += -DOSX=1 -DLINUX=0
else
LFLAGS += -lfl
CFLAGS += -DOSX=0 -DLINUX=1
endif
all: prelude
$(MAKE) parser
$(MAKE) prolog
prelude: clean
@mkdir -p $(INCLUDES_DIR)
@mkdir -p $(BUILD_DIR)
@mkdir -p $(EXEC_DIR)
$(BUILD_DIR)/%.o: %.cpp
@echo "\nBuilding $<"
$(CC) $(CFLAGS) -c -o $@ $<
prolog: $(OBJS)
@echo "\nBuilding program $(EXEC_NAME)..."
$(CC) $(CFLAGS) -o $(EXEC_DIR)/$(EXEC_NAME) $(OBJS) $(LFLAGS)
parser:
@echo "\nGenerating parser..."
flex --header-file=$(LEXER_H) -o $(LEXER_GEN) $(LEXER)
bison --defines=$(PARSER_H) -o $(PARSER_GEN) $(PARSER)
run: all
@echo "\nRunning..."
./$(EXEC_DIR)/$(EXEC_NAME)
clean:
rm -rf $(BUILD_DIR)
rm -f $(PARSER_H)
rm -f $(LEXER_H)
rm -f $(PARSER_GEN)
rm -f $(LEXER_GEN)
.PHONY: prelude prolog parser run clean