-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
49 lines (38 loc) · 1.1 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
# rule to print variables using command line
print-% : ; @echo $* = $($*)
# Main macros for compilation related objects
COMPILER:= g++
D_CFLAGS:= -O0 -g -Wall -std=c++11 -DUNIT_TEST
R_CFLAGS:= -O2 -std=c++11 -DUNIT_TEST
LFLAGS :=
MEXEC := sim_exec
BIN := bin
DOBJ := objs_d
ROBJ := objs_r
SRC := src
INCLUDES:= $(addprefix -I,$(SRC)) -I/usr/include/ -I/usr/local/include/
# setup source files, object files
src := $(foreach SRC, $(SRC), $(wildcard $(SRC)/*.cpp))
objs := $(notdir $(patsubst %.cpp, %.o, $(src)))
d_objs := $(patsubst %.o, $(DOBJ)/%.o, $(objs))
r_objs := $(patsubst %.o, $(ROBJ)/%.o, $(objs))
# setup vpath
VPATH = $(SRC)
# compile shit
all: build
rebuild: clean build
build: debug release
debug: $(d_objs)
mkdir -p $(BIN)
$(COMPILER) $^ -o $(BIN)/$(MEXEC)_d $(LFLAGS)
release: $(r_objs)
mkdir -p $(BIN)
$(COMPILER) $^ -o $(BIN)/$(MEXEC) $(LFLAGS)
$(DOBJ)/%.o: %.cpp
mkdir -p $(DOBJ)
$(COMPILER) $(D_CFLAGS) $(INCLUDES) -c $< -o $@
$(ROBJ)/%.o: %.cpp
mkdir -p $(ROBJ)
$(COMPILER) $(R_CFLAGS) $(INCLUDES) -c $< -o $@
clean:
rm -rf $(DOBJ) $(ROBJ) $(BIN)/$(MEXEC)*