10 if command -v cygpath >/dev/null
12 if [ "${file_path}" = '-' ]
15 | xargs -0 -n1 -P1 -I{} \
18 cygpath --unix "${file_path}"
21 if [ "${file_path}" = '-' ]
25 printf '%s\n' "${file_path}"
35 sed -e 's/ (0x[0-9a-f]*)$//;s/^.* => //'
38 Multi::excludeLdd () {
39 case "${system_name}" in
41 egrep -v '/libc\.|/libdl\.|/libm\.|/libX|/libxcb|/libGL'
44 egrep -i '\.dll => [A-Z]:\\msys64\\' \
59 case "${system_name}" in
64 ntldd --recursive "${exe_file}"
69 Multi::getGtkThemeName () {
70 case "${system_name}" in
80 Multi::getGtkLibName () {
81 case "${system_name}" in
83 echo 'libgtk-x11-2.0.so.0'
86 echo 'libgtk-win32-2.0-0.dll'
91 Multi::getRootPrefix () {
94 case "${system_name}" in
100 basename "${lib_file}" \
101 | xargs -n1 -P 1 which \
107 Multi::getLibPrefix () {
108 local lib_file="${1}"
110 case "${system_name}" in
112 dirname "${lib_file}" \
121 Multi::getGtkDeps () {
122 local lib_prefix="${1}"
123 local gtk_theme_name="${2}"
126 share/themes/${gtk_theme_name}/gtk-2.0
128 ${lib_prefix}/gdk-pixbuf-2.0
129 ${lib_prefix}/gtk-2.0
132 case "${system_name}" in
135 ${lib_prefix}/libatk-bridge-2.0.so.0
136 ${lib_prefix}/libcanberra-0.30
137 ${lib_prefix}/libcanberra.so.0
138 ${lib_prefix}/libcanberra-gtk.so.0
144 Multi::bundleGtkDepsFromFile () {
145 local lib_file="${1}"
147 lib_basename="$(basename "${lib_file}")"
149 gtk_lib_name="$(Multi::getGtkLibName)"
150 if [ "${lib_basename}" = "${gtk_lib_name}" ]
152 root_prefix="$(Multi::getRootPrefix "${lib_file}")"
153 lib_prefix="$(Multi::getLibPrefix "${lib_file}")"
154 gtk_theme_name="$(Multi::getGtkThemeName)"
156 for component_dir in $(Multi::getGtkDeps "${lib_prefix}" "${gtk_theme_name}")
158 bundle_component_dir="$(echo "${component_dir}" | sed -e 's|^'"${lib_prefix}"'|lib|')"
159 if ! [ -e "${bundle_dir}/${bundle_component_dir}" ]
161 mkdir --parents "${bundle_dir}/$(dirname "${bundle_component_dir}")"
163 cp -H -r --preserve=timestamps \
164 "/${root_prefix}/${component_dir}" \
165 "${bundle_dir}/${bundle_component_dir}"
171 Multi::bundleLibFromFile () {
172 local exe_file="${1}"
174 Multi::printLdd "${exe_file}" \
176 | while read lib_file
178 lib_basename="$(basename "${lib_file}")"
180 if [ -f "${bundle_dir}/${lib_basename}" ]
185 cp --preserve=timestamps \
187 "${lib_dir}/${lib_basename}"
189 Multi::bundleGtkDepsFromFile "${lib_file}"
194 find "${bundle_dir}/lib" \
199 find "${bundle_dir}/lib" \
204 find "${bundle_dir}/lib" \
207 -exec rmdir --ignore-fail-on-non-empty {} \;
211 local exe_file="${1}"
213 patchelf --set-rpath "${rpath_string}" "${exe_file}"
222 -exec patchelf --set-rpath "${rpath_string}" {} \;
225 Windows::listLibForManifest () {
232 -exec basename {} \; \
234 | xargs -0 -n1 -P1 -I{} \
235 printf ' <file name="{}"/>\n'
238 Windows::writeManifest () {
241 cat > "${manifest_file}" <<-EOF
242 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
243 <assemblyIdentity type="win32" name="lib" version="1.0.0.0"/>
244 $(Windows::listLibForManifest "${lib_dir}")
249 system_name="${1}"; shift
250 bundle_dir="${1}"; shift
251 exe_file="${1}"; shift
253 bundle_dir="$(Common::getPath "${bundle_dir}")"
254 registry_dir="${bundle_dir}/registry"
255 lib_dir="${bundle_dir}/lib"
257 manifest_file="${lib_dir}/lib.manifest"
259 rpath_string='@executable_path:lib'
261 exe_action='Common::noOp'
262 lib_action='Common::noOp'
264 case "${system_name}" in
266 mkdir --parents "${registry_dir}"
267 Common::getPath "${exe_file}" > "${registry_dir}/$(uuidgen)"
271 exe_action='Linux::patchExe'
272 lib_action='Linux::patchLib'
275 lib_action='Windows::writeManifest'
278 printf 'ERROR: unsupported system: %s\n' "${system_name}" >&2
283 mkdir --parents "${lib_dir}"
285 if [ -d "${registry_dir}" ]
287 for registry_entry in "${registry_dir}"/*
289 exe_file="$(cat "${registry_entry}")"
291 Multi::bundleLibFromFile "${exe_file}"
293 "${exe_action}" "${exe_file}"
295 rm "${registry_entry}"
297 "${exe_action}" "${exe_file}"
300 rmdir "${registry_dir}"
303 "${lib_action}" "${lib_dir}"