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