git: 9294a2c7195a - main - ncurses: convert libncursesw.a into a static ldscript

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Sun, 10 Oct 2021 05:51:06 UTC
The branch main has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=9294a2c7195ade0055c9d0b2917d929f5b20c035

commit 9294a2c7195ade0055c9d0b2917d929f5b20c035
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2021-10-10 05:37:26 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2021-10-10 05:51:00 +0000

    ncurses: convert libncursesw.a into a static ldscript
    
    Introduce the notion of static linker scripts to allow libncursesw.a to
    track its dependency on libtinfow.a
    
    this allows the build of older freebsd source tree to happen and make
    static linking in part with dynamic linking which already provides a
    ldscript
    
    This fixes a bootstrapping FreeBSD 12 or 13 on recent FreeBSD 14
    
    Reviewed by:            imp
    Differential Revision:  https://reviews.freebsd.org/D32435
---
 lib/ncurses/ncurses/Makefile | 14 ++++++++++++++
 share/mk/bsd.lib.mk          |  9 ++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/lib/ncurses/ncurses/Makefile b/lib/ncurses/ncurses/Makefile
index d2ba1007b54a..5f80def49458 100644
--- a/lib/ncurses/ncurses/Makefile
+++ b/lib/ncurses/ncurses/Makefile
@@ -169,6 +169,11 @@ SYMLINKS+=	libncursesw_p.a ${LIBDIR}/libcurses_p.a
 
 LIBADD+=	tinfow
 SHLIB_LDSCRIPT=	libncursesw.ldscript
+STATIC_LDSCRIPT= libncursesw.aldscript
+CLEANFILES+=	${STATIC_LDSCRIPT}
+
+libncursesw.aldscript:
+	@${ECHO} "INPUT(-lncursesw_real -ltinfow)" >$@
 
 libncurses.ldscript:
 	@${ECHO} "INPUT(${SHLIB_NAME} AS NEEDED(-ltinfow))" >$@
@@ -180,4 +185,13 @@ lib_gen.c: MKlib_gen.sh ${.OBJDIR:H}/tinfo/curses.h ncurses_dll.h
 expanded.c: MKexpanded.sh
 	sh ${NCURSES_DIR}/ncurses/tty/MKexpanded.sh "${CC:N${CCACHE_BIN}} -E" ${CFLAGS} >expanded.c
 
+all: ${STATIC_LDSCRIPT}
+
+install-aldscript: ${STATIC_LDSCRIPT}
+	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+	    ${_INSTALLFLAGS} ${STATIC_LDSCRIPT} ${DESTDIR}${_LIBDI}/lib${LIB}.a
+
+realinstall: install-aldscript
+
+
 .include <bsd.lib.mk>
diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
index 4afe719b8152..10262e6bb80c 100644
--- a/share/mk/bsd.lib.mk
+++ b/share/mk/bsd.lib.mk
@@ -271,9 +271,12 @@ CLEANFILES+=	${OBJS} ${BCOBJS} ${LLOBJS} ${STATICOBJS}
 .endif
 
 .if defined(LIB) && !empty(LIB)
-_LIBS=		lib${LIB_PRIVATE}${LIB}.a
+.if defined(STATIC_LDSCRIPT)
+_STATICLIB_SUFFIX=	_real
+.endif
+_LIBS=		lib${LIB_PRIVATE}${LIB}${_STATICLIB_SUFFIX}.a
 
-lib${LIB_PRIVATE}${LIB}.a: ${OBJS} ${STATICOBJS}
+lib${LIB_PRIVATE}${LIB}${_STATICLIB_SUFFIX}.a: ${OBJS} ${STATICOBJS}
 	@${ECHO} building static ${LIB} library
 	@rm -f ${.TARGET}
 	${AR} ${ARFLAGS} ${.TARGET} ${OBJS} ${STATICOBJS} ${ARADD}
@@ -477,7 +480,7 @@ realinstall: _libinstall installpcfiles
 _libinstall:
 .if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no"
 	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
-	    ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}.a ${DESTDIR}${_LIBDIR}/
+	    ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}${_STATICLIB_SUFFIX}.a ${DESTDIR}${_LIBDIR}/
 .endif
 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
 	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \