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

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

maj par rapport a cvs

File size: 5.8 KB
Line 
1# $Id: common.gmk,v 1.44 2008/01/15 11:14:58 lgarnier 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 12/6/07.
8
9ifndef G4LIBDIR
10  G4LIBDIR := $(G4LIB)/$(G4SYSTEM)
11endif
12G4TMPDIR := $(G4TMP)/$(G4SYSTEM)/$(name)
13
14moc_inc = $(shell grep -l "Q_OBJECT" include/*.hh )
15moc_files := $(patsubst include/%.hh, src/%_moc.cc, $(moc_inc))
16sources := $(wildcard src/*.cc)
17sources += $(moc_files)
18objects := $(patsubst src/%.cc,$(G4TMPDIR)/%.o,$(sources))
19dependencies := $(patsubst src/%.cc,$(G4TMPDIR)/%.d,$(sources))
20
21   g4libraries_to_build :=
22ifeq ($(G4LIB_NO_SHARED),)
23ifneq ($(G4LIB_BUILD_SHARED),)
24   g4libraries_to_build += $(G4LIBDIR)/lib$(name).$(SHEXT)
25endif
26endif
27ifneq ($(G4LIB_BUILD_STATIC),)
28   g4libraries_to_build += $(G4LIBDIR)/lib$(name).a
29endif
30
31# GPPFLAGS is defined here to make the .d file(s) and include it(them).
32
33GPPFLAGS := "-M"
34
35###############################################################################
36#
37# Actual gmake targets.
38#
39
40lib: $(g4libraries_to_build)
41
42ifeq ($(G4LIB_NO_SHARED),)
43ifneq ($(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)
51endif
52endif
53
54ifneq ($(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
64endif
65
66###############################################################################
67#
68# Actual moc files for qt files
69#
70# moc sources and headers: used for Qt signal/slot
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"
75#  it will be used by moc to generate the file "foo_moc.cpp" (the _moc. is
76#   just an arbitrary extension to make it easier to identify sources
77#   generated by moc).
78
79src/%_moc.cc: include/%.hh
80        @echo Making moc file for $< ...
81        @if [ `$(QTHOME)/bin/moc -v 2>&1 | grep "Qt 3" | wc -l ` -gt 0 ]; then \
82        $(MOC) -o $@ $<;\
83        else $(MOC) $(MOC_MACRO) -o $@ $<; \
84        fi;
85
86###############################################################################
87#
88# Actual targets for .o, .d files
89#
90
91$(G4TMPDIR)/%.o: src/%.cc
92ifdef CPPVERBOSE
93        $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
94else
95        @echo Compiling $*.cc ...
96        @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
97endif
98
99# .PHONY targets are executed regardless of time-stamp of any file of
100# same name.
101.PHONY: all moc_inc obj lib clean clean_libs includes
102
103obj: $(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
130        @echo Making dependency for file $< ...
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 $@
136ifneq ($(dependencies),)
137ifneq ($(MAKECMDGOALS),clean)
138-include $(dependencies)
139endif
140endif
141
142#
143# Installation of include files
144#
145installed_includes:=$(foreach file,$(wildcard include/*),$(shell test -f $(file) && echo $(file)))
146installed_includes:=$(patsubst include/%,$(G4INCLUDE)/%,$(installed_includes))
147
148# NOTE: the double colon rule allows to add other rules for the same target
149#
150includes:: $(installed_includes)
151
152# Static Pattern rules, see GNU make manual for details.
153#           target(s): target-pattern : dep-pattern
154#
155$(installed_includes): $(G4INCLUDE)/% : include/%
156        @cp -p $< $@
157
158#
159# Clean up libraries
160#
161ifndef G4EXLIB
162clean::
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)
169endif
170
171clean_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)
Note: See TracBrowser for help on using the repository browser.