build_darwin_universal.sh 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh -ex
  2. abspath() {
  3. if [ -d "$1" ]; then
  4. (cd "$1"; pwd)
  5. elif [ -f "$1" ]; then
  6. if [ -z "${1##*/*}" ]; then
  7. echo "$(cd "${1%/*}"; pwd)/${1##*/}"
  8. else
  9. echo "$(pwd)/$1"
  10. fi
  11. elif [ -d "$(dirname "$1")" ]; then
  12. echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
  13. fi
  14. }
  15. REPO="$(abspath "$1")"
  16. BUILD="$(abspath "$2")"
  17. CPUS=${3:-$(nproc --all 2>/dev/null || sysctl -n hw.ncpu)}
  18. if [ ! -d "$REPO" ]; then
  19. echo "${$REPO} repository missing"
  20. exit 1
  21. fi
  22. export MACOSX_DEPLOYMENT_TARGET=10.13
  23. mkdir -p "$BUILD/build_libomp" && cd "$BUILD/build_libomp"
  24. wget -q http://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/openmp-11.0.0.src.tar.xz
  25. tar xvf openmp-11.0.0.src.tar.xz
  26. cd openmp-11.0.0.src
  27. wget https://raw.githubusercontent.com/Homebrew/formula-patches/7e2ee1d7/libomp/arm.patch
  28. patch -p1 < arm.patch
  29. mkdir -p "$BUILD/build_libomp/openmp-11.0.0.src/build-amd64" && cd "$BUILD/build_libomp/openmp-11.0.0.src/build-amd64"
  30. cmake -DLIBOMP_ENABLE_SHARED=OFF -DLIBOMP_INSTALL_ALIASES=OFF -DLIBOMP_ARCH=x86_64 -DCMAKE_CXX_FLAGS="-arch x86_64" ..
  31. make -j${CPUS}
  32. export LIBOMP_AMD64="$BUILD/build_libomp/openmp-11.0.0.src/build-amd64/runtime/src"
  33. mkdir -p "$BUILD/build_sse41" && cd "$BUILD/build_sse41"
  34. cmake -DCMAKE_INSTALL_PREFIX="${BUILD}/hhsuite" -DCMAKE_BUILD_TYPE=Release -DCHECK_MPI=0 -DHAVE_SSE4_1=1 -DCMAKE_C_FLAGS="-arch x86_64" -DCMAKE_CXX_FLAGS="-arch x86_64" -DBUILD_SHARED_LIBS=OFF -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp -I${LIBOMP_AMD64}" -DOpenMP_C_LIB_NAMES=omp -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I${LIBOMP_AMD64}" -DOpenMP_CXX_LIB_NAMES=omp -DOpenMP_omp_LIBRARY=${LIBOMP_AMD64}/libomp.a "$REPO"
  35. make -j${CPUS}
  36. make install
  37. mkdir -p "$BUILD/build_avx2" && cd "$BUILD/build_avx2"
  38. cmake -DCMAKE_BUILD_TYPE=Release -DCHECK_MPI=0 -DHAVE_AVX2=1 -DCMAKE_C_FLAGS="-arch x86_64h" -DCMAKE_CXX_FLAGS="-arch x86_64h" -DBUILD_SHARED_LIBS=OFF -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp -I${LIBOMP_AMD64}" -DOpenMP_C_LIB_NAMES=omp -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I${LIBOMP_AMD64}" -DOpenMP_CXX_LIB_NAMES=omp -DOpenMP_omp_LIBRARY=${LIBOMP_AMD64}/libomp.a "$REPO"
  39. make -j${CPUS}
  40. export MACOSX_DEPLOYMENT_TARGET=11.0
  41. mkdir -p "$BUILD/build_libomp/openmp-11.0.0.src/build-arm64" && cd "$BUILD/build_libomp/openmp-11.0.0.src/build-arm64"
  42. cmake -DLIBOMP_ENABLE_SHARED=OFF -DLIBOMP_INSTALL_ALIASES=OFF -DLIBOMP_ARCH=aarch64 -DCMAKE_CXX_FLAGS="-arch arm64" -DLIBOMP_ASMFLAGS="-arch arm64" ..
  43. make -j${CPUS}
  44. export LIBOMP_AARCH64="$BUILD/build_libomp/openmp-11.0.0.src/build-arm64/runtime/src"
  45. mkdir -p "$BUILD/build_arm64" && cd "$BUILD/build_arm64"
  46. cmake -DCMAKE_BUILD_TYPE=Release \
  47. -DCHECK_MPI=0 \
  48. -DHAVE_ARM8=1 \
  49. -DCMAKE_C_FLAGS="-arch arm64" \
  50. -DCMAKE_CXX_FLAGS="-arch arm64" \
  51. -DBUILD_SHARED_LIBS=OFF \
  52. -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \
  53. -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp -I${LIBOMP_AARCH64}" \
  54. -DOpenMP_C_LIB_NAMES=omp \
  55. -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I${LIBOMP_AARCH64}" \
  56. -DOpenMP_CXX_LIB_NAMES=omp \
  57. -DOpenMP_omp_LIBRARY=${LIBOMP_AARCH64}/libomp.a \
  58. "$REPO"
  59. make -j${CPUS}
  60. for BINARY in "${BUILD}/hhsuite/bin/"*; do
  61. BINARY_NAME="$(basename "${BINARY}")"
  62. case "${BINARY_NAME}" in
  63. *ffindex*)
  64. lipo -create \
  65. -arch x86_64 "$BUILD/build_sse41/lib/ffindex/src/${BINARY_NAME}" \
  66. -arch x86_64h "$BUILD/build_avx2/lib/ffindex/src/${BINARY_NAME}" \
  67. -arch arm64 "$BUILD/build_arm64/lib/ffindex/src/${BINARY_NAME}" \
  68. -output "$BUILD/hhsuite/bin/${BINARY_NAME}"
  69. ;;
  70. *)
  71. lipo -create \
  72. -arch x86_64 "$BUILD/build_sse41/src/${BINARY_NAME}" \
  73. -arch x86_64h "$BUILD/build_avx2/src/${BINARY_NAME}" \
  74. -arch arm64 "$BUILD/build_arm64/src/${BINARY_NAME}" \
  75. -output "$BUILD/hhsuite/bin/${BINARY_NAME}"
  76. ;;
  77. esac
  78. done