abinfo "Creating build configuration ..."
cat > "$SRCDIR/renpy/vc_version.py" << EOF
branch = 'master'
nightly = False
official = False
version = "$PKGVER"
version_name = 'TBD'
EOF

abinfo "Building Ren'Py ..."
python3 setup.py build_ext --inplace

abinfo "Installing Ren'Py ..."
mkdir -pv "$PKGDIR"/usr/share/renpy

cp -av \
    "$SRCDIR"/sdk-fonts \
    "$SRCDIR"/launcher \
    "$SRCDIR"/renpy \
    "$SRCDIR"/renpy.py \
    "$SRCDIR"/the_question \
    "$SRCDIR"/tutorial \
    "$SRCDIR"/gui \
    "$PKGDIR"/usr/share/renpy
install -Dvm644 "$SRCDIR"/launcher/game/images/logo.png \
    "$PKGDIR"/usr/share/pixmaps/renpy.png
install -Dvm644 "$SRCDIR"/sphinx/source/license.rst \
    "$PKGDIR"/usr/share/doc/renpy/LICENSE.sphinx
install -Dvm644 "$SRCDIR"/README.rst \
    "$PKGDIR"/usr/share/doc/renpy/README.rst

install -dvm755 \
    "$PKGDIR"/usr/share/renpy/lib/"py3-linux-$(uname -m)"
ln -sv ../../../../bin/renpy \
    "$PKGDIR"/usr/share/renpy/lib/"py3-linux-$(uname -m)"
# Use system font than provided to avoid CJK figure issue.
# Font path is hardcoded so we link system font here.
ln -sfv ../../fonts/TTF/NotoSansCJK-Regular.ttc \
    "$PKGDIR"/usr/share/renpy/sdk-fonts/SourceHanSansLite.ttf

abinfo "Fixing permissions ..."
chmod -R 755 "$PKGDIR"/usr/share/renpy
