]> git.ipfire.org Git - thirdparty/asterisk.git/blob - Makefile.rules
dsp.c: Fix and improve potentially inaccurate log message.
[thirdparty/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
67 ifneq ($(findstring darwin,$(OSARCH)),)
68 ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
69 # Snow Leopard/Lion has an issue with this optimization flag on large files
70 OPTIMIZE+=-fno-inline-functions
71 endif
72 endif
73
74 ifeq ($(CC),gcc)
75 # gcc version 8.2.1 and above must have partial-inlining disabled in order
76 # to avoid a documented bug. Sort to make the lowest version number come
77 # first. If it's the specified version then the current gcc version is equal
78 # to or greater, so add the custom optimization rule.
79 gcc_versions=$(shell printf "%s\n" $$(gcc -dumpversion) 8.2.1 | sort -n)
80 ifeq ($(firstword $(gcc_versions)),8.2.1)
81 OPTIMIZE+=-fno-partial-inlining
82 endif
83 endif
84
85 ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_CODE_COVERAGE),no)
86 _ASTCFLAGS+=$(OPTIMIZE)
87 else
88 _ASTCFLAGS+=-O0
89 endif
90
91 ifeq ($(AST_CODE_COVERAGE),yes)
92 _ASTCFLAGS_COVERAGE=-ftest-coverage -fprofile-arcs
93 _ASTLDFLAGS+=-ftest-coverage -fprofile-arcs
94 else
95 _ASTCFLAGS_COVERAGE=
96 endif
97
98 ifeq ($(findstring $(CONFIG_CFLAGS),$(_ASTCFLAGS)),)
99 _ASTCFLAGS+=$(CONFIG_CFLAGS)
100 endif
101
102 # shortcuts for common combinations of flags; these must be recursively expanded so that
103 # per-target settings will be applied
104 CC_CFLAGS=$(PTHREAD_CFLAGS) $(_ASTCFLAGS) $(ASTCFLAGS)
105 CXX_CFLAGS=$(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(_ASTCFLAGS) $(ASTCFLAGS))
106
107 # Clang -Werror warning suppressions
108 ifeq ($(C_COMPILER_FAMILY),clang)
109 CC_CFLAGS+=-Wno-unused-value -Wno-parentheses-equality
110 endif
111
112 ifeq ($(GNU_LD),1)
113 SO_SUPPRESS_SYMBOLS=-Wl,--version-script,$(subst .so,.exports,$@),--warn-common
114 ifneq ($(wildcard $(subst .so,.dynamics,$@)),)
115 SO_SUPPRESS_SYMBOLS+=-Wl,--dynamic-list,$(subst .so,.dynamics,$@)
116 endif
117 endif
118
119 CC_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
120 CXX_LDFLAGS_SO=$(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(SOLINK) $(SO_SUPPRESS_SYMBOLS) $(ASTLDFLAGS)
121 CC_LIBS=$(PTHREAD_LIBS) $(LIBS)
122 CXX_LIBS=$(PTHREAD_LIBS) $(LIBS)
123
124 # determine whether to double-compile so that the optimizer can report code path problems
125 # In this case, we run the preprocessor to produce a .i or .ii file from the source
126 # code, then compile once with optimizer enabled (and the output to /dev/null),
127 # and if that doesn't fail then compile again with optimizer disabled
128
129 ifeq ($(findstring COMPILE_DOUBLE,$(MENUSELECT_CFLAGS)),COMPILE_DOUBLE)
130 COMPILE_DOUBLE=yes
131 endif
132
133 ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))$(AST_DEVMODE),)
134 _ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
135 endif
136
137 ifeq ($(findstring BUILD_NATIVE,$(MENUSELECT_CFLAGS)),BUILD_NATIVE)
138 _ASTCFLAGS+=-march=native
139 endif
140
141 %.o: %.s
142 $(ECHO_PREFIX) echo " [AS] $< -> $@"
143 ifeq ($(COMPILE_DOUBLE),yes)
144 $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
145 endif
146 $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
147
148 %.o: %.i
149 $(ECHO_PREFIX) echo " [CCi] $< -> $@"
150 ifneq ($(AST_CLANG_BLOCKS),)
151 ifeq ($(COMPILE_DOUBLE),yes)
152 $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE) -Wno-unused-command-line-argument
153 endif
154 $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE) -Wno-unused-command-line-argument
155 else
156 ifeq ($(COMPILE_DOUBLE),yes)
157 $(CMD_PREFIX) $(CC) -o /dev/null -c $< $(CC_CFLAGS) $(OPTIMIZE)
158 endif
159 $(CMD_PREFIX) $(CC) -o $@ -c $< $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
160 endif
161
162 ifneq ($(COMPILE_DOUBLE),yes)
163 %.o: %.c
164 $(ECHO_PREFIX) echo " [CC] $< -> $@"
165 $(CMD_PREFIX) $(CC) -o $@ -c $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
166 endif
167
168 %.i: %.c
169 $(ECHO_PREFIX) echo " [CPP] $< -> $@"
170 $(CMD_PREFIX) $(CC) -o $@ -E $< $(MAKE_DEPS) $(CC_CFLAGS) $(_ASTCFLAGS_COVERAGE)
171
172 %.oo: %.ii
173 $(ECHO_PREFIX) echo " [CXXi] $< -> $@"
174 ifeq ($(COMPILE_DOUBLE),yes)
175 $(CMD_PREFIX) $(CXX) -o /dev/null -c $< $(CXX_CFLAGS) $(OPTIMIZE)
176 endif
177 $(CMD_PREFIX) $(CXX) -o $@ -c $< $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
178
179 ifneq ($(COMPILE_DOUBLE),yes)
180 %.oo: %.cc
181 $(ECHO_PREFIX) echo " [CXX] $< -> $@"
182 $(CMD_PREFIX) $(CXX) -o $@ -c $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
183 endif
184
185 %.ii: %.cc
186 $(ECHO_PREFIX) echo " [CPP] $< -> $@"
187 $(CMD_PREFIX) $(CXX) -o $@ -E $< $(MAKE_DEPS) $(CXX_CFLAGS) $(_ASTCFLAGS_COVERAGE)
188
189 %.so: %.o
190 ifeq ($(GNU_LD),1)
191 $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
192 endif
193 $(ECHO_PREFIX) echo " [LD] $^ -> $@"
194 $(CMD_PREFIX) $(CC) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
195
196 %.so: %.oo
197 ifeq ($(GNU_LD),1)
198 $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script $* "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
199 endif
200 $(ECHO_PREFIX) echo " [LDXX] $^ -> $@"
201 $(CMD_PREFIX) $(CXX) -o $@ $(CXX_LDFLAGS_SO) $^ $(CXX_LIBS)
202
203 %: %.o
204 $(ECHO_PREFIX) echo " [LD] $^ -> $@"
205 $(CMD_PREFIX) $(CXX) -o $@ $(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $^ $(CXX_LIBS) $(ASTLDFLAGS)
206
207 # These CC commands just create an object file with the input file embedded in it.
208 # It can be access from code as follows:
209 # If your input file is named abc_def.xml...
210 #
211 # extern const uint8_t _binary_abc_def_xml_start[];
212 # extern const uint8_t _binary_abc_def_xml_end[];
213 # extern const size_t _binary_abc_def_xml_size;
214 %.o: %.xml
215 $(ECHO_PREFIX) echo " [LD] $^ -> $@"
216 $(CMD_PREFIX) $(CC) -g -Wl,-znoexecstack -nostartfiles -nodefaultlibs -nostdlib -r -Wl,-b,binary -o $@ $^
217
218 %.o: %.xslt
219 $(ECHO_PREFIX) echo " [LD] $^ -> $@"
220 $(CMD_PREFIX) $(CC) -g -Wl,-znoexecstack -nostartfiles -nodefaultlibs -nostdlib -r -Wl,-b,binary -o $@ $^
221
222 dist-clean:: clean