source: core/c/jbigi/build_jbigi.sh

Last change on this file was 4bd0f06, checked in by zzz <zzz@…>, 23 months ago

jbigi: Support android builds using NDK
Prep for GMP 6.1.2

  • Property mode set to 100755
File size: 4.8 KB
Line 
1#!/bin/sh
2# When executed in Mingw: Produces a jbigi.dll
3# When executed in Linux/FreeBSD: Produces a libjbigi.so
4# When executed in OSX: Produces a libjbigi.jnilib
5[ -z "$CC" ] && CC="gcc"
6
7UNAME="$(uname -m)"
8if [ -z $BITS ]; then
9  if test "${UNAME#*x86_64}" != "$UNAME"; then
10    BITS=64
11  elif test "${UNAME#*i386}" != "$UNAME"; then
12    BITS=32
13  elif test "${UNAME#*i686}" != "$UNAME"; then
14    BITS=32
15  elif test "${UNAME#*armv6}" != "$UNAME"; then
16    BITS=32
17  elif test "${UNAME#*armv7}" != "$UNAME"; then
18    BITS=32
19  elif test "${UNAME#*aarch32}" != "$UNAME"; then
20    BITS=32
21  elif test "${UNAME#*aarch64}" != "$UNAME"; then
22    BITS=64
23  else
24 
25    echo "Unable to detect default setting for BITS variable"
26    exit 1
27  fi
28
29  printf "BITS variable not set, $BITS bit system detected\n" >&2
30fi
31
32# If JAVA_HOME isn't set we'll try to figure it out
33[ -z $JAVA_HOME ] && . `dirname $0`/../find-java-home
34if [ ! -f "$JAVA_HOME/include/jni.h" ]; then
35    echo "Cannot find jni.h! Looked in '$JAVA_HOME/include/jni.h'"
36    echo "Please set JAVA_HOME to a java home that has the JNI"
37    exit 1
38fi
39
40
41# Allow TARGET to be overridden (e.g. for use with cross compilers)
42[ -z $TARGET ] && TARGET=$(uname -s | tr "[A-Z]" "[a-z]")
43
44# Note, this line does not support windows (and needs to generate a win32/win64 string for that to work)
45BUILD_OS=$(uname -s | tr "[A-Z]" "[a-z]")
46echo "TARGET=$TARGET"
47
48case "$TARGET" in
49mingw*|windows*)
50        COMPILEFLAGS="-Wall"
51        INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/$BUILD_OS -I/usr/local/include"
52        LINKFLAGS="-shared -Wl,--kill-at"
53        LIBFILE="jbigi.dll";;
54cygwin*)
55        COMPILEFLAGS="-Wall -mno-cygwin"
56        INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/$BUILD_OS/ -I$JAVA_HOME/include/"
57        LINKFLAGS="-shared -Wl,--kill-at"
58        LIBFILE="jbigi.dll";;
59darwin*|osx)
60        COMPILEFLAGS="-fPIC -Wall"
61        INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/$BUILD_OS -I/usr/local/include"
62        LINKFLAGS="-dynamiclib -framework JavaVM"
63        LIBFILE="libjbigi.jnilib";;
64sunos*|openbsd*|netbsd*|*freebsd*|linux*)
65        if [ $BUILD_OS = "sunos" ]; then
66            BUILD_OS="solaris"
67        elif [ $BUILD_OS = "gnu/kfreebsd" ]; then
68            BUILD_OS="linux"
69        fi
70        COMPILEFLAGS="-fPIC -Wall $CFLAGS"
71        # change the path that build_jbigi.sh expects to find the source files at.
72        # formerly 0002-jbigi-soname.patch
73        if [ "$DEBIANVERSION" ] ; then
74            INCLUDES="-I. -I./jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/$BUILD_OS -I/usr/local/include"
75        else
76            INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/$BUILD_OS -I/usr/local/include"
77        fi
78        LINKFLAGS="-shared -Wl,-soname,libjbigi.so"
79        LIBFILE="libjbigi.so";;
80android)
81        BUILD_OS="linux"
82        if [ $BITS -eq 32 ]; then
83            COMPILEFLAGS="-O2 -pedantic -fomit-frame-pointer -march=armv7-a -mfloat-abi=softfp -mtune=cortex-a5 -fPIC -DPIC"
84        else
85            COMPILEFLAGS="-O2 -pedantic -march=armv8-a -Wa,--noexecstack -fPIC -DPIC"
86        fi
87        LINKFLAGS="-shared -Wl,-soname,libjbigi.so"
88        INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/$BUILD_OS -I/usr/local/include"
89        LIBFILE="libjbigi.so";;
90*)
91        echo "Unsupported system type."
92        exit 1;;
93esac
94
95if [ "$1" = "dynamic" ] ; then
96        echo "Building a jbigi lib that is dynamically linked to GMP"
97        LIBPATH="-L.libs -L/usr/local/lib"
98        INCLUDELIBS="-lgmp"
99else
100        echo "Building a jbigi lib that is statically linked to GMP"
101        STATICLIBS=".libs/libgmp.a"
102fi
103
104# Debian builds are presumed to be native, we don't need the -mxx flag unless cross-compile,
105# and this breaks the x32 build
106if [ -z "$DEBIANVERSION" ] ; then
107    [ $BITS -eq 32 -a "${UNAME#*86}" != "$UNAME" ] && COMPILEFLAGS="-m32 $COMPILEFLAGS" && LINKFLAGS="-m32 $LINKFLAGS"
108    [ $BITS -eq 64 -a "${UNAME#*86}" != "$UNAME" ] && COMPILEFLAGS="-m64 $COMPILEFLAGS" && LINKFLAGS="-m64 $LINKFLAGS"
109fi
110
111echo "Compiling C code..."
112# change the path that build_jbigi.sh expects to find the source files at.
113# formerly 0002-jbigi-soname.patch
114if [ "$DEBIANVERSION" ] ; then
115    echo "Compile: \"$CC -c $COMPILEFLAGS $INCLUDES ./jbigi/src/jbigi.c\""
116    $CC -c $COMPILEFLAGS $INCLUDES ./jbigi/src/jbigi.c || exit 1
117else
118    echo "Compile: \"$CC -c $COMPILEFLAGS $INCLUDES ../../jbigi/src/jbigi.c\""
119    $CC -c $COMPILEFLAGS $INCLUDES ../../jbigi/src/jbigi.c || exit 1
120fi
121echo "Link: \"$CC $LINKFLAGS $INCLUDES -o $LIBFILE jbigi.o $INCLUDELIBS $STATICLIBS $LIBPATH\""
122$CC $LINKFLAGS $INCLUDES -o $LIBFILE jbigi.o $INCLUDELIBS $STATICLIBS $LIBPATH || exit 1
123if [ ! -z "$STRIP" ]; then
124    echo "Strip: \"$STRIP $LIBFILE\""
125    $STRIP $LIBFILE
126fi
127exit 0
Note: See TracBrowser for help on using the repository browser.