From 3173e91bab9edca6b1d6eba499aefa18edb3d993 Mon Sep 17 00:00:00 2001 From: George Joseph Date: Mon, 18 Jan 2016 20:54:28 -0700 Subject: build-system: Allow building with static pjproject Background here: http://lists.digium.com/pipermail/asterisk-dev/2016-January/075266.html From CHANGES: * To help insure that Asterisk is compiled and run with the same known version of pjproject, a new option (--with-pjproject-bundled) has been added to ./configure. When specified, the version of pjproject specified in third-party/versions.mak will be downloaded and configured. When you make Asterisk, the build process will also automatically build pjproject and Asterisk will be statically linked to it. Once a particular version of pjproject is configured and built, it won't be configured or built again unless you run a 'make distclean'. To facilitate testing, when 'make install' is run, the pjsua and pjsystest utilities and the pjproject python bindings will be installed in ASTDATADIR/third-party/pjproject. The default behavior remains building with the shared pjproject installation, if any. Building: All you have to do is include the --with-pjproject-bundled option on the ./configure command line (and remove any existing --with-pjproject option if specified). Everything else is automatic. Behind the scenes: The top-level Makefile was modified to include 'third-party' in the list of MOD_SUBDIRS. The third-party directory was created to contain any third party packages that may be needed in the future. Its Makefile automatically iterates over any subdirectories passing on targets. The third-party/pjproject directory was created to house the pjproject source distribution. Its Makefile contains targets to download, patch configure, generate dependencies, compile libs, apps and python bindings, sanitized build.mak and generate a symbols list. When bootstrap.sh is run, it automatically includes the configure.m4 file in third-party/pjproject. This file has a macro to download and conifgure pjproject and get and set PJPROJECT_INCLUDE, PJPROJECT_DIR and PJPROJECT_BUNDLED. It also tests for the capabilities like PJ_TRANSACTION_GRP_LOCK by parsing preprocessor output as opposed to trying to compile. Of course, bootstrap.sh is only run once and the configure file is incldued in the patch. When configure is run with the new options, the macro in configure.m4 triggers the download, patch, conifgure and tests. No compilation is performed at this time. The downloaded tarball is cached in /tmp so it doesn't get downloaded again on a distclean. When make is run in the top-level Asterisk source directory, it will automatically descend all the subdirectories in third_party just as it does for addons, apps, etc. The top-level Makefile makes sure that the 'third-party' is built before 'main' so that dependencies from the other directories are built first. When main does build, a new shared library (libasteriskpj) is created that links statically to the pjproject .a files and exports all their symbols. The asterisk binary links to that, just as it does with libasteriskssl. When Asterisk is installed, the pjsua and pjsystest apps, and the pjproject python bindings are installed in ASTDATADIR/third-party/pjproject. This will facilitate testing, including running the testsuite which will be updated to check that directory for the pjsua module ahead of the system python library. Modules should continue to depend on pjproject if they use pjproject APIs directly. They should not care about the implementation. No changes to any res_pjsip modules were made. Change-Id: Ia7a60c28c2e9ba9537c5570f933c1ebcb20a3103 --- main/.gitignore | 2 + main/Makefile | 121 +++++++++++++++++++++++++++++++++++++++++++++++---- main/asterisk.c | 5 +++ main/libasteriskpj.c | 52 ++++++++++++++++++++++ 4 files changed, 171 insertions(+), 9 deletions(-) create mode 100644 main/libasteriskpj.c (limited to 'main') diff --git a/main/.gitignore b/main/.gitignore index 3ff465679..cb90a5e3b 100644 --- a/main/.gitignore +++ b/main/.gitignore @@ -1,4 +1,6 @@ asterisk libasteriskssl.so.1 libasteriskssl.dylib +libasteriskpj.so.2 +libasteriskpj.dylib version.c diff --git a/main/Makefile b/main/Makefile index b25fb450a..50fdc5739 100644 --- a/main/Makefile +++ b/main/Makefile @@ -22,6 +22,9 @@ SRC:=$(wildcard *.c) ast_expr2.c ast_expr2f.c ifeq ($(AST_ASTERISKSSL),yes) SRC:=$(filter-out libasteriskssl.c,$(SRC)) endif +ifeq ($(PJPROJECT_BUNDLED),yes) +SRC:=$(filter-out libasteriskpj.c,$(SRC)) +endif OBJSFILTER=fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o OBJS=$(filter-out $(OBJSFILTER),$(SRC:.c=.o)) @@ -201,7 +204,7 @@ ASTSSL_LDLIBS=-L. -lasteriskssl ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin ASTSSL_LIB:=libasteriskssl.so -$(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTSSL_LIB).$(ASTSSL_SO_VERSION) +$(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTSSL_LIB) $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskssl\" -DAST_NOT_MODULE $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): LIBS+=$(ASTSSL_LIBS) ifeq ($(GNU_LD),1) @@ -219,12 +222,14 @@ ifeq ($(GNU_LD),1) endif $(ECHO_PREFIX) echo " [LD] $^ -> $@" $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS) -ifneq ($(LDCONFIG),) - $(LDCONFIG) $(LDCONFIG_FLAGS) . -endif $(ASTSSL_LIB): $(ASTSSL_LIB).$(ASTSSL_SO_VERSION) - $(LN) -sf $< $@ + $(ECHO_PREFIX) echo " [LN] $< -> $@" +ifneq ($(LDCONFIG),) + $(CMD_PREFIX) $(LDCONFIG) $(LDCONFIG_FLAGS) . 2>/dev/null +else + $(CMD_PREFIX) $(LN) -sf $< $@ +endif else # Darwin ASTSSL_LIB:=libasteriskssl.dylib @@ -244,12 +249,92 @@ endif endif +libasteriskpj.o: _ASTCFLAGS+=$(PJPROJECT_INCLUDE) + +ifeq ($(PJPROJECT_BUNDLED),yes) + +ASTPJ_SO_VERSION=2 +ASTPJ_LDLIBS=-L. -lasteriskpj + +-include $(ASTTOPDIR)/$(PJPROJECT_DIR)/build.mak + +PJPROJECT_LDLIBS := \ +-Wl,--whole-archive \ +$(PJSUA_LIB_LDLIB) \ +$(PJSIP_UA_LDLIB) \ +$(PJSIP_SIMPLE_LDLIB) \ +$(PJSIP_LDLIB) \ +$(PJNATH_LDLIB) \ +$(PJMEDIA_CODEC_LDLIB) \ +$(PJMEDIA_VIDEODEV_LDLIB) \ +$(PJMEDIA_AUDIODEV_LDLIB) \ +$(PJMEDIA_LDLIB) \ +$(PJLIB_UTIL_LDLIB) \ +$(PJLIB_LDLIB) \ +-Wl,--no-whole-archive \ +$(APP_THIRD_PARTY_LIBS) \ +$(APP_THIRD_PARTY_EXT) + +ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin +ASTPJ_LIB:=libasteriskpj.so + +libasteriskpj.exports: $(ASTTOPDIR)/$(PJPROJECT_DIR)/pjproject.symbols + $(ECHO_PREFIX) echo " [GENERATE] libasteriskpj.exports" +ifeq ($(GNU_LD),1) + $(CMD_PREFIX) echo -e "{\n\tglobal:" > libasteriskpj.exports + $(CMD_PREFIX) sed -r -e "s/.*/\t\t$(LINKER_SYMBOL_PREFIX)&;/" $(ASTTOPDIR)/$(PJPROJECT_DIR)/pjproject.symbols >> libasteriskpj.exports + $(CMD_PREFIX) echo -e "\t\t$(LINKER_SYMBOL_PREFIX)ast_pj_init;\n" >> libasteriskpj.exports + $(CMD_PREFIX) echo -e "\tlocal:\n\t\t*;\n};" >> libasteriskpj.exports +endif + +$(ASTPJ_LIB).$(ASTPJ_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTPJ_LIB) $(PJ_LDFLAGS) +$(ASTPJ_LIB).$(ASTPJ_SO_VERSION): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskpj\" $(PJ_CFLAGS) +$(ASTPJ_LIB).$(ASTPJ_SO_VERSION): LIBS+=$(PJPROJECT_LDLIBS) -lssl -lcrypto -luuid -lm -lrt -lpthread +ifeq ($(GNU_LD),1) + $(ASTPJ_LIB).$(ASTPJ_SO_VERSION): SO_SUPPRESS_SYMBOLS=-Wl,--version-script,libasteriskpj.exports,--warn-common +endif +$(ASTPJ_LIB).$(ASTPJ_SO_VERSION): SOLINK=$(DYLINK) + +# These rules are duplicated from $(ASTTOPDIR)/Makefile.rules because the library name +# being built does not match the "%.so" pattern; there are also additional steps +# required to build a proper shared library (as opposed to the 'loadable module' +# type that are built by the standard rules) +$(ASTPJ_LIB).$(ASTPJ_SO_VERSION): libasteriskpj.o libasteriskpj.exports + $(ECHO_PREFIX) echo " [LD] $< -> $@" + $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $< $(CC_LIBS) + +$(ASTPJ_LIB): $(ASTPJ_LIB).$(ASTPJ_SO_VERSION) + $(ECHO_PREFIX) echo " [LN] $< -> $@" +ifneq ($(LDCONFIG),) + $(CMD_PREFIX) $(LDCONFIG) $(LDCONFIG_FLAGS) . 2>/dev/null +else + $(CMD_PREFIX) $(LN) -sf $< $@ +endif + +else # Darwin +ASTPJ_LIB:=libasteriskpj.dylib + +# -install_name allows library to be found if installed somewhere other than +# /lib or /usr/lib +$(ASTPJ_LIB): _ASTLDFLAGS+=-dynamiclib -install_name $(ASTLIBDIR)/$(ASTPJ_LIB) $(PJ_LDFLAGS) +$(ASTPJ_LIB): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskpj\" $(PJ_CFLAGS) +$(ASTPJ_LIB): LIBS+=$(PJPROJECT_LIBS) -lssl -lcrypto -luuid -lm -lrt -lpthread +$(ASTPJ_LIB): SOLINK=$(DYLINK) + +# Special rules for building a shared library (not a dynamically loadable module) +$(ASTPJ_LIB): libasteriskpj.o + $(ECHO_PREFIX) echo " [LD] $^ -> $@" + $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS) +endif + +endif + tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE) -$(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) +$(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) @$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS) $(ECHO_PREFIX) echo " [LD] $(OBJS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) -> $@" - $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB) + $(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) ifeq ($(GNU_LD),1) $(MAIN_TGT): asterisk.exports @@ -266,16 +351,29 @@ ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin else # Darwin $(INSTALL) -m 755 $(ASTSSL_LIB) "$(DESTDIR)$(ASTLIBDIR)/" endif +endif +ifeq ($(PJPROJECT_BUNDLED),yes) +ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin + $(INSTALL) -m 755 $(ASTPJ_LIB).$(ASTPJ_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/" + $(LN) -sf $(ASTPJ_LIB).$(ASTPJ_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/$(ASTPJ_LIB)" +else # Darwin + $(INSTALL) -m 755 $(ASTPJ_LIB) "$(DESTDIR)$(ASTLIBDIR)/" +endif +endif ifneq ($(LDCONFIG),) $(LDCONFIG) $(LDCONFIG_FLAGS) "$(DESTDIR)$(ASTLIBDIR)/" -endif endif $(LN) -sf asterisk "$(DESTDIR)$(ASTSBINDIR)/rasterisk" binuninstall: rm -f "$(DESTDIR)$(ASTSBINDIR)/$(MAIN_TGT)" rm -f "$(DESTDIR)$(ASTSBINDIR)/rasterisk" +ifneq ($(ASTSSL_LIB).$(ASTSSL_SO_VERSION),.) rm -f "$(DESTDIR)$(ASTLIBDIR)/$(ASTSSL_LIB).$(ASTSSL_SO_VERSION)" +endif +ifneq ($(ASTPJ_LIB).$(ASTPJ_SO_VERSION),.) + rm -f "$(DESTDIR)$(ASTLIBDIR)/$(ASTPJ_LIB).$(ASTPJ_SO_VERSION)" +endif ifneq ($(LDCONFIG),) $(LDCONFIG) $(LDCONFIG_FLAGS) "$(DESTDIR)$(ASTLIBDIR)/" endif @@ -285,7 +383,12 @@ clean:: ifeq ($(AST_ASTERISKSSL),yes) rm -f $(ASTSSL_LIB) $(ASTSSL_LIB).* endif - rm -f asterisk.exports libasteriskssl.exports + rm -f libasteriskpj.o + rm -f libasteriskpj.so* libasteriskpj.dynlib + rm -f .libasteriskpj* + + rm -f asterisk.exports libasteriskssl.exports libasteriskpj.exports @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi @$(MAKE) -C stdtime clean rm -f libresample/src/*.o + rm -f *.tmp diff --git a/main/asterisk.c b/main/asterisk.c index ca560cdb2..da804e196 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -4478,6 +4478,11 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou exit(1); } + if (ast_pj_init()) { + printf("Failed: ast_pj_init\n%s", term_quit()); + exit(1); + } + if (app_init()) { printf("App core initialization failed.\n%s", term_quit()); exit(1); diff --git a/main/libasteriskpj.c b/main/libasteriskpj.c new file mode 100644 index 000000000..aed0ec8b1 --- /dev/null +++ b/main/libasteriskpj.c @@ -0,0 +1,52 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2009-2012, Digium, Inc. + * Copyright (C) 2015, Fairview 5 Engineering, LLC + * + * Russell Bryant + * George Joseph + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! + * \file + * \brief Loader stub for static pjproject libraries + * + * \author George Joseph + */ + +/*** MODULEINFO + core + ***/ + +#include "asterisk.h" + +ASTERISK_REGISTER_FILE() + +#ifdef HAVE_PJPROJECT +#include +#endif + +#include "asterisk/_private.h" /* ast_pj_init() */ + +/*! + * \internal + * \brief Initialize static pjproject implementation + */ +int ast_pj_init(void) +{ +#ifdef HAVE_PJPROJECT_BUNDLED + pj_init(); +#endif + return 0; +} -- cgit v1.2.3