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

Last change on this file since 788 was 787, checked in by garnier, 18 years ago

r806@wl-72126: garnier | 2008-04-22 18:00:13 +0200
mise a jour

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