source: trunk/config/common.gmk

Last change on this file was 1349, checked in by garnier, 13 years ago

update

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        g++ $(GPPFLAGS) $(CPPFLAGS) -w $< |\
117        sed 's!$*\.o!$(G4TMPDIR)/& $@!' >$@;\
118        [ -s $@ ] || rm -f $@
119ifneq ($(dependencies),)
120ifneq ($(MAKECMDGOALS),clean)
121-include $(dependencies)
122endif
123endif
124
125#
126# Installation of include files
127#
128installed_includes:=$(foreach file,$(wildcard include/*),$(shell test -f $(file) && echo $(file)))
129installed_includes:=$(patsubst include/%,$(G4INCLUDE)/%,$(installed_includes))
130
131# NOTE: the double colon rule allows to add other rules for the same target
132#
133includes:: $(installed_includes)
134
135# Static Pattern rules, see GNU make manual for details.
136#           target(s): target-pattern : dep-pattern
137#
138$(installed_includes): $(G4INCLUDE)/% : include/%
139        @cp -p $< $@
140
141#
142# Clean up libraries
143#
144ifndef G4EXLIB
145clean::
146        @echo Cleaning up ...
147        @rm -f $(G4LIBDIR)/lib$(name).a
148        @rm -f $(G4LIBDIR)/*$(name).lib
149        @rm -f $(G4LIBDIR)/*$(name).exp
150        @rm -f $(G4LIBDIR)/lib$(name).$(SHEXT)
151        @rm -rf $(G4TMPDIR)
152        @rm -rf moc
153endif
154
155clean_libs::
156        @echo Removing library lib$(name).a ...
157        @rm -f $(G4LIBDIR)/*$(name).a
158        @echo Removing library lib$(name).$(SHEXT) ...
159        @rm -f $(G4LIBDIR)/*$(name).lib
160        @rm -f $(G4LIBDIR)/*$(name).exp
161        @rm -f $(G4LIBDIR)/*$(name).$(SHEXT)
Note: See TracBrowser for help on using the repository browser.