BuildMacOS.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. # check operating system
  35. echo
  36. if [ $TARGET_OS == "macos" ]; then
  37. if [ $(uname -m) == "x86_64" ]; then
  38. echo -e "$(tput setaf 2)macOS x86_64 found$(tput sgr0)\n"
  39. Processor="64"
  40. elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then
  41. echo "$(tput setaf 2)macOS arm64 found$(tput sgr0)\n"
  42. Processor="64"
  43. else
  44. echo "$(tput setaf 1)Unsupported OS: macOS $(uname -m)"
  45. exit -1
  46. fi
  47. else
  48. echo -e "$(tput setaf 1)This script doesn't support your Operating system!"
  49. echo -e "Please use a macOS.$(tput sgr0)\n"
  50. exit -1
  51. fi
  52. # Check if CMake is installed
  53. export CMAKE_INSTALLED=`which cmake`
  54. if [[ -z "$CMAKE_INSTALLED" ]]
  55. then
  56. echo "Can't find CMake. Either is not installed or not in the PATH. Aborting!"
  57. exit -1
  58. fi
  59. while getopts ":idaxbhcsltwr" opt; do
  60. case ${opt} in
  61. i )
  62. BUILD_IMAGE="1"
  63. ;;
  64. d )
  65. BUILD_DEPS="1"
  66. ;;
  67. a )
  68. BUILD_ARCH="arm64"
  69. BUILD_IMG="-a"
  70. ;;
  71. x )
  72. BUILD_ARCH="x86_64"
  73. BUILD_IMG="-x"
  74. ;;
  75. b )
  76. BUILD_DEBUG="1"
  77. ;;
  78. s )
  79. BUILD_SLIC3R="1"
  80. ;;
  81. t)
  82. BUILD_TESTS="1"
  83. ;;
  84. l )
  85. UPDATE_POTFILE="1"
  86. ;;
  87. c)
  88. BUILD_XCODE="1"
  89. ;;
  90. w )
  91. BUILD_WIPE="1"
  92. ;;
  93. r )
  94. BUILD_CLEANDEPEND="1"
  95. ;;
  96. h ) echo "Usage: ./BuildMacOS.sh [-h][-w][-d][-r][-a][-x][-b][-c][-s][-t][-i]"
  97. echo " -h: this message"
  98. echo " -w: wipe build directories before building"
  99. echo " -d: build dependencies"
  100. echo " -r: clean dependencies building files (reduce disk usage)"
  101. echo " -a: build for arm64 (Apple Silicon)"
  102. echo " -x: build for x86_64 (Intel)"
  103. echo " -b: build with debug symbols"
  104. echo " -c: build for XCode"
  105. echo " -s: build Slic3r/SuperSlicer"
  106. echo " -t: build tests (in combination with -s)"
  107. echo " -i: generate DMG image (optional)\n"
  108. exit 0
  109. ;;
  110. esac
  111. done
  112. if [ $OPTIND -eq 1 ]
  113. then
  114. echo "Usage: ./BuildLinux.sh [-h][-w][-d][-r][-a][-x][-b][-c][-s][-t][-i]"
  115. echo " -h: this message"
  116. echo " -w: wipe build directories before building"
  117. echo " -d: build dependencies"
  118. echo " -r: clean dependencies building files (reduce disk usage)"
  119. echo " -a: build for arm64 (Apple Silicon)"
  120. echo " -x: build for x86_64 (Intel)"
  121. echo " -b: build with debug symbols"
  122. echo " -c: build for XCode"
  123. echo " -s: build Slic3r/SuperSlicer"
  124. echo " -t: build tests (in combination with -s)"
  125. echo -e " -i: Generate DMG image (optional)\n"
  126. exit 0
  127. fi
  128. echo "Build architecture: ${BUILD_ARCH}"
  129. echo "\n/Applications:\n"
  130. ls /Applications
  131. echo "\n/Applications/Xcode_13.2.1.app:\n"
  132. ls /Applications/Xcode_13.2.1.app
  133. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs:\n"
  134. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
  135. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib:\n"
  136. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib
  137. # Iconv: /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libiconv.tbd
  138. echo "\nbrew --prefix libiconv:\n"
  139. brew --prefix libiconv
  140. echo "\nbrew --prefix zstd:\n"
  141. brew --prefix zstd
  142. export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
  143. # not enough to fix the issue on cross-compiling
  144. #if [[ -n "$BUILD_ARCH" ]]
  145. #then
  146. # export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix libiconv)/lib/
  147. #fi
  148. export $BUILD_ARCH
  149. export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
  150. echo -n "[2/9] Changing date in version..."
  151. {
  152. # change date in version
  153. sed "s/+UNKNOWN/_$(date '+%F')/" version.inc > version.date.inc
  154. mv version.date.inc version.inc
  155. } #&> $ROOT/build/Build.log # Capture all command output
  156. echo "done"
  157. if [[ -n "$BUILD_DEPS" ]]
  158. then
  159. if [[ -n $BUILD_WIPE ]]
  160. then
  161. echo -e "\n wiping deps/build directory ...\n"
  162. rm -fr deps/build
  163. echo -e " ... done\n"
  164. fi
  165. # mkdir in deps
  166. if [ ! -d "deps/build" ]
  167. then
  168. mkdir deps/build
  169. fi
  170. echo -e " \n[3/9] Configuring dependencies ... \n"
  171. BUILD_ARGS=""
  172. if [[ -n "$BUILD_ARCH" ]]
  173. then
  174. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES:STRING=${BUILD_ARCH}"
  175. fi
  176. if [[ -n "$BUILD_DEBUG" ]]
  177. then
  178. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  179. fi
  180. # cmake deps
  181. echo "Cmake command: cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.15\" ${BUILD_ARCH} "
  182. pushd deps/build > /dev/null
  183. cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET="10.15" $BUILD_ARGS
  184. echo -e "\n ... done\n"
  185. echo -e "[4/9] Building dependencies ...\n"
  186. # make deps
  187. make -j1
  188. echo -e "\n ... done\n"
  189. echo -e "[5/9] Renaming wxscintilla library ...\n"
  190. # rename wxscintilla
  191. pushd destdir/usr/local/lib > /dev/null
  192. cp libwxscintilla-3.2.a libwx_osx_cocoau_scintilla-3.2.a
  193. popd > /dev/null
  194. popd > /dev/null
  195. echo -e "\n ... done\n"
  196. fi
  197. if [[ -n "$BUILD_CLEANDEPEND" ]]
  198. then
  199. echo -e "[6/9] Cleaning dependencies...\n"
  200. pushd deps/build
  201. pwd
  202. rm -fr dep_*
  203. popd > /dev/null
  204. echo -e "\n ... done\n"
  205. fi
  206. if [[ -n "$BUILD_SLIC3R" ]]
  207. then
  208. echo -e "[5/9] Configuring Slicer ...\n"
  209. if [[ -n $BUILD_WIPE ]]
  210. then
  211. echo -e "\n wiping build directory...\n"
  212. rm -fr build
  213. echo -e " ... done\n"
  214. fi
  215. # mkdir build
  216. if [ ! -d "build" ]
  217. then
  218. mkdir build
  219. fi
  220. BUILD_ARGS=""
  221. if [[ -n "$BUILD_ARCH" ]]
  222. then
  223. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES=${BUILD_ARCH}"
  224. fi
  225. if [[ -n "$BUILD_DEBUG" ]]
  226. then
  227. BUILD_ARGS="-DCMAKE_BUILD_TYPE=Debug ${BUILD_ARGS}"
  228. fi
  229. if [[ -n "$BUILD_XCODE" ]]
  230. then
  231. BUILD_ARGS="-GXcode ${BUILD_ARGS}"
  232. fi
  233. if [[ -n "$BUILD_TESTS" ]]
  234. then
  235. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
  236. else
  237. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
  238. fi
  239. # cmake
  240. pushd build > /dev/null
  241. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  242. echo -e "\n ... done"
  243. # make Slic3r
  244. if [[ -z "$BUILD_XCODE" ]]
  245. then
  246. echo -e "\n[6/9] Building Slicer ...\n"
  247. make -j$NCORES
  248. echo -e "\n ... done"
  249. fi
  250. echo -e "\n[7/9] Generating language files ...\n"
  251. #make .mo
  252. if [[ -n "$UPDATE_POTFILE" ]]
  253. then
  254. make gettext_make_pot
  255. fi
  256. make gettext_po_to_mo
  257. popd > /dev/null
  258. echo -e "\n ... done"
  259. # Give proper permissions to script
  260. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  261. pushd build > /dev/null
  262. $ROOT/build/src/BuildMacOSImage.sh -p $BUILD_IMG
  263. popd > /dev/null
  264. echo "ls ROOT"
  265. ls $ROOT
  266. echo "ls ROOT/build"
  267. ls $ROOT/build
  268. echo "ls -al ROOT/build/src"
  269. ls -al $ROOT/build/src
  270. fi
  271. if [[ -n "$BUILD_IMAGE" ]]
  272. then
  273. # Give proper permissions to script
  274. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  275. pushd build > /dev/null
  276. $ROOT/build/src/BuildMacOSImage.sh -i $BUILD_IMG
  277. popd > /dev/null
  278. fi