| [761] | 1 | # $Id: common.gmk,v 1.51 2008/04/04 10:35:20 gcosmo Exp $
|
|---|
| [472] | 2 | # ----------------------------------------------------------------
|
|---|
| 3 | # Common part of GNUmakefile for libraries. John Allison, 5/7/95.
|
|---|
| 4 | # ----------------------------------------------------------------
|
|---|
| 5 | # Libraries are created according to G4SYSTEM. G.Cosmo, 11/6/96.
|
|---|
| 6 | # Introduced G4LIBDIR and G4TMPDIR. G.Cosmo, 23/6/98.
|
|---|
| 7 |
|
|---|
| 8 | ifndef G4LIBDIR
|
|---|
| 9 | G4LIBDIR := $(G4LIB)/$(G4SYSTEM)
|
|---|
| 10 | endif
|
|---|
| 11 | G4TMPDIR := $(G4TMP)/$(G4SYSTEM)/$(name)
|
|---|
| [646] | 12 |
|
|---|
| [761] | 13 | sources := $(wildcard src/*.cc)
|
|---|
| [758] | 14 |
|
|---|
| 15 | ifneq ($(G4INTY_BUILD_QT),)
|
|---|
| [761] | 16 | sources += $(moc_sources)
|
|---|
| [758] | 17 | endif
|
|---|
| 18 |
|
|---|
| [472] | 19 | objects := $(patsubst src/%.cc,$(G4TMPDIR)/%.o,$(sources))
|
|---|
| 20 | dependencies := $(patsubst src/%.cc,$(G4TMPDIR)/%.d,$(sources))
|
|---|
| 21 |
|
|---|
| 22 | g4libraries_to_build :=
|
|---|
| 23 | ifeq ($(G4LIB_NO_SHARED),)
|
|---|
| 24 | ifneq ($(G4LIB_BUILD_SHARED),)
|
|---|
| 25 | g4libraries_to_build += $(G4LIBDIR)/lib$(name).$(SHEXT)
|
|---|
| 26 | endif
|
|---|
| 27 | endif
|
|---|
| 28 | ifneq ($(G4LIB_BUILD_STATIC),)
|
|---|
| 29 | g4libraries_to_build += $(G4LIBDIR)/lib$(name).a
|
|---|
| 30 | endif
|
|---|
| 31 |
|
|---|
| 32 | # GPPFLAGS is defined here to make the .d file(s) and include it(them).
|
|---|
| 33 |
|
|---|
| 34 | GPPFLAGS := "-M"
|
|---|
| 35 |
|
|---|
| 36 | ###############################################################################
|
|---|
| 37 | #
|
|---|
| 38 | # Actual gmake targets.
|
|---|
| 39 | #
|
|---|
| 40 |
|
|---|
| [646] | 41 | lib: $(g4libraries_to_build)
|
|---|
| [644] | 42 |
|
|---|
| [472] | 43 | ifeq ($(G4LIB_NO_SHARED),)
|
|---|
| 44 | ifneq ($(G4LIB_BUILD_SHARED),)
|
|---|
| 45 | # Make shared library.
|
|---|
| 46 | $(G4LIBDIR)/lib$(name).$(SHEXT): $(G4TMPDIR)/obj.last
|
|---|
| 47 | @if [ ! -d $(G4LIBDIR) ] ; then mkdir $(G4LIBDIR) ;fi
|
|---|
| 48 | @echo Creating shared library $@ ...
|
|---|
| 49 | @$(RM) $@
|
|---|
| 50 | # use architecture specific macro defined in sys/$(G4SYSTEM).gmk
|
|---|
| 51 | $(build-granular-shared-lib)
|
|---|
| 52 | endif
|
|---|
| 53 | endif
|
|---|
| 54 |
|
|---|
| 55 | ifneq ($(G4LIB_BUILD_STATIC),)
|
|---|
| 56 | # Make static (archive) library.
|
|---|
| 57 | $(G4LIBDIR)/lib$(name).a: $(G4TMPDIR)/obj.last
|
|---|
| 58 | @if [ ! -d $(G4LIBDIR) ] ; then mkdir $(G4LIBDIR) ;fi
|
|---|
| 59 | @echo Creating/replacing object files in $(G4LIBDIR)/lib$(name).a ...
|
|---|
| 60 | @rm -f $(G4LIBDIR)/lib$(name).a
|
|---|
| 61 | @$(AR) $(OUT_LIB)$(G4LIBDIR)/lib$(name).a $(G4TMPDIR)/*.o
|
|---|
| 62 | @if [ X$(G4SYSTEM) != XWIN32-VC ] ; then \
|
|---|
| 63 | if [ -f /usr/bin/ranlib -o -f /bin/ranlib ] ; then \
|
|---|
| 64 | ranlib $(G4LIBDIR)/lib$(name).a ; fi ; fi
|
|---|
| 65 | endif
|
|---|
| 66 |
|
|---|
| [643] | 67 |
|
|---|
| 68 | ###############################################################################
|
|---|
| 69 | #
|
|---|
| [472] | 70 | # Actual targets for .o, .d files
|
|---|
| 71 | #
|
|---|
| 72 |
|
|---|
| 73 | $(G4TMPDIR)/%.o: src/%.cc
|
|---|
| 74 | ifdef CPPVERBOSE
|
|---|
| 75 | $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
|
|---|
| 76 | else
|
|---|
| [646] | 77 | @echo Compiling $*.cc ...
|
|---|
| [472] | 78 | @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
|
|---|
| 79 | endif
|
|---|
| 80 |
|
|---|
| 81 | # .PHONY targets are executed regardless of time-stamp of any file of
|
|---|
| 82 | # same name.
|
|---|
| [761] | 83 | .PHONY: all obj lib clean clean_libs includes
|
|---|
| [472] | 84 |
|
|---|
| 85 | obj: $(G4TMPDIR)/obj.last
|
|---|
| 86 |
|
|---|
| 87 | # Touch the versioning file
|
|---|
| 88 | $(G4TMPDIR)/obj.last: $(objects)
|
|---|
| 89 | @touch $@
|
|---|
| 90 |
|
|---|
| 91 | # Make the .d file(s) and include it(them).
|
|---|
| 92 |
|
|---|
| 93 | # The ideas for this come from the GNU Make Manual, Section 4.12,
|
|---|
| 94 | # Generating Prerequisites Automatically. The g++ compiler has an
|
|---|
| 95 | # option -M or -MM to write to standard output a list of dependencies
|
|---|
| 96 | # based on the #include statements. The "sed" adds the dependency
|
|---|
| 97 | # file itself as a second target. The result is a mini-makefile which
|
|---|
| 98 | # specifies the .o and .d files as targets which depend on all the
|
|---|
| 99 | # files found through the #include statements. This file is then
|
|---|
| 100 | # included, causing GNU Make to honour these dependencies.
|
|---|
| 101 |
|
|---|
| 102 | # The "set -e" causes the shell to exit with an error when the "g++"
|
|---|
| 103 | # fails (otherwise it would only notice the last command in the
|
|---|
| 104 | # pipeline, namely "sed"). GNU Make notices the error and exits
|
|---|
| 105 | # sooner than it otherwise would (still not as soon as I expect,
|
|---|
| 106 | # though!). Even then, an empty file is made, so "[ -s $@ ] || rm -f
|
|---|
| 107 | # $@" removes it ([ -s filename ] gives zero exit code only if file
|
|---|
| 108 | # exists and has a size greater than zero). This avoids making
|
|---|
| 109 | # corrupt .d files which would play havoc with your next build.
|
|---|
| 110 |
|
|---|
| 111 | $(G4TMPDIR)/%.d: src/%.cc
|
|---|
| [646] | 112 | @echo Making dependency for file $< ...
|
|---|
| [472] | 113 | @if [ ! -d $(G4TMPDIR) ] ; then mkdir -p $(G4TMPDIR) ;fi
|
|---|
| 114 | @set -e;\
|
|---|
| 115 | g++ $(GPPFLAGS) $(CPPFLAGS) -w $< |\
|
|---|
| 116 | sed 's!$*\.o!$(G4TMPDIR)/& $@!' >$@;\
|
|---|
| 117 | [ -s $@ ] || rm -f $@
|
|---|
| 118 | ifneq ($(dependencies),)
|
|---|
| [593] | 119 | ifneq ($(MAKECMDGOALS),clean)
|
|---|
| [472] | 120 | -include $(dependencies)
|
|---|
| 121 | endif
|
|---|
| [593] | 122 | endif
|
|---|
| [472] | 123 |
|
|---|
| 124 | #
|
|---|
| 125 | # Installation of include files
|
|---|
| 126 | #
|
|---|
| 127 | installed_includes:=$(foreach file,$(wildcard include/*),$(shell test -f $(file) && echo $(file)))
|
|---|
| 128 | installed_includes:=$(patsubst include/%,$(G4INCLUDE)/%,$(installed_includes))
|
|---|
| 129 |
|
|---|
| 130 | # NOTE: the double colon rule allows to add other rules for the same target
|
|---|
| 131 | #
|
|---|
| [593] | 132 | includes:: $(installed_includes)
|
|---|
| [472] | 133 |
|
|---|
| 134 | # Static Pattern rules, see GNU make manual for details.
|
|---|
| [593] | 135 | # target(s): target-pattern : dep-pattern
|
|---|
| [472] | 136 | #
|
|---|
| 137 | $(installed_includes): $(G4INCLUDE)/% : include/%
|
|---|
| 138 | @cp -p $< $@
|
|---|
| 139 |
|
|---|
| 140 | #
|
|---|
| 141 | # Clean up libraries
|
|---|
| 142 | #
|
|---|
| 143 | ifndef G4EXLIB
|
|---|
| 144 | clean::
|
|---|
| 145 | @echo Cleaning up ...
|
|---|
| 146 | @rm -f $(G4LIBDIR)/lib$(name).a
|
|---|
| 147 | @rm -f $(G4LIBDIR)/*$(name).lib
|
|---|
| 148 | @rm -f $(G4LIBDIR)/*$(name).exp
|
|---|
| 149 | @rm -f $(G4LIBDIR)/lib$(name).$(SHEXT)
|
|---|
| 150 | @rm -rf $(G4TMPDIR)
|
|---|
| 151 | endif
|
|---|
| 152 |
|
|---|
| 153 | clean_libs::
|
|---|
| 154 | @echo Removing library lib$(name).a ...
|
|---|
| 155 | @rm -f $(G4LIBDIR)/*$(name).a
|
|---|
| 156 | @echo Removing library lib$(name).$(SHEXT) ...
|
|---|
| 157 | @rm -f $(G4LIBDIR)/*$(name).lib
|
|---|
| 158 | @rm -f $(G4LIBDIR)/*$(name).exp
|
|---|
| 159 | @rm -f $(G4LIBDIR)/*$(name).$(SHEXT)
|
|---|