236 lines
6.7 KiB
Plaintext
236 lines
6.7 KiB
Plaintext
# $Id: binmake.gmk,v 1.4 2002/12/04 17:54:25 morita Exp $
|
|
# =====================================================================
|
|
# binmake.gmk: GNUmakefile variables for creating the binary executable
|
|
#
|
|
# Author: Youhei Morita <youhei.morita@kek.jp>
|
|
# =====================================================================
|
|
ifndef TARGET
|
|
TARGET := $(name)
|
|
endif
|
|
|
|
# Geant4 variables
|
|
include $(G4INSTALL)/config/G4UI_USE.gmk
|
|
include $(G4INSTALL)/config/G4VIS_USE.gmk
|
|
include $(G4INSTALL)/config/interactivity.gmk
|
|
include $(G4INSTALL)/config/analysis.gmk
|
|
|
|
ifdef G4DEBUG
|
|
CXXFLAGS += -g
|
|
endif
|
|
|
|
# dependency option
|
|
GPPFLAGS := "-MM"
|
|
|
|
headers := $(wildcard include/*.hh)
|
|
|
|
sources := $(wildcard src/*.cc)
|
|
|
|
objects := $(patsubst src/%.cc,$(G4PEX_TMP)/%.o,$(sources))
|
|
|
|
dependencies := $(patsubst src/%.cc,$(G4PEX_TMP)/%.d,$(sources))
|
|
|
|
ifneq ($(G4LIB_BUILD_SHARED),)
|
|
library_name := lib$(TARGET).so
|
|
endif
|
|
ifneq ($(G4LIB_BUILD_STATIC),)
|
|
library_name := lib$(TARGET).a
|
|
endif
|
|
|
|
|
|
ifneq ($(sources),)
|
|
libraries_to_build := $(G4PEX_LIB)/$(library_name)
|
|
else
|
|
libraries_to_build :=
|
|
endif
|
|
|
|
|
|
# linker option (refer to Standard Installation)
|
|
ifdef G4LIB_BUILD_SHARED
|
|
LDOPTION := -Wl,-rpath $(G4PEX_LIB) \
|
|
-Wl,-rpath $(G4LIB)/$(G4SYSTEM) \
|
|
-Wl,-rpath $(CLHEP_BASE_DIR)/lib \
|
|
-Wl,-rpath $(ROOTSYS)/lib
|
|
endif
|
|
|
|
# libraries path
|
|
LDFLAGS := -L$(G4PEX_LIB) \
|
|
-L$(G4LIB)/$(G4SYSTEM) \
|
|
-L$(CLHEP_BASE_DIR)/lib \
|
|
-L$(ROOTSYS)/lib
|
|
|
|
# extra LDFLAGS
|
|
ifneq ($(EXTLDFLAGS),)
|
|
LDFLAGS += $(EXTLDFLAGS)
|
|
endif
|
|
|
|
# libraries
|
|
LDLIBS := $(libraries_to_build) \
|
|
-lG4ROOTIO
|
|
|
|
g4libs := $(wildcard $(G4LIB)/$(G4SYSTEM)/*.so)
|
|
g4libs := $(patsubst $(G4LIB)/$(G4SYSTEM)/lib%.so,-l%,$(g4libs))
|
|
g4libs := $(patsubst -lG3toG4,,$(g4libs))
|
|
LDLIBS += $(g4libs)
|
|
|
|
LDLIBS += $(INTYLIBS)
|
|
LDLIBS += $(ANALYSISLIBS)
|
|
|
|
# external packagers
|
|
LDLIBS += -lCLHEP
|
|
# ROOT
|
|
LDLIBS += -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lRint \
|
|
-lPostscript -lMatrix -lPhysics
|
|
# etc
|
|
LDLIBS += -lm -ldl
|
|
|
|
.PHONY: all lib bin clean test
|
|
|
|
all: lib bin
|
|
|
|
bin: $(G4PEX_BIN)/$(TARGET)
|
|
|
|
lib: $(libraries_to_build)
|
|
|
|
# ---------------------------------------------------------------------
|
|
CPPFLAGS += $(shell root-config --cflags)
|
|
|
|
# ROOTCINT LinkDef.h and Dict.cc files
|
|
|
|
root_def := include/$(name)LinkDef.h
|
|
root_dict := $(G4PEX_TMP)/$(name)Dict.cc
|
|
root_dict_o := $(root_dict:.cc=.o)
|
|
|
|
# rootio files
|
|
rootio_file := $(wildcard rootio/*.rootio)
|
|
rootio_hh := $(patsubst rootio/%.rootio, include/%Root.hh, $(rootio_file))
|
|
rootio_hh += $(patsubst rootio/%.rootio, include/%sRoot.hh, $(rootio_file))
|
|
rootio_hh += $(patsubst rootio/%.rootio, include/%RootIO.hh, $(rootio_file))
|
|
rootio_cc := $(patsubst rootio/%.rootio, src/%Root.cc, $(rootio_file))
|
|
rootio_cc += $(patsubst rootio/%.rootio, src/%sRoot.cc, $(rootio_file))
|
|
rootio_cc += $(patsubst rootio/%.rootio, src/%RootIO.cc, $(rootio_file))
|
|
rootio_d := $(patsubst rootio/%.rootio, $(G4PEX_TMP)/%Root.d, $(rootio_file))
|
|
rootio_d += $(patsubst rootio/%.rootio, $(G4PEX_TMP)/%sRoot.d, $(rootio_file))
|
|
rootio_d += $(patsubst rootio/%.rootio, $(G4PEX_TMP)/%RootIO.d, $(rootio_file))
|
|
|
|
ifneq ($(rootio_file),)
|
|
root_hh := $(patsubst rootio/%.rootio, include/%Root.hh, $(rootio_file))
|
|
root_hh += $(patsubst rootio/%.rootio, include/%sRoot.hh, $(rootio_file))
|
|
else
|
|
ifneq ($(headers),)
|
|
root_hh := $(shell grep 'public.*TObject' include/*.hh|awk -F: '{print $$1}'|sort|uniq)
|
|
endif
|
|
endif
|
|
root_tmp := $(patsubst include/%,%,$(root_hh))
|
|
root_tmp += $(patsubst include/%,%,$(root_def))
|
|
root_name := $(patsubst include/%.hh,%,$(root_hh))
|
|
|
|
.PRECIOUS: $(dependencies) $(rootio_hh) $(rootio_cc) $(rootio_d)
|
|
|
|
ifneq ($(rootio_file),)
|
|
|
|
objects += $(patsubst rootio/%.rootio,$(G4PEX_TMP)/%Root.o, $(rootio_file))
|
|
objects += $(patsubst rootio/%.rootio,$(G4PEX_TMP)/%sRoot.o, $(rootio_file))
|
|
objects += $(patsubst rootio/%.rootio,$(G4PEX_TMP)/%RootIO.o, $(rootio_file))
|
|
objects += $(root_dict_o)
|
|
|
|
cleanup_target := $(rootio_hh) $(rootio_cc) $(root_def)
|
|
|
|
endif
|
|
|
|
ifneq ($(root_hh),)
|
|
|
|
include/%Root.hh include/%sRoot.hh include/%RootIO.hh src/%Root.cc src/%sRoot.cc src/%RootIO.cc: rootio/%.rootio
|
|
$(G4ROOTIO) $<
|
|
|
|
$(root_dict): $(root_hh) $(root_def)
|
|
ifdef CPPVERBOSE
|
|
cp -f $^ $(G4PEX_TMP)/
|
|
( cd $(G4PEX_TMP); \
|
|
$(PROG_ROOTCINT) -f $@ -c $(CINT_INCLUDES) -p $(root_tmp) )
|
|
( cd $(G4PEX_TMP); rm -f $(root_tmp) )
|
|
else
|
|
@echo "Generating dictionary $(root_dict) ..."
|
|
@cp -f $^ $(G4PEX_TMP)/
|
|
@( cd $(G4PEX_TMP); \
|
|
$(PROG_ROOTCINT) -f $@ -c $(CINT_INCLUDES) -p $(root_tmp) )
|
|
@( cd $(G4PEX_TMP); rm -f $(root_tmp) )
|
|
endif
|
|
|
|
$(root_def): $(root_hh)
|
|
$(G4PEX_DIR)/config/rootdict.sh "$(root_name)" $(root_def)
|
|
|
|
endif
|
|
|
|
$(root_dict_o): $(root_dict)
|
|
@echo "Compiling $< with $(CXX) ..."
|
|
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
|
|
# ---------------------------------------------------------------------
|
|
|
|
$(G4PEX_BIN)/$(TARGET): $(G4PEX_TMP)/$(TARGET).o $(libraries_to_build)
|
|
ifdef CPPVERBOSE
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $< \
|
|
$(LDOPTION) \
|
|
$(LDFLAGS) $(LDLIBS)
|
|
else
|
|
@echo Linking $(TARGET) ...
|
|
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $< \
|
|
$(LDOPTION) \
|
|
$(LDFLAGS) $(LDLIBS)
|
|
endif
|
|
|
|
$(G4PEX_TMP)/$(TARGET).o: $(TARGET).cc $(G4PEX_TMP)/$(TARGET).d
|
|
ifdef CPPVERBOSE
|
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
|
|
else
|
|
@echo "Compiling $< with $(CXX) ..."
|
|
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
|
|
endif
|
|
|
|
$(G4PEX_TMP)/$(TARGET).d: $(TARGET).cc
|
|
@echo "Making dependency file for $< ..."
|
|
@($(ECHO) $(G4PEX_TMP)/\\c ; \
|
|
g++ $(GPPFLAGS) $(CPPFLAGS) $< ) | sed 's!$(G4PEX_TMP)/$*.o!& $@!' >$@
|
|
ifneq ($(dependencies),)
|
|
-include $(dependencies)
|
|
endif
|
|
|
|
$(libraries_to_build): $(objects)
|
|
ifneq ($(G4LIB_BUILD_SHARED),)
|
|
@echo Creating shared library $@
|
|
@rm -f $(G4PEX_LIB)/lib$(TARGET).so
|
|
@cd $(G4PEX_TMP); \
|
|
$(CXX) -Wl,-soname,lib$(TARGET).so \
|
|
-shared -o $(G4PEX_LIB)/lib$(TARGET).so *.o \
|
|
$(EXTLDFLAGS) $(EXTLIBS)
|
|
endif
|
|
ifneq ($(G4LIB_BUILD_STATIC),)
|
|
@echo Creating static library $@
|
|
@rm -f $(G4PEX_LIB)/lib$(TARGET).a
|
|
$(AR) $(G4PEX_LIB)/lib$(TARGET).a $(G4PEX_TMP)/*.o
|
|
@if [ -f /usr/bin/ranlib -o -f /bin/ranlib ] ; then \
|
|
ranlib $(G4PEX_LIB)/lib$(TARGET).a ;fi
|
|
endif
|
|
|
|
$(G4PEX_TMP)/%.o: src/%.cc $(G4PEX_TMP)/%.d
|
|
@echo "Compiling $< with $(CXX) ..."
|
|
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
|
|
|
|
$(G4PEX_TMP)/%.d: src/%.cc
|
|
@echo "Making dependency file for $< ..."
|
|
@($(ECHO) $(G4PEX_TMP)/\\c ; \
|
|
g++ $(GPPFLAGS) $(CPPFLAGS) $< ) | sed 's!$(G4PEX_TMP)/$*.o!& $@!' >$@
|
|
|
|
clean:
|
|
ifneq ($(cleanup_target),)
|
|
@rm -f $(cleanup_target)
|
|
endif
|
|
@rm -f $(G4PEX_DIR)/bin/$(G4SYSTEM)/$(TARGET)
|
|
ifneq ($(libraries_to_build),)
|
|
@rm -f -r $(G4PEX_DIR)/lib/$(G4SYSTEM)/$(libraries_to_build)
|
|
endif
|
|
@rm -f -r $(G4PEX_DIR)/tmp/$(G4SYSTEM)/$(TARGET)
|
|
|
|
distclean: clean
|
|
@rm -f G4defaultOutput G4run0001.root G4History.macro core* .DAWN*.history g4_*.prim
|
|
|