-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakefile
99 lines (85 loc) · 2.61 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
############################################################################################
################################## GENERIC MAKEFILE ########################################
############################################################################################
# TODO: gèrer les extentions .hpp, .cxx, ...
# Debug mode (comment this line to build project in release mode)
DEBUG = true
# Compiler
CC = g++
# Command used to remove files
RM = -rm -f
# Compiler and pre-processor options
CPPFLAGS = -Wall -std=c++14 -O0
# Add -Ofast for opt
# Debug flags
DEBUGFLAGS = -ggdb
# Resulting program file name
EXE_NAME = c_compiler
# The source file extentions
SRC_EXT = cpp
# The header file types
# TODO allow .hpp header files
HDR_EXT = h
# Source directory
SRCDIR = source
# Headers directory
INCDIR = include
# Main output directory
OUTPUT_DIR = bin
# Release output directory
RELEASEDIR = release
# Debug output directory
DEBUGDIR = debug
# Dependency files directory
DEPDIR = dep
# Libraries (defines different library path if '.MAC' file is found in directory)
ifneq ("$(wildcard ./.MAC)","")
LIBS = -L./antlr/mac_antlr4-runtime/lib/ -lantlr4-runtime
else
LIBS = -L./antlr/runtime_source/dist/ -l:libantlr4-runtime.a
endif
# List of include paths
INCLUDES = -I ./$(INCDIR) -I ./antlr/runtime_source/runtime/src
ifdef DEBUG
BUILD_PATH = ./$(OUTPUT_DIR)/$(DEBUGDIR)
else
DEBUGFLAGS =
BUILD_PATH = ./$(OUTPUT_DIR)/$(RELEASEDIR)
endif
# Source directory path
SRC_PATH = ./$(SRCDIR)
# Dependencies path
DEP_PATH = $(BUILD_PATH)/$(DEPDIR)
# List of source files
SOURCES = $(wildcard $(SRC_PATH)/*.$(SRC_EXT)) $(wildcard $(SRC_PATH)/**/*.$(SRC_EXT))
# List of object files
OBJS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
# List of dependency files
DEPS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(DEP_PATH)/%.d)
# Source directories (VPATH is internally used by make)
VPATH := $(dir $(SOURCES))
.PHONY: all clean compile_grammar rebuild help
all: $(BUILD_PATH)/$(EXE_NAME)
clean:
@$(RM) $(BUILD_PATH) -r
@$(RM) ./include/antlr -r
@$(RM) ./source/antlr -r
compile_grammar:
./compile_grammar.sh
rebuild: clean compile_grammar all
rebuild_nogrammar : clean all
help:
@echo ' ### MAKEFILE HELP ###'
@echo 'PHONY TARGETS:'
@echo ' all ...'
@echo ' clean ...'
@echo ' rebuild ...'
@echo ' compile_grammar ...'
@echo ' help ...'
# Build object files
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@mkdir -p $(dir $(DEPS)) $(dir $(OBJS))
$(CC) $(CPPFLAGS) $(DEBUGFLAGS) $(INCLUDES) -MMD -MP -MF $(DEP_PATH)/$*.d -c $< -o $@
# Build main target
$(BUILD_PATH)/$(EXE_NAME): $(OBJS)
$(CC) $(OBJS) -o $(BUILD_PATH)/$(EXE_NAME) $(LIBS)