-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
147 lines (124 loc) · 3.83 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
CONFIG ?=
-include config.mk
CONFIG_PATH ?= etc/config/${CONFIG}.mk
ifndef CONFIG
$(info ERROR: \
CONFIG is not defined, choose a config from etc/config or define your own.)
$(info ERROR: You can:)
$(info ERROR: - run e.g. make CONFIG=icc-mkl-impi)
$(info ERROR: - define CONFIG variable in ./config.mk and run make)
$(error exiting now..)
endif
include ${CONFIG_PATH}
include Sources.mk
# Check that reqiured makefile variables are indeed defined
define assert-vardefined
$(if $(strip $($(1))),,$(error $(1) must be defined))
endef
$(foreach _a,$(REQUIRED_MAKEVARS),$(call assert-vardefined,$(_a)))
# goals:
.DEFAULT_GOAL := cc4s
.PHONY: test cc4s clean extern
BUILD_PATH = build/$(CONFIG)
OBJ_PATH = $(BUILD_PATH)/obj
BIN_PATH = $(BUILD_PATH)/bin
OBJ_FILES = $(patsubst %.cxx,$(OBJ_PATH)/%.o,$(SRC_FILES))
DEP_FILES = $(patsubst %.cxx,$(OBJ_PATH)/%.d,$(SRC_FILES))
TESTS_OBJECTS = $(patsubst %.cxx,$(OBJ_PATH)/%.o,$(TEST_SRC_FILES))
# retrieve build environment
VERSION := $(shell git describe --all --dirty --long)
DATE := $(shell git log -1 --format="%cd")
COMPILER_VERSION := $(shell ${CXX} --version | head -n 1)
CC4S_MPI_VERSION := $(shell mpirun --version | head -n 1)
# This is a trick just to make sure that the dependencies are built
EXTERN_DONE_FILE = $(BUILD_PATH)/extern-built
$(EXTERN_DONE_FILE): $(EXTERNAL_DEPENDENCIES)
@mkdir -p $(@D)
@touch $@
extern: $(EXTERN_DONE_FILE)
fetch-dependencies: $(FETCH_DEPENDENCIES)
fetch: fetch-dependencies test-data
.PHONY: fetch fetch-dependencies
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),fetch)
ifneq ($(MAKECMDGOALS),fetch-dependencies)
ifneq ($(MAKECMDGOALS),dist)
ifneq ($(MAKECMDGOALS),clean-all)
ifneq ($(MAKECMDGOALS),extern)
ifneq ($(CREATE_EXTERN),FALSE)
ifneq ($(wildcard $(EXTERN_DONE_FILE)), $(EXTERN_DONE_FILE))
$(info )
$(info )
$(info You have not built the dependencies for $(CONFIG), please build them)
$(info with: $(MAKE) extern CONFIG=$(CONFIG))
$(info )
$(info )
$(error exiting now...)
endif
# try to include dependency files in order to trigger their creation
-include $(DEP_FILES)
endif
endif
endif
endif
endif
endif
endif
$(DEP_FILES): $(INTERNAL_DEPENDENCIES)
cc4s: $(BIN_PATH)/${CC4S_TARGET}
DIST_DEPENDENCIES = \
Makefile LICENSE README.md \
./Extern.mk ./Sources.mk ./Cc4s.mk \
src test extern/src etc
DIST_NAME ?= dist-$(shell echo $(VERSION) | tr "/" "-")
dist: $(DIST_NAME).tar
$(DIST_NAME).tar: fetch
ln -s . $(DIST_NAME)
tar cf "$@" $(patsubst %,$(DIST_NAME)/%,$(DIST_DEPENDENCIES))
rm $(DIST_NAME)
.PHONY: dist
clean:
rm -rf $(OBJ_PATH)
rm -rf $(BIN_PATH)
clean-all: clean
@$(MAKE) CREATE_EXTERN=FALSE $(patsubst %,%-clean,$(EXTERNAL_DEPENDENCIES))
test-run:
$(MAKE) -C test run
test-check:
$(MAKE) -C test check
test-data:
$(MAKE) -C test pyyaml
$(MAKE) -C test data
.PHONY: test-run test-check test-data
unit-test: $(BIN_PATH)/Test
# generate documentation
doc:
doxygen
# copy binary to installation directory
install: $(BIN_PATH)/$(CC4S_TARGET)
mkdir -p ${CC4S_INSTALL}
cp $< ${CC4S_INSTALL}
# build dependencies only
depend: $(DEP_FILES)
# keep intermediate files
.PRECIOUS: ${OBJ_FILES} ${DEP_FILES}
# create a dependency for object file
$(OBJ_PATH)/%.d: src/%.cxx
$(info [DEP] $@)
mkdir -p $(dir $@)
${CXX} -MM ${CXXFLAGS} ${INCLUDE_FLAGS} -c src/$*.cxx | \
sed 's#[^ :]*\.o[ :]*#$(OBJ_PATH)/$*.o $@: #g' > $@
# compile an object file
$(OBJ_PATH)/%.o: $(OBJ_PATH)/%.d
$(info [OBJ] $@)
mkdir -p $(dir $@)
${CXX} ${CXXFLAGS} ${INCLUDE_FLAGS} -c src/$*.cxx -o $@
# compile and link executable
$(BIN_PATH)/${CC4S_TARGET}: ${OBJ_FILES}
$(info [BIN] $@)
mkdir -p $(dir $@)
${CXX} ${CXXFLAGS} ${OBJ_FILES} ${LDFLAGS} -o $@
# compile and link test executable
$(BIN_PATH)/Test: ${OBJ_FILES} $(TESTS_OBJECTS)
mkdir -p $(dir $@)
${CXX} ${CXXFLAGS} ${OBJ_FILES} $(TESTS_OBJECTS) ${LDFLAGS} -o $@