aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile.rules
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-20 00:10:33 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-20 00:10:33 +0000
commit6ac0bd44a1d3e975bb2914ea4f318358476a9da6 (patch)
treef83e1a619cc46b308db5c72ca69d0168f6b6bfce /Makefile.rules
parenteaebf32028a551876c7e946d4b1e860b80f90430 (diff)
Merged revisions 157974 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r157974 | kpfleming | 2008-11-19 18:08:12 -0600 (Wed, 19 Nov 2008) | 13 lines Merged revisions 157859 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r157859 | kpfleming | 2008-11-19 15:34:47 -0600 (Wed, 19 Nov 2008) | 7 lines the gcc optimizer frequently finds broken code (use of uninitalized variables, unreachable code, etc.), which is good. however, developers usually compile with the optimizer turned off, because if they need to debug the resulting code, optimized code makes that process very difficult. this means that we get code changes committed that weren't adequately checked over for these sorts of problems. with this build system change, if (and only if) --enable-dev-mode was used and DONT_OPTIMIZE is turned on, when a source file is compiled it will actually be preprocessed (into a .i or .ii file), then compiled once with optimization (with the result sent to /dev/null) and again without optimization (but only if the first compile succeeded, of course). while making these changes, i did some cleanup work in Makefile.rules to move commonly-used combinations of flag variables into their own variables, to make the file easier to read and maintain ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.1@157975 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'Makefile.rules')
-rw-r--r--Makefile.rules82
1 files changed, 64 insertions, 18 deletions
diff --git a/Makefile.rules b/Makefile.rules
index 3b876e6dc..92fca37c9 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -3,7 +3,7 @@
#
# Makefile rules
#
-# Copyright (C) 2006, Digium, Inc.
+# Copyright (C) 2006-2008, Digium, Inc.
#
# Kevin P. Fleming <kpfleming@digium.com>
#
@@ -11,7 +11,6 @@
# the GNU General Public License
#
-# Rules for various build phases.
# Each command is preceded by a short comment on what to do.
# Prefixing one or the other with @\# or @ or nothing makes the desired
# behaviour. ECHO_PREFIX prefixes the comment, CMD_PREFIX prefixes the command.
@@ -21,16 +20,18 @@
.PHONY: dist-clean
# extra cflags to build dependencies. Recursively expanded.
-MAKE_DEPS= -MD -MT $@ -MF .$(subst /,_,$@).d -MP
+MAKE_DEPS=-MD -MT $@ -MF .$(subst /,_,$@).d -MP
ifeq ($(NOISY_BUILD),)
ECHO_PREFIX=@
CMD_PREFIX=@
else
- ECHO_PREFIX=@\#
+ ECHO_PREFIX=@\#
CMD_PREFIX=
endif
+OPTIMIZE?=-O6
+
ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS)),)
# More GSM codec optimization
# Uncomment to enable MMXTM optimizations for x86 architecture CPU's
@@ -38,30 +39,75 @@ ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS)),)
# ppro's, etc, as well as the AMD K6 and K7.
#K6OPT=-DK6OPT
- OPTIMIZE?=-O6
ASTCFLAGS+=$(OPTIMIZE)
endif
-# build rules for various targets
-%.o: %.c
- $(ECHO_PREFIX) echo " [CC] $< -> $@"
- $(CMD_PREFIX) $(CC) -o $@ -c $< $(PTHREAD_CFLAGS) $(ASTCFLAGS) $(MAKE_DEPS)
+# shortcuts for common combinations of flags; these must be recursively expanded so that
+# per-target settings will be applied
+CC_CFLAGS=$(PTHREAD_CFLAGS) $(ASTCFLAGS)
+CXX_CFLAGS=$(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(ASTCFLAGS))
+CC_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(ASTLDFLAGS) $(SOLINK)
+CXX_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(ASTLDFLAGS) $(SOLINK)
+CC_LIBS=$(PTHREAD_LIBS) $(LIBS)
+CXX_LIBS=$(PTHREAD_LIBS) $(LIBS)
+
+# determine whether to double-compile so that the optimizer can report code path problems
+# this is only done when developer mode and DONT_OPTIMIZE are both enabled
+# in that case, we run the preprocessor to produce a .i or .ii file from the source
+# code, then compile once with optimizer enabled (and the output to /dev/null),
+# and if that doesn't fail then compile again with optimizer disabled
+ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_DEVMODE),DONT_OPTIMIZEyes)
+COMPILE_DOUBLE=yes
+endif
+
+%.o: %.s
+ $(ECHO_PREFIX) echo " [AS] $< -> $@"
+ifeq ($(COMPILE_DOUBLE),yes)
+ $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
+endif
+ $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS)
%.o: %.i
$(ECHO_PREFIX) echo " [CCi] $< -> $@"
- $(CMD_PREFIX) $(CC) -o $@ -c $< $(PTHREAD_CFLAGS) $(ASTCFLAGS) $(MAKE_DEPS)
+ifeq ($(COMPILE_DOUBLE),yes)
+ $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
+endif
+ $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS)
+
+%.o: %.c
+ $(ECHO_PREFIX) echo " [CC] $< -> $@"
+ifeq ($(COMPILE_DOUBLE),yes)
+ $(CMD_PREFIX) $(CC) -o $(@:%.o=%.i) -E $< $(CC_CFLAGS) $(MAKE_DEPS)
+ $(CMD_PREFIX) $(CC) -o /dev/null -c $(@:%.o=%.i) $(CC_CFLAGS) $(OPTIMIZE)
+ $(CMD_PREFIX) $(CC) -o $@ -c $(@:%.o=%.i) $(CC_CFLAGS)
+else
+ $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(MAKE_DEPS)
+endif
%.i: %.c
$(ECHO_PREFIX) echo " [CPP] $< -> $@"
- $(CMD_PREFIX) $(CC) -o $@ -E $< $(PTHREAD_CFLAGS) $(ASTCFLAGS) $(MAKE_DEPS)
+ $(CMD_PREFIX) $(CC) -o $@ -E $< $(CC_CFLAGS) $(MAKE_DEPS)
-%.o: %.s
- $(ECHO_PREFIX) echo " [AS] $< -> $@"
- $(CMD_PREFIX) $(CC) -o $@ -c $< $(PTHREAD_CFLAGS) $(ASTCFLAGS) $(MAKE_DEPS)
+%.oo: %.ii
+ $(ECHO_PREFIX) echo " [CXXi] $< -> $@"
+ifeq ($(COMPILE_DOUBLE),yes)
+ $(CMD_PREFIX) $(CXX) -o /dev/null -c $< $(CXX_CFLAGS) $(OPTIMIZE)
+endif
+ $(CMD_PREFIX) $(CXX) -o $@ -c $< $(CXX_CFLAGS)
%.oo: %.cc
$(ECHO_PREFIX) echo " [CXX] $< -> $@"
- $(CMD_PREFIX) $(CXX) -o $@ -c $< $(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(ASTCFLAGS)) $(MAKE_DEPS)
+ifeq ($(COMPILE_DOUBLE),yes)
+ $(CMD_PREFIX) $(CXX) -o $(@:%.oo=%.ii) -E $< $(CXX_CFLAGS) $(MAKE_DEPS)
+ $(CMD_PREFIX) $(CXX) -o /dev/null -c $(@:%.oo=%.ii) $(CXX_CFLAGS) $(MAKE_DEPS) $(OPTIMIZE)
+ $(CMD_PREFIX) $(CXX) -o $@ -c $(@:%.oo=%.ii) $(CXX_CFLAGS) $(MAKE_DEPS)
+else
+ $(CMD_PREFIX) $(CXX) -o $@ -c $< $(CXX_CFLAGS) $(MAKE_DEPS)
+endif
+
+%.ii: %.cc
+ $(ECHO_PREFIX) echo " [CPP] $< -> $@"
+ $(CMD_PREFIX) $(CXX) -o $@ -E $< $(CXX_CFLAGS) $(MAKE_DEPS)
%.c: %.y
$(ECHO_PREFIX) echo " [BISON] $< -> $@"
@@ -73,11 +119,11 @@ endif
%.so: %.o
$(ECHO_PREFIX) echo " [LD] $^ -> $@"
- $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(ASTLDFLAGS) $(SOLINK) $^ $(PTHREAD_LIBS) $(LIBS)
+ $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
%.so: %.oo
$(ECHO_PREFIX) echo " [LDXX] $^ -> $@"
- $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(ASTLDFLAGS) $(SOLINK) $^ $(PTHREAD_LIBS) $(LIBS)
+ $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(CXX_LDFLAGS_SO) $^ $(CXX_LIBS)
%.eo: %.o
$(ECHO_PREFIX) echo " [EMBED] $< -> $@"
@@ -93,6 +139,6 @@ endif
%: %.o
$(ECHO_PREFIX) echo " [LD] $^ -> $@"
- $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(ASTLDFLAGS) $^ $(PTHREAD_LIBS) $(LIBS)
+ $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(ASTLDFLAGS) $^ $(CXX_LIBS)
dist-clean:: clean