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

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

remise à jour de config

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