Skip to content

Instantly share code, notes, and snippets.

@nucleardreamer
Forked from reqshark/iosbuild.sh
Created December 21, 2015 21:10
Show Gist options
  • Save nucleardreamer/59bba758f0ac6c6f619a to your computer and use it in GitHub Desktop.
Save nucleardreamer/59bba758f0ac6c6f619a to your computer and use it in GitHub Desktop.
libmill iOS cross-compile for 32 bit (armv7) and 64 bit (arm64) iOS, and i386 and x86_64 simulators
# Copyright (c) 2015 Bent Cardan
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
# libmill cross-compiled for multi arch iOS configured for Xcode 7
# might work on Xcode 6 too, I havent tried..
# minimum deployment target is set to iOS 7.1, tested with iOS 9.2
# save this file as iosbuild.sh and $ chmod a+x iosbuild.sh so u can execute it
# it will download latest libmill, and remove these install src files afterward
# .
# ├── iosbuild.sh
# └── libmill-ios
# ├── include
# │   └── libmill.h
# └── lib
# └── libmill.a
# after cross-compiling, add the .h and .a files to ur Xcode project and go to:
#
# Build Settings -> Search Paths -> Library Search Paths
#
# add your full libmill-ios PATH/lib, a.k.a. PREFIX/lib to Library Search Paths
# On mac that will look something like /Users/reqshark/iosstuff/libmill-ios/lib
export PREFIX="$(pwd)/libmill-ios"
export IOS32_PREFIX="$PREFIX/tmp/ios32"
export IOS64_PREFIX="$PREFIX/tmp/ios64"
export SIMULATOR32_PREFIX="$PREFIX/tmp/simulator32"
export SIMULATOR64_PREFIX="$PREFIX/tmp/simulator64"
export IOS_SIMULATOR_VERSION_MIN=${IOS_SIMULATOR_VERSION_MIN-"7.1"}
export IOS_VERSION_MIN=${IOS_VERSION_MIN-"7.1"}
export XCODEDIR=$(xcode-select -p)
rm -rf libmill-ios libmill
git clone [email protected]:sustrik/libmill.git
cd libmill && ./autogen.sh
### i386 simulator
# Build
export BASEDIR="${XCODEDIR}/Platforms/iPhoneSimulator.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/iPhoneSimulator9.2.sdk"
export CFLAGS="-Oz -arch i386 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch i386 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
make distclean > /dev/null
./configure --disable-shared \
--prefix="$SIMULATOR32_PREFIX" || exit 1
make -j3 install || exit 1
### x86_64 simulator
export CFLAGS="-Oz -arch x86_64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
export LDFLAGS="-arch x86_64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN}"
make distclean > /dev/null
./configure --disable-shared \
--prefix="$SIMULATOR64_PREFIX"
make -j3 install || exit 1
# Build for iOS
# Build
export BASEDIR="${XCODEDIR}/Platforms/iPhoneOS.platform/Developer"
export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH"
export SDK="${BASEDIR}/SDKs/iPhoneOS.sdk"
### 32-bit iOS
export CFLAGS="-O2 -mthumb -arch armv7 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN} -fembed-bitcode"
export LDFLAGS="-mthumb -arch armv7 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN} -fembed-bitcode"
make distclean > /dev/null
./configure --host=arm-apple-darwin10 \
--disable-shared \
--prefix="$IOS32_PREFIX" || exit 1
make -j3 install || exit 1
## 64-bit iOS
#-fobjc-abi-version=2
export SDK="${BASEDIR}/SDKs/iPhoneOS9.2.sdk"
export CFLAGS="-O2 -arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN} -fembed-bitcode"
export LDFLAGS="-mthumb -arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN} -fembed-bitcode"
make distclean > /dev/null
./configure --host=arm-apple-darwin \
--disable-shared \
--prefix="$IOS64_PREFIX" || exit 1
make -j3 install || exit 1
# Create universal binary and include folder
rm -fr -- "$PREFIX/include" "$PREFIX/libmill.a" 2> /dev/null
mkdir -p -- "$PREFIX/lib"
lipo -create \
"$SIMULATOR32_PREFIX/lib/libmill.a" \
"$SIMULATOR64_PREFIX/lib/libmill.a" \
"$IOS32_PREFIX/lib/libmill.a" \
"$IOS64_PREFIX/lib/libmill.a" \
-output "$PREFIX/lib/libmill.a"
mv -f -- "$IOS32_PREFIX/include" "$PREFIX/"
echo
echo "libmill has been installed into $PREFIX"
echo
file -- "$PREFIX/lib/libmill.a"
# Cleanup
rm -rf -- "$PREFIX/tmp"
make distclean > /dev/null
cd .. && rm -rf libmill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment