package_linux.sh.in 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/usr/bin/env bash
  2. # Creates Linux ".AppImage" for @PROJECT_NAME_UCASE@
  3. #
  4. # Depends: linuxdeployqt
  5. #
  6. # Notes: Will attempt to fetch linuxdeployqt automatically (x86_64 only)
  7. # See Also: https://github.com/probonopd/linuxdeployqt/blob/master/BUILDING.md
  8. set -e
  9. LINUXDEPLOYQT="@CMAKE_BINARY_DIR@/linuxdeployqt"
  10. VERBOSITY=2 # 3=debug
  11. LOGFILE="@CMAKE_BINARY_DIR@/appimage.log"
  12. APPDIR="@CMAKE_BINARY_DIR@/@PROJECT_NAME_UCASE@.AppDir/"
  13. DESKTOPFILE="${APPDIR}usr/share/applications/lmms.desktop"
  14. STRIP=""
  15. # Don't strip for Debug|RelWithDebInfo builds
  16. # shellcheck disable=SC2193
  17. if [[ "@CMAKE_BUILD_TYPE@" == *"Deb"* ]]; then
  18. STRIP="-no-strip"
  19. fi
  20. # Console colors
  21. RED="\\x1B[1;31m"
  22. GREEN="\\x1B[1;32m"
  23. YELLOW="\\x1B[1;33m"
  24. PLAIN="\\x1B[0m"
  25. function error {
  26. echo -e " ${PLAIN}[${RED}error${PLAIN}] ${1}"
  27. return 1
  28. }
  29. function success {
  30. echo -e " ${PLAIN}[${GREEN}success${PLAIN}] ${1}"
  31. }
  32. function skipped {
  33. echo -e " ${PLAIN}[${YELLOW}skipped${PLAIN}] ${1}"
  34. }
  35. # Blindly assume system arch is appimage arch
  36. ARCH=$(arch)
  37. export ARCH
  38. # Check for problematic install locations
  39. INSTALL=$(echo "@CMAKE_INSTALL_PREFIX@" | sed 's/\/*$//g')
  40. if [ "$INSTALL" == "/usr/local" ] || [ "$INSTALL" == "/usr" ] ; then
  41. error "Incompatible CMAKE_INSTALL_PREFIX for creating AppImage: @CMAKE_INSTALL_PREFIX@"
  42. fi
  43. echo -e "\nWriting verbose output to \"${LOGFILE}\""
  44. # Ensure linuxdeployqt uses the same qmake version as cmake
  45. PATH="$(pwd -P)/squashfs-root/usr/bin:$(dirname "@QT_QMAKE_EXECUTABLE@")":$PATH
  46. export PATH
  47. # Fetch portable linuxdeployqt if not in PATH
  48. APPIMAGETOOL="squashfs-root/usr/bin/appimagetool"
  49. echo -e "\nDownloading linuxdeployqt to ${LINUXDEPLOYQT}..."
  50. if env -i which linuxdeployqt > /dev/null 2>&1; then
  51. skipped "System already provides this utility"
  52. else
  53. filename="linuxdeployqt-continuous-$(uname -p).AppImage"
  54. url="https://github.com/probonopd/linuxdeployqt/releases/download/continuous/$filename"
  55. down_file="$(pwd)/$filename"
  56. if [ ! -f "$LINUXDEPLOYQT" ]; then
  57. ln -s "$down_file" "$LINUXDEPLOYQT"
  58. fi
  59. echo " [.......] Downloading ($(uname -p)): ${url}"
  60. wget -N -q "$url" || (rm "$filename" && false)
  61. chmod +x "$LINUXDEPLOYQT"
  62. success "Downloaded $LINUXDEPLOYQT"
  63. # Extract AppImage and replace LINUXDEPLOYQT variable with extracted binary
  64. # to support systems without fuse
  65. # Also, we need to set LD_LIBRARY_PATH, but linuxdepoyqt's AppRun unsets it
  66. # See https://github.com/probonopd/linuxdeployqt/pull/370/
  67. "$LINUXDEPLOYQT" --appimage-extract > /dev/null 2>&1
  68. LINUXDEPLOYQT="squashfs-root/usr/bin/linuxdeployqt"
  69. success "Extracted $APPIMAGETOOL"
  70. fi
  71. # Make skeleton AppDir
  72. echo -e "\nCreating ${APPDIR}..."
  73. rm -rf "${APPDIR}"
  74. mkdir -p "${APPDIR}usr"
  75. success "Created ${APPDIR}"
  76. # Clone install to AppDir
  77. echo -e "\nCopying @CMAKE_INSTALL_PREFIX@ to ${APPDIR}..."
  78. cp -R "@CMAKE_INSTALL_PREFIX@/." "${APPDIR}usr"
  79. rm -rf "${APPDIR}usr/include"
  80. success "${APPDIR}"
  81. # Copy rawwaves directory for stk/mallets
  82. mkdir -p "${APPDIR}usr/share/stk/"
  83. cp -R /usr/share/stk/rawwaves/ "${APPDIR}usr/share/stk/"
  84. # Create a wrapper script which calls the lmms executable
  85. mv "${APPDIR}usr/bin/lmms" "${APPDIR}usr/bin/lmms.real"
  86. # shellcheck disable=SC1083
  87. cat >"${APPDIR}usr/bin/lmms" <<EOL
  88. #!/usr/bin/env bash
  89. DIR="\$( cd "\$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
  90. export PATH="\$PATH:/sbin"
  91. if which carla > /dev/null 2>&1; then
  92. CARLAPATH="\$(which carla)"
  93. CARLAPREFIX="\${CARLAPATH%/bin*}"
  94. echo "Carla appears to be installed on this system at \$CARLAPREFIX/lib[64]/carla so we'll use it."
  95. export LD_LIBRARY_PATH=\$CARLAPREFIX/lib/carla:\$CARLAPREFIX/lib64/carla:\$LD_LIBRARY_PATH
  96. else
  97. echo "Carla does not appear to be installed. That's OK, please ignore any related library errors."
  98. fi
  99. export LD_LIBRARY_PATH=\$DIR/usr/lib/:\$DIR/usr/lib/lmms:\$LD_LIBRARY_PATH
  100. # Prevent segfault on VirualBox
  101. if lsmod |grep vboxguest > /dev/null 2>&1; then
  102. echo "VirtualBox detected. Forcing libgl software rendering."
  103. export LIBGL_ALWAYS_SOFTWARE=1;
  104. fi
  105. if ldconfig -p | grep libjack.so.0 > /dev/null 2>&1; then
  106. echo "Jack appears to be installed on this system, so we'll use it."
  107. else
  108. echo "Jack does not appear to be installed. That's OK, we'll use a dummy version instead."
  109. export LD_LIBRARY_PATH=\$DIR/usr/lib/lmms/optional:\$LD_LIBRARY_PATH
  110. fi
  111. QT_X11_NO_NATIVE_MENUBAR=1 \$DIR/usr/bin/lmms.real "\$@"
  112. EOL
  113. chmod +x "${APPDIR}usr/bin/lmms"
  114. # Per https://github.com/probonopd/linuxdeployqt/issues/129
  115. unset LD_LIBRARY_PATH
  116. # Ensure linuxdeployqt can find shared objects
  117. export LD_LIBRARY_PATH="${APPDIR}usr/lib/lmms/":$LD_LIBRARY_PATH
  118. # Handle wine linking
  119. if [ -d "@WINE_32_LIBRARY_DIR@" ]; then
  120. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@WINE_32_LIBRARY_DIRS@
  121. fi
  122. if [ -d "@WINE_64_LIBRARY_DIR@" ]; then
  123. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@WINE_64_LIBRARY_DIRS@
  124. fi
  125. # Move executables so linuxdeployqt can find them
  126. ZYNLIB="${APPDIR}usr/lib/lmms/RemoteZynAddSubFx"
  127. VSTLIB32="${APPDIR}usr/lib/lmms/32/RemoteVstPlugin32.exe.so"
  128. VSTLIB64="${APPDIR}usr/lib/lmms/RemoteVstPlugin64.exe.so"
  129. ZYNBIN="${APPDIR}usr/bin/RemoteZynAddSubFx"
  130. VSTBIN32="${APPDIR}usr/bin/RemoteVstPlugin32.exe.so"
  131. VSTBIN64="${APPDIR}usr/bin/RemoteVstPlugin64.exe.so"
  132. mv "$ZYNLIB" "$ZYNBIN"
  133. mv "$VSTLIB32" "$VSTBIN32"
  134. mv "$VSTLIB64" "$VSTBIN64"
  135. # Patch the desktop file
  136. sed -i 's/.*Exec=.*/Exec=lmms.real/' "$DESKTOPFILE"
  137. # Fix linking for soft-linked plugins
  138. for file in "${APPDIR}usr/lib/lmms/"*.so; do
  139. thisfile="${APPDIR}usr/lib/lmms/${file##*/}"
  140. executables="${executables} -executable=$thisfile"
  141. done
  142. executables="${executables} -executable=${ZYNBIN}"
  143. executables="${executables} -executable=${VSTBIN32}"
  144. executables="${executables} -executable=${VSTBIN64}"
  145. executables="${executables} -executable=${APPDIR}usr/lib/lmms/ladspa/imp_1199.so"
  146. executables="${executables} -executable=${APPDIR}usr/lib/lmms/ladspa/imbeq_1197.so"
  147. executables="${executables} -executable=${APPDIR}usr/lib/lmms/ladspa/pitch_scale_1193.so"
  148. executables="${executables} -executable=${APPDIR}usr/lib/lmms/ladspa/pitch_scale_1194.so"
  149. # Bundle both qt and non-qt dependencies into appimage format
  150. echo -e "\nBundling and relinking system dependencies..."
  151. echo -e ">>>>> linuxdeployqt" > "$LOGFILE"
  152. # shellcheck disable=SC2086
  153. "$LINUXDEPLOYQT" "$DESKTOPFILE" $executables -bundle-non-qt-libs -verbose=$VERBOSITY $STRIP >> "$LOGFILE" 2>&1
  154. success "Bundled and relinked dependencies"
  155. # Link to original location so lmms can find them
  156. ln -sr "$ZYNBIN" "$ZYNLIB"
  157. ln -sr "$VSTBIN32" "$VSTLIB32"
  158. ln -sr "$VSTBIN64" "$VSTLIB64"
  159. # Remove wine library conflict
  160. rm -f "${APPDIR}/usr/lib/libwine.so.1"
  161. # Use system-provided carla
  162. rm -f "${APPDIR}usr/lib/"libcarla*.so
  163. # Remove bundled jack in LD_LIBRARY_PATH if exists
  164. if [ -e "${APPDIR}/usr/lib/libjack.so.0" ]; then
  165. rm "${APPDIR}/usr/lib/libjack.so.0"
  166. fi
  167. # Bundle jack out of LD_LIBRARY_PATH
  168. JACK_LIB=$(ldd "${APPDIR}/usr/bin/lmms.real" | sed -n 's/\tlibjack\.so\.0 => \(.\+\) (0x[0-9a-f]\+)/\1/p')
  169. if [ -e "$JACK_LIB" ]; then
  170. mkdir -p "${APPDIR}usr/lib/lmms/optional/"
  171. cp "$JACK_LIB" "${APPDIR}usr/lib/lmms/optional/"
  172. fi
  173. # Point the AppRun to the shim launcher
  174. rm -f "${APPDIR}/AppRun"
  175. ln -sr "${APPDIR}/usr/bin/lmms" "${APPDIR}/AppRun"
  176. # Create AppImage
  177. echo -e "\nFinishing the AppImage..."
  178. echo -e "\n\n>>>>> appimagetool" >> "$LOGFILE"
  179. "$APPIMAGETOOL" "${APPDIR}" "@APPIMAGE_FILE@" >> "$LOGFILE" 2>&1
  180. success "Created @APPIMAGE_FILE@"
  181. echo -e "\nFinished"