Last active
January 29, 2018 13:52
-
-
Save davidbeauchamp/b1b6b98043a27a81a8a2 to your computer and use it in GitHub Desktop.
PostgreSQL Driver for Qt on Android builder script
This file contains hidden or 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 | |
# Contributor: David Beauchamp <david ($at) xtuple ($dot) com> | |
# Description: Build PostgreSQL 9.5.0 libpq for android 4.1.2 armv7h (no reason you can't use another API level) | |
# | |
# Based on https://wiki.qt.io/Build_Qt_5_PostgreSQL_Plugin_for_Android | |
# Originally created by https://gist.github.com/RazZziel/fd607459c1f07a43cdf9 | |
# Some code taken from https://gist.github.com/hpctech/a16f94f7ac3524d49219 | |
# you may need to modify the below paths | |
export WORKDIR=$(pwd) | |
export ANDROID_NDK_ROOT="/opt/android-ndk-r10e/" | |
export QT_ROOT="/opt/Qt5.5.1/5.5" | |
# qt 5.5.1 is built with android api 9, you can use any above that | |
SR="$ANDROID_NDK_ROOT/platforms/android-16/arch-arm/" | |
BR="$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-" | |
# OpenSSL | |
pkg=openssl-1.0.2e.tar.gz | |
dir=$(basename $pkg .tar.gz) | |
if [ ! -d $dir ]; then | |
wget -c http://www.openssl.org/source/$pkg | |
tar -xf $pkg || exit 1 | |
fi | |
pushd $dir | |
RANLIB="$BR"ranlib CC="$BR"gcc ./Configure android-armv7 --prefix=$SR/usr | |
ANDROID_DEV=$SR/usr make || exit 1 | |
make install_sw || exit 1 | |
popd | |
# libiconv | |
pkg=libiconv-1.14.tar.gz | |
dir=$(basename $pkg .tar.gz) | |
if [ ! -d $dir ]; then | |
wget -c http://ftp.gnu.org/pub/gnu/libiconv/$pkg | |
tar -xf $pkg || exit 1 | |
fi | |
pushd $dir | |
STRIP="$BR"strip RANLIB="$BR"ranlib OBJDUMP="$BR"objdump AR="$BR"ar CC="$BR"gcc CFLAGS=--sysroot=$SR CPP="$BR"cpp CPPFLAGS=$CFLAGS ./configure --host=arm --prefix=$SR/usr --with-sysroot=$SR | |
make || exit 1 | |
make install || exit 1 | |
popd | |
# postgresql | |
pkg=postgresql-9.5.0.tar.gz | |
dir=$(basename $pkg .tar.gz) | |
pgdir=$WORKDIR"/"$dir | |
if [ ! -d $dir ]; then | |
wget -c https://ftp.postgresql.org/pub/source/v9.5.0/$pkg | |
tar -xf $pkg || exit 1 | |
fi | |
pushd $dir | |
STRIP="$BR"strip RANLIB="$BR"ranlib OBJDUMP="$BR"objdump AR="$BR"ar CC="$BR"gcc CFLAGS=--sysroot=$SR CPP="$BR"cpp CPPFLAGS=$CFLAGS ./configure --prefix=$SR/usr --host=arm-linux-androideabi --target=arm-linux-androideabi --build="$CHOST" --without-readline --with-openssl || exit 1 | |
sed -e 's/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)/lib$(NAME)$(DLSUFFIX)/g' -i src/Makefile.shlib || exit 1 | |
sed -e 's/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)/lib$(NAME)$(DLSUFFIX)/g' -i src/Makefile.shlib || exit 1 | |
make -C src/interfaces/libpq | |
popd | |
# qt | |
qmake="$QT_ROOT/android_armv7/bin/qmake" | |
[ ! -f "$qmake" ] && { echo "Could not find qmake in '$qmake'"; exit 1; } | |
[ ! -x "$qmake" ] && { echo "Qmake is not executable in '$qmake'"; exit 1; } | |
pkg=qtbase-opensource-src-5.5.1.tar.gz | |
dir=$(basename $pkg .tar.gz) | |
if [ ! -d $dir ]; then | |
wget -c http://download.qt.io/official_releases/qt/5.5/5.5.1/submodules/qtbase-opensource-src-5.5.1.tar.gz | |
tar -xf $pkg || exit 1 | |
fi | |
pushd $dir/src/plugins/sqldrivers/psql/ | |
$qmake "INCLUDEPATH+=$pgdir/src/interfaces/libpq $pgdir/src/include" "LIBS+=-L$pgdir/src/interfaces/libpq/ -lpq" | |
make || exit 1 | |
make install || exit 1 | |
popd | |
echo | |
echo "Complete. libpq.so should be in $pgdir/src/interfaces/libpq and should be included in your Qt project." | |
echo | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment