forked from N-BodyShop/changa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.in
301 lines (250 loc) · 10.3 KB
/
Makefile.in
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# This Makefile uses the GNU make convention that CAPITAL_NAMES are reserved
# for variables that are either derived from the environment or are explicitly
# set by the user during invocation.
.DEFAULT_GOAL := all
# ChaNGa source directory
source_dir := @srcdir@
# Directory from which `configure` was called.
build_dir := @builddir@
# These canned recipes allow for building different variations of source
# and destination file mappings. They can also be used by subprojects.
define compile-cxx
@ echo Compiling $*.cpp...
$(quiet) $(charmc) $(cxx_flags) $(depend_flags) $(depend_dir)/$*$(depend_suffix) -c $< -o $@
endef
define compile-c
@ echo Compiling $*.c...
$(quiet) $(charmc) $(c_flags) $(depend_flags) $(depend_dir)/$*$(depend_suffix) -c $< -o $@
endef
define link-charmc
@ echo Building $@...
$(quiet) $(charmc) -o $@ $^ $(ld_flags) $(ld_libs)
endef
# ------- Basic commands ------------------------------------------------------
AR := @AR@
RM := rm -f
RMR := $(RM) -r
# ------- Verbosity -----------------------------------------------------------
charm_quiet := $(if $(filter $(CHARM_VERBOSE),1),-verbose,)
quiet := $(if $(filter $(VERBOSE),1),,@)
# ------- Compiler setup ------------------------------------------------------
charmc := @CHARM_PATH@/bin/charmc $(charm_quiet)
target := $(build_dir)/ChaNGa
charmrun := charmrun
cxx_std := c++11
c_std := c99
opt_flag := -O3
target_arch := -m64
threads := -lpthread
# ------- Debugging -----------------------------------------------------------
# -DPRINT_MERGED_TREE
# -DCOSMO_PRINT=1 # enable really verbose prints
# -DCOSMO_PRINT_BK=2 # enable verbose book-keeping prints
# -DCOSMO_DEBUG=2 # enable debugging information
# -DMCLBMSV # Multistepping LB verbosity
# -DCOSMO_STATS=1 # enable statistics collection
# -DCHANGA_REFACTOR_WALKCHECK
# -DCHANGA_REFACTOR_WALKCHECK_INTERLIST
# -DCHANGA_REFACTOR_MEMCHECK
# -DCHANGA_REFACTOR_INTERLIST_PRINT_LIST_STATE
# -DCHANGA_REFACTOR_PRINT_INTERACTIONS
#
# Check walk correctness and trace walk for TEST_BUCKET on TEST_TP:
# -DCHANGA_REFACTOR_WALKCHECK_INTERLIST
# -DCHANGA_REFACTOR_INTERLIST_PRINT_LIST_STATE
# -DCHECK_WALK_COMPLETIONS
debug_defines =
ifeq (1,$(DEBUG))
debug_defines += -DCOSMO_DEBUG=2
opt_flag := @OPT_DEBUG@
target := $(target).dbg
charmrun := $(charmrun).dbg
endif
# Always emit debug symbols in case of core dumps
opt_flag += -g
# ------- SMP -----------------------------------------------------------------
ifeq (1,@CMK_SMP@)
target := $(target).smp
charmrun := $(charmrun).smp
endif
# ------- Projections ---------------------------------------------------------
ifeq (yes,@PROJECTIONS@)
target := $(target).prj
charmrun := $(charmrun).prj
debug_ldflags += -tracemode projections
endif
# ------- Sanitizers ----------------------------------------------------------
ifneq (no,@FLAG_SANITIZER@)
target := $(target).san
charmrun := $(charmrun).san
debug_flags += -fno-omit-frame-pointer -fsanitize=@FLAG_SANITIZER@
debug_ldflags += -fsanitize=@FLAG_SANITIZER@
endif
# ------- CUDA ----------------------------------------------------------------
ifeq (yes,@ENABLE_CUDA@)
# Use a conditional include so seqential cleans work
-include $(build_dir)/cuda.mk
target := $(target).cuda
charmrun := $(charmrun).cuda
endif
# ------- Include paths -------------------------------------------------------
structures_path := @STRUCT_DIR@
charm_util_path := @CHARM_PATH@/tmp
cache_lib_path := @CHARM_PATH@/tmp/libs/ck-libs/cache
threadsafe_ht_path := $(cache_lib_path)/threadsafe_hashtable
# ------- Modules to build ----------------------------------------------------
changa_modules := $(strip MultistepLB MultistepLB_notopo \
MultistepNodeLB_notopo Orb3dLB Orb3dLB_notopo HierarchOrbLB)
charm_modules := $(strip CkCache CkIO CkMulticast RefineLB \
GreedyLB RotateLB liveViz CkLoop)
# ------- Helper Variables ----------------------------------------------------
defines := $(strip @HEXADECAPOLE@ @FLAG_GDFORCE@ @FLAG_ARCH@ \
@FLAG_CHANGESOFT@ @FLAG_BIGKEYS@ @FLAG_DTADJUST@ \
@FLAG_SPH_KERNEL@ @FLAG_COOLING@ @FLAG_DIFFUSION@ \
@FLAG_FEEDBACKDIFFLIMIT@ @FLAG_CULLENALPHA@ \
@FLAG_VSIGVISC@ @FLAG_DAMPING@ @FLAG_DIFFHARMONIC@ \
@FLAG_JEANSSOFTONLY@ @FLAG_FLOAT@ \
@FLAG_TREE_BUILD@ $(debug_defines) @FLAG_INTERLIST@ \
@FLAG_NSMOOTHINNER@ @FLAG_SPLITGAS@ @FLAG_SIDMINTERACT@ \
@FLAG_SUPERBUBBLE@ $(cuda_defines) -DREDUCTION_HELPER)
modules := $(strip -language charm++ -balancer @DEFAULT_LB@ \
$(foreach m,$(charm_modules),-module $(m)) \
$(foreach m,$(changa_modules),-module $(m)))
includes := $(strip -I$(structures_path) -I$(cache_lib_path) \
-I$(source_dir) -I$(threadsafe_ht_path) -I$(build_dir) \
-I$(charm_util_path) -I@CHARM_PATH@/include) $(cuda_includes)
basic_flags := $(opt_flag) $(threads) $(target_arch) $(debug_flags)
basic_ldlibs := $(cuda_libs) $(modules) $(structures_path)/libTipsy.a $(threads)
basic_ldflags := $(debug_ldflags) $(cuda_ldflags) -L. -L@CHARM_PATH@/lib
# ------- Standard Variables --------------------------------------------------
# The global version of each flag must be at the end so that the user
# can override our defaults here from the command line
cpp_flags := $(includes) $(defines) @USER_CPPFLAGS@ @CPPFLAGS@ $(CPPFLAGS)
c_flags := $(basic_flags) -std=$(c_std) $(cpp_flags) @USER_CFLAGS@ $(CFLAGS)
cxx_flags := $(basic_flags) -std=$(cxx_std) $(cpp_flags) @USER_CXXFLAGS@ $(CXXFLAGS)
ld_libs := $(basic_ldlibs) @LIBS@ $(LDLIBS)
ld_flags := $(basic_ldflags) @USER_LDFLAGS@ @LDFLAGS@ $(LDFLAGS)
# ------- Sources -------------------------------------------------------------
# Capture all sources except the ones for cooling
c_srcs := $(filter-out $(source_dir)/cooling%,$(wildcard $(source_dir)/*.c))
cxx_srcs := $(filter-out $(source_dir)/cooling%,$(wildcard $(source_dir)/*.cpp))
# Add the cooling sources (if any)
ifeq (-DCOOLING_PLANET,@FLAG_COOLING@)
c_srcs += $(source_dir)/cooling_planet.c
endif
ifeq (-DCOOLING_COSMO,@FLAG_COOLING@)
c_srcs += $(source_dir)/cooling_cosmo.c
endif
ifeq (-DCOOLING_BOLEY,@FLAG_COOLING@)
c_srcs += $(source_dir)/cooling_boley.c
endif
ifeq (-DCOOLING_METAL,@FLAG_COOLING@)
c_srcs += $(source_dir)/cooling_metal.c
endif
ifeq (-DCOOLING_MOLECULARH,@FLAG_COOLING@)
c_srcs += $(source_dir)/cooling_metal_H2.c
endif
ifeq (-DCOOLING_GRACKLE,@FLAG_COOLING@)
c_srcs += $(source_dir)/cooling_grackle.c
endif
sources := $(c_srcs) $(cxx_srcs)
ci_files := $(wildcard $(source_dir)/*.ci)
ci_headers := $(patsubst %.ci,%.decl.h,$(subst $(source_dir),$(build_dir),$(ci_files)))
c_objs := $(patsubst %.c,%.o,$(subst $(source_dir),$(build_dir),$(c_srcs)))
cxx_objs := $(patsubst %.cpp,%.o,$(subst $(source_dir),$(build_dir),$(cxx_srcs)))
objects := $(strip $(cxx_objs) $(c_objs) $(cuda_objs))
# ------- Dependencies --------------------------------------------------------
depend_flags := -MMD -MP -MF
depend_dir := $(build_dir)/.
depend_suffix := .d
depend_files := $(wildcard $(depend_dir)/*$(depend_suffix))
# ------- Build targets -------------------------------------------------------
all: $(build_dir)/$(target)
.PHONY: show-config
show-config:
@ echo TARGET = $(target)"\n"
@ echo DEFAULT_LB = @DEFAULT_LB@"\n"
@ echo TARGET_ARCH = $(target_arch)"\n"
@ echo CPPFLAGS = $(cpp_flags)"\n"
@ echo CFLAGS = $(filter-out $(cpp_flags),$(c_flags))"\n"
@ echo CXXFLAGS = $(filter-out $(cpp_flags),$(cxx_flags))"\n"
@ echo LDFLAGS = $(ld_flags)"\n"
@ echo LDLIBS = $(ld_libs)"\n"
$(build_dir)/%.decl.h: $(source_dir)/%.ci
@ echo Compiling $<...
$(quiet) $(charmc) -E $(cpp_flags) $<
$(build_dir)/%.o: $(build_dir)/Makefile
$(cxx_srcs): $(ci_headers)
%.o: %.cpp
$(compile-cxx)
%.o: %.c
$(compile-c)
$(build_dir)/%.o: $(source_dir)/%.cpp
$(compile-cxx)
$(build_dir)/%.o: $(source_dir)/%.c
$(compile-c)
# Use a conditional include so consecutive cleans work
-include $(depend_files)
# Force a rebuild if the compiler flags have changed
.PHONY: force
$(build_dir)/settings: force
$(quiet) flags="$(cxx_flags) $(c_flags) $(ld_libs) $(ld_flags)" && \
echo "$$flags" | cmp -s - $@ || echo "$$flags" > $@
# The commitID should be refreshed on every build
$(build_dir)/cha_commitid.o: $(build_dir)/cha_commitid.c
$(compile-c)
$(build_dir)/cha_commitid.c: force
$(quiet) VER=`cd $(source_dir) && git describe --long --always` && \
echo "const char * const Cha_CommitID = \"$$VER\";" > $(build_dir)/cha_commitid.c
$(ci_files): $(build_dir)/settings
$(objects): $(build_dir)/settings
$(build_dir)/$(target): $(build_dir)/cha_commitid.o
$(build_dir)/$(target): $(foreach m,$(changa_modules),libmodule$(m).a)
$(build_dir)/$(target): $(objects) $(structures_path)/libTipsy.a
$(link-charmc)
ifneq ($(notdir $(charmrun)),charmrun)
$(quiet) if [ -e $(build_dir)/charmrun ]; then \
mv $(build_dir)/charmrun $(build_dir)/$(charmrun); \
fi
$(quiet) if [ ! -e $(build_dir)/charmrun ]; then \
ln -s $(build_dir)/$(charmrun) $(build_dir)/charmrun; \
else \
echo "$(build_dir)/charmrun already exists. No symlink created."; \
fi
endif
ifneq ($(notdir $(target)),ChaNGa)
$(quiet) if [ ! -e $(build_dir)/ChaNGa ]; then \
ln -s $(build_dir)/$(target) $(build_dir)/ChaNGa; \
else \
echo "$(build_dir)/ChaNGa already exists. No symlink created."; \
fi
endif
$(structures_path)/libTipsy.a:
$(quiet) cd $(structures_path); $(MAKE) libTipsy.a
$(build_dir)/libmodule%.a: $(build_dir)/%.o
@ echo Creating library $@...
$(quiet) $(AR) $@ $^
.PHONY: docs
docs:
@ Building docs...
$(quiet) doxygen $(source_dir)/Doxyfile
.PHONY: clean
clean:
@ echo Cleaning...
$(quiet) $(RM) $(objects) *~ *.decl.h *.def.h $(depend_files) settings
$(quiet) $(RM) $(foreach m,$(changa_modules),libmodule$(m).a)
$(quiet) cd $(structures_path); $(MAKE) clean
.PHONY: dist-clean
dist-clean: clean
$(quiet) $(RM) $(target) $(charmrun) ChaNGa* charmrun* config.status
$(quiet) $(RM) config.log config.h Makefile $(build_dir)/cha_commitid.c
.PHONY: full-clean
full-clean: dist-clean
$(quiet) $(RMR) $(source_dir)/autom4te.cache $(source_dir)/configure
# for backwards compatibility
.PHONY: ref-clean
ref-clean:
.PHONY: depends
depends:
.PHONY: test
test: