Asterisk wants either GCC nested functions, or working -fblocks in clang
which uses libBlocksRuntime. We haven't been successful in getting the latter
to work correctly with dlopen()d libs so this diff switches to ports GCC to
unbreak build.

Because this would result in a c++ library conflict with a clang/libc++
build of telephony/pjsua, it switches to an embedded pjsua/pjsip build
instead (which is generally preferable anyway, it avoids several
unnecessary deps and has a few patches wanted by asterisk).

So tests in general would be welcome, and if there's someone reading who
already has a working chan_pjsip Asterisk configuration on OpenBSD,
testing that this doesn't break things would be very appreciated.


Index: Makefile
===================================================================
RCS file: /cvs/ports/telephony/asterisk/Makefile,v
retrieving revision 1.258
diff -u -p -r1.258 Makefile
--- Makefile    16 Jul 2017 19:19:02 -0000      1.258
+++ Makefile    5 Aug 2017 00:05:54 -0000
@@ -1,31 +1,22 @@
 # $OpenBSD: Makefile,v 1.258 2017/07/16 19:19:02 espie Exp $
 
-# XXX uses -fblocks on clang, or nested functions on gcc.
-#
-# on clang/ld.bfd arches, the configure test fails to link. test looks like 
this:
-#
-#    echo 'int main(){return ^{return 42;}();}' | \
-#         clang -o /tmp/blockstest -fblocks -x c -L/usr/local/lib 
-lBlocksRuntime -
-#
-# -> undefined reference to `_NSConcreteGlobalBlock'
-#
-# on clang/ld.lld arches, it builds ok but runtime fails: dlopen()ing the .so 
modules
-# at runtime fails with undefined symbols from the BlocksRuntime lib.
-#
-BROKEN-aarch64=                linker problems with BlocksRuntime that only 
show up at runtime
+BROKEN-aarch64=        linker problems with BlocksRuntime that only show up at 
runtime
 
-COMMENT-main=          open source multi-protocol PBX and telephony toolkit
+COMMENT-main=  open source multi-protocol PBX and telephony toolkit
 
-VER=                   13.17.0
-PORTROACH=             limitw:0,odd
-DISTNAME=              asterisk-${VER:S/beta/-beta/:S/rc/-rc/}
-PKGNAME-main=          asterisk-${VER}
+VER=           13.17.0
+PJ_V=          2.6
+PORTROACH=     limitw:0,odd
+DISTNAME=      asterisk-${VER:S/beta/-beta/:S/rc/-rc/}
+DISTFILES=     ${DISTNAME}${EXTRACT_SUFX} pjproject-${PJ_V}.tar.bz2:0
+PKGNAME-main=  asterisk-${VER}
+REVISION=      0
 
-CATEGORIES=            telephony
+CATEGORIES=    telephony
 
-HOMEPAGE=              http://www.asterisk.org/
+HOMEPAGE=      http://www.asterisk.org/
 
-MAINTAINER=            Stuart Henderson <st...@openbsd.org>
+MAINTAINER=    Stuart Henderson <st...@openbsd.org>
 
 # Mostly GPL v2 (only). "Specific permission is also granted to link
 # Asterisk with OpenSSL and OpenH323 and distribute the resulting binary
@@ -34,21 +25,35 @@ MAINTAINER=         Stuart Henderson <sthen@ope
 PERMIT_PACKAGE_CDROM=  patent licensing clauses
 PERMIT_PACKAGE_FTP=    Yes
 
-WANTLIB-main += c crypto curl execinfo g7221codec gsm iconv iksemel
-WANTLIB-main += ilbccodec jansson lzma m nghttp2 ogg opencore-amrnb
-WANTLIB-main += opencore-amrwb pj pjlib-util pjmedia pjmedia-audiodev
-WANTLIB-main += pjmedia-codec pjmedia-videodev pjnath pjsip pjsip-simple
-WANTLIB-main += pjsip-ua pjsua pjsua2 portaudio pthread resample spandsp
-WANTLIB-main += speex speexdsp sqlite3 ssl ${COMPILER_LIBCXX} termcap tiff 
uriparser
-WANTLIB-main += uuid vorbis vorbisenc vorbisfile xml2 xslt z
+WANTLIB-main += ${MODGCC4_CPPWANTLIB}
+WANTLIB-main += c crypto curl execinfo gsm iconv iksemel jansson lzma
+WANTLIB-main += m nghttp2 ogg portaudio pthread spandsp sqlite3 ssl
+WANTLIB-main += termcap tiff uriparser uuid vorbis vorbisenc vorbisfile
+WANTLIB-main += xml2 xslt z
+
+# XXX Requires either nested functions (gcc only), or -fblocks (clang).
+#
+# With clang -fblocks, configure test fails on ld.bfd arches:
+#
+#    echo 'int main(){return ^{return 42;}();}' | \
+#         clang -o /tmp/blockstest -fblocks -x c -L/usr/local/lib 
-lBlocksRuntime -
+#
+# -> undefined reference to `_NSConcreteGlobalBlock'
+#
+# Runtime fails on ld.lld arches: dlopen()ing the .so modules results in
+# undefined symbols from the BlocksRuntime lib.
+#
+COMPILER =             gcc-only
 
