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

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

QT moc remove before compiling

File size: 6.1 KB
Line 
1# $Id: common.gmk,v 1.50 2008/03/19 10:55:47 lgarnier 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
14moc_inc = $(shell grep -l "Q_OBJECT" include/*.hh )
15moc_files := $(patsubst include/%.hh, src/%_moc.cc, $(moc_inc))
16
17
18ifeq ($(G4INTY_BUILD_QT),)
19  # not so beautiful. In therory we should only remove theses files from sources
20  sources := $(shell rm -f $(moc_files))
21  sources := $(wildcard src/*.cc)
22endif
23
24ifneq ($(G4INTY_BUILD_QT),)
25  sources := $(wildcard src/*.cc)
26  sources += $(moc_files)
27endif
28
29
30objects := $(patsubst src/%.cc,$(G4TMPDIR)/%.o,$(sources))
31dependencies := $(patsubst src/%.cc,$(G4TMPDIR)/%.d,$(sources))
32
33   g4libraries_to_build :=
34ifeq ($(G4LIB_NO_SHARED),)
35ifneq ($(G4LIB_BUILD_SHARED),)
36   g4libraries_to_build += $(G4LIBDIR)/lib$(name).$(SHEXT)
37endif
38endif
39ifneq ($(G4LIB_BUILD_STATIC),)
40   g4libraries_to_build += $(G4LIBDIR)/lib$(name).a
41endif
42
43# GPPFLAGS is defined here to make the .d file(s) and include it(them).
44
45GPPFLAGS := "-M"
46
47###############################################################################
48#
49# Actual gmake targets.
50#
51
52lib: $(g4libraries_to_build)
53
54ifeq ($(G4LIB_NO_SHARED),)
55ifneq ($(G4LIB_BUILD_SHARED),)
56# Make shared library.
57$(G4LIBDIR)/lib$(name).$(SHEXT): $(G4TMPDIR)/obj.last
58        @if [ ! -d $(G4LIBDIR) ] ; then mkdir $(G4LIBDIR) ;fi
59        @echo Creating shared library $@ ...
60        @$(RM) $@
61#      use architecture specific macro defined in sys/$(G4SYSTEM).gmk
62        $(build-granular-shared-lib)
63endif
64endif
65
66ifneq ($(G4LIB_BUILD_STATIC),)
67# Make static (archive) library.
68$(G4LIBDIR)/lib$(name).a: $(G4TMPDIR)/obj.last
69        @if [ ! -d $(G4LIBDIR) ] ; then mkdir $(G4LIBDIR) ;fi
70        @echo Creating/replacing object files in $(G4LIBDIR)/lib$(name).a ...
71        @rm -f $(G4LIBDIR)/lib$(name).a
72        @$(AR) $(OUT_LIB)$(G4LIBDIR)/lib$(name).a $(G4TMPDIR)/*.o
73        @if [ X$(G4SYSTEM) != XWIN32-VC ] ; then  \
74        if [ -f /usr/bin/ranlib -o -f /bin/ranlib ] ; then \
75        ranlib $(G4LIBDIR)/lib$(name).a ; fi ; fi
76endif
77
78###############################################################################
79#
80# Actual moc files for Qt files
81#
82# moc sources and headers: used for Qt signal/slot
83# - all headers which use signals/slots have the macro "Q_OBJECT" present
84#   in the class definitions; these all need to be processed by the
85#   "meta object compiler (moc)" which generates extra source code to
86#   implement the signal/slots, i.e., if "foo.h" contains the token "Q_OBJECT"
87#   it will be used by moc to generate the file "foo_moc.cpp" (the _moc. is
88#   just an arbitrary extension to make it easier to identify sources
89#   generated by moc).
90
91ifneq ($(G4INTY_BUILD_QT),)
92src/%_moc.cc: include/%.hh
93        @echo Making moc file for $< ...
94        @if [ `$(QTHOME)/bin/moc -v 2>&1 | grep "Qt 3" | wc -l ` -gt 0 ]; then \
95        $(QTMOC) -o $@ $<;\
96        else $(QTMOC) $(MOC_MACRO) -o $@ $<; \
97        fi;
98endif
99
100
101###############################################################################
102#
103# Actual targets for .o, .d files
104#
105
106$(G4TMPDIR)/%.o: src/%.cc
107ifdef CPPVERBOSE
108        $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
109else
110        @echo Compiling $*.cc ...
111        @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUT_OBJ)$(G4TMPDIR)/$(*F).o src/$*.cc
112endif
113
114# .PHONY targets are executed regardless of time-stamp of any file of
115# same name.
116.PHONY: all moc_inc obj lib clean clean_libs includes
117
118obj: $(G4TMPDIR)/obj.last
119
120# Touch the versioning file
121$(G4TMPDIR)/obj.last: $(objects)
122        @touch $@
123
124# Make the .d file(s) and include it(them).
125
126# The ideas for this come from the GNU Make Manual, Section 4.12,
127# Generating Prerequisites Automatically.  The g++ compiler has an
128# option -M or -MM to write to standard output a list of dependencies
129# based on the #include statements.  The "sed" adds the dependency
130# file itself as a second target.  The result is a mini-makefile which
131# specifies the .o and .d files as targets which depend on all the
132# files found through the #include statements.  This file is then
133# included, causing GNU Make to honour these dependencies.
134
135# The "set -e" causes the shell to exit with an error when the "g++"
136# fails (otherwise it would only notice the last command in the
137# pipeline, namely "sed").  GNU Make notices the error and exits
138# sooner than it otherwise would (still not as soon as I expect,
139# though!).  Even then, an empty file is made, so "[ -s $@ ] || rm -f
140# $@" removes it ([ -s filename ] gives zero exit code only if file
141# exists and has a size greater than zero).  This avoids making
142# corrupt .d files which would play havoc with your next build.
143
144$(G4TMPDIR)/%.d: src/%.cc
145        @echo Making dependency for file $< ...
146        @if [ ! -d $(G4TMPDIR) ] ; then mkdir -p $(G4TMPDIR)  ;fi
147        @set -e;\
148        g++ $(GPPFLAGS) $(CPPFLAGS) -w $< |\
149        sed 's!$*\.o!$(G4TMPDIR)/& $@!' >$@;\
150        [ -s $@ ] || rm -f $@
151ifneq ($(dependencies),)
152ifneq ($(MAKECMDGOALS),clean)
153-include $(dependencies)
154endif
155endif
156
157#
158# Installation of include files
159#
160installed_includes:=$(foreach file,$(wildcard include/*),$(shell test -f $(file) && echo $(file)))
161installed_includes:=$(patsubst include/%,$(G4INCLUDE)/%,$(installed_includes))
162
163# NOTE: the double colon rule allows to add other rules for the same target
164#
165includes:: $(installed_includes)
166
167# Static Pattern rules, see GNU make manual for details.
168#           target(s): target-pattern : dep-pattern
169#
170$(installed_includes): $(G4INCLUDE)/% : include/%
171        @cp -p $< $@
172
173#
174# Clean up libraries
175#
176ifndef G4EXLIB
177clean::
178        @echo Cleaning up ...
179        @rm -f $(G4LIBDIR)/lib$(name).a
180        @rm -f $(G4LIBDIR)/*$(name).lib
181        @rm -f $(G4LIBDIR)/*$(name).exp
182        @rm -f $(G4LIBDIR)/lib$(name).$(SHEXT)
183        @rm -rf $(G4TMPDIR)
184endif
185
186clean_libs::
187        @echo Removing library lib$(name).a ...
188        @rm -f $(G4LIBDIR)/*$(name).a
189        @echo Removing library lib$(name).$(SHEXT) ...
190        @rm -f $(G4LIBDIR)/*$(name).lib
191        @rm -f $(G4LIBDIR)/*$(name).exp
192        @rm -f $(G4LIBDIR)/*$(name).$(SHEXT)
Note: See TracBrowser for help on using the repository browser.