Source: zlib
Version: 1:1.2.13.dfsg-3
Severity: important
Tags: patch
User: debian-cr...@lists.debian.org
Usertags: ftcbfs
User: helm...@debian.org
Usertags: rebootstrap

zlib fails to cross build from source, because the minizip build is
performed for the build architecture. In principle, this sounds as easy
as supplying --host and being done. That proved not to be the case. I
was getting a linker error while linking miniunzip failing to find
libz.so.1. It turns out miniunzip links -lz implicitly (while minizip
links it explicitly). Therefore the passed -L../.. is not considered and
the object is not found. The -lz flag should be passed when linking
miniunzip as well.

In writing a patch I took the liberty of simplifying debian/rules a
little. dpkg's architecture.mk, buildflags.mk and buildtools.mk can
remove quite a bit of code. Similarly, employing dh_auto_configure
(which automatically passes --host) can be used to clean things up. I
hope you like this.

Helmut
diff --minimal -Nru zlib-1.2.13.dfsg/debian/changelog 
zlib-1.2.13.dfsg/debian/changelog
--- zlib-1.2.13.dfsg/debian/changelog   2023-08-15 15:35:28.000000000 +0200
+++ zlib-1.2.13.dfsg/debian/changelog   2023-09-01 08:45:25.000000000 +0200
@@ -1,3 +1,13 @@
+zlib (1:1.2.13.dfsg-3.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Fix FTCBFS: (Closes: #-1)
+    + Let dh_auto_configure pass --host to minizip.
+    + cross.patch: Link miniunzip with -lz.
+  * Use dpkg's makefiles to clean up code.
+
+ -- Helmut Grohne <hel...@subdivi.de>  Fri, 01 Sep 2023 08:45:25 +0200
+
 zlib (1:1.2.13.dfsg-3) unstable; urgency=low
 
   * Further fixes to the minizip integration, don't install the minizip
diff --minimal -Nru zlib-1.2.13.dfsg/debian/patches/cross.patch 
zlib-1.2.13.dfsg/debian/patches/cross.patch
--- zlib-1.2.13.dfsg/debian/patches/cross.patch 1970-01-01 01:00:00.000000000 
+0100
+++ zlib-1.2.13.dfsg/debian/patches/cross.patch 2023-09-01 08:45:25.000000000 
+0200
@@ -0,0 +1,18 @@
+From: Helmut Grohne <hel...@subdivi.de>
+Subject: link miniunzip with -lz
+
+We pass -L../.. to the build in order to find the local libz.so.1, but -L only
+affects -l and not libraries required from other libraries. We therefore have
+to pass -lz explicitly here.
+
+--- zlib-1.2.13.dfsg.orig/contrib/minizip/Makefile.am
++++ zlib-1.2.13.dfsg/contrib/minizip/Makefile.am
+@@ -39,7 +39,7 @@
+ EXTRA_PROGRAMS = miniunzip minizip
+ 
+ miniunzip_SOURCES = miniunz.c
+-miniunzip_LDADD = libminizip.la
++miniunzip_LDADD = libminizip.la -lz
+ 
+ minizip_SOURCES = minizip.c
+ minizip_LDADD = libminizip.la -lz
diff --minimal -Nru zlib-1.2.13.dfsg/debian/patches/series 
zlib-1.2.13.dfsg/debian/patches/series
--- zlib-1.2.13.dfsg/debian/patches/series      2023-08-15 01:27:48.000000000 
+0200
+++ zlib-1.2.13.dfsg/debian/patches/series      2023-09-01 08:45:25.000000000 
+0200
@@ -1 +1,2 @@
 CVE-2014-9485-miniunzip.patch
+cross.patch
diff --minimal -Nru zlib-1.2.13.dfsg/debian/rules zlib-1.2.13.dfsg/debian/rules
--- zlib-1.2.13.dfsg/debian/rules       2023-08-15 01:27:48.000000000 +0200
+++ zlib-1.2.13.dfsg/debian/rules       2023-09-01 08:45:25.000000000 +0200
@@ -9,24 +9,16 @@
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 
-# These are used for cross-compiling and for saving the configure script
-# from having to guess our platform (since we know it already)
-DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
-DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
-DEB_HOST_ARCH       ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
-DEB_HOST_ARCH_OS    ?= $(shell dpkg-architecture -qDEB_HOST_GNU_OS)
-DEB_HOST_MULTIARCH  ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
+include /usr/share/dpkg/architecture.mk
 
-CFLAGS = `dpkg-buildflags --get CFLAGS` `dpkg-buildflags --get CPPFLAGS` -Wall 
-D_REENTRANT
-LDFLAGS = `dpkg-buildflags --get LDFLAGS`
+DEB_CFLAGS_MAINT_APPEND = -Wall -D_REENTRANT
+include /usr/share/dpkg/buildflags.mk
+CFLAGS += $(CPPFLAGS)
+export CFLAGS LDFLAGS
+export uname=GNU
 
-# binutils doesn't supply the prefixed version normally like GCC does so
-# we can't just unconditionally use DEB_HOST_GNU_TYPE-ar
-ifeq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
-       AR=ar
-else
-       AR=$(DEB_HOST_GNU_TYPE)-ar
-endif
+include /usr/share/dpkg/buildtools.mk
+export AR
 
 ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
        CFLAGS += -O0
@@ -85,9 +78,10 @@
 
        if [ ! -f Makefile.stash ]; then cp Makefile Makefile.stash ; fi
 
-       AR=$(AR) CC="$(DEB_HOST_GNU_TYPE)-gcc" CFLAGS="$(CFLAGS)" 
LDFLAGS="$(LDFLAGS)" uname=GNU ./configure --shared --prefix=/usr 
--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)
+       CC="$(CC)" ./configure --shared --prefix=/usr 
--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)
 
