BuildMacOS.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 ":iaxbhc" opt; do
  13. case ${opt} in
  14. i )
  15. export BUILD_IMAGE="1"
  16. ;;
  17. a )
  18. export BUILD_ARCH="arm64"
  19. ;;
  20. x )
  21. export BUILD_ARCH="x86_64"
  22. ;;
  23. b )
  24. export BUILD_DEBUG="1"
  25. ;;
  26. c)
  27. export BUILD_XCODE="1"
  28. ;;
  29. h ) echo "Usage: ./BuildMacOS.sh [-i]"
  30. echo " -i: Generate DMG image (optional)"
  31. echo " -a: Build for arm64 (Apple Silicon)"
  32. echo " -x: Build for x86_64 (Intel)"
  33. echo " -b: Build with debug symbols"
  34. echo " -c: Build for XCode"
  35. exit 0
  36. ;;
  37. esac
  38. done
  39. echo "Build architecture: ${BUILD_ARCH}"
  40. echo "\n/Applications:\n"
  41. ls /Applications
  42. echo "\n/Applications/Xcode_13.2.1.app:\n"
  43. ls /Applications/Xcode_13.2.1.app
  44. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs:\n"
  45. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
  46. echo "\n/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib:\n"
  47. ls /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib
  48. # Iconv: /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libiconv.tbd
  49. echo "\nbrew --prefix libiconv:\n"
  50. brew --prefix libiconv
  51. echo "\nbrew --prefix zstd:\n"
  52. brew --prefix zstd
  53. export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
  54. # not enough to fix the issue on cross-compiling
  55. #if [[ -n "$BUILD_ARCH" ]]
  56. #then
  57. # export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix libiconv)/lib/
  58. #fi
  59. # mkdir build
  60. if [ ! -d "build" ]
  61. then
  62. mkdir build
  63. fi
  64. echo -n "[1/9] Updating submodules..."
  65. {
  66. # update submodule profiles
  67. pushd resources/profiles
  68. git submodule update --init
  69. popd
  70. } #> $ROOT/build/Build.log # Capture all command output
  71. echo "done"
  72. echo -n "[2/9] Changing date in version..."
  73. {
  74. # change date in version
  75. sed "s/+UNKNOWN/_$(date '+%F')/" version.inc > version.date.inc
  76. mv version.date.inc version.inc
  77. } #&> $ROOT/build/Build.log # Capture all command output
  78. echo "done"
  79. # mkdir in deps
  80. if [ ! -d "deps/build" ]
  81. then
  82. mkdir deps/build
  83. fi
  84. echo -n "[3/9] Configuring dependencies..."
  85. {
  86. BUILD_ARGS=""
  87. if [[ -n "$BUILD_ARCH" ]]
  88. then
  89. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES:STRING=${BUILD_ARCH}"
  90. fi
  91. if [[ -n "$BUILD_DEBUG" ]]
  92. then
  93. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  94. fi
  95. # cmake deps
  96. echo "Cmake command: cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.14\" ${BUILD_ARCH} "
  97. pushd deps/build
  98. cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" $BUILD_ARGS
  99. echo "ls deps/build:"
  100. ls -al
  101. echo "ls deps/build/dep_GLEW-prefix"
  102. ls -al dep_GLEW-prefix
  103. } #&> $ROOT/build/Build.log # Capture all command output
  104. echo "done"
  105. echo -n "[4/9] Building dependencies..."
  106. {
  107. # make deps
  108. make -j$NCORES
  109. echo "ls $PWD/destdir/usr/local/lib"
  110. ls $PWD/destdir/usr/local/lib
  111. echo "ls $PWD/destdir/usr/local/lib/cmake"
  112. ls $PWD/destdir/usr/local/lib/cmake
  113. echo "ls $PWD/destdir/usr/local/lib/cmake/boost_locale-1.75.0"
  114. ls $PWD/destdir/usr/local/lib/cmake/boost_locale-1.75.0
  115. } #&> $ROOT/build/Build.log # Capture all command output
  116. echo "done"
  117. echo -n "[5/9] Renaming wxscintilla library..."
  118. {
  119. # rename wxscintilla
  120. pushd destdir/usr/local/lib
  121. cp libwxscintilla-3.1.a libwx_osx_cocoau_scintilla-3.1.a
  122. echo "ls deps/build/destdir/usr/local/lib"
  123. ls -al
  124. popd
  125. } #&> $ROOT/build/Build.log # Capture all command output
  126. echo "done"
  127. echo -n "[6/9] Cleaning dependencies..."
  128. {
  129. # clean deps
  130. rm -rf dep_*
  131. popd
  132. } #&> $ROOT/build/Build.log # Capture all command output
  133. echo "done"
  134. echo -n "[7/9] Configuring Slic3r..."
  135. {
  136. BUILD_ARGS=""
  137. if [[ -n "$BUILD_ARCH" ]]
  138. then
  139. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_OSX_ARCHITECTURES=${BUILD_ARCH}"
  140. fi
  141. if [[ -n "$BUILD_DEBUG" ]]
  142. then
  143. BUILD_ARGS="-DCMAKE_BUILD_TYPE=Debug ${BUILD_ARGS}"
  144. fi
  145. if [[ -n "$BUILD_XCODE" ]]
  146. then
  147. BUILD_ARGS="-GXcode ${BUILD_ARGS}"
  148. fi
  149. # cmake
  150. pushd build
  151. echo "Slic3r Cmake command: cmake .. -DCMAKE_PREFIX_PATH=\"$PWD/../deps/build/destdir/usr/local\" -DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.14\" -DSLIC3R_STATIC=1 ${BUILD_ARGS}"
  152. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DCMAKE_OSX_DEPLOYMENT_TARGET="10.14" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  153. } #&> $ROOT/build/Build.log # Capture all command output
  154. echo "done"
  155. echo -n "[8/9] Building Slic3r..."
  156. {
  157. # make Slic3r
  158. if [[ -z "$BUILD_XCODE" ]]
  159. then
  160. make -j$NCORES Slic3r
  161. fi
  162. # make .mo
  163. make gettext_po_to_mo
  164. } #&> $ROOT/build/Build.log # Capture all command output
  165. echo "done"
  166. echo "ls ROOT"
  167. ls $ROOT
  168. echo "ls ROOT/build"
  169. ls $ROOT/build
  170. echo "ls -al ROOT/build/src"
  171. ls -al $ROOT/build/src
  172. # Give proper permissions to script
  173. chmod 755 $ROOT/build/src/BuildMacOSImage.sh
  174. if [[ -n "$BUILD_IMAGE" ]]
  175. then
  176. $ROOT/build/src/BuildMacOSImage.sh -i
  177. else
  178. $ROOT/build/src/BuildMacOSImage.sh
  179. fi
  180. echo "ls -al ROOT/build"
  181. ls -al $ROOT/build