forked from CBDD/rDock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
238 lines (182 loc) · 8.36 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Custom Makefile for direct compilation and installation of the rDock library and binaries
# 2023-03-31, Zaragoza, Spain
#
# How to use this Makefile:
#
# set any environment variables you need to set before (or while) invoking make with the desired target, e.g.:
# export CXX=g++-7; make -j 4
# or
# CXX=g++-9 PREFIX=~/.local make -j 4
#
# the following targets are available for the user:
# build: build the library and binaries (default target)
# build_lib: build the library
# build_bin: build the binaries
# test: run the tests suite
# test_dock_run: run rbdock and compare results with a reference run
# test_rbcavity: generates
# clean: removes the object files
# clean_lib: removes the lib folder
# clean_bin: removes the compiled binaries
# clean_tests: removes the files generated by test execution
# veryclean: removes all the above
# install: install the library, binaries, and headers in PREFIX folder
# full: cleans everything and rebuilds the library and binaries from scratch,
# then runs the tests and install everything into PREFIX folder
# lint: format the code using clang-format. Requires clang-format to be installed
# it is recommended to run this target before committing any changes to the code
# as the CI will fail if the code is not properly formatted.
#
#
# the following variables can be configured by the user:
# CONFIG: the configuration to build. Can be DEBUG or RELEASE. Default: RELEASE
# if DEBUG is set, the library and binaries are built with debug symbols and
# the -D_DEBUG macro is defined, making the code more verbose (but slower).
#
# PREFIX: the folder where to install the library, binaries, and headers. Default: /usr
#
# CXX: the c++ compiler to use. Default: g++
#
# CXX_EXTRA_FLAGS: extra flags to pass to the compiler. Default: empty
#
PREFIX ?= /usr
CONFIG ?= RELEASE
RBT_VERSION ?= v$(shell date +%y.%m-alpha)
CXX ?= g++
CXX_BASE_FLAGS += -Wall
CXX_STD ?= c++17
EXE_FOLDER = src/exe
CXX_EXTRA_FLAGS ?=
CXX_BASE_FLAGS += -pipe -std=$(CXX_STD) -fPIC
CXX_DEBUG_CONFIG_FLAGS += -O0 -g
CXX_RELEASE_CONFIG_FLAGS += -O3 -ffast-math
CXX_WARNING_FLAGS +=
DEBUG_DEFINES := -D_DEBUG
RELEASE_DEFINES := -D_NDEBUG
ifeq ($(LEGACY_BUILD),YES)
_ := $(error This option has been removed. If you really need it, checkout the rdock-legacy branch and try again.)
endif
ifeq ($(CONFIG),DEBUG)
CXX_CONFIG_FLAGS += $(CXX_DEBUG_CONFIG_FLAGS)
DEFINES += $(DEBUG_DEFINES)
else
CXX_CONFIG_FLAGS += $(CXX_RELEASE_CONFIG_FLAGS)
DEFINES += $(RELEASE_DEFINES)
endif
DEFINES += -DRBT_VERSION=\"$(RBT_VERSION)\"
CXX_FLAGS := $(CXX_BASE_FLAGS) $(CXX_CONFIG_FLAGS) $(CXX_WARNING_FLAGS) $(CXX_EXTRA_FLAGS) $(DEFINES)
LINK_FLAGS := -shared
LIB_DEPENDENCIES += -lm -lpopt
LIBS += $(LIB_DEPENDENCIES) -lRbt
INCLUDE := $(addprefix -I./, $(shell find include/ -type d )) $(addprefix -I./, $(shell find import/ -type d ))
TESTS_INCLUDE := $(INCLUDE) $(addprefix -I./, $(shell find tests/include/ -type d ))
LIBRARY := ./lib
simplex_sources = $(shell find import/simplex/src/ -type f -name '*.cxx')
simplex_objects = $(subst import/simplex/src, obj/simplex, $(simplex_sources:.cxx=.o))
GP_sources = $(shell find src/GP/ -type f -name 'Rbt*.cxx')
GP_objects = $(subst src/GP/, obj/GP/, $(GP_sources:.cxx=.o))
RBT_sources = $(shell find src/lib/ -type f -name '*.cxx')
RBT_objects = $(subst src/lib/, obj/, $(RBT_sources:.cxx=.o))
tests_sources = $(shell find tests/src/ -type f -name '*.cpp')
tests_objects = tests/obj/catch_amalgamated.o $(subst tests/src/, tests/obj/, $(tests_sources:.cpp=.o))
objects = $(RBT_objects) $(simplex_objects) $(GP_objects)
objdirs = $(sort $(dir $(objects)))
$(shell mkdir -p $(objdirs) ./lib ./bin)
bin_names = rbdock rbcavity rbmoegrid rblist rbcalcgrid
bins = $(addprefix bin/, $(bin_names))
.PHONY: \
install \
target_folders build_directories \
lib bin scripts \
build build_lib build_bin \
test test_dock_run test_rbcavity \
clean clean_bin clean_lib veryclean \
lint lint-check \
targets help \
## User directed targets
build: build_lib build_bin scripts ## build the library and binaries (default target)
install: build target_folders ## install the library, binaries, and headers in PREFIX folder
@cp -r bin/* $(PREFIX)/bin
@cp -r lib/* $(PREFIX)/lib
@cp -r include/* $(PREFIX)/include
install-include: target_folders
@cp -r include/* $(PREFIX)/include
full: ## equivalent to veryclean build test install
$(MAKE) veryclean
$(MAKE) build
$(MAKE) test
$(MAKE) install
build_bin: build_directories
$(MAKE) $(bins)
build_lib: build_directories
$(MAKE) lib
build_tests: tests_directories build
$(MAKE) tests_bin
retest: build
$(MAKE) clean_tests
$(MAKE) test
test: build ## run the tests suite
$(MAKE) test_rbcavity test_dock_run test_suite
test_dock_run: build tests/data/1YET_test.as
mkdir -p tests/results
cd tests/data ; RBT_ROOT=../.. LD_LIBRARY_PATH=../../lib:$(LD_LIBRARY_PATH) ../../bin/rbdock -r1YET_test.prm -i 1YET_c.sd -p dock.prm -n 1 -s 48151623 -o ../results/1YET_test_out > ../results/1YET_test_out.log
@tests/scripts/check_results.sh ./tests/data/1YET_reference_out.sd ./tests/results/1YET_test_out.sd
test_rbcavity: tests/data/1koc.as tests/data/1YET.as tests/data/1YET_test.as
test_suite: build_tests
LD_LIBRARY_PATH=./lib tests/bin/test_suite
clean: ## removes the object files and folder
@rm -rf obj
clean_bin: ## removes the compiled binaries and bin folder
@rm -f $(bins)
clean_lib: ## removes the compiled library file, libRbt.so
@rm -f lib/libRbt.so
clean_tests: ## removes the files generated by test execution
@rm -rf tests/results tests/data/*.as
clean_tests_objects: ## removes the object files generated by the tests
@rm -rf tests/obj
@rm -f tests/bin/test_suite
veryclean: clean clean_bin clean_lib clean_tests clean_tests_objects ## equivalent to clean clean_bin clean_lib clean_tests clean_tests_objects
lint: ## format the code using clang-format. Requires clang-format to be installed
@clang-format --style=file -i $(shell find src/ include/ tests/ -iname '*.cxx' -o -iname '*.h' -o -iname '*.cpp')
## Internal targets
target_folders:
@mkdir -p $(PREFIX)/bin $(PREFIX)/lib $(PREFIX)/include
build_directories:
@mkdir -p $(objdirs) ./lib ./bin ./log ./tests/tmp
obj/%.o: src/lib/%.cxx
@echo $(CXX) $(CXX_FLAGS) $(INCLUDE) -c -o $@ $<
@$(CXX) $(CXX_FLAGS) $(INCLUDE) -c -o $@ $<
obj/simplex/%.o: import/simplex/src/%.cxx
@echo $(CXX) $(CXX_FLAGS) $(INCLUDE) -c -o $@ $<
$(CXX) $(CXX_FLAGS) $(INCLUDE) -c -o $@ $<
obj/GP/%.o: src/GP/%.cxx
@echo $(CXX) $(CXX_FLAGS) $(INCLUDE) -c -o $@ $<
$(CXX) $(CXX_FLAGS) $(INCLUDE) -c -o $@ $<
scripts: build_directories
@cp -r scripts/* bin/
lib: lib/libRbt.so
lib/libRbt.so: $(objects)
$(CXX) $(CXX_FLAGS) -shared -L$(LIBRARY) $^ -o lib/libRbt.so $(LIB_DEPENDENCIES)
bin/%: src/exe/%.cxx lib/libRbt.so
$(CXX) $(CXX_FLAGS) $(INCLUDE) -L$(LIBRARY) -o $@ $< $(LIBS)
tests/data/%.as: tests/data/%.prm bin/rbcavity
cd tests/data ; RBT_ROOT=../.. LD_LIBRARY_PATH=../../lib:$(LD_LIBRARY_PATH) ../../bin/rbcavity -r$(notdir $<) -was
tests_directories:
@mkdir -p tests/obj tests/bin
tests_bin: $(tests_objects)
$(CXX) $(CXX_FLAGS) $(TESTS_INCLUDE) -L$(LIBRARY) -o tests/bin/test_suite $^ $(LIBS)
tests/obj/catch_amalgamated.o: import/catch2/catch_amalgamated.cpp
@echo $(CXX) $(CXX_FLAGS) $(TESTS_INCLUDE) -c -o $@ $<
$(CXX) $(CXX_FLAGS) $(TESTS_INCLUDE) -c -o $@ $<
tests/obj/%.o: tests/src/%.cpp
@echo $(CXX) $(CXX_FLAGS) $(TESTS_INCLUDE) -c -o $@ $<
$(CXX) $(CXX_FLAGS) $(TESTS_INCLUDE) -c -o $@ $<
lint-check:
@echo "Checking code style..."
# --ferror-limit=1 is used to stop the execution after the first error until we fix all the code
@clang-format --style=file -Werror --dry-run --ferror-limit=1 $(shell find src/ include/ -iname '*.cxx' -o -iname '*.h')
targets: ## Display this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) |\
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
help: ## detailed help
@ awk '/^#/ {print; next} {if (NR>1) exit}' $(MAKEFILE_LIST) | sed -e 's/^#//'