From: Thomas Debesse Date: Thu, 1 Aug 2019 19:15:08 +0000 (+0200) Subject: bundle: linux shared lib bundling X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=commitdiff_plain;h=34b409108ea87953bbdd73201d096358fc548813 bundle: linux shared lib bundling - always rely on up-to-date x11 and gl libraries, bundling them will break on future distros --- diff --git a/bundle/CMakeLists.txt b/bundle/CMakeLists.txt index 1cb5a221..1e2546d0 100644 --- a/bundle/CMakeLists.txt +++ b/bundle/CMakeLists.txt @@ -1,5 +1,7 @@ if (WIN32) set(BUNDLE_OS_NAME "windows") +elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + set(BUNDLE_OS_NAME "linux") else () set(BUNDLE_OS_NAME "unsupported") endif () diff --git a/library-bundler b/library-bundler index 0ef9567c..cdf2e960 100755 --- a/library-bundler +++ b/library-bundler @@ -37,6 +37,10 @@ Common::stripLdd () { Multi::excludeLdd () { case "${system_name}" in + 'linux') + egrep -v '/libc\./|/libX|/libxcb|/libGL' \ + | egrep -v '/libbsd\.|/libICE\.|/libselinux\.|/libSM.\.' + ;; 'windows') egrep -i '\.dll => [A-Z]:\\msys64\\' \ ;; @@ -54,6 +58,9 @@ Multi::printLdd () { local exe_file="${1}" case "${system_name}" in + 'linux') + ldd "${exe_file}" + ;; 'windows') ntldd --recursive "${exe_file}" ;; @@ -62,6 +69,9 @@ Multi::printLdd () { Multi::getGtkThemeName () { case "${system_name}" in + 'linux') + echo 'Adwaita' + ;; 'windows') echo 'MS-Windows' ;; @@ -70,6 +80,9 @@ Multi::getGtkThemeName () { Multi::getGtkLibName () { case "${system_name}" in + 'linux') + echo 'libgtk-x11-2.0.so.0' + ;; 'windows') echo 'libgtk-win32-2.0-0.dll' ;; @@ -80,6 +93,10 @@ Multi::getRootPrefix () { local lib_file="${1}" case "${system_name}" in + 'linux') + echo "${lib_file}" \ + | cut -f2 -d'/' + ;; 'windows') basename "${lib_file}" \ | xargs -n1 -P 1 which \ @@ -92,6 +109,10 @@ Multi::getLibPrefix () { local lib_file="${1}" case "${system_name}" in + 'linux') + dirname "${lib_file}" \ + | cut -f3- -d'/' + ;; 'windows') echo 'lib' ;; @@ -167,6 +188,21 @@ Multi::cleanUp () { -exec rmdir --ignore-fail-on-non-empty {} \; } +Linux::patchExe () { + local exe_file="${1}" + + patchelf --set-rpath "${rpath_string}" "${exe_file}" +} + +Linux::patchLib () { + local lib_dir="${1}" + + find "${lib_dir}" \ + -type f \ + -name '*.so*' \ + -exec patchelf --set-rpath "${rpath_string}" {} \; +} + Windows::listLibForManifest () { local lib_dir="${1}" @@ -199,8 +235,11 @@ bundle_dir="$(Common::getPath "${bundle_dir}")" registry_dir="${bundle_dir}/registry" lib_dir="${bundle_dir}/lib" +manifest_file="${lib_dir}/lib.manifest" + rpath_string='@executable_path:lib' +exe_action='Common::noOp' lib_action='Common::noOp' case "${system_name}" in @@ -209,6 +248,10 @@ case "${system_name}" in Common::getPath "${exe_file}" > "${registry_dir}/$(uuidgen)" exit ;; + 'linux') + exe_action='Linux::patchExe' + lib_action='Linux::patchLib' + ;; 'windows') lib_action='Windows::writeManifest' ;; @@ -231,6 +274,8 @@ then "${exe_action}" "${exe_file}" rm "${registry_entry}" + + "${exe_action}" "${exe_file}" done rmdir "${registry_dir}"