-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (64 loc) · 2.02 KB
/
Makefile
File metadata and controls
82 lines (64 loc) · 2.02 KB
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
PRJNAME=jsprint
CXX=g++
CXXFLAGS=
CXXFLAGSDEF=-std=c++20 -pedantic -Wall -Wextra -Werror
CXXFLAGSDEB=$(CXXFLAGSDEF) -g -pg -O0 -DDEBUG
CXXFLAGSREL=$(CXXFLAGSDEF) -O3 -s -DNDEBUG
LDLIBS=
LDFLAGS=
LDFLAGSDEF=-L/usr/lib -Wl,-rpath,'$$ORIGIN' -Wl,--as-needed -Llib -Lbin/
LDFLAGSDEB=$(LDFLAGSDEF) $(LDLIBS)
LDFLAGSREL=$(LDFLAGSDEF) $(LDLIBS)
LDFLAGSTST=
DEPDIR=bin
OUTDIR=trg
OUTDIRBIN=$(OUTDIR)/bin
OUTDIROBJ=$(OUTDIR)/obj
OUTDIREXE=$(PRJNAME)
SRC=src
SRCAPP=$(SRC)
SRCDIRSAPP := $(shell find $(SRCAPP) -maxdepth 5 -type d)
SRCFILESAPP := $(foreach dir,$(SRCDIRSAPP),$(wildcard $(dir)/*.cpp))
OBJFILESAPP := $(addprefix $(OUTDIROBJ)/,$(subst $(SRCAPP)/, ,$(patsubst %.cpp,%.o,$(SRCFILESAPP))))
define set_real_src_file
$(eval REAL_SRC_FILE=$(strip $(1)))
endef
define set_nothing
endef
define get_real_src_file
$(if $(strip $(findstring $(strip $(1)),$(strip $(2)))),$(call set_real_src_file,$(2)),$(call set_nothing))
endef
define get_source_file
$(eval REAL_SRC_SEARCH=$(notdir $(patsubst %.o,%.cpp,$(1))))
$(eval REAL_SRC_FILE=)
$(foreach word,$(2), $(call get_real_src_file, $(REAL_SRC_SEARCH),$(word)))
$(if $(strip $(findstring $(PRJNAME),$(REAL_SRC_SEARCH))),$(call inc_build_version))
@echo "Compile : $(REAL_SRC_FILE) -> $(1)"
endef
define create_object_dir
@mkdir -p $(1)
endef
.PHONY: all
all: debug
debug:CXXFLAGS=$(CXXFLAGSDEB)
debug:LDFLAGS=$(LDFLAGSDEB)
debug:$(OBJFILESAPP)
@mkdir -p $(OUTDIRBIN)
@echo " Target :" $(OUTDIRBIN)/$(OUTDIREXE)
@ $(CXX) -o $(OUTDIRBIN)/$(OUTDIREXE) $^ $(LDFLAGS)
@mkdir -p $(DEPDIR)
@ cp -f $(OUTDIRBIN)/$(OUTDIREXE) $(DEPDIR)
release:CXXFLAGS=$(CXXFLAGSREL)
release:LDFLAGS=$(LDFLAGSREL)
release:$(OBJFILESAPP)
@mkdir -p $(OUTDIRBIN)
@echo " Target :" $(OUTDIRBIN)/$(OUTDIREXE)
@ $(CXX) -o $(OUTDIRBIN)/$(OUTDIREXE) $^ $(LDFLAGS)
@mkdir -p $(DEPDIR)
@ cp -f $(OUTDIRBIN)/$(OUTDIREXE) $(DEPDIR)
$(OBJFILESAPP): $(SRCFILESAPP)
$(call create_object_dir,$(@D))
$(call get_source_file,$@,$^,$<)
@ $(CXX) $(CXXFLAGS) -c $(REAL_SRC_FILE) -o $@
clean:
@rm -rf $(OUTDIR)