name=binutils
version=2.42
revision=1
tarball_url="https://ftp.gnu.org/gnu/binutils/binutils-${version}.tar.xz"
tarball_blake2b="e67a5c028fba70e70088fd11b38ec8c9c4ed5a019badefda25abeb6275997b16f0891e7ff3424c4b82bbfae92e8992669826920dd53df61cd48469d8f7cd5bd1"
source_hostdeps="autoconf-2.69 automake libtool pkg-config"
imagedeps="gcc"
hostdeps="gcc autoconf-2.69 automake libtool pkg-config"
deps="core-libs zlib zstd"

regenerate() {
    autotools_recursive_regen -I"$(realpath ./config)"

    cp -pv /usr/local/share/libtool/build-aux/{config.sub,config.guess,install-sh} libiberty/
}

build() {
    autotools_configure \
        --target=${OS_TRIPLET} \
        --with-build-sysroot=${sysroot_dir} \
        --enable-cet \
        --enable-colored-disassembly \
        --disable-werror \
        --with-system-zlib

    make -j${parallelism} all
}

package() {
    DESTDIR="${dest_dir}" make install

    # Remove unnecessary directory
    rm -rf "${dest_dir}${prefix}"/${OS_TRIPLET}

    # Remove static libraries
    rm -rf "${dest_dir}${prefix}"/lib/*.a

    post_package_strip
}