-SHARED_LIBS=           asteriskssl 0.0         # 1
+SHARED_LIBS+=          asteriskssl 0.0         # 1
+SHARED_LIBS+=          asteriskpj 0.0          # 2
 
 MULTI_PACKAGES=                -main -calendar -http_post -ldap -odbc \
                        -pgsql -snmp -speex -tds
 PSEUDO_FLAVORS=                ${MULTI_PACKAGES:N-main:C/-/no_/g}
 
-LIB_DEPENDS-main=      audio/gsm \
+LIB_DEPENDS-main=      ${MODGCC4_CPPLIBDEP} \
+                       audio/gsm \
                        audio/libogg \
                        audio/libvorbis \
                        audio/portaudio-svn \
@@ -59,7 +64,6 @@ LIB_DEPENDS-main=     audio/gsm \
                        graphics/tiff \
                        net/curl \
                        sysutils/e2fsprogs \
-                       telephony/pjsua,-main \
                        telephony/spandsp \
                        textproc/iksemel \
                        textproc/libxml \
@@ -71,19 +75,7 @@ BUILD_DEPENDS=               security/libsrtp>=1.4.4 
 
 MASTER_SITES=  http://downloads.asterisk.org/pub/telephony/asterisk/releases/ \
                
http://downloads.asterisk.org/pub/telephony/asterisk/old-releases/
-
-# if using bundled pjproject:
-#
-#CONFIGURE_ARGS+= --with-pjproject-bundled
-#PJ_V=         2.5.5
-#MASTER_SITES0=        http://www.pjsip.org/release/${PJ_V}/
-#EXTRACT_ONLY= ${DISTNAME}${EXTRACT_SUFX}
-#DISTFILES=    ${DISTNAME}${EXTRACT_SUFX} pjproject-${PJ_V}.tar.bz2:0
-#
-#      @cd ${WRKSRC}/third-party/; \
-#          grep 'PJPROJECT_VERSION = ${PJ_V}$$' versions.mak > /dev/null || \
-#          (echo "PJ_V != PJPROJECT_VERSION; update in port"; \
-#           grep 'PJPROJECT_VERSION' versions.mak; exit 1)
+MASTER_SITES0= http://www.pjsip.org/release/${PJ_V}/
 
 USE_GMAKE=             Yes
 
@@ -105,11 +97,13 @@ CONFIGURE_ENV+=            CPPFLAGS="${CPPFLAGS}" 
 MAKE_FLAGS+=           ASTCFLAGS="${CFLAGS}" \
                        ASTLDFLAGS="${LDFLAGS}" \
                        ASTSSL_SO_VERSION="${LIBasteriskssl_VERSION}" \
+                       ASTPJ_SO_VERSION="${LIBasteriskpj_VERSION}" \
                        NOISY_BUILD="Yes" \
                        OPTIMIZE=
 
 CONFIGURE_ARGS+=       --localstatedir=/var \
-                       --with-externals-cache=${FULLDISTDIR}
+                       --with-externals-cache=${FULLDISTDIR} \
+                       --with-pjproject-bundled
 
 CONFIGURE_ARGS+=       --with-asound=no \
                        --with-cap=no \
@@ -249,6 +243,20 @@ RUN_DEPENDS$i +=   asterisk-${VER}:telepho
 .if ${PROPERTIES:Mclang}
 BUILD_DEPENDS+=                devel/blocksruntime
 .endif
