-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
371 lines (320 loc) · 11.9 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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
############################################################
# Makefile for DDCalc #
# #
# Simple usage: #
# make all #
# #
# GAMBIT Dark Matter Workgroup #
# ddcalc@projects.hepforge.org #
# #
############################################################
#################### INITIALIZATION ########################
# Generate variables needed for substitution.
empty :=
space := ${empty} ${empty}
lpar := ${empty}(${empty}
rpar := ${empty})${empty}
#################### VERSION ###############################
# Software release version. Extracted from main code file.
DDDCALC_VERSION=$(shell grep "VERSION_STRING =" $(SRC)/DDConstants.f90 | cut -d \' -f2)
#$(info DDCalc version is $(DDDCALC_VERSION))
#################### DIRECTORIES ###########################
DDCALC_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
SRC := $(DDCALC_DIR)src
INCLUDE := $(DDCALC_DIR)include
EXAMPLES := $(DDCALC_DIR)examples
DOC := $(DDCALC_DIR)doc
DATA := $(DDCALC_DIR)data
BUILD := $(DDCALC_DIR)build
LIB := $(DDCALC_DIR)lib
#################### COMPILER ##############################
# The fortran compiler is set here, along with the
# compilation options. If the compiler is not specified via
# an environmental variable or as an argument to the make
# invocation (FC=<...>), make will search for ifort and
# gfortran, in that order, and use one of those.
# If you want to set your own FFLAGS, set FOPT and this
# makefile will ensure that the appropriate things are appended.
# Alternate compilation flags intended for debugging can be
# used by setting DEBUG to any non-empty value, which may be
# done from the command line with e.g. 'make DEBUG=Y'.
# If FC is not set, search for ifort or gfortran compilers,
# in that order. If neither is found, make stops with an
# error message.
ifneq (,$(findstring "$(origin FC)","undefined" "default"))
FC := $(or $(shell which ifort 2> /dev/null),\
$(shell which gfortran 2> /dev/null),\
$(error Could not find ifort or gfortran compiler \
in the path. A valid compiler must be given.))
FC := $(notdir $(FC))
endif
# Check if using ifort or gfortran and give a warning
# otherwise. These are the only supported compilers.
ifeq (,$(findstring ifort,$(FC))$(findstring gfortran,$(FC)))
$(info $(empty)------------------------------------------------------------)
$(info $(empty) WARNING:)
$(info $(empty) Only the ifort $(lpar)Intel$(rpar) and gfortran \
$(lpar)GCC$(rpar) compilers have)
$(info $(empty) been tested with DDCalc. Proceeding with unsupported)
$(info $(empty) compiler $(FC).)
$(info $(empty)------------------------------------------------------------)
#$(info $(empty))
endif
# Fortran compiler flags. Update only if not already specified.
ifneq (,$(findstring "$(origin FOPT)","undefined" "default"))
# Default flags.
ifeq (,$(DEBUG))
ifneq (,$(findstring ifort,$(FC)))
FFLAGS := -fast -module $(BUILD) -fpp
else ifneq (,$(findstring gfortran,$(FC)))
FFLAGS := -O3 -fno-range-check -J $(BUILD) -cpp
else
$(info WARNING: No default compilation flags for compiler $(FC).)
endif
# Debugging flags, activated by setting DEBUG non-empty,
# e.g. 'make DEBUG=Y'.
else
ifneq (,$(findstring ifort,$(FC)))
FFLAGS := -O0 -g -traceback -check bounds
else ifneq (,$(findstring gfortran,$(FC)))
FFLAGS := -O0 -g -fbacktrace -fbounds-check -fno-range-check
else
$(info WARNING: No default compilation flags for compiler $(FC).)
endif
endif
else
FFLAGS = $(FOPT)
endif
# Ensure required compiler flags.
ifneq (,$(findstring gfortran,$(FC)))
# disable compile-time range checking due to large integer
# constants in math routines (allows for INTEGER*8)
ifeq (,$(findstring -fno-range-check,$(FFLAGS)))
# If FFLAGS passed as an argument, must override
ifeq ("$(origin FFLAGS)","command line")
override FFLAGS += -fno-range-check
else
FFLAGS += -fno-range-check
endif
endif
endif
# Flags used for shared object library.
ifeq (,$(findstring -fPIC,$(FFLAGS)))
FFLAGS += -fPIC
endif
# Flags used to specify DDCalc folder
FFLAGS += -D DDCALC_DIR=\"$(DDCALC_DIR)\" -D DATA_DIR=\"$(DATA)\"
# C++ compiler and flags. Only used for test program.
# CXX_FLIBS are libraries necessary for linking fortran
# routines (compiler specific).
ifneq (,$(findstring "$(origin CXX)","undefined" "default"))
ifneq (,$(findstring ifort,$(FC)))
CXX := icc
else ifneq (,$(findstring gfortran,$(FC)))
CXX := g++
endif
endif
ifneq (,$(findstring "$(origin CXXFLAGS)","undefined" "default"))
ifneq (,$(findstring icc,$(CXX)))
CXXFLAGS :=
else ifneq (,$(findstring g++,$(CXX)))
CXXFLAGS :=
endif
endif
ifneq (,$(findstring icc,$(CXX)))
CXX_FLIBS := -lifcore
else ifneq (,$(findstring g++,$(CXX)))
CXX_FLIBS := -lgfortran
else
$(info WARNING: Unsupported C++ compiler $(CXX). Build may fail due to)
$(info unknown library dependencies.)
CXX_FLIBS :=
endif
# Debugging
#$(info FC =$(FC) ($(origin FC)))
#$(info FFLAGS =$(FFLAGS) ($(origin FFLAGS)))
#$(info FOPT =$(FOPT) ($(origin FOPT)))
#################### FILES / TARGETS #######################
# Main programs
fprograms := DDCalc_test
# Example/test programs
ftestprograms := DDCalc_exampleF DDCalc_exclusionF
ctestprograms := DDCalc_exampleC DDCalc_exclusionC
pytestprograms := DDCalc_DirectDM_InterfaceExample.py \
DDCalc_examplePython.py DDCalc_exclusionPython.py
# Fortran sources
fsrc := DDConstants.f90 DDTypes.f90 DDNuclear.f90 \
DDUtils.f90 DDNumerical.f90 DDStats.f90 DDCouplings.f90 \
DDWIMP.f90 DDInput.f90 DDHalo.f90 DDRates.f90 \
DDDetectors.f90 DDExperiments.f90 \
DDCalc.f90 DDNREffectiveTheory.f90
analyses := LUX_2013.f90 SIMPLE_2014.f90 DARWIN.f90 \
SuperCDMS_2014.f90 XENON100_2012.f90 LUX_2016.f90 \
PandaX_2016.f90 LUX_2015.f90 PICO_2L.f90 CDMSlite.f90 \
PICO_60.f90 XENON1T_2017.f90 PICO_60_2017.f90 \
CRESST_II.f90 PandaX_2017.f90 XENON1T_2018.f90 \
DarkSide_20k.f90 DarkSide_50.f90 PICO_500.f90 \
CRESST_III.f90 PICO_60_2019.f90 DarkSide_50_S2.f90 \
LZ_2022.f90 PandaX_4T.f90 XENON1T_2022.f90
# Include files
fincludes :=
fincludes := $(patsubst %,$(INCLUDE)/%,$(fincludes))
cincludes := DDCalc.hpp DDExperiments.hpp
cincludes := $(patsubst %,$(INCLUDE)/%,$(cincludes)) \
# Libraries
libname := DDCalc
statlib := lib$(libname).a
sharedlib := lib$(libname).so
libraries := $(statlib) $(sharedlib)
# Source files.
fsources := $(fincludes) \
$(patsubst %,$(SRC)/%,$(fsrc)) \
$(patsubst %,$(SRC)/analyses/%,$(analyses)) \
$(patsubst %,$(SRC)/%.f90,$(fprograms)) \
$(patsubst %,$(EXAMPLES)/%.f90,$(ftestprograms))
csources := $(cincludes) \
$(patsubst %,$(EXAMPLES)/%.cpp,$(ctestprograms))
sources := $(fsources) $(csources)
fobjects := $(patsubst %.f90,$(BUILD)/%.o,$(fsrc) $(analyses))
# Additional files to include in distribution tar file
extrafiles := Makefile README LICENSE DDCalc.bib
# Distribution tar file and subdirectory
distfile := DDCalc-$(DDDCALC_VERSION).tar.gz
DIST_DIR := DDCalc-$(DDDCALC_VERSION)
# Files to remove when cleaning.
# Note some compilers leave .dSYM files/directories for debugging.
cleanfiles := $(BUILD)/* \
$(fprograms) $(fprograms:=.dSYM) \
$(ftestprograms) $(ftestprograms:=.dSYM) \
$(ctestprograms) $(pytestprograms) \
$(EXAMPLES)/DDCalcInclude.py $(INCLUDE)/DDCalcInclude.py
# ...also tar file and libs
distcleanfiles := $(cleanfiles) $(LIB)/* $(distfile)
#################### DEPENDENCIES ##########################
# General include file dependencies
$(ctestprograms): $(cincludes)
# Some objects depend on each other
$(BUILD)/DDCalc.o: $(BUILD)/DDExperiments.o \
$(BUILD)/DDConstants.o \
$(BUILD)/DDTypes.o \
$(BUILD)/DDNumerical.o \
$(BUILD)/DDWIMP.o \
$(BUILD)/DDDetectors.o \
$(BUILD)/DDRates.o \
$(BUILD)/DDStats.o \
$(BUILD)/DDHalo.o \
$(BUILD)/DDNREffectiveTheory.o
$(BUILD)/DDCouplings.o: $(BUILD)/DDConstants.o
$(BUILD)/DDDetectors.o: $(BUILD)/DDTypes.o \
$(BUILD)/DDNuclear.o \
$(BUILD)/DDUtils.o \
$(BUILD)/DDInput.o
$(BUILD)/DDExperiments.o: $(BUILD)/XENON100_2012.o \
$(BUILD)/LUX_2013.o \
$(BUILD)/SIMPLE_2014.o \
$(BUILD)/SuperCDMS_2014.o \
$(BUILD)/CDMSlite.o \
$(BUILD)/LUX_2016.o \
$(BUILD)/PandaX_2016.o \
$(BUILD)/PandaX_2017.o \
$(BUILD)/LUX_2015.o \
$(BUILD)/PICO_2L.o \
$(BUILD)/PICO_60.o \
$(BUILD)/PICO_60_2017.o \
$(BUILD)/PICO_60_2019.o \
$(BUILD)/XENON1T_2017.o \
$(BUILD)/XENON1T_2018.o \
$(BUILD)/XENON1T_2022.o \
$(BUILD)/CRESST_II.o \
$(BUILD)/CRESST_III.o \
$(BUILD)/LZ_2022.o \
$(BUILD)/PandaX_4T.o \
$(BUILD)/DARWIN.o \
$(BUILD)/DarkSide_20k.o \
$(BUILD)/DarkSide_50.o \
$(BUILD)/DarkSide_50_S2.o \
$(BUILD)/PICO_500.o
$(BUILD)/DDHalo.o: $(BUILD)/DDConstants.o \
$(BUILD)/DDTypes.o \
$(BUILD)/DDUtils.o \
$(BUILD)/DDNumerical.o \
$(BUILD)/DDInput.o
$(BUILD)/DDInput.o: $(BUILD)/DDUtils.o
$(BUILD)/DDNuclear.o: $(BUILD)/DDConstants.o \
$(BUILD)/DDInput.o
$(BUILD)/DDNumerical.o: $(BUILD)/DDUtils.o
$(BUILD)/DDNREffectiveTheory.o: $(BUILD)/DDConstants.o \
$(BUILD)/DDHalo.o \
$(BUILD)/DDCouplings.o \
$(BUILD)/DDTypes.o
$(BUILD)/DDRates.o: $(BUILD)/DDTypes.o \
$(BUILD)/DDHalo.o \
$(BUILD)/DDNREffectiveTheory.o
$(BUILD)/DDStats.o: $(BUILD)/DDTypes.o \
$(BUILD)/DDNumerical.o
$(BUILD)/DDUtils.o: $(BUILD)/DDTypes.o
$(BUILD)/DDWIMP.o: $(BUILD)/DDTypes.o \
$(BUILD)/DDUtils.o \
$(BUILD)/DDCouplings.o
#################### RULES #################################
# Default: build only the programs
.DEFAULT_GOAL := bin
# Phony targets
.PHONY: all bin lib examples FORCE clean distclean
# Build everything (except archives)
all: lib bin examples
# Binaries (programs)
bin: $(fprograms)
# Libraries
lib: $(libraries)
# Example/test binaries (programs)
examples: $(ftestprograms) $(ctestprograms) $(pytestprograms) ddcalcinclude
# Define a do-nothing rule for dummy targets
# (avoids "nothing to be done" messages)
ifort gfortran:
@:
# Rule for building programs
$(fprograms): $(statlib)
$(fprograms): % : $(SRC)/%.f90
$(FC) $(FFLAGS) -I$(BUILD) -o $@ $< $(LIB)/$(statlib)
# Rule for building test programs (F)
$(ftestprograms): $(statlib)
$(ftestprograms): % : $(EXAMPLES)/%.f90
$(FC) $(FFLAGS) -I$(BUILD) -o $@ $< $(LIB)/$(statlib)
# Rule for building test programs (C++)
$(ctestprograms): $(statlib)
$(ctestprograms): % : $(EXAMPLES)/%.cpp
$(CXX) $(CXXFLAGS) -I$(INCLUDE) -o $@ $< $(LIB)/$(statlib) $(CXX_FLIBS)
$(pytestprograms): % : $(EXAMPLES)/%
ln -sf $< $(DDCALC_DIR)$@
ddcalcinclude:
echo "ddcalc_dir = '$(DDCALC_DIR)'" > $(EXAMPLES)/DDCalcInclude.py
echo "include_dir = '$(INCLUDE)'" >> $(EXAMPLES)/DDCalcInclude.py
echo "lib_dir = '$(LIB)'" >> $(EXAMPLES)/DDCalcInclude.py
ln -sf $(EXAMPLES)/DDCalcInclude.py $(INCLUDE)/DDCalcInclude.py
# Rules for building objects
$(BUILD)/%.o : $(SRC)/%.f90
$(FC) $(FFLAGS) -o $@ -c $<
$(BUILD)/%.o : $(SRC)/analyses/%.f90 $(BUILD)/DDTypes.o $(BUILD)/DDDetectors.o
$(FC) $(FFLAGS) -o $@ -c $<
# Rule for building static library
$(statlib): $(fobjects)
ar rcs $(LIB)/$@ $^
# Rule for building shared library
$(sharedlib): $(fobjects)
$(FC) $(FFLAGS) -shared -o $(LIB)/$@ $^
# Generate archive file
dist: $(distfile)
$(distfile): $(sources) $(extrafiles)
mkdir -p ".archive-temp/$(DIST_DIR)/build"
mkdir -p ".archive-temp/$(DIST_DIR)/lib"
cp -r -al $(SRC) $(INCLUDE) $(DOC) $(EXAMPLES) \
$(DATA) $(extrafiles) ".archive-temp/$(DIST_DIR)/"
tar -czf $@ -C ".archive-temp" "$(DIST_DIR)"
rm -rf ".archive-temp"
# Remove files
clean: FORCE
-rm -rf $(cleanfiles)
# Remove more files
distclean:FORCE
-rm -rf $(distcleanfiles)