-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
51 lines (36 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
50
#usefull make flags:
#- `-k` continue to compile even if it encounters error
CPP := g++
CPPFLAGS := -Wall -Wextra
#CPPFLAGS += -Werror
CPPFLAGS += -g
#-pg #profiling gprof
#ncurses wide caracter varaint library
LDFLAGS := -lncursesw -ltinfow
CXXFLAGS :=
EXEC := main
BUILD_DIR := ./build
SRC_DIR := ./src
SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
#OBJS:=$(patsubst $(SRC_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(SRCS))
# Every folder in ./src will need to be passed to GCC so that it can find header files
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
#info:
# Outputs the target name
# echo $@
# Outputs all prerequisites
# echo $(BUILD_DIR)/$(EXEC)
run: $(BUILD_DIR)/$(EXEC)
${BUILD_DIR}/${EXEC}
#if the program exit with an error make will tell something like: "make: *** [makefile:--: run] Error 1"
# The final build step.
build: $(BUILD_DIR)/$(EXEC)
$(BUILD_DIR)/$(EXEC): $(OBJS)
$(CPP) $(OBJS) -o $@ $(LDFLAGS)
$(BUILD_DIR)/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(CPP) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
clean:
rm -r $(BUILD_DIR)
rebuild: clean $(BUILD_DIR)/$(EXEC)