cd553cb0dd220086f094313b1b18e70507bc2b8d
[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
144 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
145         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2f.c
146         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2.c
147         $(CC) -g -o testexpr2 ast_expr2f.o ast_expr2.o -lm
148         rm ast_expr2.o ast_expr2f.o
149
150 ifneq ($(LIBEDIT_INTERNAL),no)
151 LIBEDIT_OBJ=editline/libedit.a
152 LIBEDIT_INCLUDE=-I. -Ieditline
153 endif
154
155 db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
156 asterisk.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
157 cli.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
158 json.o: _ASTCFLAGS+=$(JANSSON_INCLUDE)
159 bucket.o: _ASTCFLAGS+=$(URIPARSER_INCLUDE)
160 crypt.o: _ASTCFLAGS+=$(CRYPT_INCLUDE)
161 uuid.o: _ASTCFLAGS+=$(UUID_INCLUDE)
162
163 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
164 http.o: _ASTCFLAGS+=$(GMIME_INCLUDE)
165 endif
166
167 stdtime/localtime.o: _ASTCFLAGS+=$(AST_NO_STRICT_OVERFLOW) -Wno-format-nonliteral
168
169 OBJS:=$(sort $(OBJS))
170
171 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
172 MAIN_TGT:=asterisk.dll
173 asterisk: cygload
174         mv cygload.exe asterisk.exe
175
176 cygload: asterisk.dll
177 else
178 MAIN_TGT:=asterisk
179 endif
180
181 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
182 GMIMELDFLAGS+=$(GMIME_LIB)
183 endif
184
185 $(OBJS): _ASTCFLAGS+=-DAST_MODULE=\"core\" -DAST_IN_CORE
186
187 libasteriskssl.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
188
189 ifeq ($(AST_ASTERISKSSL),yes)
190 # The ABI *version* of the asteriskssl library; don't change this unless there truly is a
191 # non-backwards-compatible ABI change in the library
192 ASTSSL_SO_VERSION=1
193
194 ASTSSL_LDLIBS=-L. -lasteriskssl
195
196 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
197 ASTSSL_LIB:=libasteriskssl.so
198
199 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTSSL_LIB).$(ASTSSL_SO_VERSION)
200 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskssl\" -DAST_NOT_MODULE
201 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): LIBS+=$(ASTSSL_LIBS)
202 ifeq ($(GNU_LD),1)
203     $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): SO_SUPPRESS_SYMBOLS=-Wl,--version-script,libasteriskssl.exports,--warn-common
204 endif
205 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): SOLINK=$(DYLINK)
206
207 # These rules are duplicated from $(ASTTOPDIR)/Makefile.rules because the library name
208 # being built does not match the "%.so" pattern; there are also additional steps
209 # required to build a proper shared library (as opposed to the 'loadable module'
210 # type that are built by the standard rules)
211 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): libasteriskssl.o
212 ifeq ($(GNU_LD),1)
213         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script libasteriskssl "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
214 endif
215         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
216         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
217
218 $(ASTSSL_LIB): $(ASTSSL_LIB).$(ASTSSL_SO_VERSION)
219         $(ECHO_PREFIX) echo "   [LN] $< -> $@"
220         $(LN) -sf $< $@ ;\
221
222 else # Darwin
223 ASTSSL_LIB:=libasteriskssl.dylib
224
225 # -install_name allows library to be found if installed somewhere other than
226 # /lib or /usr/lib
227 $(ASTSSL_LIB): _ASTLDFLAGS+=-dynamiclib -install_name $(ASTLIBDIR)/$(ASTSSL_LIB)
228 $(ASTSSL_LIB): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskssl\" -DAST_NOT_MODULE
229 $(ASTSSL_LIB): LIBS+=$(ASTSSL_LIBS)
230 $(ASTSSL_LIB): SOLINK=$(DYLINK)
231
232 # Special rules for building a shared library (not a dynamically loadable module)
233 $(ASTSSL_LIB): libasteriskssl.o
234         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
235         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
236 endif
237
238 endif
239
240 libasteriskpj.o: _ASTCFLAGS+=$(PJPROJECT_INCLUDE)
241
242 ifeq ($(PJPROJECT_BUNDLED),yes)
243
244 ASTPJ_SO_VERSION=2
245 ASTPJ_LDLIBS=-L. -lasteriskpj
246
247 PJDIR=$(ASTTOPDIR)/$(PJPROJECT_DIR)/source
248 -include $(ASTTOPDIR)/$(PJPROJECT_DIR)/build.mak
249
250 PJPROJECT_LDLIBS := \
251 -Wl,--whole-archive \
252 $(PJSUA_LIB_LDLIB) \
253 $(PJSIP_UA_LDLIB) \
254 $(PJSIP_SIMPLE_LDLIB) \
255 $(PJSIP_LDLIB) \
256 $(PJNATH_LDLIB) \
257 $(PJMEDIA_CODEC_LDLIB) \
258 $(PJMEDIA_VIDEODEV_LDLIB) \
259 $(PJMEDIA_AUDIODEV_LDLIB) \
260 $(PJMEDIA_LDLIB) \
261 $(PJLIB_UTIL_LDLIB) \
262 $(PJLIB_LDLIB) \
263 -Wl,--no-whole-archive \
264 $(APP_THIRD_PARTY_LIBS) \
265 $(APP_THIRD_PARTY_EXT)
266
267 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
268 ASTPJ_LIB:=libasteriskpj.so
269
270 libasteriskpj.exports: $(ASTTOPDIR)/$(PJPROJECT_DIR)/pjproject.symbols
271         $(ECHO_PREFIX) echo "   [GENERATE] libasteriskpj.exports"
272 ifeq ($(GNU_LD),1)
273         $(CMD_PREFIX) echo -e "{\nglobal:" > libasteriskpj.exports
274         $(CMD_PREFIX) sed -r -e "s/.*/$(LINKER_SYMBOL_PREFIX)&;/" $(ASTTOPDIR)/$(PJPROJECT_DIR)/pjproject.symbols >> libasteriskpj.exports
275         $(CMD_PREFIX) echo -e "$(LINKER_SYMBOL_PREFIX)ast_pj_init;\n" >> libasteriskpj.exports
276         $(CMD_PREFIX) echo -e "local:\n*;\n};" >> libasteriskpj.exports
277 endif
278
279 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTPJ_LIB).$(ASTPJ_SO_VERSION) $(PJ_LDFLAGS)
280 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskpj\" -DAST_NOT_MODULE $(PJ_CFLAGS)
281 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): LIBS+=$(PJPROJECT_LDLIBS) -lssl -lcrypto -luuid -lm -lpthread $(RT_LIB)
282 ifeq ($(GNU_LD),1)
283     $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): SO_SUPPRESS_SYMBOLS=-Wl,--version-script,libasteriskpj.exports,--warn-common
284 endif
285 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): SOLINK=$(DYLINK)
286
287 # These rules are duplicated from $(ASTTOPDIR)/Makefile.rules because the library name
288 # being built does not match the "%.so" pattern; there are also additional steps
289 # required to build a proper shared library (as opposed to the 'loadable module'
290 # type that are built by the standard rules)
291 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): libasteriskpj.o libasteriskpj.exports
292         $(ECHO_PREFIX) echo "   [LD] $< -> $@"
293         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $< $(CC_LIBS)
294
295 $(ASTPJ_LIB): $(ASTPJ_LIB).$(ASTPJ_SO_VERSION)
296         $(ECHO_PREFIX) echo "   [LN] $< -> $@"
297         $(LN) -sf $< $@ ;\
298
299 else # Darwin
300 ASTPJ_LIB:=libasteriskpj.dylib
301
302 # -install_name allows library to be found if installed somewhere other than
303 # /lib or /usr/lib
304 $(ASTPJ_LIB): _ASTLDFLAGS+=-dynamiclib -install_name $(ASTLIBDIR)/$(ASTPJ_LIB) $(PJ_LDFLAGS)
305 $(ASTPJ_LIB): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskpj\" $(PJ_CFLAGS) -DAST_NOT_MODULE
306 $(ASTPJ_LIB): LIBS+=$(PJPROJECT_LIBS)  -lssl -lcrypto -luuid -lm -lpthread $(RT_LIB)
307 $(ASTPJ_LIB): SOLINK=$(DYLINK)
308
309 # Special rules for building a shared library (not a dynamically loadable module)
310 $(ASTPJ_LIB): libasteriskpj.o
311         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
312         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
313 endif
314
315 endif
316
317 tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
318
319 $(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB) $(LIBEDIT_OBJ)
320         @$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS)
321         $(ECHO_PREFIX) echo "   [LD] $(OBJS) $(LIBEDIT_OBJ) -> $@"
322         $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(ASTPJ_LDLIBS) $(LIBEDIT_OBJ) buildinfo.o $(AST_LIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)
323
324 ifeq ($(GNU_LD),1)
325 $(MAIN_TGT): asterisk.exports
326 asterisk.exports: asterisk.exports.in
327         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script asterisk $(LINKER_SYMBOL_PREFIX)
328 endif
329
330 bininstall:
331         $(INSTALL) -m 755 $(MAIN_TGT) "$(DESTDIR)$(ASTSBINDIR)/"
332 ifeq ($(AST_ASTERISKSSL),yes)
333 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
334         $(INSTALL) -m 755 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/"
335         $(LN) -sf $(ASTSSL_LIB).$(ASTSSL_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/$(ASTSSL_LIB)"
336 else # Darwin
337         $(INSTALL) -m 755 $(ASTSSL_LIB) "$(DESTDIR)$(ASTLIBDIR)/"
338 endif
339 endif
340 ifeq ($(PJPROJECT_BUNDLED),yes)
341 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
342         $(INSTALL) -m 755 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/"
343         $(LN) -sf $(ASTPJ_LIB).$(ASTPJ_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/$(ASTPJ_LIB)"
344 else # Darwin
345         $(INSTALL) -m 755 $(ASTPJ_LIB) "$(DESTDIR)$(ASTLIBDIR)/"
346 endif
347 endif
348         $(LN) -sf asterisk "$(DESTDIR)$(ASTSBINDIR)/rasterisk"
349
350 binuninstall:
351         rm -f "$(DESTDIR)$(ASTSBINDIR)/$(MAIN_TGT)"
352         rm -f "$(DESTDIR)$(ASTSBINDIR)/rasterisk"
353         rm -f "$(DESTDIR)$(ASTLIBDIR)/libasterisk"* || :
354         rm -f "$(subst lib64,lib,$(DESTDIR)$(ASTLIBDIR))/libasterisk"* || :
355
356 clean::
357         rm -f asterisk libasteriskssl.o
358 ifeq ($(AST_ASTERISKSSL),yes)
359         rm -f $(ASTSSL_LIB) $(ASTSSL_LIB).*
360 endif
361         rm -f libasteriskpj.o
362         rm -f libasteriskpj.so* libasteriskpj.dynlib
363         rm -f .libasteriskpj*
364
365         rm -f asterisk.exports libasteriskssl.exports libasteriskpj.exports
366         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
367         @$(MAKE) -C stdtime clean
368         rm -f libresample/src/*.o
369         rm -f *.tmp