Updated compile-ios.sh script.
This commit is contained in:
1 parent
24564b2d34
commit
4c2e63a658
1 file changed
+85
-81
+85
-81
@@ -1,102 +1,106 @@
|
|||||||
#!/bin/bash
|
-#!/usr/bin/env bash
|
||||||
|
# Mac C. compile-ios.sh for JQ.
|
||||||
|
|
||||||
# old values
|
# Defaults
|
||||||
OLD_CFLAGS=$CFLAGS
|
set -e
|
||||||
OLD_LDFLAGS=$LDFLAGS
|
oniguruma='6.9.3'
|
||||||
ORIG_PWD=`pwd`
|
|
||||||
|
|
||||||
# For parallelism in make
|
unset CFLAGS
|
||||||
NJOBS="-j`sysctl -n hw.ncpu || echo 1`"
|
unset CXXFLAGS
|
||||||
|
unset LDFLAGS
|
||||||
|
|
||||||
|
# Parse args.
|
||||||
|
usage(){
|
||||||
|
cat << EOF
|
||||||
|
${0##*/}: usage
|
||||||
|
|
||||||
# Get oniguruma
|
Description:
|
||||||
rm -rf $PWD/build/ios oniguruma-5.9.6
|
This simple script builds oniguruma and jq for all *-apple-darwin devices.
|
||||||
echo "Downloading oniguruma 5.9.6"
|
|
||||||
curl -L https://github.com/kkos/oniguruma/archive/v5.9.6.tar.gz | tar xz
|
|
||||||
cd oniguruma-5.9.6
|
|
||||||
|
|
||||||
# So, we need to remake the configure scripts so that the arm64 architecture
|
Arguments:
|
||||||
# exists in config.sub. In order to keep autoreconf from failing, create
|
--extra-cflags <arg>: Pass defines or includes to clang.
|
||||||
# NEWS and ChangeLog.
|
--extra-ldflags <arg>: Pass libs or included to ld64.
|
||||||
touch NEWS ChangeLog
|
|
||||||
autoreconf -fi >/dev/null 2>&1
|
|
||||||
|
|
||||||
|
--with-oniguruma <arg>: Change default version of onigurma from ${oniguruma}.
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
while (( $# )); do
|
||||||
|
case "$1" in
|
||||||
|
--with-oniguruma) shift; oniguruma="${1}" ;;
|
||||||
|
|
||||||
|
--extra-cflags) shift; export CFLAGS_="${1}" ;;
|
||||||
|
--extra-ldflags) shift; export LDFLAGS_="${1}" ;;
|
||||||
|
|
||||||
CC=`xcrun -f clang`
|
--help) usage ;;
|
||||||
cd $ORIG_PWD
|
*) echo -e "Unknown option: ${1}\n"; usage ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
autoreconf -fi
|
# Start building.
|
||||||
for arch in i386 x86_64 armv7 armv7s arm64; do
|
echo "Building..."
|
||||||
|
MAKEJOBS="$(sysctl -n hw.ncpu || echo 1)"
|
||||||
|
CC_="$(xcrun -f clang || echo clang)"
|
||||||
|
|
||||||
# Some of the architectures are a bit different...
|
onig_url="https://github.com/kkos/oniguruma/releases/download/v${oniguruma}/onig-${oniguruma}.tar.gz"
|
||||||
if [[ "$arch" = "i386" || "$arch" = "x86_64" ]]
|
builddir="${TMPDIR:-/tmp}/${RANDOM:-'xxxxx'}-compile-ios-build"
|
||||||
then
|
cwd="$(realpath ${PWD})"
|
||||||
SYSROOT=`xcrun -f --sdk iphonesimulator --show-sdk-path`
|
|
||||||
else
|
|
||||||
SYSROOT=`xcrun -f --sdk iphoneos --show-sdk-path`
|
|
||||||
fi
|
|
||||||
if [[ "$arch" = "arm64" ]]
|
|
||||||
then
|
|
||||||
HOST="aarch64-apple-darwin"
|
|
||||||
else
|
|
||||||
HOST="$arch-apple-darwin"
|
|
||||||
fi
|
|
||||||
|
|
||||||
CFLAGS="-arch $arch -miphoneos-version-min=6.0 -isysroot $SYSROOT $OLD_CFLAGS"
|
t_exit() {
|
||||||
LDFLAGS="-arch $arch -miphoneos-version-min=6.0 -isysroot $SYSROOT $OLD_LDFLAGS"
|
cat << EOF
|
||||||
|
|
||||||
|
A error as occured.
|
||||||
|
oniguruma location: ${builddir}/onig
|
||||||
|
jq location: ${cwd}
|
||||||
|
|
||||||
|
Provide config.log and console logs when posting a issue.
|
||||||
|
|
||||||
# Build oniguruma for this architecture
|
EOF
|
||||||
cd oniguruma-5.9.6
|
}
|
||||||
CC=$CC CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS ./configure --disable-shared --enable-static --host=$HOST --prefix=$ORIG_PWD/build/ios/$arch
|
trap t_exit ERR
|
||||||
STATUS=$?
|
|
||||||
if [ $STATUS -ne 0 ]
|
|
||||||
then
|
|
||||||
echo "Failed to configure oniguruma for architecture $arch. Check `pwd`/config.log for details."
|
|
||||||
cd $PWD
|
|
||||||
exit $STATUS
|
|
||||||
fi
|
|
||||||
make clean
|
|
||||||
make $NJBOS install
|
|
||||||
STATUS=$?
|
|
||||||
if [ $STATUS -ne 0 ]
|
|
||||||
then
|
|
||||||
echo "Failed to make oniguruma for architecture $arch."
|
|
||||||
cd $PWD
|
|
||||||
exit $STATUS
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Onig.
|
||||||
|
mkdir -p "${builddir}/onig"
|
||||||
|
cd "${builddir}/"
|
||||||
|
curl -L ${onig_url} | tar xz
|
||||||
|
for arch in i386 x86_64 armv7 armv7s arm64; do
|
||||||
|
if [[ "$arch" = "i386" || "$arch" = "x86_64" ]]; then
|
||||||
|
SYSROOT=$(xcrun -f --sdk iphonesimulator --show-sdk-path)
|
||||||
|
else
|
||||||
|
SYSROOT=$(xcrun -f --sdk iphoneos --show-sdk-path)
|
||||||
|
fi
|
||||||
|
HOST="${arch}-apple-darwin"
|
||||||
|
[[ "${arch}" = "arm64" ]] && HOST="aarch64-apple-darwin"
|
||||||
|
|
||||||
|
CFLAGS="-arch ${arch} -miphoneos-version-min=9.0 -isysroot ${SYSROOT} ${CFLAGS_} -D_REENTRANT"
|
||||||
|
LDFLAGS="-arch ${arch} -miphoneos-version-min=9.0 -isysroot ${SYSROOT} ${LDFLAGS_}"
|
||||||
|
CC="${CC_} ${CFLAGS}"
|
||||||
|
|
||||||
# Build jq for this architecture
|
# ./configure; make install
|
||||||
cd $ORIG_PWD
|
cd "${builddir}/onig-${oniguruma}"
|
||||||
CC=$CC CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS ./configure --disable-shared --enable-static -host=$HOST --prefix=$ORIG_PWD/build/ios/$arch --with-oniguruma=$ORIG_PWD/build/ios/$arch
|
CC=${CC} LDFLAGS=${LDFLAGS} \
|
||||||
STATUS=$?
|
./configure --host=${HOST} --build=$(./config.guess) --enable-shared=no --enable-static=yes --prefix=/
|
||||||
if [ $STATUS -ne 0 ]
|
make -j${MAKEJOBS} install DESTDIR="${cwd}/ios/onig/${arch}"
|
||||||
then
|
make clean
|
||||||
echo "Failed to configure jq for architecture $arch"
|
|
||||||
exit $STATUS
|
# Jump back to JQ.
|
||||||
fi
|
cd ${cwd}
|
||||||
make clean
|
[[ ! -f ./configure ]] && autoreconf -ivf
|
||||||
make $NJOBS install
|
CC=${CC} LDFLAGS=${LDFLAGS} \
|
||||||
STATUS=$?
|
./configure --host=${HOST} --build=$(./config/config.guess) --enable-docs=no --enable-shared=no --enable-static=yes --prefix=/ --with-oniguruma=${cwd}/ios/onig/${arch} $(test -z ${BISON+x} && echo '--disable-maintainer-mode')
|
||||||
if [ $STATUS -ne 0 ]
|
make -j${MAKEJOBS} install DESTDIR="${cwd}/ios/jq/${arch}" # No jobs on purpose.
|
||||||
then
|
make clean
|
||||||
echo "Failed to make jq for architecture $arch"
|
done
|
||||||
exit $STATUS
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
mkdir -p "${cwd}/ios/dest/lib"
|
||||||
|
# lipo, make a static lib.
|
||||||
|
lipo -create -output ${cwd}/ios/dest/lib/libonig.a ${cwd}/ios/onig/{i386,x86_64,armv7,armv7s,arm64}/lib/libonig.a
|
||||||
|
lipo -create -output ${cwd}/ios/dest/lib/libjq.a ${cwd}/ios/jq/{i386,x86_64,armv7,armv7s,arm64}/lib/libjq.a
|
||||||
|
|
||||||
# lipo together the different architectures into a universal 'fat' file
|
# Take the arm64 headers- the most common target.
|
||||||
lipo -create -output $ORIG_PWD/build/ios/libonig.a $ORIG_PWD/build/ios/{i386,x86_64,armv7,armv7s,arm64}/lib/libonig.a
|
cp -r ${cwd}/ios/jq/arm64/include ${cwd}/ios/dest/
|
||||||
lipo -create -output $ORIG_PWD/build/ios/libjq.a $ORIG_PWD/build/ios/{i386,x86_64,armv7,armv7s,arm64}/lib/libjq.a
|
rm -rf ${cwd}/build/ios/{i386,x86_64,armv7,armv7s,arm64}
|
||||||
|
|
||||||
# copy the products into the destination directory and clean up the single-architecture files.
|
echo "Output to ${cwd}/ios/dest"
|
||||||
cp $ORIG_PWD/build/ios/i386/include/*.h $ORIG_PWD/build/ios/
|
|
||||||
rm -rf $ORIG_PWD/build/ios/{i386,x86_64,armv7,armv7s,arm64}
|
|
||||||
|
|
||||||
echo "Products are in $ORIG_PWD/build/ios"
|
|
||||||
Reference in new issue
Block a user