|
| 1 | +# Copyright 1999-2023 Gentoo Authors |
| 2 | +# Distributed under the terms of the GNU General Public License v2 |
| 3 | + |
| 4 | +EAPI=8 |
| 5 | + |
| 6 | +# Worth keeping an eye on 'develop' branch upstream for possible backports. |
| 7 | +AUTOTOOLS_AUTO_DEPEND="no" |
| 8 | +VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/madler.asc |
| 9 | +inherit autotools multilib-minimal flag-o-matic toolchain-funcs usr-ldscript verify-sig |
| 10 | + |
| 11 | +DESCRIPTION="Standard (de)compression library" |
| 12 | +HOMEPAGE="https://zlib.net/" |
| 13 | +SRC_URI="https://zlib.net/${P}.tar.xz |
| 14 | + https://zlib.net/fossils/${P}.tar.xz |
| 15 | + https://zlib.net/current/beta/${P}.tar.xz |
| 16 | + verify-sig? ( https://zlib.net/${P}.tar.xz.asc )" |
| 17 | + |
| 18 | +LICENSE="ZLIB" |
| 19 | +SLOT="0/1" # subslot = SONAME |
| 20 | +KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris" |
| 21 | +IUSE="minizip static-libs" |
| 22 | + |
| 23 | +RDEPEND="!sys-libs/zlib-ng[compat]" |
| 24 | +DEPEND="${RDEPEND}" |
| 25 | +BDEPEND=" |
| 26 | + minizip? ( ${AUTOTOOLS_DEPEND} ) |
| 27 | + verify-sig? ( sec-keys/openpgp-keys-madler ) |
| 28 | +" |
| 29 | + |
| 30 | +PATCHES=( |
| 31 | + # Don't install unexpected & unused crypt.h header (which would clash with other pkgs) |
| 32 | + # Pending upstream. bug #658536 |
| 33 | + "${FILESDIR}"/${PN}-1.2.11-minizip-drop-crypt-header.patch |
| 34 | + |
| 35 | + # Respect AR, RANLIB, NM during build. Pending upstream. bug #831628 |
| 36 | + "${FILESDIR}"/${PN}-1.2.11-configure-fix-AR-RANLIB-NM-detection.patch |
| 37 | + |
| 38 | + # Respect LDFLAGS during configure tests. Pending upstream |
| 39 | + "${FILESDIR}"/${PN}-1.2.13-use-LDFLAGS-in-configure.patch |
| 40 | + |
| 41 | + # Fix building on sparc with older binutils, we pass it in ebuild instead |
| 42 | + "${FILESDIR}"/${PN}-1.2.13-Revert-Turn-off-RWX-segment-warnings-on-sparc-system.patch |
| 43 | + |
| 44 | + # CVE-2023-45853 (bug #916484) |
| 45 | + "${FILESDIR}"/${PN}-1.2.13-CVE-2023-45853.patch |
| 46 | +) |
| 47 | + |
| 48 | +src_prepare() { |
| 49 | + default |
| 50 | + |
| 51 | + if use minizip ; then |
| 52 | + cd contrib/minizip || die |
| 53 | + eautoreconf |
| 54 | + fi |
| 55 | + |
| 56 | + case ${CHOST} in |
| 57 | + *-mingw*|mingw*) |
| 58 | + # Uses preconfigured Makefile rather than configure script |
| 59 | + multilib_copy_sources |
| 60 | + |
| 61 | + ;; |
| 62 | + esac |
| 63 | +} |
| 64 | + |
| 65 | +echoit() { echo "$@"; "$@"; } |
| 66 | + |
| 67 | +multilib_src_configure() { |
| 68 | + # We pass manually instead of relying on the configure script/makefile |
| 69 | + # because it would pass it even for older binutils. |
| 70 | + use sparc && append-flags $(test-flags-CCLD -Wl,--no-warn-rwx-segments) |
| 71 | + |
| 72 | + # ideally we want !tc-ld-is-bfd for best future-proofing, but it needs |
| 73 | + # https://github.com/gentoo/gentoo/pull/28355 |
| 74 | + # mold needs this too but right now tc-ld-is-mold is also not available |
| 75 | + if tc-ld-is-lld; then |
| 76 | + append-ldflags -Wl,--undefined-version |
| 77 | + fi |
| 78 | + |
| 79 | + case ${CHOST} in |
| 80 | + *-mingw*|mingw*) |
| 81 | + ;; |
| 82 | + |
| 83 | + *) |
| 84 | + # bug #347167 |
| 85 | + local uname=$("${BROOT}"/usr/share/gnuconfig/config.sub "${CHOST}" | cut -d- -f3) |
| 86 | + |
| 87 | + local myconf=( |
| 88 | + --shared |
| 89 | + --prefix="${EPREFIX}/usr" |
| 90 | + --libdir="${EPREFIX}/usr/$(get_libdir)" |
| 91 | + ${uname:+--uname=${uname}} |
| 92 | + ) |
| 93 | + |
| 94 | + # Not an autoconf script, so can't use econf |
| 95 | + echoit "${S}"/configure "${myconf[@]}" || die |
| 96 | + |
| 97 | + ;; |
| 98 | + esac |
| 99 | + |
| 100 | + if use minizip ; then |
| 101 | + local minizipdir="contrib/minizip" |
| 102 | + mkdir -p "${BUILD_DIR}/${minizipdir}" || die |
| 103 | + |
| 104 | + cd ${minizipdir} || die |
| 105 | + ECONF_SOURCE="${S}/${minizipdir}" econf $(use_enable static-libs static) |
| 106 | + fi |
| 107 | +} |
| 108 | + |
| 109 | +multilib_src_compile() { |
| 110 | + case ${CHOST} in |
| 111 | + *-mingw*|mingw*) |
| 112 | + emake -f win32/Makefile.gcc STRIP=true PREFIX=${CHOST}- |
| 113 | + sed \ |
| 114 | + -e 's|@prefix@|'"${EPREFIX}"'/usr|g' \ |
| 115 | + -e 's|@exec_prefix@|${prefix}|g' \ |
| 116 | + -e 's|@libdir@|${exec_prefix}/'$(get_libdir)'|g' \ |
| 117 | + -e 's|@sharedlibdir@|${exec_prefix}/'$(get_libdir)'|g' \ |
| 118 | + -e 's|@includedir@|${prefix}/include|g' \ |
| 119 | + -e 's|@VERSION@|'${PV}'|g' \ |
| 120 | + zlib.pc.in > zlib.pc || die |
| 121 | + ;; |
| 122 | + |
| 123 | + *) |
| 124 | + emake |
| 125 | + |
| 126 | + ;; |
| 127 | + esac |
| 128 | + |
| 129 | + use minizip && emake -C contrib/minizip |
| 130 | +} |
| 131 | + |
| 132 | +sed_macros() { |
| 133 | + # Clean up namespace a little, bug #383179 |
| 134 | + # We do it here so we only have to tweak 2 files |
| 135 | + sed -i -r 's:\<(O[FN])\>:_Z_\1:g' "$@" || die |
| 136 | +} |
| 137 | + |
| 138 | +multilib_src_install() { |
| 139 | + case ${CHOST} in |
| 140 | + *-mingw*|mingw*) |
| 141 | + emake -f win32/Makefile.gcc install \ |
| 142 | + BINARY_PATH="${ED}/usr/bin" \ |
| 143 | + LIBRARY_PATH="${ED}/usr/$(get_libdir)" \ |
| 144 | + INCLUDE_PATH="${ED}/usr/include" \ |
| 145 | + SHARED_MODE=1 |
| 146 | + |
| 147 | + # Overwrites zlib.pc created from win32/Makefile.gcc, bug #620136 |
| 148 | + insinto /usr/$(get_libdir)/pkgconfig |
| 149 | + doins zlib.pc |
| 150 | + |
| 151 | + ;; |
| 152 | + |
| 153 | + *) |
| 154 | + emake install DESTDIR="${D}" LDCONFIG=: |
| 155 | + gen_usr_ldscript -a z |
| 156 | + |
| 157 | + ;; |
| 158 | + esac |
| 159 | + |
| 160 | + sed_macros "${ED}"/usr/include/*.h |
| 161 | + |
| 162 | + if use minizip ; then |
| 163 | + emake -C contrib/minizip install DESTDIR="${D}" |
| 164 | + sed_macros "${ED}"/usr/include/minizip/*.h |
| 165 | + |
| 166 | + # This might not exist if slibtool is used. |
| 167 | + # bug #816756 |
| 168 | + rm -f "${ED}"/usr/$(get_libdir)/libminizip.la || die |
| 169 | + fi |
| 170 | + |
| 171 | + if ! use static-libs ; then |
| 172 | + # bug #419645 |
| 173 | + rm "${ED}"/usr/$(get_libdir)/libz.a || die |
| 174 | + fi |
| 175 | +} |
| 176 | + |
| 177 | +multilib_src_install_all() { |
| 178 | + dodoc FAQ README ChangeLog doc/*.txt |
| 179 | + |
| 180 | + if use minizip ; then |
| 181 | + dodoc contrib/minizip/*.txt |
| 182 | + doman contrib/minizip/*.1 |
| 183 | + fi |
| 184 | +} |
0 commit comments