diff --git a/pmb/aportgen/binutils.py b/pmb/aportgen/binutils.py index d944686b..7bc50f4b 100644 --- a/pmb/aportgen/binutils.py +++ b/pmb/aportgen/binutils.py @@ -16,45 +16,12 @@ def generate(args, pkgname): "pkgname": pkgname, "pkgdesc": f"Tools necessary to build programs for {arch} targets", "arch": pmb.config.arch_native, - "makedepends_build": "", - "makedepends_host": "", - "makedepends": "gettext libtool autoconf automake bison texinfo", - "subpackages": "", } - replace_functions = { - "build": """ - _target="$(arch_to_hostspec """ + arch + """)" - "$builddir"/configure \\ - --build="$CBUILD" \\ - --target=$_target \\ - --with-lib-path=/usr/lib \\ - --prefix=/usr \\ - --with-sysroot=/usr/$_target \\ - --enable-ld=default \\ - --enable-gold=yes \\ - --enable-plugins \\ - --enable-deterministic-archives \\ - --disable-multilib \\ - --disable-werror \\ - --disable-nls - make - """, - "package": """ - make install DESTDIR="$pkgdir" - - # remove man, info folders - rm -rf "$pkgdir"/usr/share - - # remove files that conflict with non-cross binutils - rm -rf "$pkgdir"/usr/lib/bfd-plugins - """, - "libs": None, - "gold": None, - } - - replace_simple = {"\tsubpackages=*": "\tsubpackages=\"\""} + below_header = """ + CTARGET_ARCH=""" + arch + """ + CTARGET="$(arch_to_hostspec $CTARGET_ARCH)" + """ pmb.aportgen.core.rewrite(args, pkgname, "main/binutils", fields, - "binutils", replace_functions, replace_simple, - remove_indent=8) + "binutils", below_header=below_header) diff --git a/test/testdata/aportgen/pmaports/cross/binutils-armhf/APKBUILD b/test/testdata/aportgen/pmaports/cross/binutils-armhf/APKBUILD index 44d38192..29e7cfe6 100644 --- a/test/testdata/aportgen/pmaports/cross/binutils-armhf/APKBUILD +++ b/test/testdata/aportgen/pmaports/cross/binutils-armhf/APKBUILD @@ -2,14 +2,21 @@ # Generator: pmbootstrap aportgen binutils-armhf # Based on: main/binutils + +CTARGET_ARCH=armhf +CTARGET="$(arch_to_hostspec $CTARGET_ARCH)" + pkgname=binutils-armhf pkgver=2.35.2 pkgrel=1 pkgdesc="Tools necessary to build programs for armhf targets" url="https://www.gnu.org/software/binutils/" -makedepends="gettext libtool autoconf automake bison texinfo" +makedepends_build="bison flex texinfo" +makedepends_host="zlib-dev" +makedepends="$makedepends_build $makedepends_host" arch="x86_64" license="GPL-2.0 GPL-3.0-or-later LGPL-2.0 BSD" +subpackages="binutils-dev binutils-doc" source="https://ftp.gnu.org/gnu/binutils/binutils-$pkgver.tar.xz binutils-ld-fix-static-linking.patch gold-mips.patch @@ -20,7 +27,7 @@ source="https://ftp.gnu.org/gnu/binutils/binutils-$pkgver.tar.xz builddir="$srcdir/binutils-$pkgver" if [ "$CHOST" = "$CBUILD" ] && [ "$CBUILD" = "$CTARGET" ] && [ "$CTARGET_ARCH" != "riscv64" ]; then - subpackages="" + subpackages="$subpackages binutils-gold" fi if [ "$CHOST" != "$CTARGET" ]; then @@ -41,34 +48,91 @@ fi # - CVE-2017-7614 build() { - _target="$(arch_to_hostspec armhf)" - "$builddir"/configure \ - --build="$CBUILD" \ - --target=$_target \ - --with-lib-path=/usr/lib \ + local _sysroot=/ + local _cross_configure="--enable-install-libiberty --enable-shared" + local _arch_configure="" + local _gold_configure="--disable-gold" + + if [ "$CHOST" != "$CTARGET" ]; then + _sysroot="$CBUILDROOT" + _cross_configure="--disable-install-libiberty" + fi + + if [ "$CHOST" = "$CBUILD" ] && [ "$CBUILD" = "$CTARGET" ] && [ "$CTARGET_ARCH" != "riscv64" ]; then + _gold_configure="--enable-gold" + fi + + if [ "$CTARGET_ARCH" = "x86_64" ]; then + _arch_configure="--enable-targets=x86_64-pep" + fi + + if [ "$CTARGET_ARCH" = "riscv64" ]; then + _gold_configure="--disable-gold" + fi + + case "$CTARGET_ARCH" in + mips*) _hash_style_configure="--enable-default-hash-style=sysv" ;; + *) _hash_style_configure="--enable-default-hash-style=gnu" ;; + esac + + ./configure \ + --build=$CBUILD \ + --host=$CHOST \ + --target=$CTARGET \ + --with-build-sysroot="$CBUILDROOT" \ + --with-sysroot=$_sysroot \ --prefix=/usr \ - --with-sysroot=/usr/$_target \ - --enable-ld=default \ - --enable-gold=yes \ - --enable-plugins \ - --enable-deterministic-archives \ + --mandir=/usr/share/man \ + --infodir=/usr/share/info \ --disable-multilib \ + --enable-ld=default \ + $_gold_configure \ + --enable-64-bit-bfd \ + --enable-plugins \ + --enable-relro \ + --enable-deterministic-archives \ + $_cross_configure \ + $_arch_configure \ + $_hash_style_configure \ + --with-pic \ --disable-werror \ - --disable-nls + --disable-nls \ + --with-mmap \ + --with-system-zlib make } package() { make install DESTDIR="$pkgdir" - - # remove man, info folders - rm -rf "$pkgdir"/usr/share - - # remove files that conflict with non-cross binutils - rm -rf "$pkgdir"/usr/lib/bfd-plugins + if [ -d "$pkgdir"/usr/lib64 ]; then + mv "$pkgdir"/usr/lib64/* "$pkgdir"/usr/lib/ + rmdir "$pkgdir"/usr/lib64 + fi + if [ "$CHOST" != "$CTARGET" ]; then + # creating cross tools: remove any files that would conflict + # with the native tools, or other cross tools + rm -r "${pkgdir:?}"/usr/share + rm -f "$pkgdir"/usr/lib/libiberty.a + fi } +libs() { + pkgdesc="Runtime libraries from binutils - libbfd and libopcodes" + mkdir -p "$subpkgdir"/usr/lib + mv "$pkgdir"/usr/lib/lib*.so "$subpkgdir"/usr/lib/ +} + +gold() { + pkgdesc="GNU binutils - gold linker" + + if [ -e "$pkgdir"/usr/bin/ld.gold ]; then + mkdir -p "$subpkgdir"/usr/bin + mv "$pkgdir"/usr/bin/ld.gold "$subpkgdir"/usr/bin + fi + mkdir -p "$subpkgdir"/usr/$CTARGET/bin + mv "$pkgdir"/usr/$CTARGET/bin/ld.gold "$subpkgdir"/usr/$CTARGET/bin/ld.gold +} sha512sums="9974ede5978d32e0d68fef23da48fa00bd06b0bff7ec45b00ca075c126d6bbe0cf2defc03ecc3f17bc6cc85b64271a13009c4049d7ba17de26e84e3a6e2c0348 binutils-2.35.2.tar.xz ecee33b0e435aa704af1c334e560f201638ff79e199aa11ed78a72f7c9b46f85fbb227af5748e735fd681d1965fcc42ac81b0c8824e540430ce0c706c81e8b49 binutils-ld-fix-static-linking.patch