From 4c2e63a658ba1dfa483223a009e6e2eba3ac6f34 Mon Sep 17 00:00:00 2001 From: MCApollo <34170230+MCApollo@users.noreply.github.com> Date: Fri, 8 Nov 2019 18:18:09 -0800 Subject: Updated compile-ios.sh script. --- compile-ios.sh | 208 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 106 insertions(+), 102 deletions(-) diff --git a/compile-ios.sh b/compile-ios.sh index 1daa40d3..4b47f6dd 100755 --- a/compile-ios.sh +++ b/compile-ios.sh @@ -1,102 +1,106 @@ -#!/bin/bash - -# old values -OLD_CFLAGS=$CFLAGS -OLD_LDFLAGS=$LDFLAGS -ORIG_PWD=`pwd` - -# For parallelism in make -NJOBS="-j`sysctl -n hw.ncpu || echo 1`" - - -# Get oniguruma -rm -rf $PWD/build/ios oniguruma-5.9.6 -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 -# exists in config.sub. In order to keep autoreconf from failing, create -# NEWS and ChangeLog. -touch NEWS ChangeLog -autoreconf -fi >/dev/null 2>&1 - - - - -CC=`xcrun -f clang` -cd $ORIG_PWD - -autoreconf -fi -for arch in i386 x86_64 armv7 armv7s arm64; do - - # Some of the architectures are a bit different... - 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 - 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" - LDFLAGS="-arch $arch -miphoneos-version-min=6.0 -isysroot $SYSROOT $OLD_LDFLAGS" - - - - # Build oniguruma for this architecture - cd oniguruma-5.9.6 - CC=$CC CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS ./configure --disable-shared --enable-static --host=$HOST --prefix=$ORIG_PWD/build/ios/$arch - 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 - - - - # Build jq for this architecture - cd $ORIG_PWD - 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 - STATUS=$? - if [ $STATUS -ne 0 ] - then - echo "Failed to configure jq for architecture $arch" - exit $STATUS - fi - make clean - make $NJOBS install - STATUS=$? - if [ $STATUS -ne 0 ] - then - echo "Failed to make jq for architecture $arch" - exit $STATUS - fi -done - - -# lipo together the different architectures into a universal 'fat' file -lipo -create -output $ORIG_PWD/build/ios/libonig.a $ORIG_PWD/build/ios/{i386,x86_64,armv7,armv7s,arm64}/lib/libonig.a -lipo -create -output $ORIG_PWD/build/ios/libjq.a $ORIG_PWD/build/ios/{i386,x86_64,armv7,armv7s,arm64}/lib/libjq.a - -# copy the products into the destination directory and clean up the single-architecture files. -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" +-#!/usr/bin/env bash +# Mac C. compile-ios.sh for JQ. + +# Defaults +set -e +oniguruma='6.9.3' + +unset CFLAGS +unset CXXFLAGS +unset LDFLAGS + +# Parse args. +usage(){ +cat << EOF +${0##*/}: usage + + Description: + This simple script builds oniguruma and jq for all *-apple-darwin devices. + + Arguments: + --extra-cflags : Pass defines or includes to clang. + --extra-ldflags : Pass libs or included to ld64. + + --with-oniguruma : 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}" ;; + + --help) usage ;; + *) echo -e "Unknown option: ${1}\n"; usage ;; + esac + shift +done + +# Start building. +echo "Building..." +MAKEJOBS="$(sysctl -n hw.ncpu || echo 1)" +CC_="$(xcrun -f clang || echo clang)" + +onig_url="https://github.com/kkos/oniguruma/releases/download/v${oniguruma}/onig-${oniguruma}.tar.gz" +builddir="${TMPDIR:-/tmp}/${RANDOM:-'xxxxx'}-compile-ios-build" +cwd="$(realpath ${PWD})" + +t_exit() { +cat << EOF + +A error as occured. + oniguruma location: ${builddir}/onig + jq location: ${cwd} + + Provide config.log and console logs when posting a issue. + +EOF +} +trap t_exit ERR + +# 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}" + + # ./configure; make install + cd "${builddir}/onig-${oniguruma}" + CC=${CC} LDFLAGS=${LDFLAGS} \ + ./configure --host=${HOST} --build=$(./config.guess) --enable-shared=no --enable-static=yes --prefix=/ + make -j${MAKEJOBS} install DESTDIR="${cwd}/ios/onig/${arch}" + make clean + + # Jump back to JQ. + cd ${cwd} + [[ ! -f ./configure ]] && autoreconf -ivf + CC=${CC} LDFLAGS=${LDFLAGS} \ + ./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') + make -j${MAKEJOBS} install DESTDIR="${cwd}/ios/jq/${arch}" # No jobs on purpose. + make clean + 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 + +# Take the arm64 headers- the most common target. +cp -r ${cwd}/ios/jq/arm64/include ${cwd}/ios/dest/ +rm -rf ${cwd}/build/ios/{i386,x86_64,armv7,armv7s,arm64} + +echo "Output to ${cwd}/ios/dest" -- cgit v1.2.3