-
Notifications
You must be signed in to change notification settings - Fork 1
/
binmake.gmk
435 lines (395 loc) · 16.9 KB
/
binmake.gmk
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# $Id: binmake.gmk,v 1.135 2007/11/22 14:08:10 gcosmo Exp $
# ----------------------------------------------------------
# Script defining rules and paths for making binaries.
# First implementation: Gabriele Cosmo, 25/06/1998.
# ----------------------------------------------------------
ifndef LDFLAGS
include $(G4INSTALL)/config/architecture.gmk
endif
G4LIBDIR := $(G4LIB)/$(G4SYSTEM)
echo $G4LIBDIR
# Define variable checking for existence of centrally installed headers.
# If check will be true, avoid explicit definition of paths to INCFLAGS.
#
G4INCLUDE_EXEC := $(shell [ -r $(G4INCLUDE)/globals.hh ] && echo 1)
include $(G4INSTALL)/config/G4UI_USE.gmk
include $(G4INSTALL)/config/G4VIS_USE.gmk
include $(G4INSTALL)/config/interactivity.gmk
include $(G4INSTALL)/config/analysis.gmk
# Verify the existance of the global static libraries first.
# if not verify the existance of global shared libraries (Unix only).
#
ifndef G4LIB_USE_GRANULAR
GLOBALLIBS := $(shell test -f $(G4LIB)/$(G4SYSTEM)/libG4global.a && echo yes)
ifndef GLOBALLIBS
GLOBALLIBS := $(shell test -f $(G4LIB)/$(G4SYSTEM)/libG4global.$(SHEXT) && echo yes)
SHAREDLIBS := $(shell test -f $(G4LIB)/$(G4SYSTEM)/libG4global.$(SHEXT) && echo yes)
endif
endif
# Verify the existance of granular shared libraries (Unix) or global DLLs (Windows)
#
ifndef SHAREDLIBS
SHAREDLIBS := $(shell test -f $(G4LIB)/$(G4SYSTEM)/libG4globman.$(SHEXT) && echo yes)
endif
ifneq (,$(findstring WIN32-VC,$(G4SYSTEM)))
SHAREDLIBS := $(shell test -f $(G4LIB)/$(G4SYSTEM)/G4global.$(SHEXT) && echo yes)
endif
ifndef INCFLAGS
ifeq ($(G4INCLUDE_EXEC),1)
INCFLAGS := -I$(G4INCLUDE)
else
INCFLAGS := \
-I$(G4BASE)/global/management/include \
-I$(G4BASE)/global/HEPRandom/include \
-I$(G4BASE)/global/HEPGeometry/include \
-I$(G4BASE)/global/HEPNumerics/include \
-I$(G4BASE)/run/include \
-I$(G4BASE)/materials/include \
-I$(G4BASE)/parameterisations/gflash/include \
-I$(G4BASE)/particles/management/include \
-I$(G4BASE)/particles/bosons/include \
-I$(G4BASE)/particles/leptons/include \
-I$(G4BASE)/particles/hadrons/barions/include \
-I$(G4BASE)/particles/hadrons/ions/include \
-I$(G4BASE)/particles/hadrons/mesons/include \
-I$(G4BASE)/particles/shortlived/include \
-I$(G4BASE)/physics_lists/lists/include \
-I$(G4BASE)/physics_lists/builders/include \
-I$(G4BASE)/processes/management/include \
-I$(G4BASE)/processes/cuts/include \
-I$(G4BASE)/processes/biasing/include \
-I$(G4BASE)/processes/scoring/include \
-I$(G4BASE)/processes/decay/include \
-I$(G4BASE)/processes/optical/include \
-I$(G4BASE)/processes/transportation/include \
-I$(G4BASE)/processes/parameterisation/include \
-I$(G4BASE)/processes/electromagnetic/standard/include \
-I$(G4BASE)/processes/electromagnetic/muons/include \
-I$(G4BASE)/processes/electromagnetic/utils/include \
-I$(G4BASE)/processes/electromagnetic/xrays/include \
-I$(G4BASE)/processes/electromagnetic/lowenergy/include \
-I$(G4BASE)/processes/electromagnetic/highenergy/include \
-I$(G4BASE)/processes/electromagnetic/polarisation/include \
-I$(G4BASE)/processes/hadronic/cross_sections/include \
-I$(G4BASE)/processes/hadronic/management/include \
-I$(G4BASE)/processes/hadronic/models/abrasion/include \
-I$(G4BASE)/processes/hadronic/models/binary_cascade/include \
-I$(G4BASE)/processes/hadronic/models/cascade/cascade/include \
-I$(G4BASE)/processes/hadronic/models/cascade/evaporation/include \
-I$(G4BASE)/processes/hadronic/models/cascade/utils/include \
-I$(G4BASE)/processes/hadronic/models/chiral_inv_phase_space/body/include \
-I$(G4BASE)/processes/hadronic/models/chiral_inv_phase_space/interface/include \
-I$(G4BASE)/processes/hadronic/models/coherent_elastic/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/ablation/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/evaporation/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/fermi_breakup/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/fission/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/gem_evaporation/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/handler/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/management/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/multifragmentation/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/photon_evaporation/include \
-I$(G4BASE)/processes/hadronic/models/de_excitation/util/include \
-I$(G4BASE)/processes/hadronic/models/em_dissociation/include \
-I$(G4BASE)/processes/hadronic/models/general_finalstate/include \
-I$(G4BASE)/processes/hadronic/models/high_energy/include \
-I$(G4BASE)/processes/hadronic/models/im_r_matrix/include \
-I$(G4BASE)/processes/hadronic/models/incl/include \
-I$(G4BASE)/processes/hadronic/models/inucl/include \
-I$(G4BASE)/processes/hadronic/models/isotope_production/include \
-I$(G4BASE)/processes/hadronic/models/leading_particle/include \
-I$(G4BASE)/processes/hadronic/models/lll_fission/include \
-I$(G4BASE)/processes/hadronic/models/low_energy/include \
-I$(G4BASE)/processes/hadronic/models/management/include \
-I$(G4BASE)/processes/hadronic/models/neutron_hp/include \
-I$(G4BASE)/processes/hadronic/models/parton_string/diffraction/include \
-I$(G4BASE)/processes/hadronic/models/parton_string/hadronization/include \
-I$(G4BASE)/processes/hadronic/models/parton_string/management/include \
-I$(G4BASE)/processes/hadronic/models/parton_string/qgsm/include \
-I$(G4BASE)/processes/hadronic/models/photolepton_hadron/muon_nuclear/include \
-I$(G4BASE)/processes/hadronic/models/pre_equilibrium/exciton_model/include \
-I$(G4BASE)/processes/hadronic/models/qmd/include \
-I$(G4BASE)/processes/hadronic/models/quark_molecular_dynamics/body/include \
-I$(G4BASE)/processes/hadronic/models/quark_molecular_dynamics/util/include \
-I$(G4BASE)/processes/hadronic/models/radioactive_decay/include \
-I$(G4BASE)/processes/hadronic/models/relativistic_qmd/include \
-I$(G4BASE)/processes/hadronic/models/relativistic_qmd/uplusplus/include \
-I$(G4BASE)/processes/hadronic/models/rpg/include \
-I$(G4BASE)/processes/hadronic/models/theo_high_energy/include \
-I$(G4BASE)/processes/hadronic/models/util/include \
-I$(G4BASE)/processes/hadronic/processes/include \
-I$(G4BASE)/processes/hadronic/stopping/include \
-I$(G4BASE)/processes/hadronic/util/include \
-I$(G4BASE)/geometry/management/include \
-I$(G4BASE)/geometry/solids/CSG/include \
-I$(G4BASE)/geometry/solids/specific/include \
-I$(G4BASE)/geometry/solids/BREPS/include \
-I$(G4BASE)/geometry/solids/Boolean/include \
-I$(G4BASE)/geometry/divisions/include \
-I$(G4BASE)/geometry/volumes/include \
-I$(G4BASE)/geometry/navigation/include \
-I$(G4BASE)/geometry/magneticfield/include \
-I$(G4BASE)/geometry/biasing/include \
-I$(G4BASE)/track/include \
-I$(G4BASE)/tracking/include \
-I$(G4BASE)/digits_hits/detector/include \
-I$(G4BASE)/digits_hits/hits/include \
-I$(G4BASE)/digits_hits/digits/include \
-I$(G4BASE)/digits_hits/scorer/include \
-I$(G4BASE)/digits_hits/utils/include \
-I$(G4BASE)/persistency/gdml/include \
-I$(G4BASE)/persistency/mctruth/include \
-I$(G4BASE)/readout/include \
-I$(G4BASE)/event/include \
-I$(G4BASE)/error_propagation/include \
-I$(G4BASE)/graphics_reps/include \
-I$(G4BASE)/intercoms/include
ifdef G4LIB_USE_G3TOG4
INCFLAGS += -I$(G4BASE)/g3tog4/include
endif
endif
endif
CPPFLAGS += $(INCFLAGS)
LDFLAGS += -L$(G4LIBDIR)
G4TMPDIR := $(G4TMP)/$(G4SYSTEM)/$(G4TARGET)
G4BINDIR := $(G4BIN)/$(G4SYSTEM)
ifdef G4EXLIB
G4LIBDIR := $(G4TMPDIR)
LDFLAGS += -L$(G4LIBDIR)
ifdef SHAREDLIBS
ifdef G4RUNPATHOPTION
# For the example dependent directory, keep the
# path to the shared lib in the executable.
LDFLAGS += $(G4RUNPATHOPTION)$(G4LIBDIR)
endif
endif
include $(G4INSTALL)/config/common.gmk
endif
ifdef LDLIBS
USER_DEFINED_LDLIBS := 1
endif
# Because of the script for granular libraries which replaces part of LDLIBS
# and because of the way user defined LDLIBS was augmented historically I
# have split LDLIBS into 4 parts...
#
ifndef USER_DEFINED_LDLIBS
# TARGETLIB is the library generated for the final user application;
# TARGOBJEXT defines the target object extension
#
ifdef G4EXLIB
ifeq (,$(findstring WIN32-VC,$(G4SYSTEM)))
# Unix
TARGETLIB := -l$(G4TARGET)
TARGOBJEXT := o
else
# Windows
TARGETLIB := lib$(G4TARGET).a
TARGOBJEXT := OBJ
endif
endif
# LDLIBS1 contains the very high level libraries...
#
LDLIBS1 := $(EXTRALIBS)
# VISLIBS (and UILIBS?) is handled by the granular library script...
#
ifdef GLOBALLIBS
LDLIBS2 := $(VISLIBS) -lG4interfaces -lG4persistency
ifdef G4LIB_USE_G3TOG4
LDLIBS2 += -lG3toG4
endif
LDLIBS2 += -lG4error_propagation \
-lG4readout \
-lG4physicslists \
-lG4run \
-lG4event \
-lG4tracking \
-lG4parmodels \
-lG4processes \
-lG4digits_hits \
-lG4track \
-lG4particles \
-lG4geometry \
-lG4materials \
-lG4graphics_reps \
-lG4intercoms \
-lG4global
else
# The next lines specifically should read LDLIBS2 = , not LDLIBS2 :=, so
# that it is not expanded until the directory G4TMPDIR is created.
ifeq ($(G4INCLUDE_EXEC),1)
LDLIBS2 = $(shell \
G4TMP=$(G4TMP); export G4TMP; \
if [ \( -f $(G4LIB)/$(G4SYSTEM)/liblist \
-a -f $(G4LIB)/$(G4SYSTEM)/libname.map \) ]; then \
$(G4LIB)/$(G4SYSTEM)/liblist \
-m $(G4LIB)/$(G4SYSTEM) \
< $(G4LIB)/$(G4SYSTEM)/libname.map; fi)
else
LDLIBS2 = $(shell \
G4TMP=$(G4TMP); export G4TMP; \
if [ \( -f $(G4LIB)/$(G4SYSTEM)/liblist \
-a -f $(G4LIB)/$(G4SYSTEM)/libname.map \) ]; then \
$(G4LIB)/$(G4SYSTEM)/liblist \
-d $(G4TMPDIR) \
< $(G4LIB)/$(G4SYSTEM)/libname.map; fi)
# Warning: do not add to LDLIBS2 with += because this causes it to be
# expanded too soon. Hence extra libraries must have a different name...
# Extra libraries to resolve remaining circular dependencies...
# LDLIBS2EXTRA =
endif
endif
ifdef G4LIB_USE_ZLIB
LDLIBS2 += -lG4zlib
endif
# LDLIBS3 contains the first set of low level libraries...
#
ifdef G4LIB_USE_GDML
LDLIBS3 += $(GDMLLIBS)
endif
LDLIBS3 += $(INTYLIBS)
LDLIBS3 += $(ANALYSISLIBS)
endif # ifndef USER_DEFINED_LDLIBS
# LDLIBS4 contains the next set of low level libraries which historically
# (why?) the user is not supposed to be able to define...
#
LDLIBS4 += $(LOADLIBS)
# Finally assemble libraries...
#
ifdef USER_DEFINED_LDLIBS
LDLIBS_PREFINAL := $(LDLIBS)
LDLIBS_KERNEL := $(LDLIBS)
else
# Again, do not use := or +=. See note on LDLIBS2 above.
LDLIBS_PREFINAL = $(LDLIBS1) $(LDLIBS2) $(LDLIBS2EXTRA) $(LDLIBS3)
# Version leaving out EXTRALIBS
LDLIBS_KERNEL = $(LDLIBS2) $(LDLIBS2EXTRA) $(LDLIBS3)
endif
LDLIBS_PREFINAL += $(LDLIBS4)
LDLIBS_KERNEL += $(LDLIBS4)
ifneq (,$(findstring WIN32-VC,$(G4SYSTEM)))
# Windows
WIN32TMP := $(patsubst -L%,$(LIB_PATH)%,$(LDFLAGS))
LDFLAGS = $(patsubst /,$(PATH_DEL),$(WIN32TMP))
WIN32TMP2 := $(patsubst -L%,$(LIB_PATH)%,$(LDLIBS_PREFINAL))
WIN32TMP3 := $(patsubst -L%,$(LIB_PATH)%,$(LDLIBS1))
WIN32TMP4 := $(patsubst -L%,$(LIB_PATH)%,$(LDLIBS_KERNEL))
ifdef SHAREDLIBS
ifdef G4LIB_USE_DLL
LDLIBS = $(TARGETLIB) $(patsubst -l%,lib%.a,$(WIN32TMP3)) $(patsubst -l%,lib%.lib,$(WIN32TMP4))
else
LDLIBS = $(TARGETLIB) $(patsubst -l%,lib%.lib,$(WIN32TMP2))
endif
else
LDLIBS = $(TARGETLIB) $(patsubst -l%,lib%.a,$(WIN32TMP2))
endif
OUT := /Fe
else
# Unix
LDLIBS = $(TARGETLIB) $(LDLIBS_PREFINAL)
OUT := -o
endif
ifdef transform-RPath
# Invoke system specific transformation of
include $(G4INSTALL)/config/sys/$(G4SYSTEM)-runpath.gmk
endif
sources := $(wildcard $(G4TARGET).cc)
objects := $(patsubst %.cc,$(G4TMPDIR)/exe/%.$(TARGOBJEXT),$(sources))
dependencies := $(patsubst %.cc,$(G4TMPDIR)/exe/%.d,$(sources))
LINK_DEPENDENCIES := $(G4TMPDIR)/exe/obj.last $(EXTRA_LINK_DEPENDENCIES)
.PHONY: bin clean clean_bin debug
# Make $(G4TARGET) executable.
bin: $(G4BINDIR)/$(G4TARGET)
$(G4BINDIR)/$(G4TARGET): $(LINK_DEPENDENCIES)
ifndef USER_DEFINED_LDLIBS
ifndef GLOBALLIBS
@echo "Using granular libraries ..."
@if [ ! \( -f $(G4LIB)/$(G4SYSTEM)/liblist \
-a -f $(G4LIB)/$(G4SYSTEM)/libname.map \) ]; then \
echo "ERROR: No liblist program or library map file."; \
echo " These are needed for building with granular"; \
echo " libraries."; \
echo ' cd $$G4INSTALL/source'; \
echo " gmake"; \
echo " or if you are sure you have already made all the"; \
echo " granular libraries:"; \
echo " gmake libmap"; \
exit 1; fi
else
@echo "Using global libraries ..."
endif
endif
@if [ ! -d $(G4BINDIR) ] ; then mkdir $(G4BINDIR) ;fi
ifdef CPPVERBOSE
$(CXX) $(CXXFLAGS) $(CPPFLAGS) \
$(OUT)$(G4BINDIR)/$(G4TARGET) $(objects) $(LDFLAGS) \
$(LDLIBS)
else
@echo Linking $(G4TARGET) ...
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) \
$(OUT)$(G4BINDIR)/$(G4TARGET) $(objects) $(LDFLAGS) \
$(LDLIBS)
@if [ \( -f $(G4BINDIR)/$(G4TARGET) \) ]; then \
echo "... Done!"; fi
endif
# Touch the versioning file
ifdef G4EXLIB
$(G4TMPDIR)/exe/obj.last: lib $(objects)
else
$(G4TMPDIR)/exe/obj.last: $(objects)
endif
@touch $@
# Make the $(G4TARGET).$(TARGOBJEXT) file.
$(G4TMPDIR)/exe/$(G4TARGET).$(TARGOBJEXT) : $(G4TARGET).cc
ifdef CPPVERBOSE
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(APPFLAGS) \
-c $(OUT_OBJ)$(G4TMPDIR)/exe/$(G4TARGET).$(TARGOBJEXT) $(G4TARGET).cc
else
@echo Compiling $(G4TARGET).cc ...
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(APPFLAGS) \
-c $(OUT_OBJ)$(G4TMPDIR)/exe/$(G4TARGET).$(TARGOBJEXT) $(G4TARGET).cc
endif
GPPFLAGS := "-M"
# Make the $(G4TARGET).d file and include it.
# The ideas for this come from the GNU Make Manual, Section 4.12,
# Generating Prerequisites Automatically. The g++ compiler has an
# option -M or -MM to write to standard output a list of dependencies
# based on the #include statements. The "sed" adds the dependency
# file itself as a second target. The result is a mini-makefile which
# specifies the .o and .d files as targets which depend on all the
# files found through the #include statements. This file is then
# included, causing GNU Make to honour these dependencies.
# The "set -e" causes the shell to exit with an error when the "g++"
# fails (otherwise it would only notice the last command in the
# pipeline, namely "sed"). GNU Make notices the error and exits
# sooner than it otherwise would (still not as soon as I expect,
# though!). Even then, an empty file is made, so "[ -s $@ ] || rm -f
# $@" removes it ([ -s filename ] gives zero exit code only if file
# exists and has a size greater than zero). This avoids making
# corrupt .d files which would play havoc with your next build.
$(G4TMPDIR)/exe/$(G4TARGET).d: $(G4TARGET).cc
@if [ ! -d $(G4TMP)/$(G4SYSTEM) ] ; then mkdir $(G4TMP)/$(G4SYSTEM) ;fi
@if [ ! -d $(G4TMPDIR) ] ; then mkdir $(G4TMPDIR) ;fi
@if [ ! -d $(G4TMPDIR)/exe ] ; then mkdir $(G4TMPDIR)/exe ;fi
@echo Making dependency for file $< ...
@set -e;\
g++ $(GPPFLAGS) $(CPPFLAGS) -w $< |\
sed 's!$(G4TARGET)\.$(TARGOBJEXT)!$(G4TMPDIR)/exe/& $@!' >$@;\
[ -s $@ ] || rm -f $@
ifneq ($(dependencies),)
ifneq ($(MAKECMDGOALS),clean)
-include $(dependencies)
endif
endif
clean::
@echo Cleaning up ...
@rm -f ./core
@rm -rf $(G4TMPDIR)
@rm -f $(G4LIBDIR)/lib$(G4TARGET).a
@rm -f $(G4BINDIR)/$(G4TARGET)
ifdef CFRONT
@rm -rf $(G4TREP)/exec
endif
clean_bin::
@echo Removing application $(G4TARGET) ...
@rm -f ./core
@rm -f $(G4BINDIR)/$(G4TARGET)