PJPROJECT logging: Made easier to get available logging levels.
[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.embed_rules $(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   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
52   AST_LIBS+=-ldl
53   endif
54   ifneq (x$(CAP_LIB),x)
55     AST_LIBS+=$(CAP_LIB)
56   endif
57   AST_LIBS+=-lpthread $(EDITLINE_LIB) -lm -lresolv
58 else
59   AST_LIBS+=$(EDITLINE_LIB) -lm
60 endif
61
62 ifneq ($(findstring BETTER_BACKTRACES,$(MENUSELECT_CFLAGS)),)
63   AST_LIBS+=$(BFD_LIB)
64 endif
65
66 ifneq ($(findstring darwin,$(OSARCH)),)
67   AST_LIBS+=-lresolv
68   ASTLINK=-mmacosx-version-min=10.6 -Wl,-undefined,dynamic_lookup -force_flat_namespace
69   ASTLINK+=/usr/lib/bundle1.o
70 else
71 # These are used for all but Darwin
72   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
73     ASTLINK+=-Wl,--export-dynamic
74   else
75     ASTLINK+=${GC_LDFLAGS}
76   endif
77   ifneq ($(findstring BSD,$(OSARCH)),)
78     LDFLAGS+=-L/usr/local/lib
79   endif
80 endif
81
82 ifeq ($(OSARCH),FreeBSD)
83   # -V is understood by BSD Make, not by GNU make.
84   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
85   AST_LIBS+=$(shell if test $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
86   AST_LIBS+=-lcrypto
87 endif
88
89 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
90   AST_LIBS+=-lminires -ldl
91   ASTLINK+=-shared -Wl,--out-implib,libasterisk.a
92 endif
93 ifeq ($(OSARCH),NetBSD)
94   AST_LIBS+=-lpthread -lcrypto -lm -L/usr/pkg/lib $(EDITLINE_LIB)
95 endif
96
97 ifeq ($(OSARCH),OpenBSD)
98   AST_LIBS+=-lcrypto -lpthread -lm $(EDITLINE_LIB)
99 endif
100
101 ifeq ($(OSARCH),SunOS)
102   AST_LIBS+=-lpthread -ldl -lrt -lnsl -lsocket -lresolv
103   ASTSSL_LIBS+=-L/opt/ssl/lib -L/usr/local/ssl/lib
104   ASTLINK=
105 endif
106
107 ifneq ($(findstring USE_HOARD_ALLOCATOR,$(MENUSELECT_CFLAGS)),)
108   ifneq ($(HOARD_LIB),)
109     AST_LIBS+=$(HOARD_LIB)
110   endif
111 endif
112
113 ifeq ($(GNU_LD),1)
114 ASTLINK+=-Wl,--version-script,asterisk.exports
115   ifeq ($(HAVE_DYNAMIC_LIST),1)
116   ASTLINK+=-Wl,--dynamic-list,asterisk.dynamics
117   endif
118 endif
119
120 .PHONY: CHECK_SUBDIR
121 CHECK_SUBDIR:   # do nothing, just make sure that we recurse in the subdir/
122
123 editline/libedit.a: CHECK_SUBDIR
124         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)
125         $(MAKE) -C editline libedit.a
126
127 ifneq ($(findstring REBUILD_PARSERS,$(MENUSELECT_CFLAGS)),)
128 ast_expr2.c ast_expr2.h: ast_expr2.y
129 else
130 ast_expr2.c ast_expr2.h:
131 endif
132         $(ECHO_PREFIX) echo "   [BISON] $< -> $@"
133         $(CMD_PREFIX) $(BISON) -o $@ -d --name-prefix=ast_yy ast_expr2.y
134
135 ifneq ($(findstring REBUILD_PARSERS,$(MENUSELECT_CFLAGS)),)
136 ast_expr2f.c: ast_expr2.fl
137 else
138 ast_expr2f.c:
139 endif
140         $(ECHO_PREFIX) echo "   [FLEX] $< -> $@"
141         $(CMD_PREFIX) $(FLEX) -o $@ ast_expr2.fl
142         $(CMD_PREFIX) sed 's@#if __STDC_VERSION__ >= 199901L@#if !defined __STDC_VERSION__ || __STDC_VERSION__ >= 199901L@' $@ > $@.fix
143         $(CMD_PREFIX) echo "#include \"asterisk.h\"" > $@
144         $(CMD_PREFIX) echo >> $@
145         $(CMD_PREFIX) cat $@.fix >> $@
146         $(CMD_PREFIX) rm $@.fix
147
148 ast_expr2f.o: _ASTCFLAGS+=-Wno-unused
149
150 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
151         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2f.c
152         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2.c
153         $(CC) -g -o testexpr2 ast_expr2f.o ast_expr2.o -lm
154         rm ast_expr2.o ast_expr2f.o
155
156 ifneq ($(LIBEDIT_INTERNAL),no)
157 LIBEDIT_OBJ=editline/libedit.a
158 LIBEDIT_INCLUDE=-I. -Ieditline
159 endif
160
161 db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
162 asterisk.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
163 cli.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
164 json.o: _ASTCFLAGS+=$(JANSSON_INCLUDE)
165 bucket.o: _ASTCFLAGS+=$(URIPARSER_INCLUDE)
166 crypt.o: _ASTCFLAGS+=$(CRYPT_INCLUDE)
167 uuid.o: _ASTCFLAGS+=$(UUID_INCLUDE)
168
169 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
170 http.o: _ASTCFLAGS+=$(GMIME_INCLUDE)
171 endif
172
173 stdtime/localtime.o: _ASTCFLAGS+=$(AST_NO_STRICT_OVERFLOW) -Wno-format-nonliteral
174
175 AST_EMBED_LDSCRIPTS:=$(sort $(EMBED_LDSCRIPTS))
176 AST_EMBED_LDFLAGS:=$(foreach dep,$(EMBED_LDFLAGS),$(value $(dep)))
177 AST_EMBED_LIBS:=$(foreach dep,$(EMBED_LIBS),$(value $(dep)))
178 OBJS:=$(sort $(OBJS))
179
180 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
181 MAIN_TGT:=asterisk.dll
182 asterisk: cygload
183         mv cygload.exe asterisk.exe
184
185 cygload: asterisk.dll
186 else
187 MAIN_TGT:=asterisk
188 endif
189
190 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
191 GMIMELDFLAGS+=$(GMIME_LIB)
192 endif
193
194 $(OBJS): _ASTCFLAGS+=-DAST_MODULE=\"core\" -DAST_IN_CORE
195
196 libasteriskssl.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
197
198 ifeq ($(AST_ASTERISKSSL),yes)
199 # The ABI *version* of the asteriskssl library; don't change this unless there truly is a
200 # non-backwards-compatible ABI change in the library
201 ASTSSL_SO_VERSION=1
202
203 ASTSSL_LDLIBS=-L. -lasteriskssl
204
205 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
206 ASTSSL_LIB:=libasteriskssl.so
207
208 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTSSL_LIB)
209 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskssl\" -DAST_NOT_MODULE
210 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): LIBS+=$(ASTSSL_LIBS)
211 ifeq ($(GNU_LD),1)
212     $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): SO_SUPPRESS_SYMBOLS=-Wl,--version-script,libasteriskssl.exports,--warn-common
213 endif
214 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): SOLINK=$(DYLINK)
215
216 # These rules are duplicated from $(ASTTOPDIR)/Makefile.rules because the library name
217 # being built does not match the "%.so" pattern; there are also additional steps
218 # required to build a proper shared library (as opposed to the 'loadable module'
219 # type that are built by the standard rules)
220 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): libasteriskssl.o
221 ifeq ($(GNU_LD),1)
222         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script libasteriskssl "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
223 endif
224         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
225         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
226
227 $(ASTSSL_LIB): $(ASTSSL_LIB).$(ASTSSL_SO_VERSION)
228         $(ECHO_PREFIX) echo "   [LN] $< -> $@"
229         $(LN) -sf $< $@ ;\
230
231 else # Darwin
232 ASTSSL_LIB:=libasteriskssl.dylib
233
234 # -install_name allows library to be found if installed somewhere other than
235 # /lib or /usr/lib
236 $(ASTSSL_LIB): _ASTLDFLAGS+=-dynamiclib -install_name $(ASTLIBDIR)/$(ASTSSL_LIB)
237 $(ASTSSL_LIB): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskssl\" -DAST_NOT_MODULE
238 $(ASTSSL_LIB): LIBS+=$(ASTSSL_LIBS)
239 $(ASTSSL_LIB): SOLINK=$(DYLINK)
240
241 # Special rules for building a shared library (not a dynamically loadable module)
242 $(ASTSSL_LIB): libasteriskssl.o
243         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
244         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
245 endif
246
247 endif
248
249 libasteriskpj.o: _ASTCFLAGS+=$(PJPROJECT_INCLUDE)
250
251 ifeq ($(PJPROJECT_BUNDLED),yes)
252
253 ASTPJ_SO_VERSION=2
254 ASTPJ_LDLIBS=-L. -lasteriskpj
255
256 PJDIR=$(ASTTOPDIR)/$(PJPROJECT_DIR)/source
257 -include $(ASTTOPDIR)/$(PJPROJECT_DIR)/build.mak
258
259 PJPROJECT_LDLIBS := \
260 -Wl,--whole-archive \
261 $(PJSUA_LIB_LDLIB) \
262 $(PJSIP_UA_LDLIB) \
263 $(PJSIP_SIMPLE_LDLIB) \
264 $(PJSIP_LDLIB) \
265 $(PJNATH_LDLIB) \
266 $(PJMEDIA_CODEC_LDLIB) \
267 $(PJMEDIA_VIDEODEV_LDLIB) \
268 $(PJMEDIA_AUDIODEV_LDLIB) \
269 $(PJMEDIA_LDLIB) \
270 $(PJLIB_UTIL_LDLIB) \
271 $(PJLIB_LDLIB) \
272 -Wl,--no-whole-archive \
273 $(APP_THIRD_PARTY_LIBS) \
274 $(APP_THIRD_PARTY_EXT)
275
276 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
277 ASTPJ_LIB:=libasteriskpj.so
278
279 libasteriskpj.exports: $(ASTTOPDIR)/$(PJPROJECT_DIR)/pjproject.symbols
280         $(ECHO_PREFIX) echo "   [GENERATE] libasteriskpj.exports"
281 ifeq ($(GNU_LD),1)
282         $(CMD_PREFIX) echo -e "{\nglobal:" > libasteriskpj.exports
283         $(CMD_PREFIX) sed -r -e "s/.*/$(LINKER_SYMBOL_PREFIX)&;/" $(ASTTOPDIR)/$(PJPROJECT_DIR)/pjproject.symbols >> libasteriskpj.exports
284         $(CMD_PREFIX) echo -e "$(LINKER_SYMBOL_PREFIX)ast_pj_init;\n" >> libasteriskpj.exports
285         $(CMD_PREFIX) echo -e "local:\n*;\n};" >> libasteriskpj.exports
286 endif
287
288 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTPJ_LIB) $(PJ_LDFLAGS)
289 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskpj\" -DAST_NOT_MODULE $(PJ_CFLAGS)
290 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): LIBS+=$(PJPROJECT_LDLIBS) -lssl -lcrypto -luuid -lm -lpthread $(RT_LIB)
291 ifeq ($(GNU_LD),1)
292     $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): SO_SUPPRESS_SYMBOLS=-Wl,--version-script,libasteriskpj.exports,--warn-common
293 endif
294 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): SOLINK=$(DYLINK)
295
296 # These rules are duplicated from $(ASTTOPDIR)/Makefile.rules because the library name
297 # being built does not match the "%.so" pattern; there are also additional steps
298 # required to build a proper shared library (as opposed to the 'loadable module'
299 # type that are built by the standard rules)
300 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): libasteriskpj.o libasteriskpj.exports
301         $(ECHO_PREFIX) echo "   [LD] $< -> $@"
302         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $< $(CC_LIBS)
303
304 $(ASTPJ_LIB): $(ASTPJ_LIB).$(ASTPJ_SO_VERSION)
305         $(ECHO_PREFIX) echo "   [LN] $< -> $@"
306         $(LN) -sf $< $@ ;\
307
308 else # Darwin
309 ASTPJ_LIB:=libasteriskpj.dylib
310
311 # -install_name allows library to be found if installed somewhere other than
312 # /lib or /usr/lib
313 $(ASTPJ_LIB): _ASTLDFLAGS+=-dynamiclib -install_name $(ASTLIBDIR)/$(ASTPJ_LIB) $(PJ_LDFLAGS)
314 $(ASTPJ_LIB): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskpj\" $(PJ_CFLAGS) -DAST_NOT_MODULE
315 $(ASTPJ_LIB): LIBS+=$(PJPROJECT_LIBS)  -lssl -lcrypto -luuid -lm -lpthread $(RT_LIB)
316 $(ASTPJ_LIB): SOLINK=$(DYLINK)
317
318 # Special rules for building a shared library (not a dynamically loadable module)
319 $(ASTPJ_LIB): libasteriskpj.o
320         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
321         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
322 endif
323
324 endif
325
326 tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
327
328 $(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS)
329         @$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS)
330         $(ECHO_PREFIX) echo "   [LD] $(OBJS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) -> $@"
331         $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(ASTPJ_LDLIBS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)
332
333 ifeq ($(GNU_LD),1)
334 $(MAIN_TGT): asterisk.exports
335 asterisk.exports: asterisk.exports.in
336         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script asterisk $(LINKER_SYMBOL_PREFIX)
337 endif
338
339 bininstall:
340         $(INSTALL) -m 755 $(MAIN_TGT) "$(DESTDIR)$(ASTSBINDIR)/"
341 ifeq ($(AST_ASTERISKSSL),yes)
342 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
343         $(INSTALL) -m 755 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/"
344         $(LN) -sf $(ASTSSL_LIB).$(ASTSSL_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/$(ASTSSL_LIB)"
345 else # Darwin
346         $(INSTALL) -m 755 $(ASTSSL_LIB) "$(DESTDIR)$(ASTLIBDIR)/"
347 endif
348 endif
349 ifeq ($(PJPROJECT_BUNDLED),yes)
350 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
351         $(INSTALL) -m 755 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/"
352         $(LN) -sf $(ASTPJ_LIB).$(ASTPJ_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/$(ASTPJ_LIB)"
353 else # Darwin
354         $(INSTALL) -m 755 $(ASTPJ_LIB) "$(DESTDIR)$(ASTLIBDIR)/"
355 endif
356 endif
357 ifneq ($(LDCONFIG),)
358         $(LDCONFIG) $(LDCONFIG_FLAGS) "$(DESTDIR)$(ASTLIBDIR)/"
359 endif
360         $(LN) -sf asterisk "$(DESTDIR)$(ASTSBINDIR)/rasterisk"
361
362 binuninstall:
363         rm -f "$(DESTDIR)$(ASTSBINDIR)/$(MAIN_TGT)"
364         rm -f "$(DESTDIR)$(ASTSBINDIR)/rasterisk"
365 ifneq ($(ASTSSL_LIB).$(ASTSSL_SO_VERSION),.)
366         rm -f "$(DESTDIR)$(ASTLIBDIR)/$(ASTSSL_LIB).$(ASTSSL_SO_VERSION)"
367 endif
368 ifneq ($(ASTPJ_LIB).$(ASTPJ_SO_VERSION),.)
369         rm -f "$(DESTDIR)$(ASTLIBDIR)/$(ASTPJ_LIB).$(ASTPJ_SO_VERSION)"
370 endif
371 ifneq ($(LDCONFIG),)
372         $(LDCONFIG) $(LDCONFIG_FLAGS) "$(DESTDIR)$(ASTLIBDIR)/"
373 endif
374
375 clean::
376         rm -f asterisk libasteriskssl.o
377 ifeq ($(AST_ASTERISKSSL),yes)
378         rm -f $(ASTSSL_LIB) $(ASTSSL_LIB).*
379 endif
380         rm -f libasteriskpj.o
381         rm -f libasteriskpj.so* libasteriskpj.dynlib
382         rm -f .libasteriskpj*
383
384         rm -f asterisk.exports libasteriskssl.exports libasteriskpj.exports
385         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
386         @$(MAKE) -C stdtime clean
387         rm -f libresample/src/*.o
388         rm -f *.tmp