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

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

r627@mac-90108: laurentgarnier | 2007-11-09 07:57:42 +0100
modif dans les includes directives

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