-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
117 lines (102 loc) · 3.51 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Blacklight Makefile
# Basic usage: "make"
# Optional arguments:
# Targets:
# <empty>: build bin/blacklight
# all: same as <empty>
# clean: remove bin/blacklight, as well as .o and .d files in obj/
# Compiler options:
# CXX=g++: use GNU g++ (default)
# CXX=icpc: use Intel icpc for AVX512 architectures (Skylake and more recent)
# CXX=icpc-host: use Intel icpc for host architecture
# CXX=icpc-phi: use Intel icpc for Knights Landing architecture
# Other options:
# -j <n>: use n processes to work in parallel (recommended)
# -j<n>: same as -j <n>
# -j: spawn as many processes as tasks, even if they outnumber cores
# Set executable and directory names
BIN_NAME = blacklight
BIN_DIR = bin
SRC_DIR = src
OBJ_DIR = obj
SRC_EXT = cpp
OBJ_EXT = o
DEP_EXT = d
# Set default compiler
CXX := g++
# Set compiler options: g++
ifeq ($(CXX), g++)
DEPENDENCY_OPTIONS := -MMD -MP
INCLUDE_OPTIONS :=
DIALECT_OPTIONS := -std=c++17 -fopenmp
OPTIMIZATION_OPTIONS := -O3 -flto -fno-math-errno -fno-signed-zeros -fno-trapping-math
WARNING_OPTIONS := -Wpedantic -Wall -Wextra -Wdouble-promotion -Wformat=2 -Wformat-signedness \
-Wnull-dereference -Wmissing-include-dirs -Wunused -Wuninitialized -Wstringop-truncation \
-Walloc-zero -Wduplicated-branches -Wduplicated-cond -Wshadow -Wundef -Wunused-macros \
-Wcast-qual -Wcast-align -Wconversion -Wsign-conversion -Wlogical-op -Wmissing-declarations \
-Wredundant-decls -Wlto-type-mismatch
WARNING_OPTIONS += -Wctor-dtor-privacy -Wnoexcept -Wnon-virtual-dtor -Wstrict-null-sentinel \
-Wold-style-cast -Woverloaded-virtual -Wsign-promo -Wzero-as-null-pointer-constant \
-Wplacement-new=2 -Wextra-semi -Wuseless-cast
LINKER_OPTIONS :=
LIBRARY_OPTIONS :=
# Set compiler options: icpc
else ifeq ($(CXX), icpc)
DEPENDENCY_OPTIONS := -MMD -MP
INCLUDE_OPTIONS :=
DIALECT_OPTIONS := -std=c++17 -qopenmp
OPTIMIZATION_OPTIONS := -O3 -ipo -xCORE-AVX512
WARNING_OPTIONS :=
LINKER_OPTIONS :=
LIBRARY_OPTIONS :=
# Set compiler options: icpc-host
else ifeq ($(CXX), icpc-host)
DEPENDENCY_OPTIONS := -MMD -MP
INCLUDE_OPTIONS :=
DIALECT_OPTIONS := -std=c++17 -qopenmp
OPTIMIZATION_OPTIONS := -O3 -ipo -xhost
WARNING_OPTIONS :=
LINKER_OPTIONS :=
LIBRARY_OPTIONS :=
# Set compiler options: icpc-phi
else ifeq ($(CXX), icpc-phi)
DEPENDENCY_OPTIONS := -MMD -MP
INCLUDE_OPTIONS :=
DIALECT_OPTIONS := -std=c++17 -qopenmp
OPTIMIZATION_OPTIONS := -O3 -ipo -xMIC-AVX512
WARNING_OPTIONS :=
LINKER_OPTIONS :=
LIBRARY_OPTIONS :=
# Handle unknown compiler
else
$(error "$(CXX)" not supported)
endif
# Set compiler flags
CPPFLAGS := $(DEPENDENCY_OPTIONS) $(INCLUDE_OPTIONS)
CXXFLAGS := $(DIALECT_OPTIONS) $(OPTIMIZATION_OPTIONS) $(WARNING_OPTIONS)
LDFLAGS := $(LINKER_OPTIONS)
LDLIBS := $(LIBRARY_OPTIONS)
# Set lists of files to be considered
SRC_FILES := $(shell find $(SRC_DIR) -name "*.$(SRC_EXT)")
OBJ_FILES := $(addprefix $(OBJ_DIR)/,$(notdir $(SRC_FILES:.$(SRC_EXT)=.$(OBJ_EXT))))
DEP_FILES := $(OBJ_FILES:.$(OBJ_EXT)=.$(DEP_EXT))
VPATH := $(sort $(dir $(SRC_FILES)))
# Set default target
.PHONY : all
all : $(BIN_DIR)/$(BIN_NAME)
# Include dependency lists
-include $(DEP_FILES)
# Compile sources into objects
$(OBJ_DIR)/%.$(OBJ_EXT) : %.$(SRC_EXT)
@echo compiling $(basename $(notdir $@))
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
# Link objects into executable
$(BIN_DIR)/$(BIN_NAME) : $(OBJ_FILES)
@echo linking $(basename $(notdir $@))
@$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) $^ -o $@
# Clean up
.PHONY : clean
clean :
rm -f $(OBJ_DIR)/*.$(OBJ_EXT)
rm -f $(OBJ_DIR)/*.$(DEP_EXT)
rm -f $(BIN_DIR)/$(BIN_NAME)