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