git: 6318e220e3b8 - stable/13 - Bootstrap libz when cross-building from non-FreeBSD

From: Jessica Clarke <jrtc27_at_FreeBSD.org>
Date: Tue, 25 Jan 2022 01:39:59 UTC
The branch stable/13 has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=6318e220e3b8e34943fa74406a2de72273340cdb

commit 6318e220e3b8e34943fa74406a2de72273340cdb
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2021-12-06 18:12:46 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2022-01-24 23:59:14 +0000

    Bootstrap libz when cross-building from non-FreeBSD
    
    This is needed now libdwarf depends on libz.
    
    Fixes:          dbf05458e3bd ("libdwarf: Support consumption of compressed ELF sections")
    MFC after:      1 week
    
    (cherry picked from commit 8d5d329553b345c0887405db741750b0f728d902)
---
 Makefile.inc1                | 4 ++++
 lib/libz/Makefile            | 7 ++++++-
 tools/build/mk/Makefile.boot | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Makefile.inc1 b/Makefile.inc1
index f4b1f0b9340b..98caae210c85 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -2459,6 +2459,10 @@ _other_bootstrap_tools+=usr.bin/bmake
 # Avoid dependency on host bz2 headers:
 _other_bootstrap_tools+=lib/libbz2
 ${_bt}-usr.bin/grep: ${_bt}-lib/libbz2
+
+# libdwarf depends on libz
+_other_bootstrap_tools+=lib/libz
+${_bt}-lib/libdwarf: ${_bt}-lib/libz
 .else
 # All tools in _basic_bootstrap_tools have the same name as the subdirectory
 # so we can use :T to get the name of the symlinks that we need to create.
diff --git a/lib/libz/Makefile b/lib/libz/Makefile
index 4ece3e3e059f..a954fee95118 100644
--- a/lib/libz/Makefile
+++ b/lib/libz/Makefile
@@ -38,9 +38,14 @@ SRCS+=		inflate.c
 SRCS+=		inftrees.c
 SRCS+=		trees.c
 SRCS+=		uncompr.c
-SRCS+=		zopen.c
 SRCS+=		zutil.c
 
+# Wrapper relies on FreeBSD-specific fpos_t representation and non-portable
+# funopen. Not needed for bootstrapping, so just disable it.
+.if ${.MAKE.OS} == "FreeBSD" || !defined(BOOTSTRAPPING)
+SRCS+=		zopen.c
+.endif
+
 .if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64"
 CFLAGS+=	-DUNALIGNED_OK
 .endif
diff --git a/tools/build/mk/Makefile.boot b/tools/build/mk/Makefile.boot
index 8ac360e663c9..4e6f3508b30d 100644
--- a/tools/build/mk/Makefile.boot
+++ b/tools/build/mk/Makefile.boot
@@ -16,7 +16,6 @@ NM:=	/usr/bin/nm
 
 # Avoid stale dependecy warnings:
 LIBC:=
-LIBZ:=
 LIBM:=
 LIBUTIL:=
 LIBCPLUSPLUS:=
@@ -30,6 +29,7 @@ LIBL:=${WORLDTMP}/legacy/usr/lib/libl.a
 LIBROKEN:=${WORLDTMP}/legacy/usr/lib/libroken.a
 LIBDWARF:=${WORLDTMP}/legacy/usr/lib/libdwarf.a
 LIBELF:=${WORLDTMP}/legacy/usr/lib/libelf.a
+LIBZ:=${WORLDTMP}/legacy/usr/lib/libz.a
 
 # Add various -Werror flags to catch missing function declarations
 CFLAGS+=	-Werror=implicit-function-declaration -Werror=implicit-int \