asterisk/Makefile.rules

223 lines
7.4 KiB
Makefile
Raw Permalink Normal View History

#
# Asterisk -- An open source telephony toolkit.
#
# Makefile rules
#
# Copyright (C) 2006-2010, Digium, Inc.
#
# Kevin P. Fleming <kpfleming@digium.com>
#
# This program is free software, distributed under the terms of
# the GNU General Public License
#
# 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.
-include $(ASTTOPDIR)/makeopts
# Helpful functions
# call with $(call function,...)
tolower = $(shell echo $(1) | tr '[:upper:]' '[:lower:]')
# Takes a list of MENUSELECT_CFLAG Id and returns CFLAGS to declare
# the ones which are enabled.
get_menuselect_cflags=$(patsubst %,-D%,$(filter $1,$(MENUSELECT_CFLAGS)))
.PHONY: dist-clean
# If 'make' decides to create intermediate files to satisfy a build requirement
# (like producing a .i from a .c), we want to keep them, so tell make to keep
# all intermediate files
.SECONDARY:
# extra cflags to build dependencies. Recursively expanded.
MAKE_DEPS=-MD -MT $@ -MF .$(subst /,_,$@).d -MP
ifeq ($(findstring ADDRESS_SANITIZER,$(MENUSELECT_CFLAGS)),ADDRESS_SANITIZER)
_ASTLDFLAGS+=-fsanitize=address
_ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=address
endif
ifeq ($(findstring THREAD_SANITIZER,$(MENUSELECT_CFLAGS)),THREAD_SANITIZER)
_ASTLDFLAGS+=-fsanitize=thread -pie -fPIE
_ASTCFLAGS+=-fno-omit-frame-pointer -pie -fPIE -fsanitize=thread
endif
ifeq ($(findstring LEAK_SANITIZER,$(MENUSELECT_CFLAGS)),LEAK_SANITIZER)
_ASTLDFLAGS+=-fsanitize=leak
_ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=leak
endif
ifeq ($(findstring UNDEFINED_SANITIZER,$(MENUSELECT_CFLAGS)),UNDEFINED_SANITIZER)
_ASTLDFLAGS+=-fsanitize=undefined
_ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=undefined
endif
ifeq ($(NOISY_BUILD),)
ECHO_PREFIX=@
CMD_PREFIX=@
else
ECHO_PREFIX=@\#
CMD_PREFIX=
endif
OPTIMIZE?=-O3
ifneq ($(findstring darwin,$(OSARCH)),)
ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
# Snow Leopard/Lion has an issue with this optimization flag on large files
OPTIMIZE+=-fno-inline-functions
endif
endif
ifeq ($(CC),gcc)
# gcc version 8.2.1 and above must have partial-inlining disabled in order
# to avoid a documented bug. Sort to make the lowest version number come
# first. If it's the specified version then the current gcc version is equal
# to or greater, so add the custom optimization rule.
gcc_versions=$(shell printf "%s\n" $$(gcc -dumpversion) 8.2.1 | sort -n)
ifeq ($(firstword $(gcc_versions)),8.2.1)
OPTIMIZE+=-fno-partial-inlining
endif
endif
ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_CODE_COVERAGE),no)
_ASTCFLAGS+=$(OPTIMIZE)
else
_ASTCFLAGS+=-O0
endif
ifeq ($(AST_CODE_COVERAGE),yes)
_ASTCFLAGS_COVERAGE=-ftest-coverage -fprofile-arcs
_ASTLDFLAGS+=-ftest-coverage -fprofile-arcs
else
_ASTCFLAGS_COVERAGE=
endif
ifeq ($(findstring $(CONFIG_CFLAGS),$(_ASTCFLAGS)),)
_ASTCFLAGS+=$(CONFIG_CFLAGS)
endif
# shortcuts for common combinations of flags; these must be recursively expanded so that
# per-target settings will be applied
CC_CFLAGS=$(PTHREAD_CFLAGS) $(_ASTCFLAGS) $(ASTCFLAGS)
CXX_CFLAGS=$(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(_ASTCFLAGS) $(ASTCFLAGS))
Update configure.ac/Makefile for clang Created autoconf/ast_check_raii.m4: contains AST_CHECK_RAII which checks compiler requirements for RAII: gcc: -fnested-functions support clang: -fblocks (and if required -lBlocksRuntime) The original check was implemented in configure.ac and now has it's own file. This function also sets C_COMPILER_FAMILY to either gcc or clang for use by makefile Created autoconf/ast_check_strsep_array_bounds.m4 (contains AST_CHECK_STRSEP_ARRAY_BOUNDS): which checks if clang is able to handle the optimized strsep & strcmp functions (linux). If not, the standard libc implementation should be used instead. Clang + the optimized macro's work with: strsep(char *, char []), but not with strsepo(char *, char *). Instead of replacing all the occurences throughout the source code, not using the optimized macro version seemed easier See 'define __strcmp_gc(s1, s2, l2) in bits/string2.h': llvm-comment: Normally, this array-bounds warning are suppressed for macros, so that unused paths like the one that accesses __s1[3] are not warned about. But if you preprocess manually, and feed the result to another instance of clang, it will warn about all the possible forks of this particular if statement. Instead of switching of this optimization, another solution would be to run the preproces- sing step with -frewrite-includes, which should preserve enough information so that clang should still be able to suppress the diag- nostic at the compile step later on. See also "https://llvm.org/bugs/show_bug.cgi?id=20144" See also "https://llvm.org/bugs/show_bug.cgi?id=11536" Makefile.rules: If C_COMPILER_FAMILY=clang then add two warning suppressions: -Wno-unused-value -Wno-parentheses-equality In an earlier review (reviewboard: 4550 and 4554), they were deemed a nuisace and less than benefitial. configure.ac: Added AST_CHECK_RAII() see earlier Added AST_CHECK_STRSEP_ARRAY_BOUNDS() see earlier Removed moved content ASTERISK-24917 Change-Id: I12ea29d3bda2254ad3908e279b7effbbac6a97cb
2015-04-20 18:03:56 +00:00
# Clang -Werror warning suppressions
ifeq ($(C_COMPILER_FAMILY),clang)
CC_CFLAGS+=-Wno-unused-value -Wno-parentheses-equality
endif
ifeq ($(GNU_LD),1)
SO_SUPPRESS_SYMBOLS=-Wl,--version-script,$(subst .so,.exports,$@),--warn-common
ifneq ($(wildcard $(subst .so,.dynamics,$@)),)
SO_SUPPRESS_SYMBOLS+=-Wl,--dynamic-list,$(subst .so,.dynamics,$@)
endif
endif
CC_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
CXX_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
CC_LIBS=$(PTHREAD_LIBS) $(LIBS)
CXX_LIBS=$(PTHREAD_LIBS) $(LIBS)
# determine whether to double-compile so that the optimizer can report code path problems
build_system: Split COMPILE_DOUBLE from DONT_OPTIMIZE I can't ever recall actually needing the intermediate files or the checking that a double compile produces. What I CAN remember is every DONT_OPTIMIZE build needing 3 invocations of gcc instead of 1 just to do the checks and produce those intermediate files. Having said that, Richard pointed out that the reason for the double compile was that there were cases in the past where a submitted patch failed to compile because the submitter never tried it with the optimizations turned on. To get the best of both worlds, COMPILE_DOUBLE has been split into its own option. If DONT_OPTIMIZE is turned on, COMPILE_DOUBLE will also be selected BUT you can then turn it off if all you need are the debugging symbols. This way you have to make an informed decision about disabling COMPILE_DOUBLE. To allow COMPILE_DOUBLE to be both auto-selected and turned off, a new feature was added to menuselect. The <use> element can now contain an "autoselect" attribute which will turn the used member on but not create a hard dependency. The cflags.xml implementation for COMPILE_DOUBLE looks like this... <member name="DONT_OPTIMIZE" displayname="Disable Optimizations ..."> <use autoselect="yes">COMPILE_DOUBLE</use> <support_level>core</support_level> </member> <member name="COMPILE_DOUBLE" displayname="Pre-compile with ...> <depend>DONT_OPTIMIZE</depend> <support_level>core</support_level> </member> When DONT_OPTIMIZE is turned on, COMPILE_DOUBLE is turned on because of the use. When DONT_OPTIMIZE is turned off, COMPILE_DOUBLE is turned off because of the depend. When COMPILE_DOUBLE is turned on, DONT_OPTIMIZE is turned on because of the depend. When COMPILE_DOUBLE is turned off, DONT_OPTIMIZE is left as is because it only uses COMPILE_DOUBLE, it doesn't depend on it. I also made a few tweaks to the ncurses implementation to move things left a bit to allow longer descriptions. Change-Id: Id49ca930ac4b5ec4fc2d8141979ad888da7b1611
2016-03-12 22:02:20 +00:00
# In this 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
build_system: Split COMPILE_DOUBLE from DONT_OPTIMIZE I can't ever recall actually needing the intermediate files or the checking that a double compile produces. What I CAN remember is every DONT_OPTIMIZE build needing 3 invocations of gcc instead of 1 just to do the checks and produce those intermediate files. Having said that, Richard pointed out that the reason for the double compile was that there were cases in the past where a submitted patch failed to compile because the submitter never tried it with the optimizations turned on. To get the best of both worlds, COMPILE_DOUBLE has been split into its own option. If DONT_OPTIMIZE is turned on, COMPILE_DOUBLE will also be selected BUT you can then turn it off if all you need are the debugging symbols. This way you have to make an informed decision about disabling COMPILE_DOUBLE. To allow COMPILE_DOUBLE to be both auto-selected and turned off, a new feature was added to menuselect. The <use> element can now contain an "autoselect" attribute which will turn the used member on but not create a hard dependency. The cflags.xml implementation for COMPILE_DOUBLE looks like this... <member name="DONT_OPTIMIZE" displayname="Disable Optimizations ..."> <use autoselect="yes">COMPILE_DOUBLE</use> <support_level>core</support_level> </member> <member name="COMPILE_DOUBLE" displayname="Pre-compile with ...> <depend>DONT_OPTIMIZE</depend> <support_level>core</support_level> </member> When DONT_OPTIMIZE is turned on, COMPILE_DOUBLE is turned on because of the use. When DONT_OPTIMIZE is turned off, COMPILE_DOUBLE is turned off because of the depend. When COMPILE_DOUBLE is turned on, DONT_OPTIMIZE is turned on because of the depend. When COMPILE_DOUBLE is turned off, DONT_OPTIMIZE is left as is because it only uses COMPILE_DOUBLE, it doesn't depend on it. I also made a few tweaks to the ncurses implementation to move things left a bit to allow longer descriptions. Change-Id: Id49ca930ac4b5ec4fc2d8141979ad888da7b1611
2016-03-12 22:02:20 +00:00
ifeq ($(findstring COMPILE_DOUBLE,$(MENUSELECT_CFLAGS)),COMPILE_DOUBLE)
COMPILE_DOUBLE=yes
build_system: Split COMPILE_DOUBLE from DONT_OPTIMIZE I can't ever recall actually needing the intermediate files or the checking that a double compile produces. What I CAN remember is every DONT_OPTIMIZE build needing 3 invocations of gcc instead of 1 just to do the checks and produce those intermediate files. Having said that, Richard pointed out that the reason for the double compile was that there were cases in the past where a submitted patch failed to compile because the submitter never tried it with the optimizations turned on. To get the best of both worlds, COMPILE_DOUBLE has been split into its own option. If DONT_OPTIMIZE is turned on, COMPILE_DOUBLE will also be selected BUT you can then turn it off if all you need are the debugging symbols. This way you have to make an informed decision about disabling COMPILE_DOUBLE. To allow COMPILE_DOUBLE to be both auto-selected and turned off, a new feature was added to menuselect. The <use> element can now contain an "autoselect" attribute which will turn the used member on but not create a hard dependency. The cflags.xml implementation for COMPILE_DOUBLE looks like this... <member name="DONT_OPTIMIZE" displayname="Disable Optimizations ..."> <use autoselect="yes">COMPILE_DOUBLE</use> <support_level>core</support_level> </member> <member name="COMPILE_DOUBLE" displayname="Pre-compile with ...> <depend>DONT_OPTIMIZE</depend> <support_level>core</support_level> </member> When DONT_OPTIMIZE is turned on, COMPILE_DOUBLE is turned on because of the use. When DONT_OPTIMIZE is turned off, COMPILE_DOUBLE is turned off because of the depend. When COMPILE_DOUBLE is turned on, DONT_OPTIMIZE is turned on because of the depend. When COMPILE_DOUBLE is turned off, DONT_OPTIMIZE is left as is because it only uses COMPILE_DOUBLE, it doesn't depend on it. I also made a few tweaks to the ncurses implementation to move things left a bit to allow longer descriptions. Change-Id: Id49ca930ac4b5ec4fc2d8141979ad888da7b1611
2016-03-12 22:02:20 +00:00
endif
ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_DEVMODE),)
_ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
endif
ifeq ($(findstring BUILD_NATIVE,$(MENUSELECT_CFLAGS)),BUILD_NATIVE)
_ASTCFLAGS+=-march=native
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) $(_ASTCFLAGS_COVERAGE)
%.o: %.i
$(ECHO_PREFIX) echo " [CCi] $< -> $@"
ifneq ($(AST_CLANG_BLOCKS),)
ifeq ($(COMPILE_DOUBLE),yes)
$(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE) -Wno-unused-command-line-argument
endif
$(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE) -Wno-unused-command-line-argument
else
ifeq ($(COMPILE_DOUBLE),yes)
$(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
endif
$(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
endif
ifneq ($(COMPILE_DOUBLE),yes)
%.o: %.c
$(ECHO_PREFIX) echo " [CC] $< -> $@"
$(CMD_PREFIX) $(CC) -o $@ -c $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
endif
%.i: %.c
$(ECHO_PREFIX) echo " [CPP] $< -> $@"
$(CMD_PREFIX) $(CC) -o $@ -E $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
%.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) $(_ASTCFLAGS_COVERAGE)
ifneq ($(COMPILE_DOUBLE),yes)
%.oo: %.cc
$(ECHO_PREFIX) echo " [CXX] $< -> $@"
$(CMD_PREFIX) $(CXX) -o $@ -c $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
endif
%.ii: %.cc
$(ECHO_PREFIX) echo " [CPP] $< -> $@"
$(CMD_PREFIX) $(CXX) -o $@ -E $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
%.so: %.o
ifeq ($(GNU_LD),1)
$(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
endif
$(ECHO_PREFIX) echo " [LD] $^ -> $@"
$(CMD_PREFIX) $(CC) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
%.so: %.oo
ifeq ($(GNU_LD),1)
$(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
endif
$(ECHO_PREFIX) echo " [LDXX] $^ -> $@"
$(CMD_PREFIX) $(CXX) -o $@ $(CXX_LDFLAGS_SO) $^ $(CXX_LIBS)
%: %.o
$(ECHO_PREFIX) echo " [LD] $^ -> $@"
$(CMD_PREFIX) $(CXX) -o $@ $(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $^ $(CXX_LIBS) $(ASTLDFLAGS)
# These CC commands just create an object file with the input file embedded in it.
# It can be access from code as follows:
# If your input file is named abc_def.xml...
#
# extern const uint8_t _binary_abc_def_xml_start[];
# extern const uint8_t _binary_abc_def_xml_end[];
# extern const size_t _binary_abc_def_xml_size;
%.o: %.xml
$(ECHO_PREFIX) echo " [LD] $^ -> $@"
$(CMD_PREFIX) $(CC) -g -Wl,-znoexecstack -nostartfiles -nodefaultlibs -nostdlib -r -Wl,-b,binary -o $@ $^
%.o: %.xslt
$(ECHO_PREFIX) echo " [LD] $^ -> $@"
$(CMD_PREFIX) $(CC) -g -Wl,-znoexecstack -nostartfiles -nodefaultlibs -nostdlib -r -Wl,-b,binary -o $@ $^
dist-clean:: clean