build.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #! /bin/bash
  2. set -e
  3. # Check arguments
  4. if [[ $# != 2 ]]; then
  5. >&2 echo "Bad usage!"
  6. echo "Usage: $0 <build dir> <output file>"
  7. exit 1
  8. fi
  9. # Get paths
  10. ARCH="$(uname -m)"
  11. SYSTEM_LIBS="/usr/lib"
  12. SYSTEM_LIBS64="/usr/lib64"
  13. YUZU_BIN="${1}/bin"
  14. YUZU_BIN_GUI="${YUZU_BIN}/yuzu"
  15. # Make sure executable exists
  16. if [[ $(file -b --mime-type "$YUZU_BIN_GUI") != application/x-pie-executable ]]; then
  17. >&2 echo "Invalid yuzu executable!"
  18. fi
  19. # Clean up build dir
  20. rm -rf build
  21. mkdir build
  22. # NOTE: some of these aren't used now, but can be reordered in priority when torzu is converted to QT6
  23. # QT5 - /usr/lib/${ARCH}-linux-gnu/qt5 (debian), /usr/lib64/qt5 (fedora), /usr/lib/qt (steam deck)
  24. # QT5 - /usr/lib/${ARCH}-linux-gnu/qt6 (debian), /usr/lib64/qt6 (fedora), /usr/lib/qt6 (steam deck)
  25. QTFOUND="true"
  26. QTDIR="$SYSTEM_LIBS"/${ARCH}-linux-gnu/qt5/plugins
  27. if [ ! -d "$QTDIR" ]; then
  28. # default qt5 folder not found, check for 64-bit qt5 folder
  29. QTDIR="$SYSTEM_LIBS64"/qt5/plugins
  30. if [ ! -d "$QTDIR" ]; then
  31. # 64-bit qt5 folder not found, check for Steam Deck qt (qt5) folder
  32. QTDIR="$SYSTEM_LIBS"/qt/plugins
  33. if [ ! -d "$QTDIR" ]; then
  34. # Steam Deck qt (qt5) folder not found, check for regular qt6 folder
  35. QTDIR="$SYSTEM_LIBS"/${ARCH}-linux-gnu/qt6/plugins
  36. if [ ! -d "$QTDIR" ]; then
  37. # regular qt6 folder not found, check for 64-bit qt6 folder
  38. QTDIR="$SYSTEM_LIBS64"/qt6/plugins
  39. if [ ! -d "$QTDIR" ]; then
  40. # 64-bit qt6 folder not found, check for Steam Deck qt6 folder
  41. QTDIR="$SYSTEM_LIBS"/qt6/plugins
  42. if [ ! -d "$QTDIR" ]; then
  43. QTFOUND="false"
  44. fi
  45. fi
  46. fi
  47. fi
  48. fi
  49. fi
  50. if [ $QTFOUND == "true" ]; then
  51. echo "QT plugins from $QTDIR will be used."
  52. # Copy system dependencies used to build and required by the yuzu binary
  53. # includes:
  54. # - '/lib64/ld-linux-x86-64.so.2' or `/lib/ld-linux-aarch64.so.1` file per architecture
  55. # - required files from `/usr/lib/x86_64-linux-gnu` or `/usr/lib/aarch64-linux-gnu`
  56. # - different for SteamDeck, but still does it automatically
  57. for lib in $(ldd "$YUZU_BIN_GUI"); do
  58. (cp -v "$lib" ./build/ 2> /dev/null) || true
  59. done
  60. # Copy QT dependency folders, path determined above
  61. cp -rv "$QTDIR"/{imageformats,platforms,platformthemes,xcbglintegrations} ./build/
  62. # Copy executable
  63. cp -v "$YUZU_BIN_GUI" ./build/
  64. # Copy assets for the appropriate arch
  65. cp -v ./assets_"${ARCH}"/* ./build/
  66. # Copy common assets
  67. cp -v ./assets/* ./build/
  68. # Strip all libraries and executables
  69. for file in $(find ./build -type f); do
  70. (strip -v "$file" 2> /dev/null) || true
  71. done
  72. PASSED_CHECKSUM="false"
  73. FILE=appimagetool.AppImage
  74. # total number of times to try downloading if a checksum doesn't match
  75. DL_TRIES=3
  76. while [ $PASSED_CHECKSUM == "false" ] && [ "$DL_TRIES" -gt 0 ]; do
  77. case $ARCH in
  78. x86_64)
  79. # Static copy from the 'ext-linux-bin' repo.
  80. # Checksum will need to be changed when/if this file in the repo is updated.
  81. if ! test -f "$FILE"; then
  82. echo "Downloading appimagetool for architecture '$ARCH'"
  83. wget -O appimagetool.AppImage https://github.com/litucks/ext-linux-bin/raw/refs/heads/main/appimage/appimagetool-x86_64.AppImage
  84. fi
  85. if [ $(shasum -a 256 appimagetool.AppImage | cut -d' ' -f1) = "110751478abece165a18460acbd7fd1398701f74a9405ad8ac053427d937bd5d" ] ; then
  86. PASSED_CHECKSUM="true"
  87. fi
  88. # DISABLED TO USE THE ABOVE
  89. # The current continuous release channel option, until a static copy is put in 'ext-linux-bin'.
  90. # The checksum will pass until the continuous release is updated, then a new one needs to be
  91. # generated to update this script.
  92. #if ! test -f "$FILE"; then
  93. # echo "Downloading appimagetool for architecture '$ARCH'"
  94. # wget -O appimagetool.AppImage https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage
  95. #fi
  96. #if [ $(shasum -a 256 appimagetool.AppImage | cut -d' ' -f1) = "46fdd785094c7f6e545b61afcfb0f3d98d8eab243f644b4b17698c01d06083d1" ] ; then
  97. # PASSED_CHECKSUM="true"
  98. #fi
  99. ;;
  100. aarch64)
  101. # Currently set to the continuous release channel until a static copy is put in 'ext-linux-bin'.
  102. # The checksum will pass until the continuous release is updated, then a new one needs to be
  103. # generated to update this script.
  104. if ! test -f "$FILE"; then
  105. echo "Downloading appimagetool for architecture '$ARCH'"
  106. wget -O appimagetool.AppImage https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-aarch64.AppImage
  107. fi
  108. if [ $(shasum -a 256 appimagetool.AppImage | cut -d' ' -f1) = "04f45ea45b5aa07bb2b071aed9dbf7a5185d3953b11b47358c1311f11ea94a96" ] ; then
  109. PASSED_CHECKSUM="true"
  110. fi
  111. ;;
  112. *)
  113. PASSED_CHECKSUM="invalid_arch"
  114. ;;
  115. esac
  116. # delete the appimagetool downloaded if the checksum doesn't match.
  117. if [ ! $PASSED_CHECKSUM == "true" ]; then
  118. rm -f appimagetool.AppImage
  119. fi
  120. ((DL_TRIES-=1))
  121. done
  122. if [ $PASSED_CHECKSUM == "true" ]; then
  123. echo "Checksum passed. Proceeding to build image."
  124. # Build AppImage
  125. chmod a+x appimagetool.AppImage
  126. ./appimagetool.AppImage ./build "$2"
  127. elif [ $PASSED_CHECKSUM == "invalid_arch" ]; then
  128. echo "No download found for architecture '$ARCH'. Building halted."
  129. else
  130. echo "Checksum for appimagetool does not match. Building halted."
  131. echo "If the file to be downloaded has been changed, a new checksum will need to be generated for this script."
  132. fi
  133. else
  134. echo "QT not found, aborting AppImage build."
  135. fi