Skip to content

Instantly share code, notes, and snippets.

@blakek
Created November 21, 2013 16:05
Show Gist options
  • Save blakek/7584421 to your computer and use it in GitHub Desktop.
Save blakek/7584421 to your computer and use it in GitHub Desktop.
Meant to help me make open source libraries with for iPhone. Only works with systems that use the "./configure && make && make install" approach.
#!/bin/sh
# Runs `./configure && make && make install' with variables set to help build libraries for iOS devices more easily.
# Hopefully, this will work as-is, but some notes...
# TODO: At least attempt to find correct directories without just failing with weird error messages
# > $DEVROOT _will_ have to change according to Xcode installation directory.
# > $CC or $CXX will probably change whenever a new compiler version is installed
# > $IOS_BASE_SDK or $IOS_DEPLOY_TGT may be changed to fit developer's needs as well as future Xcode layout changes (e.g. dropping support for older iOS versions)
# > Currently, a library for the simulator isn't being made (but should be _really_ easy to add with the existing script)
IOS_BASE_SDK="5.0"
IOS_DEPLOY_TGT="4.2"
setenv_all()
{
# Add internal libs
export CFLAGS="$CFLAGS -I$GLOBAL_OUTDIR/include -L$GLOBAL_OUTDIR/lib"
export CXX="$DEVROOT/usr/bin/llvm-g++-4.2"
export CC="$DEVROOT/usr/bin/llvm-gcc-4.2"
export LD=$DEVROOT/usr/bin/ld
export AR=$DEVROOT/usr/bin/ar
export AS=$DEVROOT/usr/bin/as
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib
export LDFLAGS="-L$SDKROOT/usr/lib/"
export CPPFLAGS=$CFLAGS
export CXXFLAGS=$CFLAGS
}
setenv_arm6()
{
unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
export CFLAGS="-arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"
setenv_all
}
setenv_arm7()
{
unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
export CFLAGS="-arch armv7 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"
setenv_all
}
setenv_i386()
{
unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator$IOS_BASE_SDK.sdk
export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT"
setenv_all
}
#Starts here!
make distclean
set -e
# Make for ARM v6
setenv_arm6
./configure --host=armv6-apple-darwin --prefix=`pwd`/armv6 --enable-shared=no --enable-static=yes && make -j4 && make install
# Make for ARM v7
make distclean
setenv_arm7
./configure --host=armv7-apple-darwin --prefix=`pwd`/armv7 --enable-shared=no --enable-static=yes && make -j4 && make install
# Combine and make everything needed accessible from one location
mkdir lib
LIB_NAME=`ls armv6/lib/ | grep -m1 '\.a$'`
lipo -arch armv6 armv6/lib/${LIB_NAME} -arch armv7 armv7/lib/${LIB_NAME} -output lib/${LIB_NAME} -create
ln -s armv7/include .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment