# $Id: common.gmk,v 1.30 2001/06/25 10:58:51 morita Exp $ # ---------------------------------------------------------------- # Common part of GNUmakefile for libraries. John Allison, 5/7/95. # ---------------------------------------------------------------- # Libraries are created according to G4SYSTEM. G.Cosmo, 11/6/96. # Introduced G4LIBDIR and G4TMPDIR. G.Cosmo, 23/6/98. # Introduced G4SCHEMA_HEADER_DIR and G4SCHEMA_SRC_DIR. Y.Morita, 16/11/99. # Actual targets splitted into common_kernel.gmk and common_objy.gmk, # Y.Morita, 15/3/01. ifndef G4LIBDIR G4LIBDIR := $(G4LIB)/$(G4SYSTEM) endif G4TMPDIR := $(G4TMP)/$(G4SYSTEM)/$(name) sources := $(wildcard src/*.cc) objects := $(patsubst src/%.cc,$(G4TMPDIR)/%.o,$(sources)) dependencies := $(patsubst src/%.cc,$(G4TMPDIR)/%.d,$(sources)) g4libraries_to_build := ifneq ($(G4LIB_BUILD_SHARED),) g4libraries_to_build += $(G4LIBDIR)/lib$(name).$(SHEXT) endif ifneq ($(G4LIB_BUILD_STATIC),) g4libraries_to_build += $(G4LIBDIR)/lib$(name).a endif # GPPFLAGS is defined here to make the .d file(s) and include it(them). # This variable is actually used in common_kernel.gmk and common_objy.gmk. ifdef G4ODBMS GPPFLAGS := "-MM" else GPPFLAGS := "-M" endif ############################################################################### # # Actual gmake targets. # # # Target "lib" requires dependency files when G4ODBMS=1. # gmake must be recursively called with MAKE_DFILES=1. # ifdef G4ODBMS lib: @if [ ! -d $(G4TMPDIR) ] ; then mkdir -p $(G4TMPDIR) ;fi @(MAKE_DFILES=1; export MAKE_DFILES; $(MAKE) lib_d) lib_d: $(g4libraries_to_build) else lib: $(g4libraries_to_build) endif ifneq ($(G4LIB_BUILD_SHARED),) # Make shared library. $(G4LIBDIR)/lib$(name).$(SHEXT): $(G4TMPDIR)/obj.last @if [ ! -d $(G4LIBDIR) ] ; then mkdir $(G4LIBDIR) ;fi @echo Creating shared library $@ @$(RM) $@ # use architecture specific macro defined in sys/$(G4SYSTEM).gmk $(build-granular-shared-lib) endif ifneq ($(G4LIB_BUILD_STATIC),) # Make static (archive) library. $(G4LIBDIR)/lib$(name).a: $(G4TMPDIR)/obj.last @if [ ! -d $(G4LIBDIR) ] ; then mkdir $(G4LIBDIR) ;fi @echo Creating/replacing object files in $(G4LIBDIR)/lib$(name).a @rm -f $(G4LIBDIR)/lib$(name).a @$(AR) $(OUT_LIB)$(G4LIBDIR)/lib$(name).a $(G4TMPDIR)/*.o @if [ -f /usr/bin/ranlib -o -f /bin/ranlib ] ; then ranlib $(G4LIBDIR)/lib$(name).a ;fi endif ############################################################################### # # Actual targets for .o, .d files and others are defined in # common_kernel.gmk and common_objy.gmk. # ifndef G4ODBMS include $(G4INSTALL)/config/common_kernel.gmk else include $(G4INSTALL)/config/common_objy.gmk endif ############################################################################### # Touch the versioning file $(G4TMPDIR)/obj.last: $(objects) $(schema_o) @touch $@ # Make the .d file(s) and include it(them). # g++ -MM (or -M) is good at this, except it forgets the subdirectory # (hence the use of $G4TMP/). # schema_hh and schema_ref_hh are defined in common_objy.gmk. $(G4TMPDIR)/%.d: src/%.cc $(schema_hh) $(schema_ref_hh) @echo Making dependency for file $< ... @if [ ! -d $(G4TMPDIR) ] ; then mkdir -p $(G4TMPDIR) ;fi @($(ECHO) $(G4TMPDIR)/\\c ; \ g++ $(GPPFLAGS) $(CPPFLAGS) $< ) | sed 's!$(G4TMPDIR)/$*.o!& $@!' >$@ ifneq ($(dependencies),) ifndef G4ODBMS -include $(dependencies) else ifdef MAKE_DFILES -include $(dependencies) endif endif endif # # Installation of include files # installed_includes:=$(foreach file,$(wildcard include/*),$(shell test -f $(file) && echo $(file))) installed_includes:=$(patsubst include/%,$(G4INCLUDE)/%,$(installed_includes)) # NOTE: the double colon rule allows to add other rules for the same target # includes:: $(installed_includes) # Static Pattern rules, see GNU make manual for details. # target(s): target-pattern : dep-pattern # $(installed_includes): $(G4INCLUDE)/% : include/% @cp -p $< $@ # # Clean up libraries # ifndef G4EXLIB clean: @echo Cleaning up ... @rm -f $(G4LIBDIR)/lib$(name).a @rm -f $(G4LIBDIR)/lib$(name).$(SHEXT) ifdef schema_hh @rm -f $(schema_hh) $(schema_ref_hh) endif @rm -rf $(G4TMPDIR) endif clean_libs: @if [ -f $(G4LIBDIR)/lib$(name).a ] ; then \ $(ECHO) Removing library lib$(name).a ... ; \ $(RM) -f $(G4LIBDIR)/lib$(name).a ; fi @if [ -f $(G4LIBDIR)/lib$(name).$(SHEXT) ] ; then \ $(ECHO) Removing library lib$(name).$(SHEXT) ... ; \ $(RM) -f $(G4LIBDIR)/lib$(name).$(SHEXT) ; fi