BuildLinux.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #!/bin/bash
  2. export ROOT=`pwd`
  3. export NCORES=`nproc --all`
  4. FOUND_GTK2=$(dpkg -l libgtk* | grep gtk2)
  5. FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3)
  6. unset name
  7. while getopts ":dsiuhgb" opt; do
  8. case ${opt} in
  9. u )
  10. UPDATE_LIB="1"
  11. ;;
  12. i )
  13. BUILD_IMAGE="1"
  14. ;;
  15. d )
  16. BUILD_DEPS="1"
  17. ;;
  18. s )
  19. BUILD_SLIC3R="1"
  20. ;;
  21. b )
  22. BUILD_DEBUG="1"
  23. ;;
  24. g )
  25. FOUND_GTK3=""
  26. ;;
  27. h ) echo "Usage: ./BuildLinux.sh [-i][-u][-d][-s][-b][-g]"
  28. echo " -i: Generate appimage (optional)"
  29. echo " -g: force gtk2 build"
  30. echo " -b: build in debug mode"
  31. echo " -d: build deps (optional)"
  32. echo " -s: build slic3r (optional)"
  33. echo " -u: only update clock & dependency packets (optional and need sudo)"
  34. echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
  35. echo " and then './BuildLinux.sh -dsi'"
  36. exit 0
  37. ;;
  38. esac
  39. done
  40. if [ $OPTIND -eq 1 ]
  41. then
  42. echo "Usage: ./BuildLinux.sh [-i][-u][-d][-s][-b][-g]"
  43. echo " -i: Generate appimage (optional)"
  44. echo " -g: force gtk2 build"
  45. echo " -b: build in debug mode"
  46. echo " -d: build deps (optional)"
  47. echo " -s: build slic3r (optional)"
  48. echo " -u: only update clock & dependency packets (optional and need sudo)"
  49. echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
  50. echo " and then './BuildLinux.sh -dsi'"
  51. exit 0
  52. fi
  53. # mkdir build
  54. if [ ! -d "build" ]
  55. then
  56. mkdir build
  57. fi
  58. if [[ -n "$UPDATE_LIB" ]]
  59. then
  60. echo -n -e "Updating linux ...\n"
  61. hwclock -s
  62. apt update
  63. if [[ -z "$FOUND_GTK3" ]]
  64. then
  65. echo -e "\nInstalling: libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
  66. apt install libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git
  67. else
  68. echo -e "\nFind libgtk-3, installing: libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
  69. apt install libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git
  70. fi
  71. # for ubuntu 22.04:
  72. ubu_version="$(cat /etc/issue)"
  73. if [[ $ubu_version == "Ubuntu 22.04"* ]]
  74. then
  75. apt install curl libssl-dev libcurl4-openssl-dev m4
  76. fi
  77. if [[ -n "$BUILD_DEBUG" ]]
  78. then
  79. echo -e "\nInstalling: libssl-dev libcurl4-openssl-dev\n"
  80. apt install libssl-dev libcurl4-openssl-dev
  81. fi
  82. echo -e "done\n"
  83. exit 0
  84. fi
  85. FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev)
  86. FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev)
  87. echo "FOUND_GTK2=$FOUND_GTK2)"
  88. if [[ -z "$FOUND_GTK2_DEV" ]]
  89. then
  90. if [[ -z "$FOUND_GTK3_DEV" ]]
  91. then
  92. echo "Error, you must install the dependencies before."
  93. echo "Use option -u with sudo"
  94. exit 0
  95. fi
  96. fi
  97. echo "[1/9] Updating submodules..."
  98. {
  99. # update submodule profiles
  100. pushd resources/profiles
  101. git submodule update --init
  102. popd
  103. }
  104. echo "[2/9] Changing date in version..."
  105. {
  106. # change date in version
  107. sed -i "s/+UNKNOWN/_$(date '+%F')/" version.inc
  108. }
  109. echo "done"
  110. # mkdir in deps
  111. if [ ! -d "deps/build" ]
  112. then
  113. mkdir deps/build
  114. fi
  115. if [[ -n "$BUILD_DEPS" ]]
  116. then
  117. echo "[3/9] Configuring dependencies..."
  118. BUILD_ARGS=""
  119. if [[ -n "$FOUND_GTK3_DEV" ]]
  120. then
  121. BUILD_ARGS="-DDEP_WX_GTK3=ON"
  122. fi
  123. if [[ -n "$BUILD_DEBUG" ]]
  124. then
  125. # have to build deps with debug & release or the cmake won't find evrything it needs
  126. mkdir deps/build/release
  127. pushd deps/build/release
  128. cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
  129. make -j$NCORES
  130. popd
  131. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  132. fi
  133. # cmake deps
  134. pushd deps/build
  135. cmake .. $BUILD_ARGS
  136. echo "done"
  137. # make deps
  138. echo "[4/9] Building dependencies..."
  139. make -j$NCORES
  140. echo "done"
  141. # rename wxscintilla
  142. echo "[5/9] Renaming wxscintilla library..."
  143. pushd destdir/usr/local/lib
  144. if [[ -z "$FOUND_GTK3_DEV" ]]
  145. then
  146. cp libwxscintilla-3.1.a libwx_gtk2u_scintilla-3.1.a
  147. else
  148. cp libwxscintilla-3.1.a libwx_gtk3u_scintilla-3.1.a
  149. fi
  150. popd
  151. echo "done"
  152. # clean deps
  153. echo "[6/9] Cleaning dependencies..."
  154. rm -rf dep_*
  155. popd
  156. echo "done"
  157. fi
  158. if [[ -n "$BUILD_SLIC3R" ]]
  159. then
  160. echo "[7/9] Configuring Slic3r..."
  161. BUILD_ARGS=""
  162. if [[ -n "$FOUND_GTK3_DEV" ]]
  163. then
  164. BUILD_ARGS="-DSLIC3R_GTK=3"
  165. fi
  166. if [[ -n "$BUILD_DEBUG" ]]
  167. then
  168. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  169. fi
  170. # cmake
  171. pushd build
  172. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  173. echo "done"
  174. # make Slic3r
  175. echo "[8/9] Building Slic3r..."
  176. make -j$NCORES Slic3r
  177. # make .mo
  178. make gettext_po_to_mo
  179. popd
  180. echo "done"
  181. fi
  182. # Give proper permissions to script
  183. chmod 755 $ROOT/build/src/BuildLinuxImage.sh
  184. echo "[9/9] Generating Linux app..."
  185. pushd build
  186. if [[ -n "$BUILD_IMAGE" ]]
  187. then
  188. $ROOT/build/src/BuildLinuxImage.sh -i
  189. else
  190. $ROOT/build/src/BuildLinuxImage.sh
  191. fi
  192. popd
  193. echo "done"