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

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

r792@wl-72126: garnier | 2008-04-17 18:09:44 +0200
modif pour test sur un dossier moc

File size: 5.0 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
15objects := $(patsubst src/%.cc,$(G4TMPDIR)/%.o,$(sources))
16
17dependencies := $(patsubst src/%.cc,$(G4TMPDIR)/%.d,$(sources))
18
19#ifneq ($(G4INTY_BUILD_QT),)
20  sources += $(moc_sources)
21  objects += $(moc_objects)
22  dependencies += $(moc_dependencies)
23#endif
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 $@ ... $(objects)
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#
73# Actual targets for .o, .d files
74#
75
76$(G4TMPDIR)/%.o: src/%.cc
77ifdef CPPVERBOSE
78        $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
79else
80        @echo Compiling $*.cc ...
81        @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
82endif
83
84# .PHONY targets are executed regardless of time-stamp of any file of
85# same name.
86.PHONY: all obj lib clean clean_libs includes
87
88obj: $(G4TMPDIR)/obj.last
89
90# Touch the versioning file
91$(G4TMPDIR)/obj.last: $(objects)
92        @touch $@
93
94# Make the .d file(s) and include it(them).
95
96# The ideas for this come from the GNU Make Manual, Section 4.12,
97# Generating Prerequisites Automatically.  The g++ compiler has an
98# option -M or -MM to write to standard output a list of dependencies
99# based on the #include statements.  The "sed" adds the dependency
100# file itself as a second target.  The result is a mini-makefile which
101# specifies the .o and .d files as targets which depend on all the
102# files found through the #include statements.  This file is then
103# included, causing GNU Make to honour these dependencies.
104
105# The "set -e" causes the shell to exit with an error when the "g++"
106# fails (otherwise it would only notice the last command in the
107# pipeline, namely "sed").  GNU Make notices the error and exits
108# sooner than it otherwise would (still not as soon as I expect,
109# though!).  Even then, an empty file is made, so "[ -s $@ ] || rm -f
110# $@" removes it ([ -s filename ] gives zero exit code only if file
111# exists and has a size greater than zero).  This avoids making
112# corrupt .d files which would play havoc with your next build.
113
114$(G4TMPDIR)/%.d: src/%.cc
115        @echo Making dependency for file $< ...
116        @if [ ! -d $(G4TMPDIR) ] ; then mkdir -p $(G4TMPDIR)  ;fi
117        @set -e;\
118        g++ $(GPPFLAGS) $(CPPFLAGS) -w $< |\
119        sed 's!$*\.o!$(G4TMPDIR)/& $@!' >$@;\
120        [ -s $@ ] || rm -f $@
121ifneq ($(dependencies),)
122ifneq ($(MAKECMDGOALS),clean)
123-include $(dependencies)
124endif
125endif
126
127#
128# Installation of include files
129#
130installed_includes:=$(foreach file,$(wildcard include/*),$(shell test -f $(file) && echo $(file)))
131installed_includes:=$(patsubst include/%,$(G4INCLUDE)/%,$(installed_includes))
132
133# NOTE: the double colon rule allows to add other rules for the same target
134#
135includes:: $(installed_includes)
136
137# Static Pattern rules, see GNU make manual for details.
138#           target(s): target-pattern : dep-pattern
139#
140$(installed_includes): $(G4INCLUDE)/% : include/%
141        @cp -p $< $@
142
143#
144# Clean up libraries
145#
146ifndef G4EXLIB
147clean::
148        @echo Cleaning up ...
149        @rm -f $(G4LIBDIR)/lib$(name).a
150        @rm -f $(G4LIBDIR)/*$(name).lib
151        @rm -f $(G4LIBDIR)/*$(name).exp
152        @rm -f $(G4LIBDIR)/lib$(name).$(SHEXT)
153        @rm -rf $(G4TMPDIR)
154endif
155
156clean_libs::
157        @echo Removing library lib$(name).a ...
158        @rm -f $(G4LIBDIR)/*$(name).a
159        @echo Removing library lib$(name).$(SHEXT) ...
160        @rm -f $(G4LIBDIR)/*$(name).lib
161        @rm -f $(G4LIBDIR)/*$(name).exp
162        @rm -f $(G4LIBDIR)/*$(name).$(SHEXT)
Note: See TracBrowser for help on using the repository browser.