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

Last change on this file since 644 was 644, checked in by garnier, 17 years ago

deuxieme version de la correction du ticket #99

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