Merge "res_pjsip_mwi: update unsolicited MWI subscriptions on updating contact"
[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
24 .PHONY: dist-clean
25
26 # If 'make' decides to create intermediate files to satisfy a build requirement
27 # (like producing a .i from a .c), we want to keep them, so tell make to keep
28 # all intermediate files
29 .SECONDARY:
30
31 # extra cflags to build dependencies. Recursively expanded.
32 MAKE_DEPS=-MD -MT $@ -MF .$(subst /,_,$@).d -MP
33
34 ifeq ($(findstring ADDRESS_SANITIZER,$(MENUSELECT_CFLAGS)),ADDRESS_SANITIZER)
35     _ASTLDFLAGS+=-fsanitize=address
36     _ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=address
37 endif
38
39 ifeq ($(findstring THREAD_SANITIZER,$(MENUSELECT_CFLAGS)),THREAD_SANITIZER)
40     _ASTLDFLAGS+=-fsanitize=thread -pie -fPIE
41     _ASTCFLAGS+=-fno-omit-frame-pointer -pie -fPIE -fsanitize=thread
42 endif
43
44 ifeq ($(findstring LEAK_SANITIZER,$(MENUSELECT_CFLAGS)),LEAK_SANITIZER)
45     _ASTLDFLAGS+=-fsanitize=leak
46     _ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=leak
47 endif
48
49 ifeq ($(findstring UNDEFINED_SANITIZER,$(MENUSELECT_CFLAGS)),UNDEFINED_SANITIZER)
50     _ASTLDFLAGS+=-fsanitize=undefined
51     _ASTCFLAGS+=-fno-omit-frame-pointer -fsanitize=undefined
52 endif
53
54 ifeq ($(NOISY_BUILD),)
55     ECHO_PREFIX=@
56     CMD_PREFIX=@
57 else
58     ECHO_PREFIX=@\# 
59     CMD_PREFIX=
60 endif
61
62 OPTIMIZE?=-O3
63 ifneq ($(findstring darwin,$(OSARCH)),)
64   ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
65     # Snow Leopard/Lion has an issue with this optimization flag on large files (like chan_sip)
66     OPTIMIZE+=-fno-inline-functions
67   endif
68 endif
69
70 ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_CODE_COVERAGE),no)
71     _ASTCFLAGS+=$(OPTIMIZE)
72 else
73     _ASTCFLAGS+=-O0
74 endif
75
76 ifeq ($(AST_CODE_COVERAGE),yes)
77     _ASTCFLAGS_COVERAGE=-ftest-coverage -fprofile-arcs
78     _ASTLDFLAGS+=-ftest-coverage -fprofile-arcs
79 else
80     _ASTCFLAGS_COVERAGE=
81 endif
82
83 ifeq ($(findstring $(CONFIG_CFLAGS),$(_ASTCFLAGS)),)
84     _ASTCFLAGS+=$(CONFIG_CFLAGS)
85 endif
86
87 # shortcuts for common combinations of flags; these must be recursively expanded so that
88 # per-target settings will be applied
89 CC_CFLAGS=$(PTHREAD_CFLAGS) $(_ASTCFLAGS) $(ASTCFLAGS)
90 CXX_CFLAGS=$(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(_ASTCFLAGS) $(ASTCFLAGS))
91
92 # Clang -Werror warning suppressions
93 ifeq ($(C_COMPILER_FAMILY),clang)
94         CC_CFLAGS+=-Wno-unused-value -Wno-parentheses-equality
95 endif
96
97 ifeq ($(GNU_LD),1)
98 SO_SUPPRESS_SYMBOLS=-Wl,--version-script,$(subst .so,.exports,$@),--warn-common
99 ifneq ($(wildcard $(subst .so,.dynamics,$@)),)
100 SO_SUPPRESS_SYMBOLS+=-Wl,--dynamic-list,$(subst .so,.dynamics,$@)
101 endif
102 endif
103
104 CC_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
105 CXX_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
106 CC_LIBS=$(PTHREAD_LIBS) $(LIBS)
107 CXX_LIBS=$(PTHREAD_LIBS) $(LIBS)
108
109 # determine whether to double-compile so that the optimizer can report code path problems
110 # In this case, we run the preprocessor to produce a .i or .ii file from the source
111 # code, then compile once with optimizer enabled (and the output to /dev/null),
112 # and if that doesn't fail then compile again with optimizer disabled
113
114 ifeq ($(findstring COMPILE_DOUBLE,$(MENUSELECT_CFLAGS)),COMPILE_DOUBLE)
115 COMPILE_DOUBLE=yes
116 endif
117
118 ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_DEVMODE),)
119 _ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
120 endif
121
122 ifeq ($(findstring BUILD_NATIVE,$(MENUSELECT_CFLAGS)),BUILD_NATIVE)
123     _ASTCFLAGS+=-march=native
124 endif
125
126 %.o: %.s
127         $(ECHO_PREFIX) echo "   [AS] $< -> $@"
128 ifeq ($(COMPILE_DOUBLE),yes)
129         $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
130 endif
131         $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
132
133 %.o: %.i
134         $(ECHO_PREFIX) echo "   [CCi] $< -> $@"
135 ifneq ($(AST_CLANG_BLOCKS),)
136 ifeq ($(COMPILE_DOUBLE),yes)
137         $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE) -Wno-unused-command-line-argument
138 endif
139         $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE) -Wno-unused-command-line-argument
140 else
141 ifeq ($(COMPILE_DOUBLE),yes)
142         $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
143 endif
144         $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
145 endif
146
147 ifneq ($(COMPILE_DOUBLE),yes)
148 %.o: %.c
149         $(ECHO_PREFIX) echo "   [CC] $< -> $@"
150         $(CMD_PREFIX) $(CC) -o $@ -c $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
151 endif
152
153 %.i: %.c
154         $(ECHO_PREFIX) echo "   [CPP] $< -> $@"
155         $(CMD_PREFIX) $(CC) -o $@ -E $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
156
157 %.oo: %.ii
158         $(ECHO_PREFIX) echo "   [CXXi] $< -> $@"
159 ifeq ($(COMPILE_DOUBLE),yes)
160         $(CMD_PREFIX) $(CXX) -o /dev/null -c $< $(CXX_CFLAGS) $(OPTIMIZE)
161 endif
162         $(CMD_PREFIX) $(CXX) -o $@ -c $< $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
163
164 ifneq ($(COMPILE_DOUBLE),yes)
165 %.oo: %.cc
166         $(ECHO_PREFIX) echo "   [CXX] $< -> $@"
167         $(CMD_PREFIX) $(CXX) -o $@ -c $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
168 endif
169
170 %.ii: %.cc
171         $(ECHO_PREFIX) echo "   [CPP] $< -> $@"
172         $(CMD_PREFIX) $(CXX) -o $@ -E $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
173
174 %.so: %.o
175 ifeq ($(GNU_LD),1)
176         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
177 endif
178         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
179         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
180
181 %.so: %.oo
182 ifeq ($(GNU_LD),1)
183         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
184 endif
185         $(ECHO_PREFIX) echo "   [LDXX] $^ -> $@"
186         $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(CXX_LDFLAGS_SO) $^ $(CXX_LIBS)
187
188 %: %.o
189         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
190         $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $^ $(CXX_LIBS) $(ASTLDFLAGS)
191
192 dist-clean:: clean