source: trunk/geant4/config/common.gmk @ 763

Last change on this file since 763 was 761, checked in by garnier, 16 years ago

modif depuis que mon mac a plante : mise a jour des moc en mieux

File size: 4.9 KB
Line 
1# $Id: common.gmk,v 1.51 2008/04/04 10:35:20 gcosmo Exp $
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
8ifndef G4LIBDIR
9  G4LIBDIR := $(G4LIB)/$(G4SYSTEM)
10endif
11G4TMPDIR := $(G4TMP)/$(G4SYSTEM)/$(name)
12
13sources := $(wildcard src/*.cc)
14
15ifneq ($(G4INTY_BUILD_QT),)
16  sources += $(moc_sources)
17endif
18
19objects := $(patsubst src/%.cc,$(G4TMPDIR)/%.o,$(sources))
20dependencies := $(patsubst src/%.cc,$(G4TMPDIR)/%.d,$(sources))
21
22   g4libraries_to_build :=
23ifeq ($(G4LIB_NO_SHARED),)
24ifneq ($(G4LIB_BUILD_SHARED),)
25   g4libraries_to_build += $(G4LIBDIR)/lib$(name).$(SHEXT)
26endif
27endif
28ifneq ($(G4LIB_BUILD_STATIC),)
29   g4libraries_to_build += $(G4LIBDIR)/lib$(name).a
30endif
31
32# GPPFLAGS is defined here to make the .d file(s) and include it(them).
33
34GPPFLAGS := "-M"
35
36###############################################################################
37#
38# Actual gmake targets.
39#
40
41lib: $(g4libraries_to_build)
42
43ifeq ($(G4LIB_NO_SHARED),)
44ifneq ($(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)
52endif
53endif
54
55ifneq ($(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
65endif
66
67
68###############################################################################
69#
70# Actual targets for .o, .d files
71#
72
73$(G4TMPDIR)/%.o: src/%.cc
74ifdef CPPVERBOSE
75        $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
76else
77        @echo Compiling $*.cc ...
78        @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
79endif
80
81# .PHONY targets are executed regardless of time-stamp of any file of
82# same name.
83.PHONY: all obj lib clean clean_libs includes
84
85obj: $(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
112        @echo Making dependency for file $< ...
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 $@
118ifneq ($(dependencies),)
119ifneq ($(MAKECMDGOALS),clean)
120-include $(dependencies)
121endif
122endif
123
124#
125# Installation of include files
126#
127installed_includes:=$(foreach file,$(wildcard include/*),$(shell test -f $(file) && echo $(file)))
128installed_includes:=$(patsubst include/%,$(G4INCLUDE)/%,$(installed_includes))
129
130# NOTE: the double colon rule allows to add other rules for the same target
131#
132includes:: $(installed_includes)
133
134# Static Pattern rules, see GNU make manual for details.
135#           target(s): target-pattern : dep-pattern
136#
137$(installed_includes): $(G4INCLUDE)/% : include/%
138        @cp -p $< $@
139
140#
141# Clean up libraries
142#
143ifndef G4EXLIB
144clean::
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)
151endif
152
153clean_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)
Note: See TracBrowser for help on using the repository browser.