Last active
November 8, 2018 13:58
-
-
Save niltsh/4067c983dcc91fe65d5f662370bef716 to your computer and use it in GitHub Desktop.
Scripts for building Gdal into a static library for iOS, build-gdal-combined-lib.sh will build a single lib with armv7 armv7s arm64 and simulator slices
This file contains 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/bash | |
PREFIX=`pwd`/install/ | |
rm -rf $PREFIX | |
mkdir $PREFIX | |
LOG=./log | |
rm -rf $LOG | |
mkdir $LOG | |
if [ -e ${PREFIX} ] | |
then | |
echo removing ${PREFIX} | |
rm -rf ${PREFIX} | |
fi | |
mkdir ${PREFIX} | |
for f in "armv7" "armv7s" "arm64"; do | |
echo Building $f | |
./build_gdal_ios.sh -p ${PREFIX} -a $f device 2>&1 | tee "${LOG}/${f}.txt" | |
done | |
echo Building simulator | |
for f in "i386" "x86_64"; do | |
echo Building $f | |
./build_gdal_ios.sh -p ${PREFIX} -a $f simulator 2>&1 | tee "${LOG}/simulator.txt" | |
done | |
SDK_VERSION=8.3 | |
lipo \ | |
${PREFIX}/i386/iphonesimulator${SDK_VERSION}.sdk/lib/libgdal.a \ | |
${PREFIX}/x86_64/iphonesimulator${SDK_VERSION}.sdk/lib/libgdal.a \ | |
${PREFIX}/armv7/iphoneos${SDK_VERSION}.sdk/lib/libgdal.a \ | |
${PREFIX}/armv7s/iphoneos${SDK_VERSION}.sdk/lib/libgdal.a \ | |
${PREFIX}/arm64/iphoneos${SDK_VERSION}.sdk/lib/libgdal.a \ | |
-output ${PREFIX}/libgdal.a \ | |
-create | tee $LOG/lipo.txt | |
lipo \ | |
${PREFIX}/i386/iphonesimulator${SDK_VERSION}.sdk/lib/libproj.a \ | |
${PREFIX}/x86_64/iphonesimulator${SDK_VERSION}.sdk/lib/libproj.a \ | |
${PREFIX}/armv7/iphoneos${SDK_VERSION}.sdk/lib/libproj.a \ | |
${PREFIX}/armv7s/iphoneos${SDK_VERSION}.sdk/lib/libproj.a \ | |
${PREFIX}/arm64/iphoneos${SDK_VERSION}.sdk/lib/libproj.a \ | |
-output ${PREFIX}/libproj.a \ | |
-create | tee $LOG/lipo-proj.txt | |
#create zipfile for cocoapods distribution | |
cd ${PREFIX} | |
mkdir GDAL | |
cp libgdal.a ${PREFIX}/libproj.a GDAL | |
cp arm64/iphoneos8.3.sdk/include/*.h GDAL | |
zip gdal.zip GDAL/* |
This file contains 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/bash | |
set -u | |
default_iphoneos_version=8.3 | |
default_architecture=armv7 | |
export IPHONEOS_DEPLOYMENT_TARGET="${IPHONEOS_DEPLOYMENT_TARGET:-$default_iphoneos_version}" | |
DEFAULT_ARCHITECTURE="${DEFAULT_ARCHITECTURE:-$default_architecture}" | |
DEFAULT_PREFIX="${HOME}/Desktop/iOS_GDAL" | |
usage () | |
{ | |
cat >&2 << EOF | |
Usage: ${0} [-h] [-p prefix] [-a arch] target [configure_args] | |
-h Print help message | |
-p Installation prefix (default: \$HOME/Documents/iOS_GDAL...) | |
-a Architecture target for compilation (default: armv7) | |
The target must be "device" or "simulator". Any additional arguments | |
are passed to configure. | |
The following environment variables affect the build process: | |
IPHONEOS_DEPLOYMENT_TARGET (default: $default_iphoneos_version) | |
DEFAULT_PREFIX (default: $default_prefix) | |
EOF | |
} | |
prefix="${DEFAULT_PREFIX}" | |
while getopts ":hp:a:" opt; do | |
case $opt in | |
h ) usage ; exit 0 ;; | |
p ) prefix="$OPTARG" ;; | |
a ) DEFAULT_ARCHITECTURE="$OPTARG" ;; | |
\? ) usage ; exit 2 ;; | |
esac | |
done | |
shift $(( $OPTIND - 1 )) | |
if (( $# < 1 )); then | |
usage | |
exit 2 | |
fi | |
target=$1 | |
shift | |
case $target in | |
device ) | |
arch="${DEFAULT_ARCHITECTURE}" | |
platform=iphoneos | |
extra_cflags=" " | |
;; | |
simulator ) | |
arch="${DEFAULT_ARCHITECTURE}" | |
platform=iphonesimulator | |
extra_cflags="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000" | |
;; | |
* ) | |
echo No target found!!! | |
usage | |
exit 2 | |
esac | |
if [ $arch = "arm64" ] | |
then | |
host="arm-apple-darwin" | |
else | |
host="${arch}-apple-darwin" | |
fi | |
echo "building for host ${host}" | |
platform_dir=`xcrun -find -sdk ${platform} --show-sdk-platform-path` | |
platform_sdk_dir=`xcrun -find -sdk ${platform} --show-sdk-path` | |
prefix="${prefix}/${arch}/${platform}${IPHONEOS_DEPLOYMENT_TARGET}.sdk" | |
echo | |
echo library will be exported to $prefix | |
#setup compiler flags | |
export CC=`xcrun -find -sdk iphoneos gcc` | |
export CFLAGS="-Wno-error=implicit-function-declaration -arch ${arch} -pipe -Os -gdwarf-2 -isysroot ${platform_sdk_dir} ${extra_cflags}" | |
export LDFLAGS="-arch ${arch} -isysroot ${platform_sdk_dir}" | |
export CXX=`xcrun -find -sdk iphoneos g++` | |
export CXXFLAGS="${CFLAGS}" | |
export CPP=`xcrun -find -sdk iphoneos cpp` | |
export CXXCPP="${CPP}" | |
echo CFLAGS ${CFLAGS} | |
#set proj4 install destination | |
proj_prefix=$prefix | |
echo install proj to $proj_prefix | |
#download proj4 if necesary | |
if [ ! -e proj-4.8.0 ] | |
then | |
echo proj4 missing, downloading | |
curl -L http://download.osgeo.org/proj/proj-4.8.0.tar.gz > proj-4.8.0.tar.gz | |
tar -xzf proj-4.8.0.tar.gz | |
fi | |
#configure and build proj4 | |
pushd proj-4.8.0 | |
echo | |
echo "cleaning proj" | |
make clean | |
echo | |
echo "configure proj" | |
./configure \ | |
--prefix=${proj_prefix} \ | |
--enable-shared=no \ | |
--enable-static=yes \ | |
--host=$host \ | |
"$@" || exit | |
echo | |
echo "make install proj" | |
time make install || exit | |
popd | |
#download gdal if necesary | |
if [ ! -e gdal-1.11.2 ] | |
then | |
curl -L http://download.osgeo.org/gdal/1.11.2/gdal-1.11.2.tar.gz > gdal-1.11.2.tar.gz | |
tar -xzf gdal-1.11.2.tar.gz | |
fi | |
#configure and build gdal | |
cd gdal-1.11.2 | |
echo "cleaning gdal" | |
make clean | |
echo | |
echo "configure gdal" | |
./configure \ | |
--prefix="${prefix}" \ | |
--host=$host \ | |
--disable-shared \ | |
--enable-static \ | |
--with-hide-internal-symbols \ | |
--with-unix-stdio-64=no \ | |
--with-geos=no \ | |
--without-pg \ | |
--without-grass \ | |
--without-libgrass \ | |
--without-cfitsio \ | |
--without-pcraster \ | |
--without-netcdf \ | |
--without-ogdi \ | |
--without-fme \ | |
--without-hdf4 \ | |
--without-hdf5 \ | |
--without-jasper \ | |
--without-kakadu \ | |
--without-grib \ | |
--without-mysql \ | |
--without-ingres \ | |
--without-xerces \ | |
--without-odbc \ | |
--without-curl \ | |
--without-idb \ | |
--without-sde \ | |
--with-sse=no \ | |
--with-avx=no \ | |
--with-static-proj4=${prefix} \ | |
--with-sqlite3=${platform_sdk_dir} \ | |
|| exit | |
#echo '#include "cpl_config_extras.h"' >> port/cpl_config.h | |
echo | |
echo "building gdal" | |
time make -j8 | |
echo | |
echo "installing" | |
time make install | |
echo "Gdal build complete" |
Author
niltsh
commented
Jul 26, 2017
- use curl rather than wget, since Mac does not have wget anymore.
- correct download URL of goal, original one is wrong
- use make -j8
Thank you for share the scripts. I am trying to build libgdal.a from gdal 2.1.1 but it is not working. Do you know why?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment