for i in wmc wrc wine64 wineserver; do
    abinfo "Deleting rpath from '$i'..."
    test -e "$PKGDIR"/usr/bin/$i && chrpath --delete "$PKGDIR"/usr/bin/$i
done

abinfo "Installing Gecko components ..."
mkdir -pv "$PKGDIR"/usr/share/wine/gecko
cp -av "$SRCDIR"/../wine-gecko-${__GECKO_VER}-x86{,_64} \
    "$PKGDIR"/usr/share/wine/gecko/

abinfo "Installing Mono components ..."
mkdir -pv "$PKGDIR"/usr/share/wine/mono
cp -av "$SRCDIR"/../wine-mono-${__MONO_VER} \
    "$PKGDIR"/usr/share/wine/mono/

abinfo "Patching DXVK DLLs as built-in Wine libraries ..."
for dir in "$SRCDIR"/../dxvk-${__DXVK_VER}/{x32,x64}; do
    for file in "$dir"/*; do
        [ -f "$file" ] && printf 'Wine builtin DLL\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' | dd of="$file" bs=1 seek=64 conv=notrunc
    done
done

abinfo "Installing DXVK DLLs ..."
cp -av "$SRCDIR"/../dxvk-${__DXVK_VER}/x64/. \
    "$PKGDIR"/usr/lib/wine/x86_64-windows/
cp -av "$SRCDIR"/../dxvk-${__DXVK_VER}/x32/. \
    "$PKGDIR"/usr/lib/wine/i386-windows/

abinfo "Patching vkd3d-proton DLLs as built-in Wine libraries ..."
for dir in "$SRCDIR"/../vkd3d-proton-${__VKD3D_PROTON_VER}/{x86,x64}; do
    for file in "$dir"/*; do 
        [ -f "$file" ] && printf 'Wine builtin DLL\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' | dd of="$file" bs=1 seek=64 conv=notrunc
    done
done

abinfo "Installing vkd3d-proton DLLs ..."
cp -av "$SRCDIR"/../vkd3d-proton-${__VKD3D_PROTON_VER}/x64/. \
    "$PKGDIR"/usr/lib/wine/x86_64-windows/
cp -av "$SRCDIR"/../vkd3d-proton-${__VKD3D_PROTON_VER}/x86/. \
    "$PKGDIR"/usr/lib/wine/i386-windows/ 

# Routine adapted from Fedora.
#
# Ref: https://src.fedoraproject.org/rpms/wine/blob/b6dbe710ac007feb968c471054f0235cc8ca01b7/f/wine.spec#_841
abinfo "Installing icons ..."
# Fedora: This replacement masks a composite program icon .SVG down so that
# only its full-size scalable icon is visible
PROGRAM_ICONFIX='s/height="272"/height="256"/;'\
's/width="632"/width="256"\n'\
'   x="368"\n'\
'   y="8"\n'\
'   viewBox="368, 8, 256, 256"/;'
MAIN_ICONFIX='s/height="272"/height="256"/;'\
's/width="632"/width="256"\n'\
'   x="8"\n'\
'   y="8"\n'\
'   viewBox="8, 8, 256, 256"/;'

# Fedora: This icon file is still in the legacy format.
install -Dvm644 "$SRCDIR"/dlls/user32/resources/oic_winlogo.svg \
    "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/wine.svg
sed -e "$MAIN_ICONFIX" \
    -i "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/wine.svg

# Fedora: The rest come from programs/, and contain larger scalable icons with
# a new layout that requires the PROGRAM_ICONFIX sed adjustment.
install -Dvm644 "$SRCDIR"/programs/notepad/notepad.svg \
    "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/notepad.svg
sed -e "$PROGRAM_ICONFIX" \
    -i "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/notepad.svg
install -Dvm644 "$SRCDIR"/programs/regedit/regedit.svg \
    "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/regedit.svg
sed -e "$PROGRAM_ICONFIX" \
    -i "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/regedit.svg
install -Dvm644 "$SRCDIR"/programs/msiexec/msiexec.svg \
    "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/msiexec.svg
sed -e "$PROGRAM_ICONFIX" \
    -i "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/msiexec.svg
install -Dvm644 "$SRCDIR"/programs/winecfg/winecfg.svg \
    "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/winecfg.svg
sed -e "$PROGRAM_ICONFIX" \
    -i "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/winecfg.svg
install -Dvm644 "$SRCDIR"/programs/winefile/winefile.svg \
    "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/winefile.svg
sed -e "$PROGRAM_ICONFIX" \
    -i "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/winefile.svg
install -Dvm644 "$SRCDIR"/programs/winemine/winemine.svg \
    "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/winemine.svg
sed -e "$PROGRAM_ICONFIX" \
    -i "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/winemine.svg
install -Dvm644 "$SRCDIR"/programs/winhlp32/winhelp.svg \
    "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/winhelp.svg
sed -e "$PROGRAM_ICONFIX" \
    -i "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/winhelp.svg
install -Dvm644 "$SRCDIR"/programs/wordpad/wordpad.svg \
    "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/wordpad.svg
sed -e "$PROGRAM_ICONFIX" \
    -i "$PKGDIR"/usr/share/icons/hicolor/scalable/apps/wordpad.svg
