BuildLinux.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #!/bin/bash
  2. #
  3. # This script can download and compile dependencies, compile SuperSlicer
  4. # and optional build a .tgz and an appimage.
  5. #
  6. # Original script from SuperSlicer by supermerill https://github.com/supermerill/SuperSlicer
  7. #
  8. # Change log:
  9. #
  10. # 20 Nov 2023, wschadow, branding and minor changes
  11. # 01 Jan 2024, wschadow, added build options
  12. #
  13. set -e # exit on first error
  14. export ROOT=`pwd`
  15. export NCORES=`nproc`
  16. function usage() {
  17. echo "Usage: ./BuildLinux.sh [-h][-u][-w][-g][-b][-r][-d][-s][-l][-t][-i]"
  18. echo " -h: this message"
  19. echo " -u: only update dependency packets (optional and need sudo)"
  20. echo " -w: wipe build directories before building"
  21. echo " -g: force gtk2 build"
  22. echo " -b: build in debug mode"
  23. echo " -r: clean dependencies"
  24. echo " -d: build deps"
  25. echo " -s: build Slic3r"
  26. echo " -l: update language .pot file"
  27. echo " -t: build tests (in combination with -s)"
  28. echo " -i: generate .tgz and appimage (optional)"
  29. echo -e "\n For a first use, you want to 'sudo ./BuildLinux.sh -u'"
  30. echo -e " and then './BuildLinux.sh -dsi'\n"
  31. exit 0
  32. }
  33. function check_operating_system() {
  34. # check operating system
  35. OS_FOUND=$( command -v uname)
  36. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  37. linux*)
  38. TARGET_OS="linux"
  39. ;;
  40. msys*|cygwin*|mingw*)
  41. # or possible 'bash on windows'
  42. TARGET_OS='windows'
  43. ;;
  44. nt|win*)
  45. TARGET_OS='windows'
  46. ;;
  47. darwin)
  48. TARGET_OS='macos'
  49. ;;
  50. *)
  51. TARGET_OS='unknown'
  52. ;;
  53. esac
  54. echo
  55. if [ $TARGET_OS == "linux" ]; then
  56. if [ $(uname -m) == "x86_64" ]; then
  57. echo -e "$(tput setaf 2)Linux 64-bit found$(tput sgr0)\n"
  58. Processor="64"
  59. elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  60. echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)\n"
  61. Processor="32"
  62. else
  63. echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)"
  64. exit -1
  65. fi
  66. else
  67. echo -e "$(tput setaf 1)This script doesn't support your Operating system!"
  68. echo -e "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash.$(tput sgr0)\n"
  69. exit -1
  70. fi
  71. }
  72. function check_available_memory_and_disk() {
  73. FREE_MEM_GB=$(free -g -t | grep 'Mem:' | rev | cut -d" " -f1 | rev)
  74. MIN_MEM_GB=5
  75. FREE_DISK_KB=$(df -k . | tail -1 | awk '{print $4}')
  76. MIN_DISK_KB=$((10 * 1024 * 1024))
  77. if [ ${FREE_MEM_GB} -le ${MIN_MEM_GB} ]; then
  78. echo -e "\nERROR: SuperSlicer Builder requires at least ${MIN_MEM_GB}G of 'available' mem (systen has only ${FREE_MEM_GB}G available)"
  79. echo && free -h && echo
  80. exit 2
  81. fi
  82. if [[ ${FREE_DISK_KB} -le ${MIN_DISK_KB} ]]; then
  83. echo -e "\nERROR: SuperSlicer Builder requires at least $(echo ${MIN_DISK_KB} |awk '{ printf "%.1fG\n", $1/1024/1024; }') (systen has only $(echo ${FREE_DISK_KB} | awk '{ printf "%.1fG\n", $1/1024/1024; }') disk free)"
  84. echo && df -h . && echo
  85. exit 1
  86. fi
  87. }
  88. function check_distribution() {
  89. DISTRIBUTION=$(awk -F= '/^ID=/ {print $2}' /etc/os-release)
  90. # treat ubuntu as debian
  91. if [ "${DISTRIBUTION}" == "ubuntu" ]
  92. then
  93. DISTRIBUTION="debian"
  94. fi
  95. echo -e "$(tput setaf 2)${DISTRIBUTION} found$(tput sgr0)\n"
  96. if [ ! -f ./src/platform/unix/linux.d/${DISTRIBUTION} ]
  97. then
  98. echo "Your distribution does not appear to be currently supported by these build scripts"
  99. exit 1
  100. fi
  101. }
  102. #=======================================================================================
  103. check_operating_system
  104. check_distribution
  105. check_available_memory_and_disk
  106. #---------------------------------------------------------------------------------------
  107. #check command line arguments
  108. unset name
  109. while getopts ":hugbdrsltiw" opt; do
  110. case ${opt} in
  111. u )
  112. UPDATE_LIB="1"
  113. ;;
  114. i )
  115. BUILD_IMAGE="1"
  116. ;;
  117. d )
  118. BUILD_DEPS="1"
  119. ;;
  120. s )
  121. BUILD_SLIC3R="1"
  122. ;;
  123. l )
  124. UPDATE_POTFILE="1"
  125. ;;
  126. t )
  127. BUILD_TESTS="1"
  128. ;;
  129. b )
  130. BUILD_DEBUG="1"
  131. ;;
  132. g )
  133. FORCE_GTK2="-g"
  134. ;;
  135. r )
  136. BUILD_CLEANDEPEND="1"
  137. ;;
  138. w )
  139. BUILD_WIPE="1"
  140. ;;
  141. h ) usage
  142. # exit 0
  143. ;;
  144. * ) usage
  145. # exit 0
  146. ;;
  147. esac
  148. done
  149. if [ ${OPTIND} -eq 1 ]
  150. then
  151. usage
  152. exit 0
  153. fi
  154. #---------------------------------------------------------------------------------------
  155. # check installation of required packages or update when -u is set
  156. source ./src/platform/unix/linux.d/${DISTRIBUTION}
  157. if [[ -n "$FORCE_GTK2" ]]
  158. then
  159. FOUND_GTK2=$(dpkg -l libgtk* | grep gtk2)
  160. FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev)
  161. echo -e "\nFOUND_GTK2:\n$FOUND_GTK2\n"
  162. else
  163. FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3)
  164. FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev)
  165. echo -e "\nFOUND_GTK3:\n$FOUND_GTK3)\n"
  166. fi
  167. if [[ -n "$BUILD_DEPS" ]]
  168. then
  169. if [[ -n $BUILD_WIPE ]]
  170. then
  171. echo -e "\n wiping deps/build directory...\n"
  172. rm -fr deps/build
  173. echo -e " ... done\n"
  174. fi
  175. # mkdir build in deps
  176. if [ ! -d "deps/build" ]
  177. then
  178. mkdir deps/build
  179. fi
  180. echo -e "[1/9] Configuring dependencies ...\n"
  181. BUILD_ARGS=""
  182. if [[ -n "$FOUND_GTK3_DEV" ]]
  183. then
  184. BUILD_ARGS="-DDEP_WX_GTK3=ON"
  185. else
  186. BUILD_ARGS="-DDEP_WX_GTK3=OFF"
  187. fi
  188. if [[ -n "$BUILD_DEBUG" ]]
  189. then
  190. # have to build deps with debug & release or the cmake won't find evrything it needs
  191. if [ ! -d "deps/build/release" ]
  192. then
  193. mkdir deps/build/release
  194. fi
  195. pushd deps/build/release > /dev/null
  196. cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
  197. popd > /dev/null
  198. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  199. fi
  200. pushd deps/build > /dev/null
  201. cmake .. $BUILD_ARGS
  202. echo -e "\n ... done\n"
  203. echo -e "\n[2/9] Building dependencies...\n"
  204. # make deps
  205. make -j$NCORES
  206. echo -e "\n ... done\n"
  207. # rename wxscintilla
  208. echo "[3/9] Renaming wxscintilla library..."
  209. pushd destdir/usr/local/lib > /dev/null
  210. if [[ -z "$FOUND_GTK3_DEV" ]]
  211. then
  212. cp libwxscintilla-3.2.a libwx_gtk2u_scintilla-3.2.a
  213. else
  214. cp libwxscintilla-3.2.a libwx_gtk3u_scintilla-3.2.a
  215. fi
  216. popd > /dev/null
  217. popd > /dev/null
  218. echo -e "\n ... done\n"
  219. fi
  220. if [[ -n "$BUILD_CLEANDEPEND" ]]
  221. then
  222. echo -e "[4/9] Cleaning dependencies...\n"
  223. pushd deps/build > /dev/null
  224. rm -fr dep_*
  225. popd > /dev/null
  226. echo -e " ... done\n"
  227. fi
  228. if [[ -n "$BUILD_SLIC3R" ]]
  229. then
  230. echo -e "[5/9] Configuring SuperSlicer ...\n"
  231. if [[ -n $BUILD_WIPE ]]
  232. then
  233. echo -e "\n wiping build directory ...\n"
  234. rm -fr build
  235. echo -e "\n ... done"
  236. fi
  237. # mkdir build
  238. if [ ! -d "build" ]
  239. then
  240. mkdir build
  241. fi
  242. BUILD_ARGS=""
  243. if [[ -n "$FOUND_GTK3_DEV" ]]
  244. then
  245. BUILD_ARGS="-DSLIC3R_GTK=3"
  246. fi
  247. if [[ -n "$BUILD_DEBUG" ]]
  248. then
  249. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  250. fi
  251. if [[ -n "$BUILD_TESTS" ]]
  252. then
  253. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
  254. else
  255. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
  256. fi
  257. # cmake
  258. pushd build > /dev/null
  259. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  260. echo " ... done"
  261. # make SuperSlicer
  262. echo -e "\n[6/9] Building SuperSlicer ...\n"
  263. make -j$NCORES Slic3r
  264. make -j$NCORES OCCTWrapper
  265. echo -e "\n ... done"
  266. echo -e "\n[7/9] Generating language files ...\n"
  267. #make .mo
  268. if [[ -n "$UPDATE_POTFILE" ]]
  269. then
  270. make gettext_make_pot
  271. fi
  272. make gettext_po_to_mo
  273. popd > /dev/null
  274. echo -e "\n ... done"
  275. # Give proper permissions to script
  276. chmod 755 $ROOT/build/src/BuildLinuxImage.sh
  277. pushd build > /dev/null
  278. $ROOT/build/src/BuildLinuxImage.sh -a $FORCE_GTK2
  279. popd > /dev/null
  280. fi
  281. if [[ -n "$BUILD_IMAGE" ]]
  282. then
  283. # Give proper permissions to script
  284. chmod 755 $ROOT/build/src/BuildLinuxImage.sh
  285. pushd build > /dev/null
  286. $ROOT/build/src/BuildLinuxImage.sh -i $FORCE_GTK2
  287. popd > /dev/null
  288. fi