File indexing completed on 2025-04-04 08:05:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 CXX_COMP := g++
0035 CXX_FLAGS := -std=c++17 -O2 -g -Wall -pedantic -malign-double
0036
0037
0038
0039 F_COMP := gfortran
0040 F_FLAGS := -g -Wall -pedantic
0041
0042
0043
0044 LD_FLAGS := -lgfortran
0045
0046
0047
0048 IS_CXX_COMP_GT_7 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 7)
0049 ifneq "$(IS_CXX_COMP_GT_7)" "1"
0050 $(error "gcc suite version = $(shell gcc -dumpversion). Only versions >= 7 are supported!")
0051 endif
0052
0053
0054
0055
0056
0057
0058
0059
0060 FLUKA_PATH := $(realpath $(shell dirname $(shell which fluka))/..)
0061 ifeq ($(wildcard $(FLUKA_PATH)/.*),)
0062 $(error "fluka executables not found. FLUKA_REPO=$(FLUKA_PATH). Add your fluka_repo/bin to the PATH." )
0063 endif
0064
0065 FLUKA_INCLUDE_DIR := $(FLUKA_PATH)/include
0066 ifeq ($(wildcard $(FLUKA_INCLUDE_DIR)/.*),)
0067 $(error "FLUKA_INCLUDE_DIR=$(FLUKA_INCLUDE_DIR)/ does not contain any file. Add your fluka_repo/bin to the PATH." )
0068 endif
0069 FLUKA_LIB_DIR := $(FLUKA_PATH)/lib
0070 ifeq ($(wildcard $(FLUKA_LIB_DIR)/$(FLUKA_LIB)),)
0071 $(error "FLUKA_LIB_DIR=$(FLUKA_LIB_DIR)/ does not contain $(FLUKA_LIB). Add your fluka_repo/bin to the PATH." )
0072 endif
0073 FLUKA_LIB_NAME := fluka
0074 FLUKA_LIB := lib$(FLUKA_LIB_NAME).a
0075 FLUKA_NO_RANDOM_LIB_NAME := fluka_no_random
0076 FLUKA_NO_RANDOM_LIB := lib$(FLUKA_NO_RANDOM_LIB_NAME).a
0077 FLUKA_OBJ_REMOVE := flrm64.o flrndm.o flrnlp.o flrnoc.o
0078 FLUKA_RELEASE_LIB_LINK := -L$(FLUKA_LIB_DIR) -l$(FLUKA_LIB_NAME)
0079 FLUKA_LIB_LINK := -L$(FLUKA_LIB_DIR) -l$(FLUKA_NO_RANDOM_LIB_NAME)
0080
0081
0082
0083 G4_PATH := $(realpath $(shell geant4-config --prefix))
0084 G4_INCLUDE_DIR := $(G4_PATH)/include/Geant4
0085 G4_INCLUDE := -I$(G4_INCLUDE_DIR)
0086 G4_CXX_FLAGS := $(shell geant4-config --cflags)
0087 G4_LIBRARIES := $(shell geant4-config --libs)
0088
0089
0090
0091
0092
0093
0094
0095
0096 BASE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
0097
0098
0099 SRC_DIR := $(BASE_DIR)/source
0100
0101
0102 OBJ_DIR := $(BASE_DIR)/obj
0103 INTERFACE_OBJ_DIR := $(OBJ_DIR)/interface
0104 TEST_INTERFACE_TO_G4_OBJ_DIR := $(OBJ_DIR)/test_interface_to_G4
0105
0106
0107 BIN_DIR := $(BASE_DIR)/bin
0108
0109 CLEAN_DIR := $(OBJ_DIR) $(BIN_DIR)
0110
0111
0112
0113
0114
0115
0116
0117
0118 F_SRC_DIR := $(SRC_DIR)/fluka4_wrapper/fortran/procedures \
0119 $(SRC_DIR)/cpp_fortran_bridges/fortran
0120
0121 F_SRC := $(foreach src_dir, $(F_SRC_DIR), $(wildcard $(src_dir)/*.f))
0122 F_OBJ := $(addprefix $(OBJ_DIR)/, $(notdir $(F_SRC:.f=.o)))
0123
0124
0125 CXX_SRC_DIR := $(SRC_DIR)/fluka4_wrapper/cpp/procedures \
0126 $(SRC_DIR)/cpp_fortran_bridges/cpp \
0127 $(SRC_DIR)/cpp_utils
0128
0129 CXX_INCLUDE_DIR := $(CXX_SRC_DIR) $(FLUKA_INCLUDE_DIR)
0130 CXX_INCLUDE := $(addprefix -I, $(CXX_INCLUDE_DIR))
0131 CXX_SRC := $(foreach src_dir, $(CXX_SRC_DIR), $(wildcard $(src_dir)/*.cc))
0132 CXX_OBJ := $(addprefix $(OBJ_DIR)/, $(notdir $(CXX_SRC:.cc=.o)))
0133
0134
0135 INTERFACE_SRC_DIR := $(SRC_DIR)/fluka5/hadronic_interactions/interface_to_G4 \
0136 $(SRC_DIR)/fluka_G4_bridges \
0137 $(SRC_DIR)/fluka_G4_physics_list
0138
0139 INTERFACE_INCLUDE_DIR := $(INTERFACE_SRC_DIR)
0140 INTERFACE_INCLUDE := $(addprefix -I, $(INTERFACE_INCLUDE_DIR))
0141 INTERFACE_SRC := $(foreach src_dir, $(INTERFACE_SRC_DIR), $(wildcard $(src_dir)/*.cc))
0142 INTERFACE_OBJ := $(addprefix $(INTERFACE_OBJ_DIR)/, $(notdir $(INTERFACE_SRC:.cc=.o)))
0143
0144
0145 TEST_INTERFACE_TO_G4_SRC_DIR := $(SRC_DIR)/fluka5/hadronic_interactions/test/interface_to_G4
0146 TEST_INTERFACE_TO_G4_SRC := $(foreach src_dir, $(TEST_INTERFACE_TO_G4_SRC_DIR), $(wildcard $(src_dir)/*.cc))
0147 TEST_INTERFACE_TO_G4_INCLUDE_DIR := $(TEST_INTERFACE_TO_G4_SRC_DIR)
0148 TEST_INTERFACE_TO_G4_INCLUDE := $(addprefix -I, $(TEST_INTERFACE_TO_G4_INCLUDE_DIR))
0149 TEST_INTERFACE_TO_G4_OBJ := $(addprefix $(TEST_INTERFACE_TO_G4_OBJ_DIR)/, $(notdir $(TEST_INTERFACE_TO_G4_SRC:.cc=.o)))
0150 TEST_INTERFACE_TO_G4_EXE := $(BIN_DIR)/test_interface
0151
0152
0153
0154
0155
0156
0157
0158 .PHONY: all
0159 all: interface test
0160 @echo
0161 @echo "Full build successfull."
0162
0163 .PHONY: test
0164 test: test_interface_to_g4
0165 @echo
0166 @echo "Full tests build successfull."
0167
0168 .PHONY: interface
0169 interface: check_G4 $(INTERFACE_OBJ) fluka_no_random_lib
0170 @echo
0171 @echo "Full FLUKA-G4 interface build successfull."
0172
0173 .PHONY: check_G4
0174 check_G4:
0175 @[ -d $(G4_PATH) ] || { echo "!!! G4 repo not found. Please source geant4.sh, or G4 setup.sh (need to have G4 already installed). !!!"; exit 1; }
0176 @[ -d $(G4_INCLUDE_DIR) ] || { echo "!!! G4_INCLUDE_DIR=$(G4_INCLUDE_DIR)/ does not exist. !!! "; exit 1; }
0177
0178 .PHONY: env
0179 env: env_FLUKA env_FLUKA_G4_interface
0180 @echo
0181 @echo "Full env scripts creation successfull."
0182
0183 .PHONY: env_FLUKA
0184 env_FLUKA: env_FLUKA.sh
0185 env_FLUKA.sh: GNUmakefile
0186 @echo '#! /bin/bash' > $@
0187 @echo >> $@
0188 @echo 'export FLUKA_PATH=$$(realpath $$(dirname $$(which fluka))/..)' >> $@
0189 @echo 'if [ ! -d "$$FLUKA_PATH" ]; then' >> $@
0190 @echo ' echo "!!! fluka not found. FLUKA_REPO=$$FLUKA_PATH. Add your fluka_repo/bin to the PATH. !!!";' >> $@
0191 @echo 'fi' >> $@
0192 @echo >> $@
0193 @echo 'export FLUKADATA=$$FLUKA_PATH/data' >> $@
0194 @echo 'if [ ! -d "$$FLUKADATA" ]; then' >> $@
0195 @echo ' echo "!!! fluka data repo not found. FLUKADATA=$$FLUKADATA. Add your fluka_repo/bin to the PATH. !!!";' >> $@
0196 @echo 'fi' >> $@
0197 @echo >> $@
0198 @echo 'export FLUKA_LIB_DIR=$$FLUKA_PATH/lib' >> $@
0199 @echo 'if [ ! -d "$$FLUKA_LIB_DIR" ]; then' >> $@
0200 @echo ' echo "!!! fluka lib repo not found. FLUKA_LIB_DIR=$$FLUKA_LIB_DIR. Add your fluka_repo/bin to the PATH. !!!";' >> $@
0201 @echo 'fi' >> $@
0202 @echo
0203 @echo "Created file: env_FLUKA.sh"
0204
0205 .PHONY: env_FLUKA_G4_interface
0206 env_FLUKA_G4_interface: env_FLUKA_G4_interface.sh
0207 env_FLUKA_G4_interface.sh: GNUmakefile
0208 @echo '#! /bin/bash' > $@
0209 @echo 'echo "source $(BASE_DIR)/env_FLUKA.sh"' >> $@
0210 @echo 'if [ ! -e "$(BASE_DIR)/env_FLUKA.sh" ]; then' >> $@
0211 @echo ' echo "env_FLUKA.sh does not exist. Please create it: go to $(BASE_DIR), and do make env. Then, source again this script."' >> $@
0212 @echo 'else' >> $@
0213 @echo ' source $(BASE_DIR)/env_FLUKA.sh' >> $@
0214 @echo ' echo ""' >> $@
0215 @echo ' echo "Setting FLUKAInterface_INCLUDE_DIR:"' >> $@
0216 @echo ' export FLUKAInterface_INCLUDE_DIR="$(SRC_DIR)/cpp_utils $(INTERFACE_INCLUDE_DIR)"' >> $@
0217 @echo ' echo "export FLUKAInterface_INCLUDE_DIR=$$FLUKAInterface_INCLUDE_DIR"' >> $@
0218 @echo ' echo "FLUKAInterface_INCLUDE_DIR successfully set."' >> $@
0219 @echo ' echo ""' >> $@
0220 @echo ' echo "Setting FLUKAInterface_LIBRARIES:"' >> $@
0221 @echo ' export FLUKAInterface_LIBRARIES="$(INTERFACE_OBJ) $(CXX_OBJ) $(F_OBJ)"' >> $@
0222 @echo ' missing_obj=false;' >> $@
0223 @echo ' for obj in $$FLUKAInterface_LIBRARIES; do' >> $@
0224 @echo ' if [ ! -e "$$obj" ]; then' >> $@
0225 @echo ' echo "$$obj does not exist."' >> $@
0226 @echo ' missing_obj=true' >> $@
0227 @echo ' fi' >> $@
0228 @echo ' done' >> $@
0229 @echo ' if [ "$$missing_obj" = true ]; then' >> $@
0230 @echo ' echo "!!! Object file(s) in FLUKAInterface_LIBRARIES is/are missing. Please (re)compile the G4 interface (make or make interface)!";' >> $@
0231 @echo ' else' >> $@
0232 @echo ' export FLUKAInterface_LIBRARIES="$$FLUKAInterface_LIBRARIES $(FLUKA_LIB_DIR)/$(FLUKA_NO_RANDOM_LIB)"' >> $@
0233 @echo ' export FLUKAInterface_LIBRARIES="$$FLUKAInterface_LIBRARIES $(LD_FLAGS)"' >> $@
0234 @echo ' echo "export FLUKAInterface_LIBRARIES=$$FLUKAInterface_LIBRARIES"' >> $@
0235 @echo ' echo "FLUKAInterface_LIBRARIES successfully set."' >> $@
0236 @echo ' fi' >> $@
0237 @echo 'fi' >> $@
0238 @echo 'echo ""' >> $@
0239 @echo "Created file: env_FLUKA_G4_interface.sh"
0240
0241 .PHONY: clean
0242 clean:
0243 rm -fr $(CLEAN_DIR) env_FLUKA_G4_interface.sh
0244
0245
0246
0247
0248
0249
0250
0251
0252 .PHONY: test_interface_to_g4
0253 test_interface_to_g4: fluka_no_random_lib $(TEST_INTERFACE_TO_G4_EXE)
0254 $(TEST_INTERFACE_TO_G4_EXE): $(TEST_INTERFACE_TO_G4_OBJ) $(INTERFACE_OBJ) $(CXX_OBJ) $(F_OBJ)
0255 @[ -d $(@D) ] || mkdir -p $(@D)
0256 @echo
0257 @echo "Building $(notdir $@) executable to test FLUKA-G4 interface:"
0258 $(CXX_COMP) $^ $(FLUKA_LIB_LINK) $(LD_FLAGS) $(G4_LIBRARIES) -o $@
0259 @echo "Built $(notdir $@) successfully."
0260
0261
0262 define TEST_INTERFACE_TO_G4_BUILD_template
0263 $(TEST_INTERFACE_TO_G4_OBJ_DIR)/%.o: $(1)/%.cc
0264 @echo
0265 @echo "Building $$(notdir $$@) to test FLUKA-G4 interface:"
0266 @[ -d $$(@D) ] || mkdir -p $$(@D)
0267 $(CXX_COMP) -DG4_USE_FLUKA $(G4_CXX_FLAGS) $(CXX_INCLUDE) $(TEST_INTERFACE_TO_G4_INCLUDE) $(INTERFACE_INCLUDE) -c $$< -o $$@
0268 @echo "Built $$(notdir $$@) successfully."
0269 endef
0270 $(foreach src_dir, $(TEST_INTERFACE_TO_G4_SRC_DIR), $(eval $(call TEST_INTERFACE_TO_G4_BUILD_template, $(src_dir))))
0271
0272
0273 define INTERFACE_BUILD_template
0274 $(INTERFACE_OBJ_DIR)/%.o: $(1)/%.cc $(CXX_OBJ) $(F_OBJ)
0275 @echo
0276 @echo "Building $$(notdir $$@) for FLUKA-G4 interface:"
0277 @[ -d $$(@D) ] || mkdir -p $$(@D)
0278 $(CXX_COMP) -DG4_USE_FLUKA $(G4_CXX_FLAGS) $(CXX_INCLUDE) $(INTERFACE_INCLUDE) -c $$< -o $$@
0279 @echo "Built $$(notdir $$@) successfully."
0280 endef
0281 $(foreach src_dir, $(INTERFACE_SRC_DIR), $(eval $(call INTERFACE_BUILD_template, $(src_dir))))
0282
0283
0284 define CXX_BUILD_template
0285 $(OBJ_DIR)/%.o: $(1)/%.cc
0286 @echo
0287 @echo "Building $$(notdir $$@) for core FLUKA5 C++ source:"
0288 @[ -d $$(@D) ] || mkdir -p $$(@D)
0289 $(CXX_COMP) -DG4_USE_FLUKA $(CXX_FLAGS) -c $$< -o $$@
0290 @echo "Built $$(notdir $$@) successfully."
0291 endef
0292 $(foreach src_dir, $(CXX_SRC_DIR), $(eval $(call CXX_BUILD_template, $(src_dir))))
0293
0294
0295 define F_BUILD_template
0296 $(OBJ_DIR)/%.o: $(1)/%.f
0297 @echo
0298 @echo "Building $$(notdir $$@) for core FLUKA5 FORTRAN source:"
0299 @[ -d $$(@D) ] || mkdir -p $$(@D)
0300 $(F_COMP) -DG4_USE_FLUKA $(F_FLAGS) -c $$< -o $$@
0301 @echo "Built $$(notdir $$@) successfully."
0302 endef
0303 $(foreach src_dir, $(F_SRC_DIR), $(eval $(call F_BUILD_template, $(src_dir))))
0304
0305
0306
0307
0308
0309
0310
0311 .PHONY: fluka
0312 fluka: fluka_no_random_lib
0313
0314 .PHONY: fluka_no_random_lib
0315 fluka_no_random_lib: $(FLUKA_LIB_DIR)/$(FLUKA_NO_RANDOM_LIB)
0316 $(FLUKA_LIB_DIR)/$(FLUKA_NO_RANDOM_LIB): $(FLUKA_LIB_DIR)/$(FLUKA_LIB)
0317 @echo
0318 @cp $(FLUKA_LIB_DIR)/$(FLUKA_LIB) $(FLUKA_LIB_DIR)/$(FLUKA_NO_RANDOM_LIB)
0319 @echo "cp $(FLUKA_LIB_DIR)/$(FLUKA_LIB) $(FLUKA_LIB_DIR)/$(FLUKA_NO_RANDOM_LIB)"
0320 $(foreach obj,$(FLUKA_OBJ_REMOVE),ar d $(FLUKA_LIB_DIR)/$(FLUKA_NO_RANDOM_LIB) $(obj);)
0321 @echo "$(FLUKA_NO_RANDOM_LIB) creation / update successfull."
0322