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