sys-apps/file: refactor cross-compile logic
authorMike Gilbert <floppym@gentoo.org>
Sat, 4 Jan 2020 18:07:12 +0000 (13:07 -0500)
committerMike Gilbert <floppym@gentoo.org>
Sat, 4 Jan 2020 18:08:29 +0000 (13:08 -0500)
Add build_src_configure and need_build_file helper functions.
Pass --disable-{bzlib,xzlib,zlib} to configure in build_src_configure.
Use tc-env_build helper in build_src_configure.
Convert "ROOT=/ has_version" to PMS-compliant "has_version -b".
Make ECONF_SOURCE and PATH local variables.

Closes: https://bugs.gentoo.org/704776
Package-Manager: Portage-2.3.84_p2, Repoman-2.3.20_p24
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
sys-apps/file/file-5.38.ebuild
sys-apps/file/file-9999.ebuild

index 74b955f43b6d38e5cef0cbd95ffd7210c243a107..93d716314d531a91d801c8b573ab7c2c2569dc84 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2019 Gentoo Authors
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=7
@@ -55,28 +55,34 @@ multilib_src_configure() {
                $(use_enable static-libs static)
                $(use_enable zlib)
        )
-       ECONF_SOURCE="${S}" econf "${myeconfargs[@]}"
+       econf "${myeconfargs[@]}"
 }
 
-src_configure() {
+build_src_configure() {
+       local myeconfargs=(
+               --disable-shared
+               --disable-libseccomp
+               --disable-bzlib
+               --disable-xzlib
+               --disable-zlib
+       )
+       tc-env_build econf "${myeconfargs[@]}"
+}
+
+need_build_file() {
        # when cross-compiling, we need to build up our own file
        # because people often don't keep matching host/target
        # file versions #362941
-       if tc-is-cross-compiler && ! ROOT=/ has_version ~${CATEGORY}/${P} ; then
+       tc-is-cross-compiler && ! has_version -b "~${CATEGORY}/${P}"
+}
+
+src_configure() {
+       local ECONF_SOURCE=${S}
+
+       if need_build_file; then
                mkdir -p "${WORKDIR}"/build || die
                cd "${WORKDIR}"/build || die
-               tc-export_build_env BUILD_C{C,XX}
-               ECONF_SOURCE="${S}" \
-               ac_cv_header_zlib_h=no \
-               ac_cv_lib_z_gzopen=no \
-               CHOST=${CBUILD} \
-               CFLAGS=${BUILD_CFLAGS} \
-               CXXFLAGS=${BUILD_CXXFLAGS} \
-               CPPFLAGS=${BUILD_CPPFLAGS} \
-               LDFLAGS="${BUILD_LDFLAGS} -static" \
-               CC=${BUILD_CC} \
-               CXX=${BUILD_CXX} \
-               econf --disable-shared --disable-libseccomp
+               build_src_configure
        fi
 
        multilib-minimal_src_configure
@@ -93,10 +99,10 @@ multilib_src_compile() {
 }
 
 src_compile() {
-       if tc-is-cross-compiler && ! ROOT=/ has_version "~${CATEGORY}/${P}" ; then
+       if need_build_file; then
                emake -C "${WORKDIR}"/build/src magic.h #586444
                emake -C "${WORKDIR}"/build/src file
-               PATH="${WORKDIR}/build/src:${PATH}"
+               local -x PATH="${WORKDIR}/build/src:${PATH}"
        fi
        multilib-minimal_src_compile
 
index fb29c4f2a25cf8a50730b6cd7983b73925087b70..d834362dd1e846751ea4953d9454c55f04a7b19b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2019 Gentoo Authors
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=7
@@ -56,28 +56,34 @@ multilib_src_configure() {
                $(use_enable static-libs static)
                $(use_enable zlib)
        )
-       ECONF_SOURCE="${S}" econf "${myeconfargs[@]}"
+       econf "${myeconfargs[@]}"
 }
 
-src_configure() {
+build_src_configure() {
+       local myeconfargs=(
+               --disable-shared
+               --disable-libseccomp
+               --disable-bzlib
+               --disable-xzlib
+               --disable-zlib
+       )
+       tc-env_build econf "${myeconfargs[@]}"
+}
+
+need_build_file() {
        # when cross-compiling, we need to build up our own file
        # because people often don't keep matching host/target
        # file versions #362941
-       if tc-is-cross-compiler && ! ROOT=/ has_version ~${CATEGORY}/${P} ; then
+       tc-is-cross-compiler && ! has_version -b "~${CATEGORY}/${P}"
+}
+
+src_configure() {
+       local ECONF_SOURCE=${S}
+
+       if need_build_file; then
                mkdir -p "${WORKDIR}"/build || die
                cd "${WORKDIR}"/build || die
-               tc-export_build_env BUILD_C{C,XX}
-               ECONF_SOURCE="${S}" \
-               ac_cv_header_zlib_h=no \
-               ac_cv_lib_z_gzopen=no \
-               CHOST=${CBUILD} \
-               CFLAGS=${BUILD_CFLAGS} \
-               CXXFLAGS=${BUILD_CXXFLAGS} \
-               CPPFLAGS=${BUILD_CPPFLAGS} \
-               LDFLAGS="${BUILD_LDFLAGS} -static" \
-               CC=${BUILD_CC} \
-               CXX=${BUILD_CXX} \
-               econf --disable-shared $(use_enable seccomp libseccomp)
+               build_src_configure
        fi
 
        multilib-minimal_src_configure
@@ -94,10 +100,10 @@ multilib_src_compile() {
 }
 
 src_compile() {
-       if tc-is-cross-compiler && ! ROOT=/ has_version "~${CATEGORY}/${P}" ; then
+       if need_build_file; then
                emake -C "${WORKDIR}"/build/src magic.h #586444
                emake -C "${WORKDIR}"/build/src file
-               PATH="${WORKDIR}/build/src:${PATH}"
+               local -x PATH="${WORKDIR}/build/src:${PATH}"
        fi
        multilib-minimal_src_compile