abinfo "Building DMD ..."
cd "$SRCDIR"/dmd
make \
    BUILD=release \
    ENABLE_RELEASE=1 \
    PIC=1 \
    ENABLE_LTO=0 \
    AUTO_BOOTSTRAP=1

abinfo "Building DMD D Runtime ..."
cd "$SRCDIR"/dmd/druntime
make \
    DMD="$SRCDIR"/dmd/generated/linux/release/*/dmd \
    BUILD=release \
    ENABLE_RELEASE=1 \
    PIC=1

abinfo "Building libphobos ..."
cd "$SRCDIR"/phobos
make \
    DMD="$SRCDIR"/dmd/generated/linux/release/*/dmd \
    BUILD=release \
    ENABLE_RELEASE=1 \
    PIC=1

abinfo "Building docs ..."
cd "$SRCDIR"/dmd/compiler
make -C docs

abinfo "Installing DMD and runtime ..."
install -Dvm755 "$SRCDIR"/dmd/generated/linux/release/*/dmd \
    "$PKGDIR"/usr/bin/dmd
mkdir -vp "$PKGDIR"/usr/lib
cp -vP $(find "$SRCDIR"/dmd/generated/linux/release/ -maxdepth 2 \( -iname "*.a" -a \! -iname "*.so.a" \) \
         -o \( -iname "*.so*" -a \! -iname "*.o" -a \! -iname "*.a" \) ) \
    "$PKGDIR"/usr/lib
cp -vP $(find "$SRCDIR"/phobos/generated/linux/release/ \( -iname "*.a" -a \! -iname "*.so.a" \) \
         -o \( -iname "*.so*" -a \! -iname "*.o" -a \! -iname "*.a" \) ) \
    "$PKGDIR"/usr/lib

abinfo "Installing man pages ..."
install -Dvm644 "$SRCDIR"/dmd/generated/docs/man/man1/*.1 \
    -t "$PKGDIR"/usr/share/man/man1/
install -Dvm644 "$SRCDIR"/dmd/generated/docs/man/man5/*.5 \
    -t "$PKGDIR"/usr/share/man/man5/

abinfo "Installing headers and sources ..."
mkdir -pv "$PKGDIR"/usr/include/dlang/dmd
cp -rv "$SRCDIR"/phobos/{*.d,etc,std} \
    "$PKGDIR"/usr/include/dlang/dmd
cp -rv "$SRCDIR"/dmd/druntime/import/* \
    "$PKGDIR"/usr/include/dlang/dmd/
