name=libgcc
revision=1
hostdeps="gcc autoconf-2.69 automake libtool pkg-config"
imagedeps="gcc"
deps="mlibc"

build() {
    cd "${base_dir}"/host-builds/gcc/build

    make -j${parallelism} all-target-libgcc
}

package() {
    cd "${base_dir}"/host-builds/gcc/build

    rm -rf tmp_libgcc_dir
    mkdir tmp_libgcc_dir

    DESTDIR="$(realpath tmp_libgcc_dir)" make install-target-libgcc

    mkdir -p "${dest_dir}${prefix}"

    cp -r tmp_libgcc_dir/usr/local/lib "${dest_dir}${prefix}"/
    cp -r tmp_libgcc_dir/usr/local/${OS_TRIPLET}/* "${dest_dir}${prefix}"/

    # Copy libgcc into GCC's tree else it will complain.
    mkdir -p "${base_dir}"/host-pkgs/gcc/usr/local/lib
    cp -r tmp_libgcc_dir/usr/local/lib/* "${base_dir}"/host-pkgs/gcc/usr/local/lib/
}
