While building a wxWidgets app for iOS, I wanted to build wxWidgets as a library, not include it as part of the application as the minimal iOS example does. The following script (based on ios-autotools) sets up the required environment and then calls the supplied configure script.
- The main changes are:
- the configure script is passed as a parameter so that it does not need to be in the same directory as the iconfigure script which keeps the source folder unchanged
- if an SDK version is passed in and the SDK for that version of the SDK does not exist then the default SDK is used with the ios-min-version set to the specified version.
#!/bin/sh
set -e
usage () {
echo "Usage: [VARIABLE...] $(basename $0) architecture path"
echo ""
echo " architecture Target architecture. [armv7|armv7s|arm64|i386|x86_64]"
echo " path path to configure script to run"
echo ""
echo " VARIABLEs are:"
echo " SDKVERSION Target a specific SDK version."
echo " PREFIX Custom install prefix, useful for local installs."
echo " CHOST Configure host, set if not deducable by ARCH."
echo " SDK SDK target, set if not deducable by ARCH. [iphoneos|iphonesimulator]"
echo ""
echo " CFLAGS CPPFLAGS CXXFLAGS LDFLAGS PKG_CONFIG_PATH"
echo ""
echo " All additional parameters are passed to the configure script."
exit 1
}
# Sanity checks
if [ "$#" -lt 2 ]; then
echo "Please supply an architecture name and configure file"
usage
fi
# Build architecture
export ARCH=$1
# Configure script
CONFIG=$2
# Export supplied CHOST or deduce by ARCH
if [ ! -z "$CHOST" ]; then
export CHOST
else
case $ARCH in
armv7 | armv7s )
export CHOST=arm-apple-darwin
;;
arm64 )
export CHOST=aarch64-apple-darwin
;;
i386 | x86_64 )
export CHOST=$ARCH-apple-darwin
;;
* )
usage
;;
esac
fi
# Export supplied SDK or deduce by ARCH
if [ ! -z "$SDK" ]; then
export SDK
echo Using supplied SDK of "$SDK"
else
case $ARCH in
armv7 | armv7s | arm64 )
export SDK=iphoneos
;;
i386 | x86_64 )
export SDK=iphonesimulator
;;
* )
usage
;;
esac
fi
# Export supplied SDKVERSION or use system default
if [ ! -z "$SDKVERSION" ]; then
SDKNAME=$(basename $(xcrun --sdk $SDK --show-sdk-platform-path) .platform)
export SDKVERSION
export SDKROOT=$(xcrun --sdk $SDK --show-sdk-platform-path)"/Developer/SDKs/$SDKNAME.$SDKVERSION.sdk"
# If the SDK for the supplied version doesn't exist, use the current one
if [ ! -d "$SDKROOT" ]; then
export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version
fi
else
export SDKVERSION=$(xcrun --sdk $SDK --show-sdk-version) # current version
export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version
fi
# Export supplied SDKVERSION or use system default
if [ ! -z "$SDKVERSION" ]; then
SDKNAME=$(basename $(xcrun --sdk $SDK --show-sdk-platform-path) .platform)
export SDKVERSION
export SDKROOT=$(xcrun --sdk $SDK --show-sdk-platform-path)"/Developer/SDKs/$SDKNAME.$SDKVERSION.sdk"
# If the SDK for the supplied version doesn't exist, use the current one
if [ ! -d "$SDKROOT" ]; then
export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version
fi
else
export SDKVERSION=$(xcrun --sdk $SDK --show-sdk-version) # current version
export SDKROOT=$(xcrun --sdk $SDK --show-sdk-path) # current version
fi
# Export supplied PREFIX or use default
if [ ! -z "$PREFIX" ]; then
export PREFIX
else
export PREFIX="/opt/$SDK-$SDKVERSION/$ARCH"
fi
# Binaries
export CC=$(xcrun --sdk $SDK --find gcc)
export CPP=$(xcrun --sdk $SDK --find gcc)" -E"
export CXX=$(xcrun --sdk $SDK --find g++)
export LD=$(xcrun --sdk $SDK --find ld)
# Flags
export CFLAGS="$CFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -mios-version-min=$SDKVERSION"
export CPPFLAGS="$CPPFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include -mios-version-min=$SDKVERSION"
export CXXFLAGS="$CXXFLAGS -arch $ARCH -isysroot $SDKROOT -I$PREFIX/include"
export LDFLAGS="$LDFLAGS -arch $ARCH -isysroot $SDKROOT -L$PREFIX/lib"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH":"$SDKROOT/usr/lib/pkgconfig":"$PREFIX/lib/pkgconfig"
echo CFLAGS="$CFLAGS"
# Remove script parameters
shift 2
# Run configure
$CONFIG \
--prefix="$PREFIX" \
--host="$CHOST" \
$@
No comments:
Post a Comment