res_rtp_asterisk.c: Fix rtp source address learning for broken clients
[asterisk/asterisk.git] / main / Makefile
1 #
2 # Asterisk -- An open source telephony toolkit.
3 #
4 # Makefile to build main Asterisk binary
5 #
6 # Copyright (C) 1999-2006, Digium, Inc.
7 #
8 # Mark Spencer <markster@digium.com>
9 #
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
12 #
13
14 -include $(ASTTOPDIR)/menuselect.makeopts $(ASTTOPDIR)/menuselect.makedeps $(ASTTOPDIR)/makeopts
15
16 all: asterisk
17
18 include $(ASTTOPDIR)/Makefile.moddir_rules
19
20 # Must include the extra ast_expr2.c, ast_expr2f.c, in case they need to be regenerated (because to force regeneration, we delete them)
21 SRC:=$(wildcard *.c) ast_expr2.c ast_expr2f.c
22 ifeq ($(AST_ASTERISKSSL),yes)
23 SRC:=$(filter-out libasteriskssl.c,$(SRC))
24 endif
25 ifeq ($(PJPROJECT_BUNDLED),yes)
26 SRC:=$(filter-out libasteriskpj.c,$(SRC))
27 endif
28 OBJSFILTER=fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o
29 OBJS=$(filter-out $(OBJSFILTER),$(SRC:.c=.o))
30
31 # we need to link in the objects statically, not as a library, because
32 # otherwise modules will not have them available if none of the static
33 # objects use it.
34 OBJS+=stdtime/localtime.o
35
36 ASTSSL_LIBS:=$(OPENSSL_LIB)
37 AST_LIBS+=$(BKTR_LIB)
38 AST_LIBS+=$(LIBXML2_LIB)
39 AST_LIBS+=$(LIBXSLT_LIB)
40 AST_LIBS+=$(SQLITE3_LIB)
41 AST_LIBS+=$(ASTSSL_LIBS)
42 AST_LIBS+=$(JANSSON_LIB)
43 AST_LIBS+=$(URIPARSER_LIB)
44 AST_LIBS+=$(UUID_LIB)
45 AST_LIBS+=$(CRYPT_LIB)
46 AST_LIBS+=$(AST_CLANG_BLOCKS_LIBS)
47 AST_LIBS+=$(RT_LIB)
48 AST_LIBS+=$(SYSTEMD_LIB)
49
50 ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc linux-musl kfreebsd-gnu),)
51   AST_LIBS+=-ldl
52   ifneq (x$(CAP_LIB),x)
53     AST_LIBS+=$(CAP_LIB)
54   endif
55   AST_LIBS+=-lpthread $(EDITLINE_LIB) -lm -lresolv
56 else
57   AST_LIBS+=$(EDITLINE_LIB) -lm
58 endif
59
60 ifneq ($(findstring BETTER_BACKTRACES,$(MENUSELECT_CFLAGS)),)
61   AST_LIBS+=$(BFD_LIB)
62 endif
63
64 ifneq ($(findstring darwin,$(OSARCH)),)
65   AST_LIBS+=-lresolv
66   ASTLINK=-mmacosx-version-min=10.6 -Wl,-undefined,dynamic_lookup -force_flat_namespace
67   ASTLINK+=/usr/lib/bundle1.o
68 else
69 # These are used for all but Darwin
70   ASTLINK+=-Wl,--export-dynamic
71   ifneq ($(findstring BSD,$(OSARCH)),)
72     LDFLAGS+=-L/usr/local/lib
73   endif
74 endif
75
76 ifeq ($(OSARCH),FreeBSD)
77   # -V is understood by BSD Make, not by GNU make.
78   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
79   AST_LIBS+=$(shell if test $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
80   AST_LIBS+=-lcrypto
81 endif
82
83 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
84   AST_LIBS+=-lminires -ldl
85   ASTLINK+=-shared -Wl,--out-implib,libasterisk.a
86 endif
87 ifeq ($(OSARCH),NetBSD)
88   AST_LIBS+=-lpthread -lcrypto -lm -L/usr/pkg/lib $(EDITLINE_LIB)
89 endif
90
91 ifeq ($(OSARCH),OpenBSD)
92   AST_LIBS+=-lcrypto -lpthread -lm $(EDITLINE_LIB)
93 endif
94
95 ifeq ($(OSARCH),SunOS)
96   AST_LIBS+=-lpthread -ldl -lrt -lnsl -lsocket -lresolv
97   ASTSSL_LIBS+=-L/opt/ssl/lib -L/usr/local/ssl/lib
98   ASTLINK=
99 endif
100
101 ifneq ($(findstring USE_HOARD_ALLOCATOR,$(MENUSELECT_CFLAGS)),)
102   ifneq ($(HOARD_LIB),)
103     AST_LIBS+=$(HOARD_LIB)
104   endif
105 endif
106
107 ifeq ($(GNU_LD),1)
108 ASTLINK+=-Wl,--version-script,asterisk.exports
109   ifeq ($(HAVE_DYNAMIC_LIST),1)
110   ASTLINK+=-Wl,--dynamic-list,asterisk.dynamics
111   endif
112 endif
113
114 .PHONY: CHECK_SUBDIR
115 CHECK_SUBDIR:   # do nothing, just make sure that we recurse in the subdir/
116
117 editline/libedit.a: CHECK_SUBDIR
118         cd editline && test -f config.h || CFLAGS="$(PTHREAD_CFLAGS) $(subst $(ASTTOPDIR),../../,$(_ASTCFLAGS:-Werror=) $(ASTCFLAGS))" LDFLAGS="$(_ASTLDFLAGS) $(ASTLDFLAGS)" ./configure --build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM) --with-ncurses=$(NCURSES_DIR) --with-curses=$(CURSES_DIR) --with-termcap=$(TERMCAP_DIR) --with-tinfo=$(TINFO_DIR)
119         $(MAKE) -C editline libedit.a
120
121 ifneq ($(findstring REBUILD_PARSERS,$(MENUSELECT_CFLAGS)),)
122 ast_expr2.c ast_expr2.h: ast_expr2.y
123 else
124 ast_expr2.c ast_expr2.h:
125 endif
126         $(ECHO_PREFIX) echo "   [BISON] $< -> $@"
127         $(CMD_PREFIX) $(BISON) -o $@ -d --name-prefix=ast_yy ast_expr2.y
128
129 ifneq ($(findstring REBUILD_PARSERS,$(MENUSELECT_CFLAGS)),)
130 ast_expr2f.c: ast_expr2.fl
131 else
132 ast_expr2f.c:
133 endif
134         $(ECHO_PREFIX) echo "   [FLEX] $< -> $@"
135         $(CMD_PREFIX) $(FLEX) -o $@ ast_expr2.fl
136         $(CMD_PREFIX) sed 's@#if __STDC_VERSION__ >= 199901L@#if !defined __STDC_VERSION__ || __STDC_VERSION__ >= 199901L@' $@ > $@.fix
137         $(CMD_PREFIX) echo "#include \"asterisk.h\"" > $@
138         $(CMD_PREFIX) echo >> $@
139         $(CMD_PREFIX) cat $@.fix >> $@
140         $(CMD_PREFIX) rm $@.fix
141
142 ast_expr2f.o: _ASTCFLAGS+=-Wno-unused
143 cdr.o: _ASTCFLAGS+=$(AST_NO_FORMAT_TRUNCATION)
144
145 ifneq ($(LIBEDIT_INTERNAL),no)
146 LIBEDIT_OBJ=editline/libedit.a
147 LIBEDIT_INCLUDE=-I. -Ieditline
148 endif
149
150 db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
151 asterisk.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
152 loader.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
153 json.o: _ASTCFLAGS+=$(JANSSON_INCLUDE)
154 bucket.o: _ASTCFLAGS+=$(URIPARSER_INCLUDE)
155 crypt.o: _ASTCFLAGS+=$(CRYPT_INCLUDE)
156 uuid.o: _ASTCFLAGS+=$(UUID_INCLUDE)
157
158 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
159 http.o: _ASTCFLAGS+=$(GMIME_INCLUDE)
160 endif
161
162 stdtime/localtime.o: _ASTCFLAGS+=$(AST_NO_STRICT_OVERFLOW) -Wno-format-nonliteral
163
164 OBJS:=$(sort $(OBJS))
165
166 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
167 MAIN_TGT:=asterisk.dll
168 asterisk: cygload
169         mv cygload.exe asterisk.exe
170
171 cygload: asterisk.dll
172 else
173 MAIN_TGT:=asterisk
174 endif
175
176 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
177 GMIMELDFLAGS+=$(GMIME_LIB)
178 endif
179
180 $(OBJS): _ASTCFLAGS+=-DAST_MODULE=\"core\" -DAST_IN_CORE
181
182 libasteriskssl.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
183
184 ifeq ($(AST_ASTERISKSSL),yes)
185 # The ABI *version* of the asteriskssl library; don't change this unless there truly is a
186 # non-backwards-compatible ABI change in the library
187 ASTSSL_SO_VERSION=1
188
189 ASTSSL_LDLIBS=-L. -lasteriskssl
190
191 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
192 ASTSSL_LIB:=libasteriskssl.so
193
194 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTSSL_LIB).$(ASTSSL_SO_VERSION)
195 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskssl\" -DAST_NOT_MODULE
196 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): LIBS+=$(ASTSSL_LIBS)
197 ifeq ($(GNU_LD),1)
198     $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): SO_SUPPRESS_SYMBOLS=-Wl,--version-script,libasteriskssl.exports,--warn-common
199 endif
200 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): SOLINK=$(DYLINK)
201
202 # These rules are duplicated from $(ASTTOPDIR)/Makefile.rules because the library name
203 # being built does not match the "%.so" pattern; there are also additional steps
204 # required to build a proper shared library (as opposed to the 'loadable module'
205 # type that are built by the standard rules)
206 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): libasteriskssl.o
207 ifeq ($(GNU_LD),1)
208         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script libasteriskssl "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
209 endif
210         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
211         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
212
213 $(ASTSSL_LIB): $(ASTSSL_LIB).$(ASTSSL_SO_VERSION)
214         $(ECHO_PREFIX) echo "   [LN] $< -> $@"
215         $(LN) -sf $< $@ ;\
216
217 else # Darwin
218 ASTSSL_LIB:=libasteriskssl.dylib
219
220 # -install_name allows library to be found if installed somewhere other than
221 # /lib or /usr/lib
222 $(ASTSSL_LIB): _ASTLDFLAGS+=-dynamiclib -install_name $(ASTLIBDIR)/$(ASTSSL_LIB)
223 $(ASTSSL_LIB): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskssl\" -DAST_NOT_MODULE
224 $(ASTSSL_LIB): LIBS+=$(ASTSSL_LIBS)
225 $(ASTSSL_LIB): SOLINK=$(DYLINK)
226
227 # Special rules for building a shared library (not a dynamically loadable module)
228 $(ASTSSL_LIB): libasteriskssl.o
229         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
230         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
231 endif
232
233 endif
234
235 libasteriskpj.o: _ASTCFLAGS+=$(PJPROJECT_INCLUDE)
236
237 ifeq ($(PJPROJECT_BUNDLED),yes)
238
239 ASTPJ_SO_VERSION=2
240 ASTPJ_LDLIBS=-L. -lasteriskpj
241
242 PJDIR=$(ASTTOPDIR)/$(PJPROJECT_DIR)/source
243 -include $(ASTTOPDIR)/$(PJPROJECT_DIR)/build.mak
244
245 PJPROJECT_LDLIBS := \
246 -Wl,--whole-archive \
247 $(PJSUA_LIB_LDLIB) \
248 $(PJSIP_UA_LDLIB) \
249 $(PJSIP_SIMPLE_LDLIB) \
250 $(PJSIP_LDLIB) \
251 $(PJNATH_LDLIB) \
252 $(PJMEDIA_CODEC_LDLIB) \
253 $(PJMEDIA_VIDEODEV_LDLIB) \
254 $(PJMEDIA_AUDIODEV_LDLIB) \
255 $(PJMEDIA_LDLIB) \
256 $(PJLIB_UTIL_LDLIB) \
257 $(PJLIB_LDLIB) \
258 -Wl,--no-whole-archive \
259 $(APP_THIRD_PARTY_LIBS) \
260 $(APP_THIRD_PARTY_EXT)
261
262 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
263 ASTPJ_LIB:=libasteriskpj.so
264
265 libasteriskpj.exports: $(ASTTOPDIR)/$(PJPROJECT_DIR)/pjproject.symbols
266         $(ECHO_PREFIX) echo "   [GENERATE] libasteriskpj.exports"
267 ifeq ($(GNU_LD),1)
268         $(CMD_PREFIX) echo -e "{\nglobal:" > libasteriskpj.exports
269         $(CMD_PREFIX) sed -r -e "s/.*/$(LINKER_SYMBOL_PREFIX)&;/" $(ASTTOPDIR)/$(PJPROJECT_DIR)/pjproject.symbols >> libasteriskpj.exports
270         $(CMD_PREFIX) echo -e "$(LINKER_SYMBOL_PREFIX)ast_pj_init;\n" >> libasteriskpj.exports
271         $(CMD_PREFIX) echo -e "local:\n*;\n};" >> libasteriskpj.exports
272 endif
273
274 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTPJ_LIB).$(ASTPJ_SO_VERSION) $(PJ_LDFLAGS)
275 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskpj\" -DAST_NOT_MODULE $(PJ_CFLAGS)
276 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): LIBS+=$(PJPROJECT_LDLIBS) -lssl -lcrypto -luuid -lm -lpthread $(RT_LIB)
277 ifeq ($(GNU_LD),1)
278     $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): SO_SUPPRESS_SYMBOLS=-Wl,--version-script,libasteriskpj.exports,--warn-common
279 endif
280 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): SOLINK=$(DYLINK)
281
282 # These rules are duplicated from $(ASTTOPDIR)/Makefile.rules because the library name
283 # being built does not match the "%.so" pattern; there are also additional steps
284 # required to build a proper shared library (as opposed to the 'loadable module'
285 # type that are built by the standard rules)
286 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): libasteriskpj.o libasteriskpj.exports
287         $(ECHO_PREFIX) echo "   [LD] $< -> $@"
288         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $< $(CC_LIBS)
289
290 $(ASTPJ_LIB): $(ASTPJ_LIB).$(ASTPJ_SO_VERSION)
291         $(ECHO_PREFIX) echo "   [LN] $< -> $@"
292         $(LN) -sf $< $@ ;\
293
294 else # Darwin
295 ASTPJ_LIB:=libasteriskpj.dylib
296
297 # -install_name allows library to be found if installed somewhere other than
298 # /lib or /usr/lib
299 $(ASTPJ_LIB): _ASTLDFLAGS+=-dynamiclib -install_name $(ASTLIBDIR)/$(ASTPJ_LIB) $(PJ_LDFLAGS)
300 $(ASTPJ_LIB): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskpj\" $(PJ_CFLAGS) -DAST_NOT_MODULE
301 $(ASTPJ_LIB): LIBS+=$(PJPROJECT_LIBS)  -lssl -lcrypto -luuid -lm -lpthread $(RT_LIB)
302 $(ASTPJ_LIB): SOLINK=$(DYLINK)
303
304 # Special rules for building a shared library (not a dynamically loadable module)
305 $(ASTPJ_LIB): libasteriskpj.o
306         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
307         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
308 endif
309
310 endif
311
312 tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE) -Wno-deprecated-declarations
313
314 $(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB) $(LIBEDIT_OBJ)
315         @$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS)
316         $(ECHO_PREFIX) echo "   [LD] $(OBJS) $(LIBEDIT_OBJ) -> $@"
317         $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(ASTPJ_LDLIBS) $(LIBEDIT_OBJ) buildinfo.o $(AST_LIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)
318
319 ifeq ($(GNU_LD),1)
320 $(MAIN_TGT): asterisk.exports
321 asterisk.exports: asterisk.exports.in
322         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script asterisk $(LINKER_SYMBOL_PREFIX)
323 endif
324
325 bininstall:
326         $(INSTALL) -m 755 $(MAIN_TGT) "$(DESTDIR)$(ASTSBINDIR)/"
327 ifeq ($(AST_ASTERISKSSL),yes)
328 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
329         $(INSTALL) -m 755 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/"
330         $(LN) -sf $(ASTSSL_LIB).$(ASTSSL_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/$(ASTSSL_LIB)"
331 else # Darwin
332         $(INSTALL) -m 755 $(ASTSSL_LIB) "$(DESTDIR)$(ASTLIBDIR)/"
333 endif
334 endif
335 ifeq ($(PJPROJECT_BUNDLED),yes)
336 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
337         $(INSTALL) -m 755 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/"
338         $(LN) -sf $(ASTPJ_LIB).$(ASTPJ_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/$(ASTPJ_LIB)"
339 else # Darwin
340         $(INSTALL) -m 755 $(ASTPJ_LIB) "$(DESTDIR)$(ASTLIBDIR)/"
341 endif
342 endif
343         $(LN) -sf asterisk "$(DESTDIR)$(ASTSBINDIR)/rasterisk"
344
345 binuninstall:
346         rm -f "$(DESTDIR)$(ASTSBINDIR)/$(MAIN_TGT)"
347         rm -f "$(DESTDIR)$(ASTSBINDIR)/rasterisk"
348         rm -f "$(DESTDIR)$(ASTLIBDIR)/libasterisk"* || :
349         test -n "$(_oldlibdir)" -a -d "$(_oldlibdir)" && rm -f "$(_oldlibdir)/libasterisk"* || :
350
351 clean::
352         rm -f asterisk libasteriskssl.o
353 ifeq ($(AST_ASTERISKSSL),yes)
354         rm -f $(ASTSSL_LIB) $(ASTSSL_LIB).*
355 endif
356         rm -f libasteriskpj.o
357         rm -f libasteriskpj.so* libasteriskpj.dynlib
358         rm -f .libasteriskpj*
359
360         rm -f asterisk.exports libasteriskssl.exports libasteriskpj.exports
361         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
362         @$(MAKE) -C stdtime clean
363         rm -f libresample/src/*.o
364         rm -f *.tmp