-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCppTemplate2.mk
55 lines (43 loc) · 1.08 KB
/
CppTemplate2.mk
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
# https://github.com/tch0/MyConfigurations/blob/master/MakefileTemplate/CppTemplate2.mk
# Makefile template 2:
# For multiple C++ files in one directory, compile into one executable.
# make debug=yes to compile with -g
# make system=windows for windows system
.PHONY : all run
.PHONY .IGNORE : clean
# add your own include path/library path/link library to CXXFLAGS
CXX = g++
CXXFLAGS += -std=c++20
CXXFLAGS += -Wall -Wextra -pedantic-errors -Wshadow
# CXXFLAGS += -Wfatal-errors
RM = rm
# final target: add your target here
target =
# debug
ifeq ($(debug), yes)
CXXFLAGS += -g
else
CXXFLAGS += -O3
CXXFLAGS += -DNDEBUG
endif
# filenames and targets
all_source_files := $(wildcard *.cpp)
all_targets := $(target)
# all targets
all : $(all_targets)
# compile
$(all_targets) : $(all_source_files)
$(CXX) $^ -o $@ $(CXXFLAGS)
# run
run : $(all_targets)
./$(all_targets)
# system: affect how to clean and executable file name
# value: windows/unix
system = unix
ifeq ($(system), windows)
all_targets := $(addsuffix .exe, $(all_targets))
RM := del
endif
# clean
clean :
-$(RM) $(all_targets)