Created
July 3, 2023 06:29
-
-
Save sunnyyoung/9a827f0e29b5f54cef01ef0bce475d12 to your computer and use it in GitHub Desktop.
A macOS/iOS universal fping binary building script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# shellcheck disable=SC2044,SC2046,SC2086,SC3009 | |
SRC=$(pwd)/fping-5.1 | |
DST=$(pwd)/fping.builds | |
XCODE_DIR=$(xcode-select -p) | |
echo "Downloading fping..." | |
curl -s -L https://github.com/schweikert/fping/releases/download/v5.1/fping-5.1.tar.gz | tar xz | |
echo "Building for macOS..." | |
for ARCH in x86_64 arm64; do | |
PREFIX="$DST/tmp/macosx-$ARCH" | |
mkdir -p "$PREFIX" && cd "$PREFIX" || exit 1 | |
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 || 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" || exit 1 | |
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 || exit 1 | |
cd $PREFIX && make install || exit 1 | |
done | |
echo "Creating universal binaries..." | |
for PLATFORM in macosx iphoneos; do | |
lipo -create $(find $DST/tmp/$PLATFORM-*/sbin -name fping) -output "$DST/fping-$PLATFORM" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment