Skip to content

Commit

Permalink
Fix libjack.so.0 detection for openSUSE (#7690)
Browse files Browse the repository at this point in the history
Fix libjack.so.0 detection for openSUSE
Add libdb-5.so to optional as symlink
  • Loading branch information
tresf authored Feb 8, 2025
1 parent 6a0a4cd commit c81d497
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 30 deletions.
75 changes: 49 additions & 26 deletions cmake/linux/LinuxDeploy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ execute_process(COMMAND "${LINUXDEPLOY_BIN}"
# Remove svg ambitiously placed by linuxdeploy
file(REMOVE "${APP}/${lmms}.svg")

# Remove libraries that are normally sytem-provided
# Remove libraries that are normally system-provided
file(GLOB EXCLUDE_LIBS
"${APP}/usr/lib/libwine*"
"${APP}/usr/lib/libcarla_native*"
Expand Down Expand Up @@ -216,32 +216,55 @@ endforeach()

file(REMOVE_RECURSE "${SUIL_MODULES_TARGET}" "${APP}/usr/lib/${lmms}/ladspa/")

# Bundle jack to avoid crash for systems without it
# See https://github.com/LMMS/lmms/pull/4186
execute_process(COMMAND ldd "${APP}/usr/bin/${lmms}"
OUTPUT_VARIABLE LDD_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ECHO ${COMMAND_ECHO}
COMMAND_ERROR_IS_FATAL ANY)
string(REPLACE "\n" ";" LDD_LIST "${LDD_OUTPUT}")
foreach(line ${LDD_LIST})
if(line MATCHES "libjack\\.so")
# Assume format "libjack.so.0 => /lib/x86_64-linux-gnu/libjack.so.0 (0x00007f48d0b0e000)"
string(REPLACE " " ";" parts "${line}")
list(LENGTH parts len)
math(EXPR index "${len}-2")
list(GET parts ${index} lib)
# Get symlink target
file(REAL_PATH "${lib}" libreal)
get_filename_component(symname "${lib}" NAME)
get_filename_component(realname "${libreal}" NAME)
file(MAKE_DIRECTORY "${APP}/usr/lib/${lmms}/optional/")
# Copy, but with original symlink name
file(COPY "${libreal}" DESTINATION "${APP}/usr/lib/${lmms}/optional/")
file(RENAME "${APP}/usr/lib/${lmms}/optional/${realname}" "${APP}/usr/lib/${lmms}/optional/${symname}")
continue()
# Copy "exclude-list" lib(s) into specified location
macro(copy_excluded ldd_target name_match destination relocated_lib)
execute_process(COMMAND ldd
"${ldd_target}"
OUTPUT_VARIABLE ldd_output
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ECHO ${COMMAND_ECHO}
COMMAND_ERROR_IS_FATAL ANY)

# escape periods to avoid double-escaping
string(REPLACE "." "\\." name_match "${name_match}")

# cli output --> list
string(REPLACE "\n" ";" ldd_list "${ldd_output}")

foreach(line ${ldd_list})
if(line MATCHES "${name_match}")
# Assumes format "libname.so.0 => /lib/location/libname.so.0 (0x00007f48d0b0e000)"
string(REPLACE " " ";" parts "${line}")
list(LENGTH parts len)
math(EXPR index "${len}-2")
list(GET parts ${index} lib)
# Resolve any possible symlinks
file(REAL_PATH "${lib}" libreal)
get_filename_component(symname "${lib}" NAME)
get_filename_component(realname "${libreal}" NAME)
file(MAKE_DIRECTORY "${destination}")
# Copy, but with original symlink name
file(COPY "${libreal}" DESTINATION "${destination}")
file(RENAME "${destination}/${realname}" "${destination}/${symname}")
set("${relocated_lib}" "${destination}/${symname}")
break()
endif()
endforeach()
endmacro()

# copy libjack
copy_excluded("${APP}/usr/bin/${lmms}" "libjack.so" "${APP}/usr/lib/jack" relocated_jack)
if(relocated_jack)
# libdb's not excluded however we'll re-use the macro as a convenient path calculation
# See https://github.com/LMMS/lmms/issues/7689s
copy_excluded("${relocated_jack}" "libdb-" "${APP}/usr/lib/jack" relocated_libdb)
get_filename_component(libdb_name "${relocated_libdb}" NAME)
if(relocated_libdb AND EXISTS "${APP}/usr/lib/${libdb_name}")
# assume a copy already resides in usr/lib and symlink
file(REMOVE "${relocated_libdb}")
create_symlink("${APP}/usr/lib/${libdb_name}" "${relocated_libdb}")
endif()
endforeach()
endif()

if(CPACK_TOOL STREQUAL "appimagetool")
# Create ".AppImage" file using appimagetool (default)
Expand Down
12 changes: 8 additions & 4 deletions cmake/linux/apprun-hooks/jack-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# Workaround crash when jack is missing by providing a dummy version
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
ME="$( basename "${BASH_SOURCE[0]}")"
if ldconfig -p | grep libjack.so.0 > /dev/null 2>&1; then
echo "[$ME] Jack appears to be installed on this system, so we'll use it." >&2
# Set language to English
export LC_ALL=C
if ldd "$DIR/usr/bin/lmms" |grep "libjack.so" |grep "not found" > /dev/null 2>&1; then
echo "[$ME] Jack does not appear to be installed. That's OK, we'll use a dummy version instead." >&2
export LD_LIBRARY_PATH="$DIR/usr/lib/jack:$LD_LIBRARY_PATH"
else
echo "[$ME] Jack does not appear to be installed. That's OK, we'll use a dummy version instead." >&2
export LD_LIBRARY_PATH=$DIR/usr/lib/lmms/optional:$LD_LIBRARY_PATH
echo "[$ME] Jack appears to be installed on this system, so we'll use it." >&2
fi
# Restore language
unset LC_ALL

0 comments on commit c81d497

Please sign in to comment.