package_linux.sh.in 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. cp "@CMAKE_CURRENT_SOURCE_DIR@/launch_lmms.sh" "${APPDIR}usr/bin/lmms"
  87. chmod +x "${APPDIR}usr/bin/lmms"
  88. # Per https://github.com/probonopd/linuxdeployqt/issues/129
  89. unset LD_LIBRARY_PATH
  90. # Ensure linuxdeployqt can find shared objects
  91. export LD_LIBRARY_PATH="${APPDIR}"usr/lib/lmms/:"${APPDIR}"usr/lib/lmms/optional:"$LD_LIBRARY_PATH"
  92. # Move executables so linuxdeployqt can find them
  93. ZYNLIB="${APPDIR}usr/lib/lmms/RemoteZynAddSubFx"
  94. VSTLIB32="${APPDIR}usr/lib/lmms/32/RemoteVstPlugin32.exe.so"
  95. VSTLIB64="${APPDIR}usr/lib/lmms/RemoteVstPlugin64.exe.so"
  96. ZYNBIN="${APPDIR}usr/bin/RemoteZynAddSubFx"
  97. VSTBIN32="${APPDIR}usr/bin/RemoteVstPlugin32.exe.so"
  98. VSTBIN64="${APPDIR}usr/bin/RemoteVstPlugin64.exe.so"
  99. mv "$ZYNLIB" "$ZYNBIN"
  100. mv "$VSTLIB32" "$VSTBIN32" || true
  101. mv "$VSTLIB64" "$VSTBIN64" || true
  102. # Handle wine linking
  103. if [ -d "@WINE_32_LIBRARY_DIR@" ] && \
  104. ldd "$VSTBIN32" | grep "libwine\.so" | grep "not found"; then
  105. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"@WINE_32_LIBRARY_DIRS@"
  106. fi
  107. if [ -d "@WINE_64_LIBRARY_DIR@" ] && \
  108. ldd "$VSTBIN64" | grep "libwine\.so" | grep "not found"; then
  109. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"@WINE_64_LIBRARY_DIRS@"
  110. fi
  111. # Patch the desktop file
  112. sed -i 's/.*Exec=.*/Exec=lmms.real/' "$DESKTOPFILE"
  113. # Fix linking for soft-linked plugins
  114. for file in "${APPDIR}usr/lib/lmms/"*.so; do
  115. thisfile="${APPDIR}usr/lib/lmms/${file##*/}"
  116. executables="${executables} -executable=$thisfile"
  117. done
  118. executables="${executables} -executable=${ZYNBIN}"
  119. executables="${executables} -executable=${VSTBIN32}"
  120. executables="${executables} -executable=${VSTBIN64}"
  121. executables="${executables} -executable=${APPDIR}usr/lib/lmms/ladspa/imp_1199.so"
  122. executables="${executables} -executable=${APPDIR}usr/lib/lmms/ladspa/imbeq_1197.so"
  123. executables="${executables} -executable=${APPDIR}usr/lib/lmms/ladspa/pitch_scale_1193.so"
  124. executables="${executables} -executable=${APPDIR}usr/lib/lmms/ladspa/pitch_scale_1194.so"
  125. # Bundle both qt and non-qt dependencies into appimage format
  126. echo -e "\nBundling and relinking system dependencies..."
  127. echo -e ">>>>> linuxdeployqt" > "$LOGFILE"
  128. # shellcheck disable=SC2086
  129. "$LINUXDEPLOYQT" "$DESKTOPFILE" $executables -bundle-non-qt-libs -verbose=$VERBOSITY $STRIP >> "$LOGFILE" 2>&1
  130. success "Bundled and relinked dependencies"
  131. # Link to original location so lmms can find them
  132. ln -sr "$ZYNBIN" "$ZYNLIB"
  133. ln -sr "$VSTBIN32" "$VSTLIB32" || true
  134. ln -sr "$VSTBIN64" "$VSTLIB64" || true
  135. # Remove wine library conflict
  136. rm -f "${APPDIR}/usr/lib/libwine.so.1"
  137. # Use system-provided carla
  138. rm -f "${APPDIR}usr/lib/"libcarla*.so
  139. rm -f "${APPDIR}usr/lib/lmms/optional/"libcarla*.so
  140. # Remove bundled jack in LD_LIBRARY_PATH if exists
  141. if [ -e "${APPDIR}/usr/lib/libjack.so.0" ]; then
  142. rm "${APPDIR}/usr/lib/libjack.so.0"
  143. fi
  144. # Bundle jack out of LD_LIBRARY_PATH
  145. JACK_LIB=$(ldd "${APPDIR}/usr/bin/lmms.real" | sed -n 's/\tlibjack\.so\.0 => \(.\+\) (0x[0-9a-f]\+)/\1/p')
  146. if [ -e "$JACK_LIB" ]; then
  147. mkdir -p "${APPDIR}usr/lib/lmms/optional/"
  148. cp "$JACK_LIB" "${APPDIR}usr/lib/lmms/optional/"
  149. fi
  150. # Point the AppRun to the shim launcher
  151. rm -f "${APPDIR}/AppRun"
  152. ln -sr "${APPDIR}/usr/bin/lmms" "${APPDIR}/AppRun"
  153. # Create AppImage
  154. echo -e "\nFinishing the AppImage..."
  155. echo -e "\n\n>>>>> appimagetool" >> "$LOGFILE"
  156. "$APPIMAGETOOL" "${APPDIR}" "@APPIMAGE_FILE@" >> "$LOGFILE" 2>&1
  157. success "Created @APPIMAGE_FILE@"
  158. echo -e "\nFinished"