# vim: set ts=4 sw=4 et ai syn=sh:

declare -gr inst_script="$(realpath "${BASH_SOURCE[0]}")"

post_install() {
    local basedir="$(pwd -W)"
    local basedir="${basedir%/}"
    local basedir="${basedir//\//\\\\}"
    local basedir_double="${basedir//\\\\/\\\\\\\\}"
    local basedir_html="${basedir//\\\\/\\\/}"

    # PREFIX is an absolute path, i.e. /mingw64             @REM@
    cd "@PREFIX@"
    printf "%s Replacing perl relocation patterns\\n" "->"
    # FILELIST (and its contents) is relative to PREFIX     @REM@
    sed '1,/^FILELIST:$/d' "${inst_script}" | base64 -d | gzip -d \
    | xargs -0 -r sed -i \
        -e "s/@PERL_RELOCATE_DOUBLE@/${basedir_double}/g" \
        -e "s/@PERL_RELOCATE@/${basedir}/g" \
        -e "s/@PERL_RELOCATE_HTML@/\\/\\/${basedir_html}/g"
}

post_upgrade() {
    post_install
}

return 0

FILELIST:
