BuildLinux.sh 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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][-v]"
  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 " -v: change the version 'UNKNOWN' to the date of the day"
  30. echo -e "\n For a first use, you want to 'sudo ./BuildLinux.sh -u'"
  31. echo -e " and then './BuildLinux.sh -dsi'\n"
  32. exit 0
  33. }
  34. function check_operating_system() {
  35. # check operating system
  36. OS_FOUND=$( command -v uname)
  37. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  38. linux*)
  39. TARGET_OS="linux"
  40. ;;
  41. msys*|cygwin*|mingw*)
  42. # or possible 'bash on windows'
  43. TARGET_OS='windows'
  44. ;;
  45. nt|win*)
  46. TARGET_OS='windows'
  47. ;;
  48. darwin)
  49. TARGET_OS='macos'
  50. ;;
  51. *)
  52. TARGET_OS='unknown'
  53. ;;
  54. esac
  55. echo
  56. if [ $TARGET_OS == "linux" ]; then
  57. if [ $(uname -m) == "x86_64" ]; then
  58. echo -e "$(tput setaf 2)Linux 64-bit found$(tput sgr0)\n"
  59. Processor="64"
  60. elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  61. echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)\n"
  62. Processor="32"
  63. else
  64. echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)"
  65. exit -1
  66. fi
  67. else
  68. echo -e "$(tput setaf 1)This script doesn't support your Operating system!"
  69. echo -e "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash.$(tput sgr0)\n"
  70. exit -1
  71. fi
  72. }
  73. function check_available_memory_and_disk() {
  74. FREE_MEM_GB=$(free -g -t | grep 'Mem:' | rev | cut -d" " -f1 | rev)
  75. MIN_MEM_GB=3
  76. FREE_DISK_KB=$(df -k . | tail -1 | awk '{print $4}')
  77. MIN_DISK_KB=$((10 * 1024 * 1024))
  78. if [ ${FREE_MEM_GB} -le ${MIN_MEM_GB} ]; then
  79. echo -e "\nERROR: SuperSlicer Builder requires at least ${MIN_MEM_GB}G of 'available' mem (systen has only ${FREE_MEM_GB}G available)"
  80. echo && free -h && echo
  81. exit 2
  82. fi
  83. if [[ ${FREE_DISK_KB} -le ${MIN_DISK_KB} ]]; then
  84. 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)"
  85. echo && df -h . && echo
  86. exit 1
  87. fi
  88. }
  89. function check_distribution() {
  90. DISTRIBUTION=$(awk -F= '/^ID=/ {print $2}' /etc/os-release)
  91. # treat ubuntu as debian
  92. if [ "${DISTRIBUTION}" == "ubuntu" ]
  93. then
  94. DISTRIBUTION="debian"
  95. fi
  96. echo -e "$(tput setaf 2)${DISTRIBUTION} found$(tput sgr0)\n"
  97. if [ ! -f ./src/platform/unix/linux.d/${DISTRIBUTION} ]
  98. then
  99. echo "Your distribution does not appear to be currently supported by these build scripts"
  100. exit 1
  101. fi
  102. }
  103. #=======================================================================================
  104. check_operating_system
  105. check_distribution
  106. check_available_memory_and_disk
  107. #---------------------------------------------------------------------------------------
  108. #check command line arguments
  109. unset name
  110. while getopts ":bdghilrstuvw" opt; do
  111. case ${opt} in
  112. u )
  113. UPDATE_LIB="1"
  114. ;;
  115. i )
  116. BUILD_IMAGE="1"
  117. ;;
  118. d )
  119. BUILD_DEPS="1"
  120. ;;
  121. s )
  122. BUILD_SLIC3R="1"
  123. ;;
  124. l )
  125. UPDATE_POTFILE="1"
  126. ;;
  127. t )
  128. BUILD_TESTS="1"
  129. ;;
  130. b )
  131. BUILD_DEBUG="1"
  132. ;;
  133. g )
  134. FORCE_GTK2="-g"
  135. ;;
  136. r )
  137. BUILD_CLEANDEPEND="1"
  138. ;;
  139. v )
  140. VERSION_DATE="1"
  141. ;;
  142. w )
  143. BUILD_WIPE="1"
  144. ;;
  145. h ) usage
  146. # exit 0
  147. ;;
  148. * ) usage
  149. # exit 0
  150. ;;
  151. esac
  152. done
  153. if [ ${OPTIND} -eq 1 ]
  154. then
  155. usage
  156. exit 0
  157. fi
  158. #---------------------------------------------------------------------------------------
  159. # check installation of required packages or update when -u is set
  160. source ./src/platform/unix/linux.d/${DISTRIBUTION}
  161. if [[ -n "$FORCE_GTK2" ]]
  162. then
  163. FOUND_GTK2=$(dpkg -l libgtk* | grep gtk2)
  164. FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev)
  165. echo -e "\nFOUND_GTK2:\n$FOUND_GTK2\n"
  166. else
  167. FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3)
  168. FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev)
  169. echo -e "\nFOUND_GTK3:\n$FOUND_GTK3)\n"
  170. fi
  171. if [[ -n "$BUILD_DEPS" ]]
  172. then
  173. if [[ -n $BUILD_WIPE ]]
  174. then
  175. echo -e "\n wiping deps/build directory...\n"
  176. rm -fr deps/build
  177. echo -e " ... done\n"
  178. fi
  179. # mkdir build in deps
  180. if [ ! -d "deps/build" ]
  181. then
  182. mkdir deps/build
  183. fi
  184. echo -e "[1/9] Configuring dependencies ...\n"
  185. BUILD_ARGS=""
  186. if [[ -n "$FOUND_GTK3_DEV" ]]
  187. then
  188. BUILD_ARGS="-DDEP_WX_GTK3=ON"
  189. else
  190. BUILD_ARGS="-DDEP_WX_GTK3=OFF"
  191. fi
  192. if [[ -n "$BUILD_DEBUG" ]]
  193. then
  194. # have to build deps with debug & release or the cmake won't find evrything it needs
  195. if [ ! -d "deps/build/release" ]
  196. then
  197. mkdir deps/build/release
  198. fi
  199. pushd deps/build/release > /dev/null
  200. cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
  201. popd > /dev/null
  202. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  203. fi
  204. pushd deps/build > /dev/null
  205. cmake .. $BUILD_ARGS
  206. echo -e "\n ... done\n"
  207. echo -e "\n[2/9] Building dependencies...\n"
  208. # make deps
  209. make -j$NCORES
  210. echo -e "\n ... done\n"
  211. # rename wxscintilla
  212. echo "[3/9] Renaming wxscintilla library..."
  213. pushd destdir/usr/local/lib > /dev/null
  214. if [[ -z "$FOUND_GTK3_DEV" ]]
  215. then
  216. cp libwxscintilla-3.2.a libwx_gtk2u_scintilla-3.2.a
  217. else
  218. cp libwxscintilla-3.2.a libwx_gtk3u_scintilla-3.2.a
  219. fi
  220. echo "> ls destdir/usr/local/lib"
  221. ls -al .
  222. echo "> ls ROOT/deps/build/destdir/usr/local/lib"
  223. ls -al $ROOT/deps/build/destdir/usr/local/lib
  224. popd > /dev/null
  225. popd > /dev/null
  226. echo -e "\n ... done\n"
  227. fi
  228. if [[ -n "$BUILD_CLEANDEPEND" ]]
  229. then
  230. echo -e "[4/9] Cleaning dependencies...\n"
  231. pushd deps/build > /dev/null
  232. rm -fr dep_*
  233. popd > /dev/null
  234. echo -e " ... done\n"
  235. fi
  236. if [[ -n "$BUILD_SLIC3R" ]]
  237. then
  238. echo -e "[5/9] Configuring SuperSlicer ...\n"
  239. if [[ -n $BUILD_WIPE ]]
  240. then
  241. echo -n "wiping build directory ..."
  242. rm -fr build
  243. echo " done"
  244. fi
  245. echo -n "Updating submodules ..."
  246. {
  247. # update submodule profiles
  248. pushd resources/profiles
  249. git submodule update --init
  250. popd
  251. } #> $ROOT/build/Build.log # Capture all command output
  252. echo " done"
  253. if [[ -n $VERSION_DATE ]]
  254. then
  255. echo -n "Changing date in version ..."
  256. # change date in version
  257. sed "s/+UNKNOWN/-$(date '+%F')/" version.inc > version.date.inc
  258. echo " done"
  259. else
  260. sed "s/+UNKNOWN//" version.inc > version.date.inc
  261. fi
  262. # mkdir build
  263. if [ ! -d "build" ]
  264. then
  265. mkdir build
  266. fi
  267. BUILD_ARGS=""
  268. if [[ -n "$FOUND_GTK3_DEV" ]]
  269. then
  270. BUILD_ARGS="-DSLIC3R_GTK=3"
  271. fi
  272. if [[ -n "$BUILD_DEBUG" ]]
  273. then
  274. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  275. fi
  276. if [[ -n "$BUILD_TESTS" ]]
  277. then
  278. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
  279. else
  280. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
  281. fi
  282. # cmake
  283. pushd build > /dev/null
  284. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  285. echo " ... done"
  286. # make SuperSlicer
  287. echo -e "\n[6/9] Building SuperSlicer ...\n"
  288. make -j$NCORES Slic3r
  289. make -j$NCORES OCCTWrapper
  290. echo -e "\n ... done"
  291. echo -e "\n[7/9] Generating language files ...\n"
  292. #make .mo
  293. if [[ -n "$UPDATE_POTFILE" ]]
  294. then
  295. make gettext_make_pot
  296. fi
  297. make gettext_po_to_mo
  298. popd > /dev/null
  299. echo -e "\n ... done"
  300. # Give proper permissions to script
  301. chmod 755 $ROOT/build/src/BuildLinuxImage.sh
  302. pushd build > /dev/null
  303. $ROOT/build/src/BuildLinuxImage.sh -a $FORCE_GTK2
  304. popd > /dev/null
  305. echo "> ls ROOT"
  306. ls -al $ROOT
  307. echo "> ls ROOT/build"
  308. ls -al $ROOT/build
  309. echo "> ls -al ROOT/build/bin"
  310. ls -al $ROOT/build/bin
  311. echo "> ls -al ROOT/build/src"
  312. ls -al $ROOT/build/src
  313. fi
  314. if [[ -n "$BUILD_IMAGE" ]]
  315. then
  316. # Give proper permissions to script
  317. chmod 755 $ROOT/build/src/BuildLinuxImage.sh
  318. pushd build > /dev/null
  319. $ROOT/build/src/BuildLinuxImage.sh -i $FORCE_GTK2
  320. popd > /dev/null
  321. echo "> ls ROOT"
  322. ls -al $ROOT
  323. echo "> ls ROOT/build"
  324. ls -al $ROOT/build
  325. echo "> ls -al ROOT/build/bin"
  326. ls -al $ROOT/build/bin
  327. echo "> ls -al ROOT/build/src"
  328. ls -al $ROOT/build/src
  329. fi