Skip to content

Instantly share code, notes, and snippets.

@bongole
Last active March 24, 2022 21:13
Show Gist options
  • Save bongole/304a006a5386220246aa to your computer and use it in GitHub Desktop.
Save bongole/304a006a5386220246aa to your computer and use it in GitHub Desktop.
compile jq for android
#!/bin/sh
autoreconf -fi >/dev/null 2>&1
NDK_ROOT=/usr/local/opt/android-ndk
curl http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.5.tar.gz | tar xz
cd onig-5.9.5
# 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
cd ..
patch -p1 <<__EOS__
--- a/builtin.c
+++ b/builtin.c
@@ -62,6 +62,11 @@ static jv f_ ## name(jq_state *jq, jv input) { \\
jv_free(input); \\
return ret; \\
}
+
+static double log2(double x){
+ return log(x)/log(2);
+}
+
#include "libm.h"
#undef LIBM_DD
__EOS__
for arch in armv7-a x86; do
case $arch in
arm*)
ANDROID_ARCH=arm-linux-androideabi
$NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=arm-linux-androideabi-4.6 --install-dir=$PWD/toolchain/$arch
INSTALL_PATH=$PWD/build
HOST=arm-linux-androidabi
GCC_ARCH=$arch
EXTRA_CFLAGS="-mfloat-abi=softfp"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8"
;;
x86)
ANDROID_ARCH=i686-linux-android
$NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=x86-4.6 --install-dir=$PWD/toolchain/$arch
INSTALL_PATH=$PWD/build
HOST=i686-linux-android
GCC_ARCH=atom
EXTRA_CFLAGS=""
EXTRA_LDFLAGS=""
;;
esac
ANDROID_TOOLCHAIN_BIN=$PWD/toolchain/$arch/bin/$ANDROID_ARCH
ANDROID_SYSROOT=$PWD/toolchain/$arch/sysroot
export CC="$ANDROID_TOOLCHAIN_BIN-gcc"
export STRIP="$ANDROID_TOOLCHAIN_BIN-strip"
export RANLIB="$ANDROID_TOOLCHAIN_BIN-ranlib"
export LD="$ANDROID_TOOLCHAIN_BIN-ld"
export AR="$ANDROID_TOOLCHAIN_BIN-ar"
export AS="$ANDROID_TOOLCHAIN_BIN-as"
cd onig-5.9.5
make clean
./configure --prefix=$INSTALL_PATH/onig/$arch --disable-shared --enable-static --with-pic --host=$HOST CFLAGS="--sysroot=$ANDROID_SYSROOT -fPIC -march=$GCC_ARCH $EXTRA_CFLAGS" LDFLAGS="$EXTRA_LDFLAGS"
make libonig.la
make install-includeHEADERS
make install-libLTLIBRARIES
cd ..
make clean
./configure --prefix=$INSTALL_PATH/jq/$arch --with-oniguruma=$INSTALL_PATH/onig/$arch --disable-shared --enable-static --with-pic --host=$HOST CFLAGS="--sysroot=$ANDROID_SYSROOT -fPIC -march=$GCC_ARCH $EXTRA_CFLAGS" LDFLAGS="$EXTRA_LDFLAGS"
make libjq.la
make install-includeHEADERS
make install-libLTLIBRARIES
done
@joydeepsaha05
Copy link

Could you update this? The URL doesn't work anymore.

@martingleria
Copy link

I replaced the outdated URL with this one:
https://src.fedoraproject.org/lookaside/extras/oniguruma/onig-5.9.5.tar.gz/970f98a4cd10021b545d84e34c34aae4/onig-5.9.5.tar.gz

However, I can not make it work from macOS (12.2.1).
When the c script is executed, I'm seeing this:

can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- a/builtin.c
|+++ b/builtin.c
--------------------------
File to patch: 

If anyone has a binary for armv8 (Android 11) or instructions on how to build it would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment