Skip to content

Instantly share code, notes, and snippets.

@trojanfoe
Created September 4, 2014 20:24
Show Gist options
  • Save trojanfoe/ad899f28f75b4c25892e to your computer and use it in GitHub Desktop.
Save trojanfoe/ad899f28f75b4c25892e to your computer and use it in GitHub Desktop.
Script to build libpng for iOS
#!/bin/sh
dobuild=1
docopy=1
doclean=1
version=1.6.9
srcdir=libpng-${version}
srcfile=${srcdir}.tar.gz
srctarball=http://sourceforge.net/projects/libpng/files/libpng16/${version}/${srcfile}/download
outdir=$(cd ../external-deps/png; pwd)
iosmin=6.0
osxmin=10.7
build() {
sdk=$1
arch=$2
case $sdk in
macosx)
minflags="-mosx-version-min=$osxmin"
;;
iphoneos)
minflags="-mios-version-min=$iosmin"
;;
iphonesimulator)
minflags="-mios-simulator-version-min=$iosmin"
;;
*)
echo $0: Invalid sdk $sdk
exit 10
esac
echo Building $sdk $arch
cpu=$(uname -m)
release=$(uname -r)
host=${cpu}-apple-darwin${release}
archout=$(pwd)/arch-${sdk}-${arch}
rm -rf $archout
(cd $srcdir; make distclean)
(cd $srcdir; CPP="xcrun --sdk $sdk clang -E -arch $arch $minflags" CC="xcrun --sdk $sdk clang" CFLAGS="-arch $arch $minflags" LD="xcrun --sdk $sdk clang" LDFLAGS="-arch $arch $minflags" ./configure --host $host --prefix=$archout --disable-shared --enable-arm-neon=off) || exit 4
(cd $srcdir; make install) || exit 5
}
makefat() {
inputdirs="$1"
inputlib=$2
outputlib=$3
mkdir -p $(dirname $outputlib) || exit 11
rm -f $outputlib
lipocmd="xcrun lipo -create -output $outputlib"
for dir in $inputdirs
do
infile=$dir/$inputlib
if [ ! -f $infile ]; then
echo $0: $infile does not exist
exit 12
fi
inarch=$(xcrun lipo -info $infile | tail -1 | awk '{print $NF }')
lipocmd="$lipocmd -arch $inarch $infile"
done
echo $0: Running $lipocmd
$lipocmd || exit 14
}
if [ ! -d $outdir ]; then
echo $0: $outdir does not exist
exit 1
fi
if [ ! -f $srcfile ]; then
curl $srctarball -o $srcfile || exit 1
fi
if [ ! -d $srcdir ]; then
tar xfv $srcfile || exit 3
if [ ! -d $srcdir ]; then
echo $0: Failed to extract to $srcdir
exit 4
fi
fi
if [ $dobuild -gt 0 ]; then
build macosx i386
build macosx x86_64
build iphoneos armv7
build iphoneos armv7s
build iphoneos arm64
build iphonesimulator i386
fi
if [ $docopy -gt 0 ]; then
makefat "arch-macosx-i386 arch-macosx-x86_64" lib/libpng16.a $outdir/lib/macosx/libpng.a
makefat "arch-iphoneos-arm64 arch-iphoneos-armv7 arch-iphoneos-armv7s arch-iphonesimulator-i386" lib/libpng16.a $outdir/lib/ios/libpng.a
for h in png.h pngconf.h pnglibconf.h
do
cp $srcdir/$h $outdir/include || exit 5
done
fi
if [ $doclean -gt 0 ]; then
rm -rf arch-* $srcdir
fi
echo $0: Done. Please check that $outdir/lib/ios does not contain arch-specific directories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment