git: e32f5ab610e4 - main - net/asterisk18: Add red_geolocation support

From: Guido Falsi <madpilot_at_FreeBSD.org>
Date: Tue, 30 Aug 2022 08:13:03 UTC
The branch main has been updated by madpilot:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e32f5ab610e49d510e70a9e5d8851a8b436fc18c

commit e32f5ab610e49d510e70a9e5d8851a8b436fc18c
Author:     Guido Falsi <madpilot@FreeBSD.org>
AuthorDate: 2022-08-30 08:06:58 +0000
Commit:     Guido Falsi <madpilot@FreeBSD.org>
CommitDate: 2022-08-30 08:06:58 +0000

    net/asterisk18: Add red_geolocation support
    
    Add a GEOLOCATION option (off by default) to allow building the new
    res_geolocation module, which allows to use geolocation information
    in SIP protocol (upstream provider support required).
    
    Since it requires architecture specific flags to be passed to ld,
    I've enabled it only for tier 1 architectures at present.
    
    PR:             266053
    Tested by:      Seneca Cunningham <seneca@vybenetworks.com>
---
 net/asterisk18/Makefile                   | 28 ++++++++++++++++++++++++++--
 net/asterisk18/files/patch-Makefile.rules | 27 +++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/net/asterisk18/Makefile b/net/asterisk18/Makefile
index b354d93cc05b..77335cc6ee26 100644
--- a/net/asterisk18/Makefile
+++ b/net/asterisk18/Makefile
@@ -62,8 +62,9 @@ OPTIONS_DEFAULT=		CURL FREETDS GSM LUA MACRO MP3PLAYER NEWT ODBC OPUS MYSQL PGSQ
 				PJSIP PORTAUDIO RADIUS SNMP SPANDSP SPEEX SRTP URIPARSER \
 				VORBIS XMLDOC
 
-OPTIONS_DEFINE_i386=		DAHDI
-OPTIONS_DEFINE_amd64=		DAHDI
+OPTIONS_DEFINE_i386=		DAHDI GEOLOCATION
+OPTIONS_DEFINE_amd64=		DAHDI GEOLOCATION
+OPTIONS_DEFINE_aarch64=		GEOLOCATION
 OPTIONS_DEFINE_sparc64=		DAHDI
 OPTIONS_DEFINE_powerpc=		DAHDI
 OPTIONS_DEFINE_powerpc64=	DAHDI
@@ -99,6 +100,7 @@ BACKTRACE_DESC?= Stack backtrace support via (lib)execinfo
 DAHDI_DESC?=	DAHDI support
 EXCHANGE_DESC?=	Exchange calendar support
 G729_DESC?=	Install G.729 format sounds for Music-on-Hold (MoH)
+GEOLOCATION_DESC?= Enable SIP Geolocation support
 MACRO_DESC?=	Enable app_macro (deprecated)
 MP3PLAYER_DESC=	Install MP3 Player for Music-On-Hold (mpg123)
 NEWG711_DESC?=	New G711 Codec
@@ -134,6 +136,8 @@ FREETDS_CONFIGURE_ON=	--with-tds=${LOCALBASE}
 FREETDS_CONFIGURE_OFF=	--without-tds
 FREETDS_LIB_DEPENDS=	libsybdb.so:databases/freetds
 
+GEOLOCATION_USE=	GNOME=libxslt
+
 GSM_CONFIGURE_WITH=	gsm
 GSM_LIB_DEPENDS=	libgsm.so:audio/gsm
 
@@ -212,6 +216,7 @@ ASTERISK_GROUP?=	asterisk
 USERS=	${ASTERISK_USER}
 GROUPS=	${ASTERISK_GROUP} dahdi
 
+.include <bsd.port.options.mk>
 .include <bsd.port.pre.mk>
 
 .if empty(ICONV_LIB)
@@ -230,6 +235,16 @@ PLIST_SUB+=	ASTERISK_USER=${ASTERISK_USER} \
 		ASTERISK_GROUP=${ASTERISK_GROUP} \
 		VARDIR=${VARDIR}
 
+.if ${PORT_OPTIONS:MGEOLOCATION}
+.if ${ARCH} == i386
+LLD_EMULATION=	elf_i386
+.elif ${ARCH} == amd64
+LLD_EMULATION=	elf_x86_64
+.elif ${ARCH} == aarch64
+LLD_EMULATION=	aarch64elf
+.endif
+.endif
+
 post-extract:
 	@${FIND} ${WRKSRC} -name '*.d' -delete
 
@@ -250,6 +265,9 @@ post-patch:
 	${CP} ${FILESDIR}/.asterisk.makeopts ${WRKSRC}/menuselect.makeopts
 .endif
 
+post-patch-GEOLOCATION-on:
+	@${REINPLACE_CMD} -e 's/%%LLD_EMULATION%%/${LLD_EMULATION}/' ${WRKSRC}/Makefile.rules
+
 post-patch-SYSINFO-on:
 	@${REINPLACE_CMD} -e 's/%%LIBSYSINFO%%/-lsysinfo/' ${WRKSRC}/main/Makefile
 
@@ -263,6 +281,12 @@ post-configure:
 	@cd ${WRKSRC} && ./menuselect/menuselect --enable chan_mgcp menuselect.makeopts
 	@cd ${WRKSRC} && ./menuselect/menuselect --enable res_pktccops menuselect.makeopts
 
+post-configure-GEOLOCATION-on:
+	@cd ${WRKSRC} && ./menuselect/menuselect --enable res_geolocation menuselect.makeopts
+
+post-configure-GEOLOCATION-off:
+	@cd ${WRKSRC} && ./menuselect/menuselect --disable res_geolocation menuselect.makeopts
+
 post-configure-MACRO-on:
 	@cd ${WRKSRC} && ./menuselect/menuselect --enable app_macro menuselect.makeopts
 
diff --git a/net/asterisk18/files/patch-Makefile.rules b/net/asterisk18/files/patch-Makefile.rules
new file mode 100644
index 000000000000..3bebe8ad02de
--- /dev/null
+++ b/net/asterisk18/files/patch-Makefile.rules
@@ -0,0 +1,27 @@
+--- Makefile.rules.orig	2022-08-18 15:18:29 UTC
++++ Makefile.rules
+@@ -107,6 +107,11 @@ ifeq ($(C_COMPILER_FAMILY),clang)
+ # Clang -Werror warning suppressions
+ ifeq ($(C_COMPILER_FAMILY),clang)
+ 	CC_CFLAGS+=-Wno-unused-value -Wno-parentheses-equality
++	BINARY_LLD_FLAGS= -z noexecstack
++	LLD_EMULATION=%%LLD_EMULATION%%
++else
++	BINARY_LLD_FLAGS=
++	LLD_EMULATION=
+ endif
+ 
+ ifeq ($(GNU_LD),1)
+@@ -213,10 +218,10 @@ endif
+ # extern const size_t _binary_abc_def_xml_size;
+ %.o: %.xml
+ 	$(ECHO_PREFIX) echo "   [LD] $^ -> $@"
+-	$(CMD_PREFIX) $(CC) -g -nostartfiles  -nodefaultlibs -nostdlib -r -Wl,-b,binary -o $@ $^
++	$(CMD_PREFIX) $(CC) -g -nostartfiles  -nodefaultlibs -nostdlib $(BINARY_LLD_FLAGS) -r -Wl,-b,binary,-m,$(LLD_EMULATION) -o $@ $^
+ 
+ %.o: %.xslt
+ 	$(ECHO_PREFIX) echo "   [LD] $^ -> $@"
+-	$(CMD_PREFIX) $(CC) -g -nostartfiles  -nodefaultlibs -nostdlib -r -Wl,-b,binary -o $@ $^
++	$(CMD_PREFIX) $(CC) -g -nostartfiles  -nodefaultlibs -nostdlib $(BINARY_LLD_FLAGS) -r -Wl,-b,binary,-m,$(LLD_EMULATION) -o $@ $^
+ 
+ dist-clean:: clean