-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
78 lines (58 loc) · 1.75 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
# Usage examples:
#
# (default:) make
# (debug): make BUILD_TYPE=debug
# (hpc): make BUILD_ENV=hpc
# (debug+hpc) make BUILD_ENV=hpc BUILD_TYPE=debug
#
# Or, by first setting the environment variables:
# export BUILD_ENV=hpc
# we can just call
# make
CC=mpic++
BIN_DIR = bin
OBJ_DIR = obj
SRC_DIR = src
# CMD variables with their default values
BUILD_TYPE ?= release
BUILD_ENV ?= local
# Set the appropriate compile/link flags
CFLAGS = -Wall -std=c++17
LFLAGS = -Wall -std=c++17
## Add flags based on BUILD_TYPE (release or debug)
ifeq ($(BUILD_TYPE), release)
CFLAGS += -O3
LFLAGS += -O3
else ifeq ($(BUILD_TYPE), debug)
BIN_DIR := ${BIN_DIR}_debug
OBJ_DIR := ${OBJ_DIR}_debug
CFLAGS += -g -O0 -DDEBUG
LFLAGS += -g -O0 -DDEBUG
endif
## Add flags based on BUILD_ENV (local or hpc)
ifeq ($(BUILD_ENV), local)
CFLAGS += -fopenmp -lblas
LFLAGS += -fopenmp -lblas
else ifeq ($(BUILD_ENV), hpc)
CFLAGS += -fopenmp $$(pkgconf --cflags openblas)
LFLAGS += -fopenmp $$(pkgconf --cflags -libs openblas)
endif
# Initiate all variables needed for building
EXEC_CPP = $(wildcard $(SRC_DIR)/*.cpp)
EXEC_OBJ = $(EXEC_CPP:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
EXEC_BIN = $(EXEC_CPP:$(SRC_DIR)/%.cpp=$(BIN_DIR)/%)
COMMON_CPP = $(wildcard $(SRC_DIR)/detail/*.cpp)
COMMON_OBJ = $(COMMON_CPP:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
.SECONDARY: $(COMMON_OBJ) $(EXEC_OBJ) #Added this so that .o files aren't deleted
DEPS = $(wildcard $(SRC_DIR)/detail/*.hpp)
# Actual build target
do_build: $(info Building version:[${BUILD_TYPE} $(BUILD_ENV)])$(EXEC_BIN)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(DEPS)
@mkdir -p '$(@D)'
$(CC) -c $< -o $@ $(CFLAGS)
$(BIN_DIR)/%: $(OBJ_DIR)/%.o $(COMMON_OBJ)
@mkdir -p '$(@D)'
$(CC) -o $@ $^ $(LFLAGS)
.PHONY: clean
clean:
rm -rf $(BIN_DIR)/* $(OBJ_DIR)/*