BuildMacOS.sh 5.2 KB

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