BuildLinux.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #!/bin/bash
  2. export ROOT=`pwd`
  3. export NCORES=`nproc`
  4. FOUND_GTK2=$(dpkg -l libgtk* | grep gtk2)
  5. FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3)
  6. unset name
  7. while getopts ":hwdrigbsyu" 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. t)
  22. BUILD_TESTS="1"
  23. ;;
  24. b )
  25. BUILD_DEBUG="1"
  26. ;;
  27. g )
  28. FOUND_GTK3=""
  29. ;;
  30. w )
  31. BUILD_WIPE="1"
  32. ;;
  33. r )
  34. BUILD_CLEANDEPEND="1"
  35. ;;
  36. h ) echo "Usage: ./BuildLinux.sh [-h][-w][-d][-r][-i][-g][-b][-s][-t][-u]"
  37. echo " -h: this message"
  38. echo " -w: wipe build directories before building"
  39. echo " -d: build deps (optional)"
  40. echo " -r: clean dependencies building files (reduce disk usage)"
  41. echo " -i: Generate appimage (optional)"
  42. echo " -g: force gtk2 build"
  43. echo " -b: build with debug symbols"
  44. echo " -s: build Slic3r/SuperSlicer"
  45. echo " -t: build tests (in combination with -s)"
  46. echo " -u: only update clock & dependency packets (optional and need sudo)"
  47. echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
  48. echo " and then './BuildLinux.sh -dsi'"
  49. exit 0
  50. ;;
  51. esac
  52. done
  53. if [ $OPTIND -eq 1 ]
  54. then
  55. echo "Usage: ./BuildLinux.sh [-h][-w][-d][-r][-i][-g][-b][-s][-t][-u]"
  56. echo " -h: this message"
  57. echo " -w: wipe build directories before building"
  58. echo " -d: build deps (optional)"
  59. echo " -r: clean dependencies building files (reduce disk usage)"
  60. echo " -i: Generate appimage (optional)"
  61. echo " -g: force gtk2 build"
  62. echo " -b: build with debug symbols"
  63. echo " -s: build Slic3r/SuperSlicer"
  64. echo " -t: build tests (in combination with -s)"
  65. echo " -u: only update clock & dependency packets (optional and need sudo)"
  66. echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
  67. echo " and then './BuildLinux.sh -dsi'"
  68. exit 0
  69. fi
  70. if [[ -n "$FOUND_GTK3" ]]
  71. then
  72. echo "Found GTK3"
  73. else
  74. if [[ -n "$FOUND_GTK2" ]]
  75. then
  76. echo "Found GTK2"
  77. fi
  78. fi
  79. if [[ -n "$UPDATE_LIB" ]]
  80. then
  81. echo -n -e "Updating linux ...\n"
  82. hwclock -s
  83. apt update
  84. apt install g++ m4
  85. if [[ -z "$FOUND_GTK3" ]]
  86. then
  87. echo -e "\nInstalling: libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse\n"
  88. apt install libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse
  89. else
  90. echo -e "\nFind libgtk-3, installing: libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse\n"
  91. apt install libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse
  92. fi
  93. # for ubuntu 22.04:
  94. ubu_version="$(cat /etc/issue)"
  95. if [[ $ubu_version == "Ubuntu 22.04"* ]]
  96. then
  97. apt install curl libssl-dev libcurl4-openssl-dev m4
  98. fi
  99. if [[ -n "$BUILD_DEBUG" ]]
  100. then
  101. echo -e "\nInstalling: libssl-dev libcurl4-openssl-dev\n"
  102. apt install libssl-dev libcurl4-openssl-dev
  103. fi
  104. echo -e "done\n"
  105. exit 0
  106. fi
  107. FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev)
  108. FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev)
  109. echo "FOUND_GTK2=$FOUND_GTK2)"
  110. if [[ -z "$FOUND_GTK2_DEV" ]]
  111. then
  112. if [[ -z "$FOUND_GTK3_DEV" ]]
  113. then
  114. echo "Error, you must install the dependencies before."
  115. echo "Use option -u with sudo"
  116. exit 0
  117. fi
  118. fi
  119. echo "[1/9] Updating submodules..."
  120. {
  121. # update submodule profiles
  122. pushd resources/profiles
  123. git submodule update --init
  124. popd
  125. }
  126. echo "[2/9] Changing date in version..."
  127. {
  128. # change date in version
  129. sed -i "s/+UNKNOWN/_$(date '+%F')/" version.inc
  130. }
  131. echo "done"
  132. # mkdir build
  133. if [ ! -d "build" ]
  134. then
  135. mkdir build
  136. fi
  137. # mkdir in deps
  138. if [ ! -d "deps/build" ]
  139. then
  140. mkdir deps/build
  141. fi
  142. if [[ -n "$BUILD_DEPS" ]]
  143. then
  144. if [[ -n $BUILD_WIPE ]]
  145. then
  146. echo -e "\n wiping deps/build directory ...\n"
  147. rm -fr deps/build
  148. echo -e " ... done\n"
  149. fi
  150. # mkdir in deps
  151. if [ ! -d "deps/build" ]
  152. then
  153. mkdir deps/build
  154. fi
  155. echo "[3/9] Configuring dependencies..."
  156. BUILD_ARGS=""
  157. if [[ -n "$FOUND_GTK3_DEV" ]]
  158. then
  159. BUILD_ARGS="-DDEP_WX_GTK3=ON"
  160. fi
  161. if [[ -n "$BUILD_DEBUG" ]]
  162. then
  163. # have to build deps with debug & release or the cmake won't find evrything it needs
  164. mkdir deps/build/release
  165. pushd deps/build/release
  166. cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
  167. make -j$NCORES
  168. popd
  169. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  170. fi
  171. # cmake deps
  172. pushd deps/build
  173. cmake .. $BUILD_ARGS
  174. echo "done"
  175. # make deps
  176. echo "[4/9] Building dependencies..."
  177. make -j$NCORES
  178. echo "done"
  179. # rename wxscintilla
  180. echo "[5/9] Renaming wxscintilla library..."
  181. pushd destdir/usr/local/lib
  182. if [[ -z "$FOUND_GTK3_DEV" ]]
  183. then
  184. cp libwxscintilla-3.2.a libwx_gtk2u_scintilla-3.2.a
  185. else
  186. cp libwxscintilla-3.2.a libwx_gtk3u_scintilla-3.2.a
  187. fi
  188. popd
  189. echo "done"
  190. popd
  191. echo "done"
  192. fi
  193. # clean deps
  194. if [[ -n "$BUILD_CLEANDEPEND" ]]
  195. then
  196. echo -e "[6/9] Cleaning dependencies...\n"
  197. pushd deps/build
  198. pwd
  199. rm -fr dep_*
  200. popd > /dev/null
  201. echo -e "\n ... done\n"
  202. fi
  203. if [[ -n "$BUILD_SLIC3R" ]]
  204. then
  205. echo "[7/9] Configuring Slic3r..."
  206. BUILD_ARGS=""
  207. if [[ -n "$FOUND_GTK3_DEV" ]]
  208. then
  209. BUILD_ARGS="-DSLIC3R_GTK=3"
  210. fi
  211. if [[ -n "$BUILD_DEBUG" ]]
  212. then
  213. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  214. fi
  215. if [[ -n "$BUILD_TESTS" ]]
  216. then
  217. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
  218. else
  219. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
  220. fi
  221. # cmake
  222. pushd build
  223. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  224. echo "done"
  225. #make avrdude-slic3r
  226. make avrdude-slic3r
  227. # make Slic3r
  228. echo "[8/9] Building Slic3r..."
  229. make -j$NCORES Slic3r
  230. # make .mo
  231. make gettext_po_to_mo
  232. # make OCCTWrapper.so
  233. make OCCTWrapper
  234. # update the pot
  235. make gettext_make_pot
  236. popd
  237. echo "done"
  238. fi
  239. # Give proper permissions to script
  240. chmod 755 $ROOT/build/src/BuildLinuxImage.sh
  241. echo "[9/9] Generating Linux app..."
  242. pushd build
  243. if [[ -n "$BUILD_IMAGE" ]]
  244. then
  245. $ROOT/build/src/BuildLinuxImage.sh -i
  246. else
  247. $ROOT/build/src/BuildLinuxImage.sh
  248. fi
  249. popd
  250. echo "done"