+
+# otherwise asterisk patchset for pjsua gets in the way
+PATCHORIG=             .orig.port
+
+# some of the patches have MS-DOS line endings which patch doesn't like
+post-extract:
+       @cd ${WRKSRC}/third-party/; \
+           grep 'PJPROJECT_VERSION = ${PJ_V}$$' versions.mak > /dev/null || \
+           (echo "PJ_V != PJPROJECT_VERSION; update in port"; \
+            grep 'PJPROJECT_VERSION' versions.mak; exit 1)
+       @perl -i -pe 's/\r$$//' ${WRKSRC}/third-party/pjproject/patches/*patch
+       mv ${WRKDIR}/pjproject-${PJ_V} ${WRKSRC}/third-party/pjproject/source
+       cd ${WRKSRC}/third-party/pjproject; ./apply_patches patches source
+       touch ${WRKSRC}/third-party/pjproject/source/.unpacked
 
 post-patch:
 .if ${PROPERTIES:Mclang}
Index: distinfo
===================================================================
RCS file: /cvs/ports/telephony/asterisk/distinfo,v
retrieving revision 1.155
diff -u -p -r1.155 distinfo
--- distinfo    12 Jul 2017 19:55:29 -0000      1.155
+++ distinfo    5 Aug 2017 00:05:54 -0000
@@ -1,2 +1,4 @@
 SHA256 (asterisk-13.17.0.tar.gz) = xKiThtfbWFIDkfy9MgKQJYS0Q0KJCUyi5Ka42toekKQ=
+SHA256 (pjproject-2.6.tar.bz2) = L1odocF02EWHHHWL2A+7WA/Kd5nTz6oNPE4IK1Fhx7Q=
 SIZE (asterisk-13.17.0.tar.gz) = 32908945
+SIZE (pjproject-2.6.tar.bz2) = 4933273
Index: patches/patch-third-party_pjproject_source_pjlib_src_pj_ssl_sock_ossl_c
===================================================================
RCS file: 
patches/patch-third-party_pjproject_source_pjlib_src_pj_ssl_sock_ossl_c
diff -N patches/patch-third-party_pjproject_source_pjlib_src_pj_ssl_sock_ossl_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-third-party_pjproject_source_pjlib_src_pj_ssl_sock_ossl_c     
5 Aug 2017 00:05:54 -0000
@@ -0,0 +1,52 @@
+$OpenBSD$
+
+excise openssl-1.0.2 EC and various openssl-1.1.0 pieces
+
+Index: third-party/pjproject/source/pjlib/src/pj/ssl_sock_ossl.c
+--- third-party/pjproject/source/pjlib/src/pj/ssl_sock_ossl.c.orig
++++ third-party/pjproject/source/pjlib/src/pj/ssl_sock_ossl.c
+@@ -54,7 +54,7 @@
+ #include <openssl/engine.h>
+ #include <openssl/opensslconf.h>
+ 
+-#if !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x1000200fL
++#if !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_NO_EC) && 
OPENSSL_VERSION_NUMBER >= 0x1000200fL
+ 
+ #   include <openssl/obj_mac.h>
+ 
+@@ -112,7 +112,7 @@ static unsigned get_nid_from_cid(unsigned cid)
+ #endif
+ 
+ 
+-#if OPENSSL_VERSION_NUMBER >= 0x10100000L
++#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
+ #  define OPENSSL_NO_SSL2         /* seems to be removed in 1.1.0 */
+ #  define M_ASN1_STRING_data(x)           ASN1_STRING_get0_data(x)
+ #  define M_ASN1_STRING_length(x)   ASN1_STRING_length(x)
+@@ -453,7 +453,7 @@ static pj_status_t init_openssl(void)
+ 
+       SSL_set_session(ssl, SSL_SESSION_new());
+ 
+-#if !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x1000200fL
++#if !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_NO_EC) && 
OPENSSL_VERSION_NUMBER >= 0x1000200fL
+       openssl_curves_num = SSL_get_shared_curve(ssl,-1);
+       if (openssl_curves_num > PJ_ARRAY_SIZE(openssl_curves))
+           openssl_curves_num = PJ_ARRAY_SIZE(openssl_curves);
+@@ -1070,7 +1070,7 @@ static pj_status_t set_cipher_list(pj_ssl_sock_t *ssoc
+ 
+ static pj_status_t set_curves_list(pj_ssl_sock_t *ssock)
+ {
+-#if !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x1000200fL
++#if !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_NO_EC) && 
OPENSSL_VERSION_NUMBER >= 0x1000200fL
+     int ret;
+     int curves[PJ_SSL_SOCK_MAX_CURVES];
+     unsigned cnt;
+@@ -1101,7 +1101,7 @@ static pj_status_t set_curves_list(pj_ssl_sock_t *ssoc
+ 
+ static pj_status_t set_sigalgs(pj_ssl_sock_t *ssock)
+ {
+-#if OPENSSL_VERSION_NUMBER >= 0x1000200fL
++#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x1000200fL
+     int ret;
+ 
+     if (ssock->param.sigalgs.ptr && ssock->param.sigalgs.slen) {
Index: pkg/PLIST-main
===================================================================
RCS file: /cvs/ports/telephony/asterisk/pkg/PLIST-main,v
retrieving revision 1.68
diff -u -p -r1.68 PLIST-main
--- pkg/PLIST-main      12 Jul 2017 19:55:29 -0000      1.68
+++ pkg/PLIST-main      5 Aug 2017 00:05:54 -0000
@@ -517,6 +517,8 @@ lib/asterisk/modules/res_stun_monitor.so
 @comment lib/asterisk/modules/res_timing_kqueue.so
 lib/asterisk/modules/res_timing_pthread.so
 lib/asterisk/modules/res_xmpp.so
+@comment lib/libasteriskpj.so
+@lib lib/libasteriskpj.so.${LIBasteriskpj_VERSION}
 @comment lib/libasteriskssl.so
 @lib lib/libasteriskssl.so.${LIBasteriskssl_VERSION}
 lib/pkgconfig/asterisk.pc
@@ -581,6 +583,7 @@ share/asterisk/static-http/core-en_US.xm
 share/asterisk/static-http/mantest.html
 share/asterisk/static-http/prototype.js
 share/asterisk/third-party/
+share/asterisk/third-party/pjproject/
 share/doc/asterisk/
 share/doc/asterisk/Asterisk-13-Reference.pdf
 share/doc/asterisk/Asterisk-Admin-Guide.pdf

Reply via email to