+export LANG='C.UTF-8'
+export LANGUAGE="${LANG}"
+
+_sed () {
+ case "${system_name}" in
+ 'macos'|'freebsd')
+ gsed "${@}"
+ ;;
+ *)
+ sed "${@}"
+ ;;
+ esac
+}
+
+_cp () {
+ case "${system_name}" in
+ 'macos'|'freebsd')
+ gcp -R --preserve=timestamps -H -L "${1}" "${2}"
+ ;;
+ *)
+ cp -R --preserve=timestamps -H -L "${1}" "${2}"
+ ;;
+ esac
+}
+
+Common::noOp () {
+ true
+}
+
+Common::getPath () {
+ local file_path="${1}"
+
+ if command -v cygpath >/dev/null
+ then
+ if [ "${file_path}" = '-' ]
+ then
+ tr '\n' '\0' \
+ | xargs -0 -n1 -P1 -I{} \
+ cygpath --unix '{}'
+ else
+ cygpath --unix "${file_path}"
+ fi
+ else
+ if [ "${file_path}" = '-' ]
+ then
+ cat
+ else
+ printf '%s\n' "${file_path}"
+ fi
+ fi \
+ | _sed -e 's|/*$||'
+}
+
+Common::grepLdd () {
+ case "${system_name}" in
+ 'macos')
+ egrep '^\t/'
+ ;;
+ *)
+ egrep ' => '
+ ;;
+ esac
+}
+
+Common::stripLdd () {
+ case "${system_name}" in
+ 'macos')
+ _sed -e 's/^\t\(.*\) (compatibility version .*/\1/'
+ ;;
+ *)
+ _sed -e 's/ (0x[0-9a-f]*)$//;s/^.* => //'
+ ;;
+ esac
+}
+
+Multi::excludeLdd () {
+ case "${system_name}" in
+ 'linux'|'freebsd')
+ # - always bundle built-in libraries
+ # - always rely on up-to-date x11 and gl libraries, bundling them will break on future distros
+ # - gtk is not easily bundlable on linux because it looks for harcoded system path to optional
+ # shared libraries like image codecs, theme engines, sound notification system, etc.
+ # so expect user to install gtk first
+ # - since we ask user to instal gtk, we can also ask them to install gtkglext,
+ # which is likely to pull gtk itself, x11 and gl dependencies
+ # - old fontconfig does not work correctly if newer fontconfig configuration is installed
+ # - if gtk and fontconfig is installed, pango and freetype are
+ local ldd_line
+ while read ldd_line
+ do
+ if echo "${ldd_line}" | egrep '/builtins/'
+ then
+ echo "${ldd_line}"
+ elif echo "${ldd_line}" \
+ | egrep -q '/libc\.|/libstdc\+\+\.|/libdl\.|/libm\.|/libX|/libxcb|/libGL|/libICE\.|/libSM\.|/libpthread\.'
+ then
+ Common::noOp
+ elif echo "${ldd_line}" \
+ | egrep -q '/libatk|/libgdk|/libgtk|/libgio|/libglib|/libgmodule|/libgobject|/libcairo|/libpango|/libfontconfig|/libfreetype'
+ then
+ Common::noOp
+ # FreeBSD specific
+ elif echo "${ldd_line}" \
+ | egrep -q '/libc++|/libgxxrt'
+ then
+ Common::noOp
+ else
+ echo "${ldd_line}"
+ fi
+ done
+ ;;
+ 'windows')
+ egrep -i '\.dll => [A-Z]:\\msys64\\'
+ ;;
+ 'macos')
+ egrep -v '^\t/System/|^\t/usr/lib/'
+ ;;
+ esac
+}
+
+Multi::filterLib () {
+ Common::grepLdd \
+ | Multi::excludeLdd \
+ | Common::stripLdd \
+ | Common::getPath -
+}
+
+Multi::printLdd () {
+ local exe_file="${1}"
+
+ case "${system_name}" in
+ 'linux'|'freebsd')
+ ldd "${exe_file}"
+ ;;
+ 'windows')
+ ntldd --recursive "${exe_file}"
+ ;;
+ 'macos')
+ otool -L "${exe_file}"
+ esac
+}
+
+Multi::getGtkThemeName () {
+ case "${system_name}" in
+ 'linux'|'freebsd')
+ echo 'Adwaita'
+ ;;
+ 'windows')
+ echo 'MS-Windows'
+ ;;
+ *)
+ echo 'Raleigh'
+ ;;
+ esac
+}
+
+Multi::getGtkLibName () {
+ case "${system_name}" in
+ 'linux'|'freebsd')
+ echo 'libgtk-x11-2.0.so.0'
+ ;;
+ 'windows')
+ echo 'libgtk-win32-2.0-0.dll'
+ ;;
+ 'macos')
+ echo 'libgtk-quartz-2.0.0.dylib'
+ ;;
+ esac
+}
+
+Multi::getRootPrefix () {
+ local lib_file="${1}"
+
+ case "${system_name}" in
+ 'linux'|'freebsd')
+ echo "${lib_file}" \
+ | cut -f2 -d'/'
+ ;;
+ 'windows')
+ basename "${lib_file}" \
+ | xargs -n1 -P1 which \
+ | cut -f2 -d'/'
+ ;;
+ 'macos')
+ echo 'usr/local'
+ esac
+}
+
+Multi::getLibPrefix () {
+ local lib_file="${1}"
+
+ case "${system_name}" in
+ 'linux'|'freebsd')
+ dirname "${lib_file}" \
+ | cut -f3- -d'/'
+ ;;
+ 'windows')
+ echo 'lib'
+ ;;
+ 'macos')
+ echo 'lib'
+ ;;
+ esac
+}
+
+Multi::getGtkDeps () {
+ local lib_prefix="${1}"
+ local gtk_theme_name="${2}"
+
+ case "${system_name}" in
+ 'linux'|'freebsd'|'windows')
+ cat <<-EOF
+ share/themes/${gtk_theme_name}/gtk-2.0
+ share/icons/hicolor
+ ${lib_prefix}/gdk-pixbuf-2.0
+ ${lib_prefix}/gtk-2.0
+ EOF
+ ;;
+ 'macos')
+ cat <<-EOF
+ etc/fonts
+ share/themes/${gtk_theme_name}/gtk-2.0
+ share/fontconfig
+ share/icons/hicolor
+ share/locale
+ ${lib_prefix}/gdk-pixbuf-2.0
+ ${lib_prefix}/gtk-2.0
+ EOF
+ ;;
+ esac
+
+ case "${system_name}" in
+ 'linux'|'freebsd')
+ cat <<-EOF
+ ${lib_prefix}/libatk-bridge-2.0.so.0
+ ${lib_prefix}/libcanberra-0.30
+ ${lib_prefix}/libcanberra.so.0
+ ${lib_prefix}/libcanberra-gtk.so.0
+ EOF
+ ;;
+ esac
+}
+
+Multi::rewriteLoadersCache () {
+ local bundle_component_path="${1}"
+ local cache_file
+
+ find "${bundle_component_path}" \
+ -type f \
+ \( \
+ -name 'loaders.cache' \
+ -o -name 'immodules.cache' \
+ \) \
+ | while read cache_file
+ do
+ _sed \
+ -e 's|^"/[^"]*/lib/|"lib/|;s| "/[^"]*/share/| "share/|;/^# ModulesPath = /d;/^# Created by /d;/^#$/d' \
+ -i "${cache_file}"
+ done
+}
+
+Multi::bundleGtkDepsFromFile () {
+ local lib_file="${1}"
+ local component_dir
+ local real_component_dir
+ local bundle_component_dir
+
+ lib_basename="$(basename "${lib_file}")"
+
+ gtk_lib_name="$(Multi::getGtkLibName)"
+ if [ "${lib_basename}" = "${gtk_lib_name}" ]
+ then
+ root_prefix="$(Multi::getRootPrefix "${lib_file}")"
+ lib_prefix="$(Multi::getLibPrefix "${lib_file}")"
+ gtk_theme_name="$(Multi::getGtkThemeName)"
+
+ for component_dir in $(Multi::getGtkDeps "${lib_prefix}" "${gtk_theme_name}")