-       cd contrib/minizip && autoreconf -fis && CFLAGS="$(CFLAGS)" 
LDFLAGS="$(LDFLAGS)" uname=GNU ./configure --prefix=/usr 
--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)
+       cd contrib/minizip && autoreconf -fis
+       uname=GNU dh_auto_configure --sourcedirectory=contrib/minizip
 
        touch $@
 
@@ -96,9 +91,8 @@
 
        mkdir -p debian/64
        cp -r $(COPYLIST) debian/64
-       cd debian/64 && AR=$(AR) CC="$(DEB_HOST_GNU_TYPE)-gcc $(m64)" \
-           CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
-           uname=GNU ./configure --shared --prefix=/usr  
--libdir=\$${prefix}/usr/lib64
+       cd debian/64 && CC="$(CC) $(m64)" \
+           ./configure --shared --prefix=/usr  --libdir=\$${prefix}/usr/lib64
        touch $@
 
 configure32-stamp: configure
@@ -106,9 +100,8 @@
 
        mkdir -p debian/32
        cp -r $(COPYLIST) debian/32
-       cd debian/32 && AR=$(AR) CC="$(DEB_HOST_GNU_TYPE)-gcc $(m32)" \
-           CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
-           uname=GNU ./configure --shared --prefix=/usr 
--libdir=\$${prefix}/usr/lib32
+       cd debian/32 && CC="$(CC) $(m32)" \
+           ./configure --shared --prefix=/usr --libdir=\$${prefix}/usr/lib32
        touch $@
 
 configuren32-stamp: configure
@@ -116,9 +109,8 @@
 
        mkdir -p debian/n32
        cp -r $(COPYLIST) debian/n32
-       cd debian/n32 && AR=$(AR) CC="$(DEB_HOST_GNU_TYPE)-gcc $(mn32)" \
-           CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
-           uname=GNU ./configure --shared --prefix=/usr 
--libdir=\$${prefix}/usr/lib32
+       cd debian/n32 && CC="$(CC) $(mn32)" \
+           ./configure --shared --prefix=/usr --libdir=\$${prefix}/usr/lib32
        touch $@
 
 build: build-arch build-indep

Reply via email to