source: trunk/config/common.gmk @ 1045

Last change on this file since 1045 was 1045, checked in by garnier, 15 years ago

maj en aussi sur CVS

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