# Shadow build is necessary for a successful GCC build (at least for 4.9.2).
cd "$SRCDIR"/abbuild

abinfo "Building GCC documentations..."
make -C ${ARCH_TARGET[$ARCH]}/libstdc++-v3/doc doc-man-doxygen

abinfo "Installing libgccjit (with some files going to be overrided by general GCC) ..."
make -C "$SRCDIR"/jitbuild install DESTDIR="$PKGDIR"

abinfo "Installing GCC ..."
make install DESTDIR="$PKGDIR"

abinfo "Generating Python code cache ..."
python3 -m compileall "$PKGDIR"/usr/share/gcc-$PKGVER/python

cd "$SRCDIR"

if [ -d "$PKGDIR"/usr/lib64 ]; then
    abinfo "Moving /usr/lib64 => /usr/lib ..."
    cp -arv "$PKGDIR"/usr/lib{64/*,/}
    rm -rv "$PKGDIR"/usr/lib64
fi

if [ -d "$PKGDIR"/usr/lib32 ]; then
    abinfo "Moving /usr/lib32 => /usr/lib ..."
    cp -arv "$PKGDIR"/usr/lib{32/*,/}
    rm -rv "$PKGDIR"/usr/lib32
fi
