-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (53 loc) · 2 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
PATH_SRC := src
PATH_LIB := lib
PATH_BUILD := build
PATH_BIN := bin
PATH_OBJ := $(PATH_BUILD)/obj
PATH_DEP := $(PATH_BUILD)/dep
include common_vars.mk
LDFLAGS += # -L $(PATH_LIB)
LDLIBS += # -l
CPPFLAGS += # -I
OUT_EXE := program.exe
#----------------------------------------
VPATH = $(PATH_SRC)
FILES = $(patsubst src/%, %, $(shell find $(PATH_SRC) -name "*.cpp" -type f))
FOLDERS = $(patsubst src/%, %, $(shell find $(PATH_SRC) -mindepth 1 -type d))
FILES_DEP = $(patsubst %, $(PATH_DEP)/%.d, $(basename $(FILES)))
FILES_OBJ = $(patsubst %, $(PATH_OBJ)/%.o, $(basename $(FILES)))
#----------------------------------------
all: $(PATH_BIN)/$(OUT_EXE)
$(PATH_BIN)/$(OUT_EXE): $(FILES_OBJ)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
DEPFLAGS = -MT $@ -MMD -MP -MF $(PATH_DEP)/$*.dTMP
POSTCOMPILE = @$(MOVE) $(PATH_DEP)/$*.dTMP $(PATH_DEP)/$*.d > $(NULL_DEVICE) && touch $@
$(PATH_OBJ)/%.o: %.cpp
$(PATH_OBJ)/%.o: %.cpp $(PATH_DEP)/%.d | directories
$(CXX) $(CPPFLAGS) -c $(DEPFLAGS) $< -o $@
$(POSTCOMPILE)
.PRECIOUS: $(FILES_DEP)
$(FILES_DEP): ;
-include $(FILES_DEP)
#----------------------------------------
directories: $(PATH_BUILD) $(PATH_BIN) $(PATH_OBJ) $(PATH_DEP) nested-folders
nested-folders: $(addprefix $(PATH_OBJ)/, $(FOLDERS)) $(addprefix $(PATH_DEP)/, $(FOLDERS))
$(PATH_BUILD): ; $(MKDIR) $@
$(PATH_BIN): ; $(MKDIR) $@
$(PATH_OBJ): ; $(MKDIR) $@
$(PATH_DEP): ; $(MKDIR) $@
$(addprefix $(PATH_OBJ)/, $(FOLDERS)): ; @$(MKDIR) $@
$(addprefix $(PATH_DEP)/, $(FOLDERS)): ; @$(MKDIR) $@
#----------------------------------------
.PHONY: all directories nested-folders \
clean clean-obj clean-dep clean-exe delete-build \
run help
clean: clean-obj clean-dep clean-exe
clean-obj: ; $(RMDIR) $(PATH_OBJ)/*
clean-dep: ; $(RMDIR) $(PATH_DEP)/*
clean-exe: ; $(RM) $(PATH_BIN)/$(OUT_EXE)
delete-build: ; $(RMDIR) $(PATH_BUILD)
ARGS ?=
run: ; @cd $(PATH_BIN) && ./$(OUT_EXE) $(ARGS)
help:
@echo Targets: all clean clean-obj clean-dep clean-exe delete-build run
@echo '(make run ARGS="arg1 arg2...")'