Removing registrar_expire from basic-pbx config
[asterisk/asterisk.git] / Makefile.rules
1 #
2 # Asterisk -- An open source telephony toolkit.
3 #
4 # Makefile rules
5 #
6 # Copyright (C) 2006-2010, Digium, Inc.
7 #
8 # Kevin P. Fleming <kpfleming@digium.com>
9 #
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
12 #
13
14 # Each command is preceded by a short comment on what to do.
15 # Prefixing one or the other with @\# or @ or nothing makes the desired
16 # behaviour. ECHO_PREFIX prefixes the comment, CMD_PREFIX prefixes the command.
17
18 -include $(ASTTOPDIR)/makeopts
19
20 # Helpful functions
21 # call with $(call function,...)
22 tolower = $(shell echo $(1) | tr '[:upper:]' '[:lower:]')
23 # Takes a list of MENUSELECT_CFLAG Id and returns CFLAGS to declare
24 # the ones which are enabled.
25 get_menuselect_cflags=$(patsubst %,-D%,$(filter $1,$(MENUSELECT_CFLAGS)))
26
27 .PHONY: dist-clean
28
29 # If 'make' decides to create intermediate files to satisfy a build requirement
30 # (like producing a .i from a .c), we want to keep them, so tell make to keep
31 # all intermediate files
32 .SECONDARY:
33
34 # extra cflags to build dependencies. Recursively expanded.
35 MAKE_DEPS=-MD -MT $@ -MF .$(subst /,_,$@).d -MP
36
37 ifeq ($(findstring ADDRESS_SANITIZER,$(MENUSELECT_CFLAGS)),ADDRESS_SANITIZER)
38     _ASTLDFLAGS+=-fsanitize=address
39     _ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=address
40 endif
41
42 ifeq ($(findstring THREAD_SANITIZER,$(MENUSELECT_CFLAGS)),THREAD_SANITIZER)
43     _ASTLDFLAGS+=-fsanitize=thread -pie -fPIE
44     _ASTCFLAGS+=-fno-omit-frame-pointer -pie -fPIE -fsanitize=thread
45 endif
46
47 ifeq ($(findstring LEAK_SANITIZER,$(MENUSELECT_CFLAGS)),LEAK_SANITIZER)
48     _ASTLDFLAGS+=-fsanitize=leak
49     _ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=leak
50 endif
51
52 ifeq ($(findstring UNDEFINED_SANITIZER,$(MENUSELECT_CFLAGS)),UNDEFINED_SANITIZER)
53     _ASTLDFLAGS+=-fsanitize=undefined
54     _ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=undefined
55 endif
56
57 ifeq ($(NOISY_BUILD),)
58     ECHO_PREFIX=@
59     CMD_PREFIX=@
60 else
61     ECHO_PREFIX=@\#
62     CMD_PREFIX=
63 endif
64
65 OPTIMIZE?=-O3
66 ifneq ($(findstring darwin,$(OSARCH)),)
67   ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
68     # Snow Leopard/Lion has an issue with this optimization flag on large files (like chan_sip)
69     OPTIMIZE+=-fno-inline-functions
70   endif
71 endif
72
73 ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_CODE_COVERAGE),no)
74     _ASTCFLAGS+=$(OPTIMIZE)
75 else
76     _ASTCFLAGS+=-O0
77 endif
78
79 ifeq ($(AST_CODE_COVERAGE),yes)
80     _ASTCFLAGS_COVERAGE=-ftest-coverage -fprofile-arcs
81     _ASTLDFLAGS+=-ftest-coverage -fprofile-arcs
82 else
83     _ASTCFLAGS_COVERAGE=
84 endif
85
86 ifeq ($(findstring $(CONFIG_CFLAGS),$(_ASTCFLAGS)),)
87     _ASTCFLAGS+=$(CONFIG_CFLAGS)
88 endif
89
90 # shortcuts for common combinations of flags; these must be recursively expanded so that
91 # per-target settings will be applied
92 CC_CFLAGS=$(PTHREAD_CFLAGS) $(_ASTCFLAGS) $(ASTCFLAGS)
93 CXX_CFLAGS=$(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(_ASTCFLAGS) $(ASTCFLAGS))
94
95 # Clang -Werror warning suppressions
96 ifeq ($(C_COMPILER_FAMILY),clang)
97         CC_CFLAGS+=-Wno-unused-value -Wno-parentheses-equality
98 endif
99
100 ifeq ($(GNU_LD),1)
101 SO_SUPPRESS_SYMBOLS=-Wl,--version-script,$(subst .so,.exports,$@),--warn-common
102 ifneq ($(wildcard $(subst .so,.dynamics,$@)),)
103 SO_SUPPRESS_SYMBOLS+=-Wl,--dynamic-list,$(subst .so,.dynamics,$@)
104 endif
105 endif
106
107 CC_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
108 CXX_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
109 CC_LIBS=$(PTHREAD_LIBS) $(LIBS)
110 CXX_LIBS=$(PTHREAD_LIBS) $(LIBS)
111
112 # determine whether to double-compile so that the optimizer can report code path problems
113 # In this case, we run the preprocessor to produce a .i or .ii file from the source
114 # code, then compile once with optimizer enabled (and the output to /dev/null),
115 # and if that doesn't fail then compile again with optimizer disabled
116
117 ifeq ($(findstring COMPILE_DOUBLE,$(MENUSELECT_CFLAGS)),COMPILE_DOUBLE)
118 COMPILE_DOUBLE=yes
119 endif
120
121 ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_DEVMODE),)
122 _ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
123 endif
124
125 ifeq ($(findstring BUILD_NATIVE,$(MENUSELECT_CFLAGS)),BUILD_NATIVE)
126     _ASTCFLAGS+=-march=native
127 endif
128
129 %.o: %.s
130         $(ECHO_PREFIX) echo "   [AS] $< -> $@"
131 ifeq ($(COMPILE_DOUBLE),yes)
132         $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
133 endif
134         $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
135
136 %.o: %.i
137         $(ECHO_PREFIX) echo "   [CCi] $< -> $@"
138 ifneq ($(AST_CLANG_BLOCKS),)
139 ifeq ($(COMPILE_DOUBLE),yes)
140         $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE) -Wno-unused-command-line-argument
141 endif
142         $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE) -Wno-unused-command-line-argument
143 else
144 ifeq ($(COMPILE_DOUBLE),yes)
145         $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
146 endif
147         $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
148 endif
149
150 ifneq ($(COMPILE_DOUBLE),yes)
151 %.o: %.c
152         $(ECHO_PREFIX) echo "   [CC] $< -> $@"
153         $(CMD_PREFIX) $(CC) -o $@ -c $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
154 endif
155
156 %.i: %.c
157         $(ECHO_PREFIX) echo "   [CPP] $< -> $@"
158         $(CMD_PREFIX) $(CC) -o $@ -E $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
159
160 %.oo: %.ii
161         $(ECHO_PREFIX) echo "   [CXXi] $< -> $@"
162 ifeq ($(COMPILE_DOUBLE),yes)
163         $(CMD_PREFIX) $(CXX) -o /dev/null -c $< $(CXX_CFLAGS) $(OPTIMIZE)
164 endif
165         $(CMD_PREFIX) $(CXX) -o $@ -c $< $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
166
167 ifneq ($(COMPILE_DOUBLE),yes)
168 %.oo: %.cc
169         $(ECHO_PREFIX) echo "   [CXX] $< -> $@"
170         $(CMD_PREFIX) $(CXX) -o $@ -c $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
171 endif
172
173 %.ii: %.cc
174         $(ECHO_PREFIX) echo "   [CPP] $< -> $@"
175         $(CMD_PREFIX) $(CXX) -o $@ -E $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
176
177 %.so: %.o
178 ifeq ($(GNU_LD),1)
179         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
180 endif
181         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
182         $(CMD_PREFIX) $(CC) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
183
184 %.so: %.oo
185 ifeq ($(GNU_LD),1)
186         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
187 endif
188         $(ECHO_PREFIX) echo "   [LDXX] $^ -> $@"
189         $(CMD_PREFIX) $(CXX) -o $@ $(CXX_LDFLAGS_SO) $^ $(CXX_LIBS)
190
191 %: %.o
192         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
193         $(CMD_PREFIX) $(CXX) -o $@ $(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $^ $(CXX_LIBS) $(ASTLDFLAGS)
194
195 dist-clean:: clean