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

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

    make -j${parallelism} all-target-libstdc++-v3
}

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

    rm -rf tmp_libstdc++_dir
    mkdir tmp_libstdc++_dir

    DESTDIR="$(realpath tmp_libstdc++_dir)" make install-target-libstdc++-v3

    # For some reason this also installs libgcc even though it shouldn't...
    # Remove it.
    rm -fv tmp_libstdc++_dir/usr/local/${OS_TRIPLET}/lib/libgcc*

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

    cp -r tmp_libstdc++_dir/usr/local/share "${dest_dir}${prefix}"/
    cp -r tmp_libstdc++_dir/usr/local/${OS_TRIPLET}/* "${dest_dir}${prefix}"/

    # Copy libstdc++ and headers into GCC's tree else it will complain.
    mkdir -p "${base_dir}"/host-pkgs/gcc/usr/local/${OS_TRIPLET}
    cp -r tmp_libstdc++_dir/usr/local/${OS_TRIPLET}/* "${base_dir}"/host-pkgs/gcc/usr/local/${OS_TRIPLET}/
}
