diff --git a/build-llvm.sh b/build-llvm.sh index b5786fc..3f2bcd7 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -68,6 +68,9 @@ while [ $# -gt 0 ]; do --no-llvm-tool-reuse) NO_LLVM_TOOL_REUSE=1 ;; + --macos-native-tools) + MACOS_NATIVE_TOOLS=1 + ;; *) PREFIX="$1" ;; @@ -77,7 +80,7 @@ done BUILDDIR="$BUILDDIR$ASSERTSSUFFIX" if [ -z "$CHECKOUT_ONLY" ]; then if [ -z "$PREFIX" ]; then - echo $0 [--enable-asserts] [--with-clang] [--thinlto] [--lto] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] dest + echo $0 [--enable-asserts] [--with-clang] [--thinlto] [--lto] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] [--macos-native-tools] dest exit 1 fi @@ -331,6 +334,24 @@ fi [ -z "$CLEAN" ] || rm -rf $BUILDDIR mkdir -p $BUILDDIR cd $BUILDDIR + +if [ -n "$MACOS_NATIVE_TOOLS" ]; then + # Build tools needed for targeting macOS with LTO. + # + # The install-(-stripped) targets are unavailable for + # tools that are excluded due to LLVM_INSTALL_TOOLCHAIN_ONLY=ON and + # LLVM_TOOLCHAIN_TOOLS, so install those manually. + cmake --build . --target llvm-lipo --target llvm-libtool-darwin + # Install ld64.lld, required for -fuse-ld=lld + cmake --install . --strip --component lld + # Install llvm-libtool-darwin and lipo, needed for building with LTO. + # See the comment further above for more details about this. + cp bin/llvm-lipo bin/llvm-libtool-darwin $PREFIX/bin + strip $PREFIX/bin/llvm-lipo $PREFIX/bin/llvm-libtool-darwin + ln -sf llvm-lipo $PREFIX/bin/lipo + exit 0 +fi + [ -n "$NO_RECONF" ] || rm -rf CMake* cmake \ ${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \