Makefile 12 KB

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