BuildMacOS.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. BUILD_ARCH=$(uname -m)
  60. while getopts ":idaxbhcsltwr" opt; do
  61. case ${opt} in
  62. i )
  63. BUILD_IMAGE="1"
  64. ;;
  65. d )
  66. BUILD_DEPS="1"
  67. ;;
  68. a )
  69. BUILD_ARCH="arm64"
  70. BUILD_IMG="-a"
  71. ;;
  72. x )
  73. BUILD_ARCH="x86_64"
  74. BUILD_IMG="-x"
  75. ;;
  76. b )
  77. BUILD_DEBUG="1"
  78. ;;
  79. s )
  80. BUILD_SUPERSLICER="1"
  81. ;;
  82. l )
  83. UPDATE_POTFILE="1"
  84. ;;
  85. c)
  86. BUILD_XCODE="1"
  87. ;;
  88. w )
  89. BUILD_WIPE="1"
  90. ;;
  91. r )
  92. BUILD_CLEANDEPEND="1"
  93. ;;
  94. h ) echo "Usage: ./BuildMacOS.sh [-h][-w][-a][-r][-x][-b][-c][-d][-s][-l][-t][-i]"
  95. echo " -h: this message"
  96. echo " -w: wipe build directories bfore building"
  97. echo " -a: build for arm64 (Apple Silicon)"
  98. echo " -r: clean dependencies"
  99. echo " -x: build for x86_64 (Intel)"
  100. echo " -b: build with debug symbols"
  101. echo " -c: build for XCode"
  102. echo " -d: build dependencies"
  103. echo " -s: build SuperSlicer"
  104. echo " -t: build tests (in combination with -s)"
  105. echo " -i: generate .tgz and DMG image (optional)\n"
  106. exit 0
  107. ;;
  108. esac
  109. done
  110. if [ $OPTIND -eq 1 ]
  111. then
  112. echo "Usage: ./BuildLinux.sh [-h][-w][-a][-r][-x][-b][-c][-d][-s][-l][-t][-i]"
  113. echo " -h: this message"
  114. echo " -w: wipe build directories bfore building"
  115. echo " -a: Build for arm64 (Apple Silicon)"
  116. echo " -r: clean dependencies"
  117. echo " -x: build for x86_64 (Intel)"
  118. echo " -b: build with debug symbols"
  119. echo " -c: build for XCode"
  120. echo " -d: build dependencies"
  121. echo " -s: build SuperSlicer"
  122. echo " -t: build tests (in combination with -s)"
  123. echo -e " -i: Generate .tgz and DMG image (optional)\n"
  124. exit 0
  125. fi
  126. export $BUILD_ARCH
  127. export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
  128. if [[ -n "$BUILD_DEPS" ]]
  129. then
  130. if [[ -n $BUILD_WIPE ]]
  131. then
  132. echo -e "\n wiping deps/build directory ...\n"
  133. rm -fr deps/build
  134. echo -e " ... done\n"
  135. fi
  136. # mkdir in deps
  137. if [ ! -d "deps/build" ]
  138. then
  139. mkdir deps/build
  140. fi
  141. echo -e " \n[1/9] Configuring dependencies ... \n"
  142. BUILD_ARGS=""
  143. if [[ -n "$BUILD_ARCH" ]]
  144. then
  145. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES:STRING=${BUILD_ARCH}"
  146. fi
  147. if [[ -n "$BUILD_DEBUG" ]]
  148. then
  149. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  150. fi
  151. # cmake deps
  152. echo "Cmake command: cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.15\" ${BUILD_ARCH} "
  153. pushd deps/build > /dev/null
  154. cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET="10.15" $BUILD_ARGS
  155. echo -e "\n ... done\n"
  156. echo -e "[2/9] Building dependencies ...\n"
  157. # make deps
  158. make -j1
  159. echo -e "\n ... done\n"
  160. echo -e "[3/9] Renaming wxscintilla library ...\n"
  161. # rename wxscintilla
  162. pushd destdir/usr/local/lib > /dev/null
  163. cp libwxscintilla-3.1.a libwx_osx_cocoau_scintilla-3.1.a
  164. popd > /dev/null
  165. popd > /dev/null
  166. echo -e "\n ... done\n"
  167. fi
  168. if [[ -n "$BUILD_CLEANDEPEND" ]]
  169. then
  170. echo -e "[4/9] Cleaning dependencies...\n"
  171. pushd deps/build > /dev/null
  172. pwd
  173. rm -fr dep_*
  174. popd > /dev/null
  175. echo -e "\n ... done\n"
  176. fi
  177. if [[ -n "$BUILD_SUPERSLICER" ]]
  178. then
  179. echo -e "[5/9] Configuring SuperSlicer ...\n"
  180. if [[ -n $BUILD_WIPE ]]
  181. then
  182. echo -e "\n wiping build directory...\n"
  183. rm -fr build
  184. echo -e " ... done\n"
  185. fi
  186. # mkdir build
  187. if [ ! -d "build" ]
  188. then
  189. mkdir build
  190. fi
  191. BUILD_ARGS=""
  192. if [[ -n "$BUILD_ARCH" ]]
  193. then
  194. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES=${BUILD_ARCH}"
  195. fi
  196. if [[ -n "$BUILD_DEBUG" ]]
  197. then
  198. BUILD_ARGS="-DCMAKE_BUILD_TYPE=Debug ${BUILD_ARGS}"
  199. fi
  200. if [[ -n "$BUILD_XCODE" ]]
  201. then
  202. BUILD_ARGS="-GXcode ${BUILD_ARGS}"
  203. fi
  204. if [[ -n "$BUILD_TESTS" ]]
  205. then
  206. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
  207. else
  208. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
  209. fi
  210. # cmake
  211. pushd build > /dev/null
  212. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  213. echo -e "\n ... done"
  214. # make Slic3r
  215. if [[ -z "$BUILD_XCODE" ]]
  216. then
  217. echo -e "\n[6/9] Building SuperSlicer ...\n"
  218. make -j$NCORES
  219. echo -e "\n ... done"
  220. fi
  221. echo -e "\n[7/9] Generating language files ...\n"
  222. #make .mo
  223. if [[ -n "$UPDATE_POTFILE" ]]
  224. then
  225. make gettext_make_pot
  226. fi
  227. make gettext_po_to_mo
  228. popd > /dev/null
  229. echo -e "\n ... done"
  230. # Give proper permissions to script
  231. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  232. pushd build > /dev/null
  233. $ROOT/build/src/BuildMacOSImage.sh -a
  234. popd > /dev/null
  235. fi
  236. if [[ -n "$BUILD_IMAGE" ]]
  237. then
  238. # Give proper permissions to script
  239. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  240. pushd build > /dev/null
  241. $ROOT/build/src/BuildMacOSImage.sh -i
  242. popd > /dev/null
  243. fi