Skip to content

Instantly share code, notes, and snippets.

@sunnyyoung
Created March 24, 2023 05:04
Show Gist options
  • Save sunnyyoung/30ba8d6ef8902287e01856bcf5a31823 to your computer and use it in GitHub Desktop.
Save sunnyyoung/30ba8d6ef8902287e01856bcf5a31823 to your computer and use it in GitHub Desktop.
A macOS/iOS universal iperf3 binary building script.
#!/bin/sh
export SRC="$(pwd)/iperf"
export DST="$(pwd)/iperf.builds"
export XCODE_DIR="$(xcode-select -p)"
echo "Checking out iperf..."
git clone https://github.com/esnet/iperf.git --depth 1 --branch 3.13
echo "Building for macOS..."
for ARCH in x86_64 arm64; do
PREFIX="$DST/tmp/macosx-$ARCH"
mkdir -p "$PREFIX" && cd "$PREFIX"
if [[ ${ARCH} == "arm64" ]]; then
HOST="arm"
else
HOST="$ARCH"
fi
export CFLAGS="-O2 -arch $ARCH"
export LDFLAGS="-arch $ARCH"
$SRC/configure --srcdir=$SRC --host=$HOST-apple-darwin --prefix=$PREFIX --disable-shared || exit 1
cd ${PREFIX} && make install || exit 1
done
echo "Building for iOS..."
for ARCH in armv7 armv7s arm64; do
PREFIX="$DST/tmp/iphoneos-$ARCH"
mkdir -p "$PREFIX" && cd "$PREFIX"
export DEVELOPER="$XCODE_DIR/Platforms/iPhoneOS.platform/Developer"
export SDK="$DEVELOPER/SDKs/iPhoneOS.sdk"
export CFLAGS="-O2 -arch $ARCH -isysroot $SDK"
export LDFLAGS="-arch $ARCH -isysroot $SDK"
$SRC/configure --srcdir=$SRC --host=arm-apple-darwin --prefix=$PREFIX --disable-shared || exit 1
sed -i '' "s/#define HAVE_ENDIAN_H 1/#undef HAVE_ENDIAN_H/g" "src/iperf_config.h"
cd $PREFIX && make install || exit 1
done
echo "Creating universal binaries..."
for PLATFORM in macosx iphoneos; do
lipo -create $(find $DST/tmp/$PLATFORM-*/bin -name iperf3) -output "$DST/iperf3-$PLATFORM"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment