Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F149185920
D51087.1789644624.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D51087.1789644624.diff
View Options
Index: tools/build/cross-build-macos.sh
===================================================================
--- /dev/null
+++ tools/build/cross-build-macos.sh
@@ -0,0 +1,118 @@
+#!/bin/sh
+# Copyright (c) Mar 2025 Wolfram Schneider <wosch@FreeBSD.org>
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# cross-build-macos.sh - build FreeBSD/arm64 from source on MacOS
+# for MacOS 14.x and later
+#
+# Note: you need to install a new compiler and linker
+# with Homebrew first: brew install llvm lld
+#
+# Homebrew will install the Command Line Tools for Xcode as well.
+# If not, you can install them with: xcode-select --install
+#
+# get the FreeBSD source:
+# git clone https://codeberg.org/freebsd/freebsd-src
+# cd freebsd-src && ./tools/build/cross-build-macos.sh
+#
+
+
+set -e
+
+HOMEBREW_PATH="/opt/homebrew/opt/llvm/bin:/opt/homebrew/bin"
+PATH="$HOMEBREW_PATH:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin"; export PATH
+clt_sdk_dir="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
+
+: ${TMPDIR="/tmp"}
+: ${MAKEOBJDIRPREFIX="$TMPDIR/freebsd-obj"}; export MAKEOBJDIRPREFIX
+: ${nice_cmd="nice -n10 time"}
+
+: ${TARGET="arm64"}
+: ${TARGET_ARCH="aarch64"}
+
+if [ ! -e Makefile.inc1 ]; then
+ echo "Makefile.inc1 missing, please run inside a fresh FreeBSD source checkout as /usr/src"
+ exit 1
+fi
+
+mkdir -p $MAKEOBJDIRPREFIX
+ncpu=$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 1)
+
+if ! env PATH=$HOMEBREW_PATH /usr/bin/which clang clang++ clang-cpp ld.lld python3 >/dev/null; then
+ echo "missing programs: clang, lld, or phython3"
+ exit 1
+fi
+
+export CPP="clang-cpp"
+export CC="clang"
+export CXX="clang++"
+export XCPP="clang-cpp"
+export XCC="clang"
+export XCXX="clang++"
+export XLD="/opt/homebrew/bin/ld.lld"
+
+# keep logs from previous run
+gzip -f macos.setup macos.buildworld macos.buildkernel 2>/dev/null || true
+
+# log infos about MacOS setup
+(
+sysctl machdep.cpu.brand_string
+sysctl kern.osproductversion
+echo "$(sysctl hw.physicalcpu) / P-cores: $(sysctl hw.perflevel0.physicalcpu) / E-cores: $(sysctl hw.perflevel1.physicalcpu)"
+sysctl hw.memsize | awk '{ printf("%s %2.1f GB\n", $1, $2/1024/1024/1024) }'
+
+echo "Xcode path: $(xcode-select -p)"
+echo "Xcode version: $(pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep '^version: ')"
+
+if [ -d $clt_sdk_dir ]; then
+ echo "SDK version: $(ls -l $clt_sdk_dir)"
+fi
+
+if [ -d .git ]; then
+ echo "local git branch: $(git branch | grep '^\*')"
+fi
+
+echo ""
+echo PATH=$PATH
+
+echo "clang path: $(which clang)"
+clang --version
+
+echo "linker path: $(which ld.lld)"
+ld.lld -v 2>&1
+
+echo ""
+echo "TARGET=$TARGET TARGET_ARCH=$TARGET_ARCH"
+echo "CC=$CC CXX=$CXX CPP=$CPP"
+echo "XCC=$XCC CXX=$XCXX CPP=$XCPP XLD=$XLD"
+
+echo ""
+echo "current MAKEOBJDIRPREFIX disk usage: $(du -hs $MAKEOBJDIRPREFIX)"
+echo ""
+echo "run now buildworld and buildkernel for ${TARGET}/${TARGET_ARCH} ..."
+echo ""
+) > macos.setup
+
+#
+# build FreeBSD world and kernel
+#
+# expected runtime for
+# MacBook Air (M1, 2020, 4P/4E cores) ca. 70min
+# MacBook Pro (M1, 2021, 8P/2E cores) ca. 37min
+#
+if $nice_cmd ./tools/build/make.py -j$ncpu TARGET=$TARGET TARGET_ARCH=$TARGET_ARCH buildworld > macos.buildworld 2>&1 && \
+ $nice_cmd ./tools/build/make.py -j$ncpu TARGET=$TARGET TARGET_ARCH=$TARGET_ARCH buildkernel > macos.buildkernel 2>&1
+then
+ (
+ echo "MAKEOBJDIRPREFIX disk usage:"
+ du -hs $MAKEOBJDIRPREFIX ${MAKEOBJDIRPREFIX}${PWD}
+ echo ""
+ echo ">>> Build of buildworld and buildkernel were successfully executed <<<"
+ ) >> macos.setup
+else
+ echo "Build failed. Please look at the logfiles"
+ ls -lt macos.*
+ exit 1
+fi
+
+#EOF
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Sep 17, 11:30 AM (18 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29728032
Default Alt Text
D51087.1789644624.diff (3 KB)
Attached To
Mode
D51087: cross-build-macos.sh - build FreeBSD/arm64 from source on MacOS for MacOS 14.x and later
Attached
Detach File
Event Timeline
Log In to Comment