Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. # $Id: binmake.gmk,v 1.2 2007/07/19 14:05:37 witoldp Exp $
  2. # ----------------------------------------------------------
  3. # Script defining rules and paths for making binaries.
  4. # First implementation: Gabriele Cosmo, 25/06/1998.
  5. # ----------------------------------------------------------
  6.  
  7. ifndef LDFLAGS
  8. include $(FLUGGINSTALL)/config/architecture.gmk
  9. endif
  10.  
  11. G4LIBDIR := $(G4LIB)/$(G4SYSTEM)
  12.  
  13. # Define variable checking for existence of centrally installed headers.
  14. # If check will be true, avoid explicit definition of paths to INCFLAGS.
  15. #
  16.  
  17. G4INCLUDE_EXEC := $(shell [ -r $(G4INCLUDE)/globals.hh ] && echo 1)
  18.  
  19.  
  20. ifndef G4LIB_USE_GRANULAR
  21. GLOBALLIBS := $(shell test -f $(G4LIB)/$(G4SYSTEM)/libG4global.a && echo yes)
  22. ifndef GLOBALLIBS
  23. GLOBALLIBS := $(shell test -f $(G4LIB)/$(G4SYSTEM)/libG4global.$(SHEXT) && echo yes)
  24. SHAREDLIBS := $(shell test -f $(G4LIB)/$(G4SYSTEM)/libG4global.$(SHEXT) && echo yes)
  25. endif
  26. endif
  27.  
  28. ifndef SHAREDLIBS
  29. SHAREDLIBS := $(shell test -f $(G4LIB)/$(G4SYSTEM)/libG4globman.$(SHEXT) && echo yes)
  30. endif
  31.  
  32. ifndef INCFLAGS
  33. ifeq ($(G4INCLUDE_EXEC),1)
  34. INCFLAGS := -I$(G4INCLUDE)
  35. else
  36. INCFLAGS := \
  37. -I$(G4BASE)/global/management/include \
  38. -I$(G4BASE)/global/HEPRandom/include \
  39. -I$(G4BASE)/global/HEPGeometry/include \
  40. -I$(G4BASE)/global/HEPNumerics/include \
  41. -I$(G4BASE)/materials/include \
  42. -I$(G4BASE)/geometry/management/include \
  43. -I$(G4BASE)/geometry/solids/CSG/include \
  44. -I$(G4BASE)/geometry/solids/specific/include \
  45. -I$(G4BASE)/geometry/solids/BREPS/include \
  46. -I$(G4BASE)/geometry/solids/Boolean/include \
  47. -I$(G4BASE)/geometry/divisions/include \
  48. -I$(G4BASE)/geometry/volumes/include \
  49. -I$(G4BASE)/geometry/navigation/include \
  50. -I$(G4BASE)/geometry/verification/include \
  51. -I$(G4BASE)/geometry/magneticfield/include \
  52. -I$(G4BASE)/graphics_reps/include \
  53. -I$(G4BASE)/dummyG4/include \
  54. -I$(G4BASE)/Wrappers/include
  55.  
  56. ifdef G4USE_STEP
  57. INCFLAGS += -I$(G4BASE)/geometry/solids/STEP/include \
  58. -I$(G4BASE)/geometry/solids/STEPinterface/include
  59. endif
  60. endif
  61. endif
  62.  
  63. CPPFLAGS += $(INCFLAGS)
  64. LDFLAGS += -L$(G4LIBDIR)
  65.  
  66. # Addded for FLUGG: fortran and fluka libraries path
  67. LDFLAGS += -L/lib -L$(FLUPRO)
  68.  
  69. G4TMPDIR := $(G4TMP)/$(G4SYSTEM)/$(G4TARGET)
  70. G4BINDIR := $(G4BIN)/$(G4SYSTEM)
  71.  
  72. ifdef G4EXLIB
  73. G4LIBDIR := $(G4TMPDIR)
  74. LDFLAGS += -L$(G4LIBDIR)
  75. ifdef SHAREDLIBS
  76. ifdef G4RUNPATHOPTION
  77. # For the example dependent directory, keep the
  78. # path to the shared lib in the executable.
  79. LDFLAGS += $(G4RUNPATHOPTION)$(G4LIBDIR)
  80. endif
  81. endif
  82. include $(FLUGGINSTALL)/config/common.gmk
  83. endif
  84.  
  85. ifdef LDLIBS
  86. USER_DEFINED_LDLIBS := 1
  87. endif
  88.  
  89. # Because of the script for granular libraries which replaces part of LDLIBS
  90. # and because of the way user defined LDLIBS was augmented historically I
  91. # have split LDLIBS into 4 parts...
  92. #
  93. ifndef USER_DEFINED_LDLIBS
  94.  
  95. # LDLIBS1 contains the very high level libraries...
  96. #
  97. ifdef G4EXLIB
  98. LDLIBS1 := -l$(G4TARGET)
  99. endif
  100. LDLIBS1 += $(EXTRALIBS)
  101.  
  102. # VISLIBS and UILIBS are now handled by the granular library script...
  103. #
  104. ifdef GLOBALLIBS
  105. LDLIBS1 += $(VISLIBS) $(UILIBS) # -lG4persistency
  106.  
  107. LDLIBS2 := \
  108. -lFggWrappers \
  109. -lG4geometry \
  110. -lG4materials \
  111. -lG4graphics_reps \
  112. -lG4intercoms \
  113. -lG4dummy \
  114. -lG4global
  115. else
  116. # The next lines specifically should read LDLIBS2 = , not LDLIBS2 :=, so
  117. # that it is not expanded until the directory G4TMPDIR is created.
  118. ifeq ($(G4INCLUDE_EXEC),1)
  119. LDLIBS2 = $(shell \
  120. G4TMP=$(G4TMP); export G4TMP; \
  121. if [ \( -f $(G4LIB)/$(G4SYSTEM)/liblist \
  122. -a -f $(G4LIB)/$(G4SYSTEM)/libname.map \) ]; then \
  123. $(G4LIB)/$(G4SYSTEM)/liblist \
  124. -m $(G4LIB)/$(G4SYSTEM) \
  125. < $(G4LIB)/$(G4SYSTEM)/libname.map; fi)
  126. else
  127. LDLIBS2 = $(shell \
  128. G4TMP=$(G4TMP); export G4TMP; \
  129. if [ \( -f $(G4LIB)/$(G4SYSTEM)/liblist \
  130. -a -f $(G4LIB)/$(G4SYSTEM)/libname.map \) ]; then \
  131. $(G4LIB)/$(G4SYSTEM)/liblist \
  132. -d $(G4TMPDIR) \
  133. < $(G4LIB)/$(G4SYSTEM)/libname.map; fi)
  134. # Warning: do not add to LDLIBS2 with += because this causes it to be
  135. # expanded too soon. Hence extra libraries must have a different name...
  136. # Extra libraries to resolve remaining circular dependencies...
  137. # LDLIBS2EXTRA =
  138. endif
  139. endif
  140.  
  141. # LDLIBS3 contains the first set of low level libraries...
  142. #
  143. LDLIBS3 += $(INTYLIBS)
  144. LDLIBS3 += $(ANALYSISLIBS)
  145.  
  146. endif # ifndef USER_DEFINED_LDLIBS
  147.  
  148. # LDLIBS4 contains the next set of low level libraries which historically
  149. # (why?) the user is not supposed to be able to define...
  150. #
  151. LDLIBS4 += $(LOADLIBS)
  152.  
  153. # Finally assemble libraries...
  154. #
  155. ifdef USER_DEFINED_LDLIBS
  156. LDLIBS_PREFINAL := $(LDLIBS)
  157. else
  158. # Again, do not use := or +=. See note on LDLIBS2 above.
  159. LDLIBS_PREFINAL = $(LDLIBS1) $(LDLIBS2) $(LDLIBS2EXTRA) $(LDLIBS3)
  160. endif
  161. LDLIBS_PREFINAL += $(LDLIBS4)
  162.  
  163. ifneq (,$(findstring WIN32-VC,$(G4SYSTEM)))
  164. WIN32TMP := $(patsubst -L%,$(LIB_PATH)%,$(LDFLAGS))
  165. LDFLAGS = $(patsubst /,$(PATH_DEL),$(WIN32TMP))
  166. LDLIBS = $(patsubst -l%,lib%.a,$(LDLIBS_PREFINAL))
  167. else
  168. LDLIBS = $(LDLIBS_PREFINAL)
  169. endif
  170.  
  171. # Addded for FLUGG: fortan and fluka libraries
  172. LDLIBS += -lc
  173. LDLIBS += -lflukahp
  174. LDLIBS += -lg2c -lstdc++
  175. #
  176.  
  177. ifdef transform-RPath
  178. #invoke system specific transformation of
  179. include $(FLUGGINSTALL)/config/sys/$(G4SYSTEM)-runpath.gmk
  180. endif
  181.  
  182. sources := $(wildcard $(G4TARGET).cc)
  183. objects := $(patsubst %.cc,$(G4TMPDIR)/exe/%.o,$(sources))
  184. dependencies := $(patsubst %.cc,$(G4TMPDIR)/exe/%.d,$(sources))
  185.  
  186. #
  187. # extra fortran source files for FLUKA
  188. #
  189. sources += $(wildcard for/*.f)
  190. objects += $(patsubst for/%.f,$(G4TMPDIR)/exe/%.o,$(wildcard for/*.f))
  191.  
  192. $(G4TMPDIR)/exe/%.o: for/%.f
  193. @echo Compiling $*.f ...
  194. @$(FLUPRO)/flutil/fff for/$*.f
  195. @mv for/$*.o $(G4TMPDIR)/exe/$*.o
  196.  
  197. ##
  198. LINK_DEPENDENCIES := $(G4TMPDIR)/exe/obj.last $(EXTRA_LINK_DEPENDENCIES)
  199.  
  200. .PHONY: bin clean clean_bin debug
  201.  
  202. # Make $(G4TARGET) executable.
  203.  
  204. bin: $(G4BINDIR)/$(G4TARGET)
  205.  
  206. $(G4BINDIR)/$(G4TARGET): $(LINK_DEPENDENCIES)
  207. ifndef USER_DEFINED_LDLIBS
  208. ifndef GLOBALLIBS
  209. @echo "Using granular libraries ..."
  210. @if [ ! \( -f $(G4LIB)/$(G4SYSTEM)/liblist \
  211. -a -f $(G4LIB)/$(G4SYSTEM)/libname.map \) ]; then \
  212. echo "ERROR: No liblist program or library map file."; \
  213. echo " These are needed for building with granular"; \
  214. echo " libraries."; \
  215. echo " cd $$FLUGGINSTALL/source"; \
  216. echo " gmake"; \
  217. echo " or if you are sure you have already made all the"; \
  218. echo " granular libraries:"; \
  219. echo " gmake libmap"; \
  220. exit 1; fi
  221. else
  222. @echo "Using global libraries."
  223. endif
  224. endif
  225. @if [ ! -d $(G4BINDIR) ] ; then mkdir $(G4BINDIR) ;fi
  226. @echo $(G4EXLIB)
  227.  
  228. ifdef CPPVERBOSE
  229. $(CXX) $(CXXFLAGS) $(CPPFLAGS) \
  230. -o $(G4BINDIR)/$(G4TARGET) $(objects) $(LDFLAGS) \
  231. $(LDLIBS)
  232. else
  233. @echo Linking $(G4TARGET) ...
  234. @$(CXX) $(CXXFLAGS) $(CPPFLAGS) \
  235. -o $(G4BINDIR)/$(G4TARGET) $(objects) $(LDFLAGS) \
  236. $(LDLIBS)
  237. endif
  238.  
  239. # Touch the versioning file
  240. ifdef G4EXLIB
  241. $(G4TMPDIR)/exe/obj.last: lib $(objects)
  242. else
  243. $(G4TMPDIR)/exe/obj.last: $(objects)
  244. endif
  245. @touch $@
  246.  
  247. # Make the $(G4TARGET).o file.
  248. $(G4TMPDIR)/exe/$(G4TARGET).o : $(G4TARGET).cc
  249. ifdef CPPVERBOSE
  250. $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(APPFLAGS) \
  251. -c $(OUT_OBJ)$(G4TMPDIR)/exe/$(G4TARGET).o $(G4TARGET).cc
  252. else
  253. @echo Compiling $(G4TARGET).cc ...
  254. @$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(APPFLAGS) \
  255. -c $(OUT_OBJ)$(G4TMPDIR)/exe/$(G4TARGET).o $(G4TARGET).cc
  256. endif
  257.  
  258. GPPFLAGS := "-M"
  259.  
  260. # Make the $(G4TARGET).d file and include it.
  261.  
  262. # The ideas for this come from the GNU Make Manual, Section 4.12,
  263. # Generating Prerequisites Automatically. The g++ compiler has an
  264. # option -M or -MM to write to standard output a list of dependencies
  265. # based on the #include statements. The "sed" adds the dependency
  266. # file itself as a second target. The result is a mini-makefile which
  267. # specifies the .o and .d files as targets which depend on all the
  268. # files found through the #include statements. This file is then
  269. # included, causing GNU Make to honour these dependencies.
  270.  
  271. # The "set -e" causes the shell to exit with an error when the "g++"
  272. # fails (otherwise it would only notice the last command in the
  273. # pipeline, namely "sed"). GNU Make notices the error and exits
  274. # sooner than it otherwise would (still not as soon as I expect,
  275. # though!). Even then, an empty file is made, so "[ -s $@ ] || rm -f
  276. # $@" removes it ([ -s filename ] gives zero exit code only if file
  277. # exists and has a size greater than zero). This avoids making
  278. # corrupt .d files which would play havoc with your next build.
  279.  
  280. $(G4TMPDIR)/exe/$(G4TARGET).d: $(G4TARGET).cc
  281. @if [ ! -d $(G4TMP)/$(G4SYSTEM) ] ; then mkdir $(G4TMP)/$(G4SYSTEM) ;fi
  282. @if [ ! -d $(G4TMPDIR) ] ; then mkdir $(G4TMPDIR) ;fi
  283. @if [ ! -d $(G4TMPDIR)/exe ] ; then mkdir $(G4TMPDIR)/exe ;fi
  284. @echo Making dependency for file $<...
  285. @set -e;\
  286. g++ $(GPPFLAGS) $(CPPFLAGS) -w $< |\
  287. sed 's!$(G4TARGET)\.o!$(G4TMPDIR)/exe/& $@!' >$@;\
  288. [ -s $@ ] || rm -f $@
  289. ifneq ($(dependencies),)
  290. -include $(dependencies)
  291. endif
  292.  
  293. clean:
  294. @echo Cleaning up ...
  295. @rm -f ./core
  296. @rm -rf $(G4TMPDIR)
  297. @rm -f $(G4LIBDIR)/lib$(G4TARGET).a
  298. @rm -f $(G4BINDIR)/$(G4TARGET)
  299. ifdef CFRONT
  300. @rm -rf $(G4TREP)/exec
  301. endif
  302.  
  303. clean_bin:
  304. @echo Removing application $(G4TARGET) ...
  305. @rm -f ./core
  306. @rm -f $(G4BINDIR)/$(G4TARGET)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement