BuildMacOS.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #!/bin/bash
  2. export ROOT=`pwd`
  3. export NCORES=`sysctl -n hw.ncpu`
  4. export CMAKE_INSTALLED=`which cmake`
  5. #export ARCH=$(uname -m)
  6. # Check if CMake is installed
  7. if [[ -z "$CMAKE_INSTALLED" ]]
  8. then
  9. echo "Can't find CMake. Either is not installed or not in the PATH. Aborting!"
  10. exit -1
  11. fi
  12. while getopts ":idaxbhcstwr" opt; do
  13. case ${opt} in
  14. i )
  15. BUILD_IMAGE="1"
  16. ;;
  17. d )
  18. BUILD_DEPS="1"
  19. ;;
  20. a )
  21. BUILD_ARCH="arm64"
  22. BUILD_IMG="-a"
  23. ;;
  24. x )
  25. BUILD_ARCH="x86_64"
  26. BUILD_IMG="-x"
  27. ;;
  28. b )
  29. BUILD_DEBUG="1"
  30. ;;
  31. s )
  32. BUILD_SLIC3R="1"
  33. ;;
  34. t)
  35. BUILD_TESTS="1"
  36. ;;
  37. c)
  38. BUILD_XCODE="1"
  39. ;;
  40. w )
  41. BUILD_WIPE="1"
  42. ;;
  43. r )
  44. BUILD_CLEANDEPEND="1"
  45. ;;
  46. h ) echo "Usage: ./BuildMacOS.sh [-h][-w][-d][-r][-a][-x][-b][-c][-s][-t][-i]"
  47. echo " -h: this message"
  48. echo " -w: wipe build directories before building"
  49. echo " -d: build dependencies"
  50. echo " -r: clean dependencies building files (reduce disk usage)"
  51. echo " -a: build for arm64 (Apple Silicon)"
  52. echo " -x: build for x86_64 (Intel)"
  53. echo " -b: build with debug symbols"
  54. echo " -c: build for XCode"
  55. echo " -s: build Slic3r/SuperSlicer"
  56. echo " -t: build tests (in combination with -s)"
  57. echo " -i: generate DMG image (optional)\n"
  58. exit 0
  59. ;;
  60. esac
  61. done
  62. if [ $OPTIND -eq 1 ]
  63. then
  64. echo "Usage: ./BuildLinux.sh [-h][-w][-d][-r][-a][-x][-b][-c][-s][-t][-i]"
  65. echo " -h: this message"
  66. echo " -w: wipe build directories before building"
  67. echo " -d: build dependencies"
  68. echo " -r: clean dependencies building files (reduce disk usage)"
  69. echo " -a: build for arm64 (Apple Silicon)"
  70. echo " -x: build for x86_64 (Intel)"
  71. echo " -b: build with debug symbols"
  72. echo " -c: build for XCode"
  73. echo " -s: build Slic3r/SuperSlicer"
  74. echo " -t: build tests (in combination with -s)"
  75. echo -e " -i: Generate DMG image (optional)\n"
  76. exit 0
  77. fi
  78. echo "Build architecture: ${BUILD_ARCH}"
  79. echo "\n/Applications:\n"
  80. ls /Applications
  81. echo "\n/Applications/Xcode_13.2.1.app:\n"
  82. ls /Applications/Xcode_13.2.1.app
  83. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs:\n"
  84. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
  85. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib:\n"
  86. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib
  87. # Iconv: /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libiconv.tbd
  88. echo "\nbrew --prefix libiconv:\n"
  89. brew --prefix libiconv
  90. echo "\nbrew --prefix zstd:\n"
  91. brew --prefix zstd
  92. export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
  93. # not enough to fix the issue on cross-compiling
  94. #if [[ -n "$BUILD_ARCH" ]]
  95. #then
  96. # export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix libiconv)/lib/
  97. #fi
  98. echo -n "[1/9] Updating submodules..."
  99. {
  100. # update submodule profiles
  101. pushd resources/profiles
  102. git submodule update --init
  103. popd
  104. } #> $ROOT/build/Build.log # Capture all command output
  105. echo "done"
  106. echo -n "[2/9] Changing date in version..."
  107. {
  108. # change date in version
  109. sed "s/+UNKNOWN/_$(date '+%F')/" version.inc > version.date.inc
  110. mv version.date.inc version.inc
  111. } #&> $ROOT/build/Build.log # Capture all command output
  112. echo "done"
  113. if [[ -n "$BUILD_DEPS" ]]
  114. then
  115. if [[ -n $BUILD_WIPE ]]
  116. then
  117. echo -e "\n wiping deps/build directory ...\n"
  118. rm -fr deps/build
  119. echo -e " ... done\n"
  120. fi
  121. # mkdir in deps
  122. if [ ! -d "deps/build" ]
  123. then
  124. mkdir deps/build
  125. fi
  126. echo -e " \n[3/9] Configuring dependencies ... \n"
  127. BUILD_ARGS=""
  128. if [[ -n "$BUILD_ARCH" ]]
  129. then
  130. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES:STRING=${BUILD_ARCH}"
  131. fi
  132. if [[ -n "$BUILD_DEBUG" ]]
  133. then
  134. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  135. fi
  136. # cmake deps
  137. echo "Cmake command: cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.14\" ${BUILD_ARCH} "
  138. pushd deps/build > /dev/null
  139. cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" $BUILD_ARGS
  140. echo -e "\n ... done\n"
  141. echo -e "[4/9] Building dependencies ...\n"
  142. # make deps
  143. make -j$NCORES
  144. echo -e "\n ... done\n"
  145. echo -e "[5/9] Renaming wxscintilla library ...\n"
  146. # rename wxscintilla
  147. pushd destdir/usr/local/lib > /dev/null
  148. cp libwxscintilla-3.2.a libwx_osx_cocoau_scintilla-3.2.a
  149. popd > /dev/null
  150. popd > /dev/null
  151. echo -e "\n ... done\n"
  152. fi
  153. if [[ -n "$BUILD_CLEANDEPEND" ]]
  154. then
  155. echo -e "[6/9] Cleaning dependencies...\n"
  156. pushd deps/build
  157. pwd
  158. rm -fr dep_*
  159. popd > /dev/null
  160. echo -e "\n ... done\n"
  161. fi
  162. if [[ -n "$BUILD_SLIC3R" ]]
  163. then
  164. echo -e "[5/9] Configuring Slicer ...\n"
  165. if [[ -n $BUILD_WIPE ]]
  166. then
  167. echo -e "\n wiping build directory...\n"
  168. rm -fr build
  169. echo -e " ... done\n"
  170. fi
  171. # mkdir build
  172. if [ ! -d "build" ]
  173. then
  174. mkdir build
  175. fi
  176. BUILD_ARGS=""
  177. if [[ -n "$BUILD_ARCH" ]]
  178. then
  179. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES=${BUILD_ARCH}"
  180. fi
  181. if [[ -n "$BUILD_DEBUG" ]]
  182. then
  183. BUILD_ARGS="-DCMAKE_BUILD_TYPE=Debug ${BUILD_ARGS}"
  184. fi
  185. if [[ -n "$BUILD_XCODE" ]]
  186. then
  187. BUILD_ARGS="-GXcode ${BUILD_ARGS}"
  188. fi
  189. if [[ -n "$BUILD_TESTS" ]]
  190. then
  191. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=1"
  192. else
  193. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TESTS=0"
  194. fi
  195. # cmake
  196. pushd build > /dev/null
  197. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  198. echo -e "\n ... done"
  199. # make Slic3r
  200. if [[ -z "$BUILD_XCODE" ]]
  201. then
  202. echo -e "\n[6/9] Building Slicer ...\n"
  203. make -j1
  204. echo -e "\n ... done"
  205. fi
  206. echo -e "\n[7/9] Generating language files ...\n"
  207. #make .mo
  208. make gettext_po_to_mo
  209. popd > /dev/null
  210. echo -e "\n ... done"
  211. # Give proper permissions to script
  212. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  213. pushd build > /dev/null
  214. $ROOT/build/src/BuildMacOSImage.sh -p $BUILD_IMG
  215. popd > /dev/null
  216. echo "ls ROOT"
  217. ls $ROOT
  218. echo "ls ROOT/build"
  219. ls $ROOT/build
  220. echo "ls -al ROOT/build/src"
  221. ls -al $ROOT/build/src
  222. fi
  223. if [[ -n "$BUILD_IMAGE" ]]
  224. then
  225. # Give proper permissions to script
  226. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  227. pushd build > /dev/null
  228. $ROOT/build/src/BuildMacOSImage.sh -i $BUILD_IMG
  229. popd > /dev/null
  230. fi