BuildMacOS.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
  158. # not enough to fix the issue on cross-compiling
  159. #if [[ -n "$BUILD_ARCH" ]]
  160. #then
  161. # export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix libiconv)/lib/
  162. #fi
  163. export $BUILD_ARCH
  164. export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
  165. echo -n "[1/9] Updating submodules..."
  166. {
  167. # update submodule profiles
  168. pushd resources/profiles
  169. git submodule update --init
  170. popd
  171. } #> $ROOT/build/Build.log # Capture all command output
  172. echo "done"
  173. if [[ -n "$VERSION_DATE" ]]
  174. then
  175. echo -n "[2/9] Changing date in version ... "
  176. # change date in version
  177. sed "s/+UNKNOWN/-$(date '+%F')/" version.inc > version.date.inc
  178. echo "done"
  179. else
  180. echo -n "[2/9] Changing date in version: remove UNKNOWN ... "
  181. sed "s/+UNKNOWN//" version.inc > version.date.inc
  182. echo "done"
  183. fi
  184. if [[ -n "$BUILD_DEPS" ]]
  185. then
  186. if [[ -n $BUILD_WIPE ]]
  187. then
  188. echo -e "\n wiping deps/build directory ...\n"
  189. rm -fr deps/build
  190. echo -e " ... done\n"
  191. fi
  192. # mkdir in deps
  193. if [ ! -d "deps/build" ]
  194. then
  195. mkdir deps/build
  196. fi
  197. echo -e " \n[3/9] Configuring dependencies ... \n"
  198. BUILD_ARGS=""
  199. if [[ -n "$BUILD_ARCH" ]]
  200. then
  201. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES:STRING=${BUILD_ARCH}"
  202. fi
  203. if [[ -n "$BUILD_DEBUG" ]]
  204. then
  205. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  206. fi
  207. # cmake deps
  208. echo "Cmake command: cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.15\" ${BUILD_ARCH} "
  209. pushd deps/build > /dev/null
  210. cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET="10.15" $BUILD_ARGS
  211. echo -e "\n ... done\n"
  212. echo -e "[4/9] Building dependencies ...\n"
  213. # make deps
  214. make -j$NCORES
  215. echo -e "\n ... done\n"
  216. echo -e "[5/9] Renaming wxscintilla library ...\n"
  217. # rename wxscintilla
  218. pushd destdir/usr/local/lib > /dev/null
  219. cp libwxscintilla-3.2.a libwx_osx_cocoau_scintilla-3.2.a
  220. popd > /dev/null
  221. popd > /dev/null
  222. echo -e "\n ... done\n"
  223. fi
  224. if [[ -n "$BUILD_CLEANDEPEND" ]]
  225. then
  226. echo -e "[6/9] Cleaning dependencies...\n"
  227. pushd deps/build
  228. pwd
  229. rm -fr dep_*
  230. popd > /dev/null
  231. echo -e "\n ... done\n"
  232. fi
  233. if [[ -n "$BUILD_SLIC3R" ]]
  234. then
  235. echo -e "[5/9] Configuring Slicer ...\n"
  236. if [[ -n $BUILD_WIPE ]]
  237. then
  238. echo -e "\n wiping build directory...\n"
  239. rm -fr build
  240. echo -e " ... done\n"
  241. fi
  242. # mkdir build
  243. if [ ! -d "build" ]
  244. then
  245. mkdir build
  246. fi
  247. BUILD_ARGS=""
  248. if [[ -n "$BUILD_ARCH" ]]
  249. then
  250. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES=${BUILD_ARCH}"
  251. fi
  252. if [[ -n "$BUILD_DEBUG" ]]
  253. then
  254. BUILD_ARGS="-DCMAKE_BUILD_TYPE=Debug ${BUILD_ARGS}"
  255. fi
  256. if [[ -n "$BUILD_XCODE" ]]
  257. then
  258. BUILD_ARGS="-GXcode ${BUILD_ARGS}"
  259. fi
  260. if [[ -n "$BUILD_TESTS" ]]
  261. then
  262. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
  263. else
  264. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
  265. fi
  266. # cmake
  267. pushd build > /dev/null
  268. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  269. echo -e "\n ... done"
  270. # make Slic3r
  271. if [[ -z "$BUILD_XCODE" ]]
  272. then
  273. echo -e "\n[6/9] Building Slicer ...\n"
  274. make -j$NCORES Slic3r
  275. echo -e "\n ... done"
  276. fi
  277. echo -e "\n[7/9] Generating language files ...\n"
  278. #make .mo
  279. if [[ -n "$UPDATE_POTFILE" ]]
  280. then
  281. make gettext_make_pot
  282. fi
  283. make gettext_po_to_mo
  284. popd > /dev/null
  285. echo -e "\n ... done"
  286. popd > /dev/null
  287. echo "> ls ROOT"
  288. ls -al $ROOT
  289. echo "> ls ROOT/build"
  290. ls -al $ROOT/build
  291. echo "> ls -al ROOT/build/bin"
  292. ls -al $ROOT/build/bin
  293. echo "> ls -al ROOT/build/src"
  294. ls -al $ROOT/build/src
  295. fi
  296. if [[ -n "$BUILD_IMAGE" ]]
  297. then
  298. # Give proper permissions to script
  299. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  300. pushd build > /dev/null
  301. echo "> $ROOT/build/src/BuildMacOSImage.sh -i ${BUILD_IMG_ARCH}"
  302. $ROOT/build/src/BuildMacOSImage.sh -i $BUILD_IMG_ARCH
  303. popd > /dev/null
  304. echo "> ls ROOT"
  305. ls -al $ROOT
  306. echo "> ls ROOT/build"
  307. ls -al $ROOT/build
  308. echo "> ls -al ROOT/build/bin"
  309. ls -al $ROOT/build/bin
  310. echo "> ls -al ROOT/build/bin"
  311. ls -al $ROOT/build/bin
  312. echo "> ls -al ROOT/build/src"
  313. ls -al $ROOT/build/src
  314. fi