BuildMacOS.sh 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. export ROOT=`pwd`
  14. export NCORES=`sysctl -n hw.ncpu`
  15. OS_FOUND=$( command -v uname)
  16. case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in
  17. linux*)
  18. TARGET_OS="linux"
  19. ;;
  20. msys*|cygwin*|mingw*)
  21. # or possible 'bash on windows'
  22. TARGET_OS='windows'
  23. ;;
  24. nt|win*)
  25. TARGET_OS='windows'
  26. ;;
  27. darwin)
  28. TARGET_OS='macos'
  29. ;;
  30. *)
  31. TARGET_OS='unknown'
  32. ;;
  33. esac
  34. export TERM=xterm-256color
  35. # check operating system
  36. BUILD_IMG_ARCH=""
  37. echo
  38. if [ $TARGET_OS == "macos" ]; then
  39. if [ $(uname -m) == "x86_64" ]; then
  40. echo -e "$(tput setaf 2)macOS x86_64 found$(tput sgr0)\n"
  41. Processor="x86_64"
  42. BUILD_IMG_ARCH="-x"
  43. echo "x86 BUILD_IMG_ARCH=${BUILD_IMG_ARCH}\n"
  44. elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  45. echo "$(tput setaf 2)macOS i386 / i686 (arm?) found$(tput sgr0)\n"
  46. Processor="arm64"
  47. BUILD_IMG_ARCH="-a"
  48. elif [ $(uname -m) == "arm64" ]; then
  49. echo "$(tput setaf 2)macOS arm64 found$(tput sgr0)\n"
  50. Processor="arm64"
  51. BUILD_IMG_ARCH="-a"
  52. else
  53. echo "$(tput setaf 1)Unsupported OS: macOS $(uname -m)"
  54. exit -1
  55. fi
  56. else
  57. echo -e "$(tput setaf 1)This script doesn't support your Operating system!"
  58. echo -e "Please use a macOS.$(tput sgr0)\n"
  59. exit -1
  60. fi
  61. echo "BUILD_IMG_ARCH=${BUILD_IMG_ARCH}\n"
  62. # Check if CMake is installed
  63. export CMAKE_INSTALLED=`which cmake`
  64. if [[ -z "$CMAKE_INSTALLED" ]]
  65. then
  66. echo "Can't find CMake. Either is not installed or not in the PATH. Aborting!"
  67. exit -1
  68. fi
  69. while getopts ":idaxbhcsltwrv" opt; do
  70. case ${opt} in
  71. i )
  72. BUILD_IMAGE="1"
  73. ;;
  74. d )
  75. BUILD_DEPS="1"
  76. ;;
  77. a )
  78. BUILD_ARCH="arm64"
  79. BUILD_IMG_ARCH="-a"
  80. ;;
  81. x )
  82. BUILD_ARCH="x86_64"
  83. BUILD_IMG_ARCH="-x"
  84. ;;
  85. b )
  86. BUILD_DEBUG="1"
  87. ;;
  88. s )
  89. BUILD_SLIC3R="1"
  90. ;;
  91. t)
  92. BUILD_TESTS="1"
  93. ;;
  94. l )
  95. UPDATE_POTFILE="1"
  96. ;;
  97. c)
  98. BUILD_XCODE="1"
  99. ;;
  100. v )
  101. VERSION_DATE="1"
  102. ;;
  103. w )
  104. BUILD_WIPE="1"
  105. ;;
  106. r )
  107. BUILD_CLEANDEPEND="1"
  108. ;;
  109. h ) echo "Usage: ./BuildMacOS.sh [-h][-w][-d][-r][-a][-x][-b][-c][-s][-t][-i]"
  110. echo " -h: this message"
  111. echo " -w: wipe build directories before building"
  112. echo " -d: build dependencies"
  113. echo " -r: clean dependencies building files (reduce disk usage)"
  114. echo " -a: build for arm64 (Apple Silicon)"
  115. echo " -x: build for x86_64 (Intel)"
  116. echo " -b: build with debug symbols"
  117. echo " -c: build for XCode"
  118. echo " -s: build Slic3r/SuperSlicer"
  119. echo " -t: build tests (in combination with -s)"
  120. echo " -i: generate DMG image (optional)\n"
  121. echo " -v: change the version 'UNKNOWN' to the date of the day"
  122. exit 0
  123. ;;
  124. esac
  125. done
  126. if [ $OPTIND -eq 1 ]
  127. then
  128. echo "Usage: ./BuildLinux.sh [-h][-w][-d][-r][-a][-x][-b][-c][-s][-t][-i]"
  129. echo " -h: this message"
  130. echo " -w: wipe build directories before building"
  131. echo " -d: build dependencies"
  132. echo " -r: clean dependencies building files (reduce disk usage)"
  133. echo " -a: build for arm64 (Apple Silicon)"
  134. echo " -x: build for x86_64 (Intel)"
  135. echo " -b: build with debug symbols"
  136. echo " -c: build for XCode"
  137. echo " -s: build Slic3r/SuperSlicer"
  138. echo " -t: build tests (in combination with -s)"
  139. echo -e " -i: Generate DMG image (optional)\n"
  140. exit 0
  141. fi
  142. echo "Build architecture: ${BUILD_ARCH}"
  143. echo "Build IMG_ARCH=${BUILD_IMG_ARCH}\n"
  144. echo "\n/Applications:\n"
  145. ls /Applications
  146. echo "\n/Applications/Xcode_13.2.1.app:\n"
  147. ls /Applications/Xcode_13.2.1.app
  148. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs:\n"
  149. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
  150. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib:\n"
  151. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib
  152. # Iconv: /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libiconv.tbd
  153. echo "\nbrew --prefix libiconv:\n"
  154. brew --prefix libiconv
  155. echo "\nbrew --prefix zstd:\n"
  156. brew --prefix zstd
  157. # not enough to fix the issue on cross-compiling
  158. #if [[ -n "$BUILD_ARCH" ]]
  159. #then
  160. # export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix libiconv)/lib/
  161. #fi
  162. export $BUILD_ARCH
  163. export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
  164. echo -n "[1/9] Updating submodules..."
  165. {
  166. # update submodule profiles
  167. pushd resources/profiles
  168. git submodule update --init
  169. popd
  170. } #> $ROOT/build/Build.log # Capture all command output
  171. echo "done"
  172. if [[ -n "$VERSION_DATE" ]]
  173. then
  174. echo -n "[2/9] Changing date in version ... "
  175. # change date in version
  176. sed "s/+UNKNOWN/-$(date '+%F')/" version.inc > version.date.inc
  177. echo "done"
  178. else
  179. echo -n "[2/9] Changing date in version: remove UNKNOWN ... "
  180. sed "s/+UNKNOWN//" version.inc > version.date.inc
  181. echo "done"
  182. fi
  183. if [[ -n "$BUILD_DEPS" ]]
  184. then
  185. if [[ -n $BUILD_WIPE ]]
  186. then
  187. echo -e "\n wiping deps/build directory ...\n"
  188. rm -fr deps/build
  189. echo -e " ... done\n"
  190. fi
  191. # mkdir in deps
  192. if [ ! -d "deps/build" ]
  193. then
  194. mkdir deps/build
  195. fi
  196. echo -e " \n[3/9] Configuring dependencies ... \n"
  197. BUILD_ARGS=""
  198. if [[ -n "$BUILD_ARCH" ]]
  199. then
  200. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES:STRING=${BUILD_ARCH}"
  201. fi
  202. if [[ -n "$BUILD_DEBUG" ]]
  203. then
  204. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  205. fi
  206. # cmake deps
  207. echo "Cmake command: cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.15\" ${BUILD_ARCH} "
  208. pushd deps/build > /dev/null
  209. cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET="10.15" $BUILD_ARGS
  210. if [ $? -eq 0 ]
  211. then
  212. echo -e "\n ... done\n"
  213. else
  214. echo -e "\n ... fail\n"
  215. exit 1 # terminate and indicate error
  216. fi
  217. echo -e "[4/9] Building dependencies ...\n"
  218. # make deps
  219. make -j$NCORES
  220. if [ $? -eq 0 ]
  221. then
  222. echo -e "\n ... done\n"
  223. else
  224. echo -e "\n ... fail\n"
  225. exit 1 # terminate and indicate error
  226. fi
  227. echo -e "[5/9] Renaming wxscintilla library ...\n"
  228. # rename wxscintilla
  229. pushd destdir/usr/local/lib > /dev/null
  230. cp libwxscintilla-3.2.a libwx_osx_cocoau_scintilla-3.2.a
  231. popd > /dev/null
  232. popd > /dev/null
  233. echo -e "\n ... done\n"
  234. fi
  235. if [[ -n "$BUILD_CLEANDEPEND" ]]
  236. then
  237. echo -e "[6/9] Cleaning dependencies...\n"
  238. pushd deps/build
  239. pwd
  240. rm -fr dep_*
  241. popd > /dev/null
  242. echo -e "\n ... done\n"
  243. fi
  244. if [[ -n "$BUILD_SLIC3R" ]]
  245. then
  246. echo -e "[5/9] Configuring Slicer ...\n"
  247. if [[ -n $BUILD_WIPE ]]
  248. then
  249. echo -e "\n wiping build directory...\n"
  250. rm -fr build
  251. echo -e " ... done\n"
  252. fi
  253. # mkdir build
  254. if [ ! -d "build" ]
  255. then
  256. mkdir build
  257. fi
  258. BUILD_ARGS=""
  259. if [[ -n "$BUILD_ARCH" ]]
  260. then
  261. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES=${BUILD_ARCH}"
  262. fi
  263. if [[ -n "$BUILD_DEBUG" ]]
  264. then
  265. BUILD_ARGS="-DCMAKE_BUILD_TYPE=Debug ${BUILD_ARGS}"
  266. fi
  267. if [[ -n "$BUILD_XCODE" ]]
  268. then
  269. BUILD_ARGS="-GXcode ${BUILD_ARGS}"
  270. fi
  271. if [[ -n "$BUILD_TESTS" ]]
  272. then
  273. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
  274. else
  275. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
  276. fi
  277. # cmake
  278. pushd build > /dev/null
  279. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  280. if [ $? -eq 0 ]
  281. then
  282. echo -e "\n ... done\n"
  283. else
  284. echo -e "\n ... fail\n"
  285. exit 1 # terminate and indicate error
  286. fi
  287. # make Slic3r
  288. if [[ -z "$BUILD_XCODE" ]]
  289. then
  290. echo -e "\n[6/9] Building Slicer ...\n"
  291. make -j$NCORES Slic3r
  292. if [ $? -eq 0 ]
  293. then
  294. echo -e "\n ... done\n"
  295. else
  296. echo -e "\n ... fail\n"
  297. exit 1 # terminate and indicate error
  298. fi
  299. fi
  300. echo -e "\n[7/9] Generating language files ...\n"
  301. #make .mo
  302. if [[ -n "$UPDATE_POTFILE" ]]
  303. then
  304. make gettext_make_pot
  305. fi
  306. make gettext_po_to_mo
  307. if [ $? -eq 0 ]
  308. then
  309. echo -e "\n ... done\n"
  310. else
  311. echo -e "\n ... fail\n"
  312. exit 1 # terminate and indicate error
  313. fi
  314. popd > /dev/null
  315. echo "> ls ROOT"
  316. ls -al $ROOT
  317. echo "> ls ROOT/build"
  318. ls -al $ROOT/build
  319. echo "> ls -al ROOT/build/bin"
  320. ls -al $ROOT/build/bin
  321. echo "> ls -al ROOT/build/src"
  322. ls -al $ROOT/build/src
  323. fi
  324. if [[ -n "$BUILD_IMAGE" ]]
  325. then
  326. # Give proper permissions to script
  327. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  328. pushd build > /dev/null
  329. echo "> $ROOT/build/src/BuildMacOSImage.sh -i ${BUILD_IMG_ARCH}"
  330. if [[ -n "$BUILD_DOWNLOAD_DEP" ]]
  331. then
  332. $ROOT/build/src/BuildMacOSImage.sh -i $BUILD_IMG_ARCH
  333. else
  334. $ROOT/build/src/BuildMacOSImage.sh -i $BUILD_IMG_ARCH -z
  335. fi
  336. if [ $? -eq 0 ]
  337. then
  338. echo -e "\n BuildMacOSImage done\n"
  339. else
  340. echo -e "\n BuildMacOSImage fail\n"
  341. # exit 1 # terminate and indicate error
  342. fi
  343. popd > /dev/null
  344. echo "> ls ROOT"
  345. ls -al $ROOT
  346. echo "> ls ROOT/build"
  347. ls -al $ROOT/build
  348. echo "> ls -al ROOT/build/bin"
  349. ls -al $ROOT/build/bin
  350. echo "> ls -al ROOT/build/bin"
  351. ls -al $ROOT/build/bin
  352. echo "> ls -al ROOT/build/src"
  353. ls -al $ROOT/build/src
  354. fi