# !/bin/bash
# Build external static library for iOS in Xcode5 environment
#
# This script was originally written by MiKL for GDAL.
# http://stackoverflow.com/questions/12643898/incorporating-gdal-ogr-into-an-ios-project-a-quick-guide
#
# And modified by igorti
# https://gist.github.com/igorti/6044531
#
# Finally, modified by teuder
# https://gist.github.com/teuder/7657480
# Disallow undefined variables
set -u
# default install directory
prefix=$HOME/Output
# minimal iOS version
iphoneos_version=7.0
unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
usage ()
{
cat >&2 << EOF
Usage: ${0##*/} [-h] [-p prefix] target [additional_configure_args]
-h Print help message
-p Installation prefix (default: \$HOME/Output)
target i386, armv7, armv7s
Any additional arguments are passed to configure.
EOF
}
while getopts "hp:" opt; do
case $opt in
h ) usage ; exit 0 ;;
p ) prefix="$OPTARG" ;;
\? ) usage ; exit 2 ;;
esac
done
shift $(( $OPTIND - 1 ))
if (( $# < 1 )); then
usage
exit 2
fi
target=$1
shift
case $target in
armv7 )
arch=armv7
platform=iPhoneOS
extra_cflags=""
;;
armv7s )
arch=armv7s
platform=iPhoneOS
extra_cflags=""
;;
i386 )
arch=i386
platform=iPhoneSimulator
extra_cflags=""
;;
* )
usage
exit 2
esac
# SDK directory
platform_dir=/Applications/Xcode.app/Contents/Developer/Platforms/${platform}.platform/Developer
platform_sdk_dir=${platform_dir}/SDKs/${platform}${iphoneos_version}.sdk
# System header and library
include_path=${platform_sdk_dir}/usr/include/**
library_path=${platform_sdk_dir}/usr/lib
# Other external library compiled by this script before
include_path2=${prefix}/include/**
library_path2=${prefix}/lib
# Set environmental variables for configure
export CC="/usr/bin/clang"
export CXX="/usr/bin/clang++"
export CPP="/usr/bin/clang -E"
export LD="/usr/bin/ld"
export AR="/usr/bin/ar"
export AS="/usr/bin/as"
export NM="/usr/bin/nm"
export RANLIB="/usr/bin/ranlib"
export C_INCLUDE_PATH="${include_path}:${include_path2}"
export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
export LIBRARY_PATH="${library_path}:${library_path2}"
export LD_LIBRARY_PATH=$LIBRARY_PATH
export CFLAGS="-arch ${arch} -pipe -Os -gdwarf-2 -miphoneos-version-min=${iphoneos_version} -isysroot ${platform_sdk_dir} ${extra_cflags} -I${include_path} -I${include_path2}"
export LDFLAGS="-L${library_path} -L${library_path2}"
export CXXFLAGS="${CFLAGS}"
export CXXCPP="${CPP}"
# export CPPFLAGS="-I${include_path} -I${include_path2}"
./configure \
"$@" \
--prefix="${prefix}" \
--host="${arch}-apple-darwin" \
--disable-shared \
--enable-static || exit 2\
make install || exit 2
cat >&2 << EOF
Build succeeded! Files were installed in
$prefix
EOF
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme