source: core/c/jbigi/mbuild-all.sh @ 6d9aa92

Last change on this file since 6d9aa92 was 6d9aa92, checked in by zzz <zzz@…>, 10 months ago

Tests: Fix some bashisms, add more files to bashisms check

  • Property mode set to 100755
File size: 14.4 KB
Line 
1#!/bin/sh
2#
3# Run with BITS=32 to generate 32-bit libs on a 64-bit platform
4# On Ubuntu you will need sudo apt-get install gcc-multilib libc6-i386 libc6-dev-i386
5#
6
7# ON Solaris 11 (at least) this variable must be set.
8# Linux and *BSD will do the right thing.
9#
10
11#
12# look in configure file in gmp source for supported host CPUs, at about line 5000
13#
14
15
16# Note: You will have to add the CPU ID for the platform in the CPU ID code
17# for a new CPU. Just adding them here won't let I2P use the code!
18
19#
20# If you know of other platforms i2p on linux works on,
21# please add them here.
22# Do NOT add any X86 platforms, do that below in the x86 platform list.
23#
24MISC_LINUX_PLATFORMS="hppa2.0 alphaev56 mips64el itanium itanium2 ultrasparc2 ultrasparc2i alphaev6 powerpc970 powerpc7455 powerpc7447"
25
26#
27# If you know of other platforms i2p on *BSD works on,
28# please add them here.
29# Do NOT add any X86 platforms, do that below in the x86 platform list.
30#
31MISC_FREEBSD_PLATFORMS="alphaev56 ultrasparc2i"
32MISC_NETBSD_PLATFORMS="armv5tel mips64el ultrasparc2i sgi hppa2.0 alphaev56 powerpc powerpc64 powerpc64le powerpcle atari amiga m68knommu" # and many, many more
33MISC_OPENBSD_PLATFORMS="alphaev56 ultrasparc2i sgi powerpc powerpc64 hppa2.0 alphaev56 armv5tel mips64el"
34
35#
36# ARM
37#
38# These platforms exist as of GMP 6.0.0.
39# Some of them will be renamed in the next version of GMP.
40ARM_PLATFORMS="armv5 armv6 armv7a armcortex8 armcortex9 armcortex15"
41# Rename output of armv7a to armv7 since that's what NBI expects.
42# This is due to versions after GMP 6.0.0 changing the target name.
43TRANSLATE_NAME_armv7a="armv7"
44
45#
46# X86_64
47#
48# Are there any other X86 platforms that work on i2p? Add them here.
49#
50# Note! these build on 32bit as 32bit when operating as 32bit...
51# starting with k10 added for 6.0.0
52# As of GMP 6.0.0, libgmp 3,
53X86_64_PLATFORMS="skylake coreisbr coreihwl coreibwl bobcat jaguar bulldozer piledriver steamroller excavator atom athlon64 core2 corei nano pentium4 k10 x86_64"
54TRANSLATE_NAME_x86_64="none" # Rename x86_64 to none_64, since that is what NativeBigInteger refers to it as
55
56# Note! these are 32bit _ONLY_ (after the 64 bit ones)
57# Also note that the 64-bit entry "x86_64" is filtered out since it already has the more appropriate "i386" entry
58X86_PLATFORMS="$(echo $X86_64_PLATFORMS | sed 's/x86_64//g') pentium pentiummmx pentium2 pentium3 pentiumm k6 k62 k63 athlon geode viac3 viac32 i386"
59TRANSLATE_NAME_i386="none" # Rename i386 to none, , since that is what NativeBigInteger refers to it as
60
61DARWIN_PLATFORMS="core2 corei coreisbr coreihwl coreibwl"
62MINGW_PLATFORMS="${X86_PLATFORMS} ${MISC_MINGW_PLATFORMS}"
63LINUX_PLATFORMS="${X86_PLATFORMS} ${MISC_LINUX_PLATFORMS}"
64FREEBSD_PLATFORMS="${X86_PLATFORMS} ${MISC_FREEBSD_PLATFORMS}"
65# As they say, "Of course it runs NetBSD!"
66NETBSD_PLATFORMS="${FREEBSD_PLATFORMS} ${MISC_LINUX_PLATFORMS} ${MISC_NETBSD_PLATFORMS}"
67OPENBSD_PLATFORM="${X86_PLATFORMS} ${MISC_OPENBSD_PLATFORMS}"
68
69# Android
70# https://developer.android.com/ndk/guides/other_build_systems
71ANDROID_64_PLATFORMS="aarch64"
72ANDROID_32_PLATFORMS="armv7a"
73
74
75
76# Import gmp version variables and download gmp.
77. ./download_gmp.sh
78
79# If JAVA_HOME isn't set we'll try to figure it out
80[ -z $JAVA_HOME ] && . ../find-java-home
81if [ ! -f "$JAVA_HOME/include/jni.h" ]; then
82    echo "Cannot find jni.h! Looked in '$JAVA_HOME/include/jni.h'" >&2
83    echo "Please set JAVA_HOME to a java home that has the JNI" >&2
84    exit 1
85fi
86
87if ! command m4 > /dev/null; then
88    printf "\aWARNING: \`m4\` not found. Install m4 " >&2
89    printf "and re-run this script.\n\n\n\a" >&2
90    exit 1
91fi
92
93
94if [ -z $BITS ]; then
95  UNAME="$(uname -m)"
96  if test "${UNAME#*x86_64}" != "$UNAME"; then
97    BITS=64
98  elif test "${UNAME#*i386}" != "$UNAME"; then
99    BITS=32
100  elif test "${UNAME#*i686}" != "$UNAME"; then
101    BITS=32
102  elif test "${UNAME#*armv6}" != "$UNAME"; then
103    BITS=32
104  elif test "${UNAME#*armv7}" != "$UNAME"; then
105    BITS=32
106  elif test "${UNAME#*aarch32}" != "$UNAME"; then
107    BITS=32
108  elif test "${UNAME#*aarch64}" != "$UNAME"; then
109    BITS=64
110  else
111    echo "Unable to detect default setting for BITS variable"
112    exit 1
113  fi
114  printf "\aBITS variable not set, $BITS bit system detected\n\a" >&2
115fi
116
117
118if [ -z $CC ]; then
119  export CC="gcc"
120  printf "\aCC variable not set, defaulting to $CC\n\a" >&2
121fi
122
123# Allow TARGET to be overridden (e.g. for use with cross compilers)
124[ -z $TARGET ] && TARGET=$(uname -s |tr "[A-Z]" "[a-z]")
125
126if [ $BITS -eq 32 ]; then
127  export ABI=32
128  if [ "$TARGET" != "android" ]; then
129      export CFLAGS="-m32"
130      export LDFLAGS="-m32"
131  fi
132elif [ $BITS -eq 64 ]; then
133  export ABI=64
134  if [ "$TARGET" != "android" ]; then
135      export CFLAGS="-m64"
136      export LDFLAGS="-m64"
137  fi
138else
139  printf "\aBITS value \"$BITS\" not valid, please select 32 or 64\n\a" >&2
140  exit 1
141fi
142
143if ! command ${CC} > /dev/null; then
144  echo "The compiler you've selected \"$CC\" does not appear to exist"
145  exit 1
146fi
147
148# Set the "_64" filname filename suffix for 64-bit builds
149if [ $BITS -ne 32 -a "$TARGET" != "android" ]; then
150    [ -z $SUFFIX ] && SUFFIX="_64"
151fi
152
153# Note, this line does not support windows (and needs to generate a win32/win64 string for that to work)
154BUILD_OS=$(uname -s | tr "[A-Z]" "[a-z]")
155
156# Do some sanity checks for when we're cross-compiling and
157# set up host string, ARCH_VENDOR_OS. The "\$2" will be replaced
158# with the name of the arch at configuration time
159if [ "$TARGET" != "$BUILD_OS" ]; then
160  case "$TARGET" in
161  windows*)
162    HOST_CONFIGURE_FLAG="\$2-w64-mingw32"
163    case "$CC" in
164    *i*86*mingw32*gcc)
165      [ $BITS -ne 32 ] && echo "Error, 32-bit cross-compiler used with non 32-bit architecture" && exit 1
166      ;;
167    *x86_64*mingw32*gcc)
168      [ $BITS -ne 64 ] && echo "Error, 64-bit cross-compiler used with non 64-bit architecture" && exit 1
169      ;;
170    *)
171      echo "No recognized cross-compiler provided in CC env variable."
172      [ $BITS -eq 32 ] && echo "For 32-bit targets, i686-w64-mingw32-gcc is recommended"
173      [ $BITS -eq 64 ] && echo "For 64-bit targets, x86_64-w64-mingw32-gcc is recommended"
174      exit 1;
175      ;;
176    esac
177  ;;
178  freebsd*)
179    HOST_CONFIGURE_FLAG="\$2-pc-freebsd"
180  ;;
181  darwin*|osx)
182    HOST_CONFIGURE_FLAG="\$2-darwin"
183#     case "$CC" in
184#     *i*86*darwin*)
185
186
187#       [ $BITS -ne 32 ] && echo "Error, 32-bit cross-compiler used with non 32-bit architecture" && exit 1
188      ;;
189#     *x86_64*darwin*)
190#       HOST_CONFIGURE_FLAG="\$2-apple-darwin"
191#       [ $BITS -ne 64 ] && echo "Error, 64-bit cross-compiler used with non 64-bit architecture" && exit 1
192#       ;;
193#     *)
194#       echo "No recognized cross-compiler provided in CC env variable."
195#       [ $BITS -eq 32 ] && echo "For 32-bit targets, i686-apple-darwin10-gcc recommended"
196#       [ $BITS -eq 64 ] && echo "For 64-bit targets, x86_64-apple-darwin10-gcc recommended"
197#       exit 1;
198#       ;;
199#     esac
200#   ;;
201  android)
202    ANDROID_NDK=`realpath ../../../../android-ndk-r19c`
203    export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
204    if [ $BITS -eq 32 ]; then
205        HOST_CONFIGURE_FLAG=armv7a-linux-androideabi
206        export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
207        export AS=$TOOLCHAIN/bin/arm-linux-androideabi-as
208        export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi16-clang
209        export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi16-clang++
210        export LD=$TOOLCHAIN/bin/arm-linux-androideabi-ld
211        export RANLIB=$TOOLCHAIN/bin/arm-linux-androideabi-ranlib
212        export STRIP=$TOOLCHAIN/bin/arm-linux-androideabi-strip
213     else
214        HOST_CONFIGURE_FLAG=aarch64-linux-android
215        export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
216        export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
217        export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
218        export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
219        export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
220        export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
221        export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
222     fi
223    ;;
224  esac
225fi
226
227case "$TARGET" in
228mingw*|windows*)
229        NAME="jbigi"
230        TYPE="dll"
231        TARGET="windows"
232        if [ $BITS -ne 32 ]; then
233                PLATFORM_LIST="${X86_64_PLATFORMS}"
234        else
235                PLATFORM_LIST="${X86_PLATFORMS}"
236        fi
237        echo "Building ${TARGET} .dlls for all architectures";;
238darwin*|osx)
239        NAME="libjbigi"
240        TYPE="jnilib"
241        TARGET="osx"
242        PLATFORM_LIST="${DARWIN_PLATFORMS}"
243        echo "Building ${TARGET} .jnilibs for all architectures";;
244sunos*)
245        NAME="libjbigi"
246        TYPE="so"
247        BUILD_OS="solaris"
248        TARGET="${BUILD_OS}"
249        if [ $BITS -eq 32 ]; then
250            PLATFORM_LIST="${X86_PLATFORMS}"
251        else
252            PLATFORM_LIST="${X86_PLATFORMS}"
253        fi
254        echo "Building ${TARGET} .sos for all architectures";;
255linux*|*kfreebsd)
256        NAME="libjbigi"
257        TYPE="so"
258        PLATFORM_LIST=""
259        case "$TARGET" in
260            *kfreebsd)
261                TARGET="kfreebsd"
262                ;;
263            *)
264                TARGET="linux"
265                ;;
266        esac
267        ARCH=$(uname -m | cut -f1 -d" ")
268
269        case ${ARCH} in
270                x86_64 | amd64 | i*86)
271                        if [ $BITS -eq 32 ]; then
272                          PLATFORM_LIST="${X86_PLATFORMS}"
273                          ARCH="x86"
274                        else
275                          PLATFORM_LIST="${X86_64_PLATFORMS}"
276                          ARCH="x86_64"
277                        fi;;
278                arm*)
279                        PLATFORM_LIST="${ARM_PLATFORMS}";;
280                *)
281                        PLATFORM_LIST="${LINUX_PLATFORMS}";;
282        esac
283        echo "Building ${TARGET} .sos for ${ARCH}";;
284netbsd*|freebsd*|openbsd*)
285        NAME="libjbigi"
286        TYPE="so"
287        PLATFORM_LIST=
288        ARCH=$(uname -m | cut -f1 -d" ")
289        case ${ARCH} in
290                x86_64 | amd64 | i*86)
291                        if [ $BITS -eq 32 ]; then
292                          PLATFORM_LIST="${X86_PLATFORMS}"
293                          ARCH="x86"
294                        else
295                          PLATFORM_LIST="${X86_64_PLATFORMS}"
296                          ARCH="x86_64"
297                        fi;;
298                *)
299                        case ${TARGET} in
300                                netbsd)
301                                        PLATFORM_LIST="${NETBSD_PLATFORMS}";;
302                                openbsd)
303                                        PLATFORM_LIST="${OPENBSD_PLATFORMS}";;
304                                freebsd)
305                                        PLATFORM_LIST="${FREEBSD_PLATFORMS}";;
306                                *)
307                                        echo "Unsupported build environment"
308                                        exit 1;;
309                        esac
310        esac
311        echo "Building ${TARGET} .sos for ${ARCH}";;
312android)
313        NAME="libjbigi"
314        TYPE="so"
315        if [ $BITS -eq 32 ]; then
316            PLATFORM_LIST="${ANDROID_32_PLATFORMS}"
317            ARCH="armv7a"
318        else
319            PLATFORM_LIST="${ANDROID_64_PLATFORMS}"
320            ARCH="aarch64"
321        fi
322        echo "Building Android .so for ${PLATFORM_LIST}";;
323*)
324        echo "Unsupported build environment"
325        exit;;
326esac
327
328#####################
329# In the below functions:
330# $1 = gmp version
331# $2 = platform: such as athlon64
332# $3 = basename: "jbigi" on Windows, "libjbigi" everywhere else
333# $4 = type/extension: windows = "dll". osx = "jnilib". Everything else = "so"
334# $5 = target: "linux", "freebsd", "kfreebsd", "osx", "windows", etc.
335# $6 = suffix: null if 32bit, _64 if 64bit
336
337make_static () {
338        echo "Attempting .${4} creation for ${3}${5}${2}${6}"
339        ../../build_jbigi.sh static || return 1
340        PLATFORM="${2}"
341       
342        # Some platforms have different build-time names from
343        # what java and NativeBigInteger refers to them as.
344        # Translate to the proper name here
345        eval TRANSLATED_NAME=\$TRANSLATE_NAME_$PLATFORM
346        if [ -n "$TRANSLATED_NAME" ]; then
347            PLATFORM="${TRANSLATED_NAME}"
348        fi
349       
350        cp ${3}.${4} ../../lib/net/i2p/util/${3}${5}${PLATFORM}${6}.${4}
351        return 0
352}
353
354make_file () {
355        # Nonfatal bail out on Failed build.
356        echo "Attempting build for ${3}${5}${2}"
357        make -j && return 0
358        cd ..
359        rm -R "$2"
360        printf "\n\nFAILED! ${3}${5}${2} not made.\a"
361        sleep 10
362        return 1
363}
364
365configure_file () {
366        printf "\n\n\nAttempting configure for ${3}${5}${2}${6}\n\n\n"
367        if [ $BITS -eq 32 ] && [ "$2"  = "none" ]; then
368            unset ABI
369        elif [ $BITS -eq 32 ] && [ "$2" != "none" ]; then
370            export ABI=32
371        fi
372
373        # Nonfatal bail out on unsupported platform.
374        (cd ../../gmp-${1}; make clean)
375        if [ "$TARGET" != "$BUILD_OS" ]; then
376            # We're cross-compiling, supply a --host flag
377           
378            # Here we're making sure that the platform we're target is injected into
379            # the HOST_CONFIGURE_FLAG string. The string looks somehing like this
380            # before the eval: "$2_VENDOR_OS"
381            # and this after:  "x86_VENDOR_OS"
382            eval HOST_CONFIGURE_FLAG=$HOST_CONFIGURE_FLAG
383            echo "../../gmp-${1}/configure --host=${HOST_CONFIGURE_FLAG} --with-pic && return 0"
384            ../../gmp-${1}/configure --host=${HOST_CONFIGURE_FLAG} --with-pic && return 0
385        else
386            # We're not cross-compiling, we are however building
387            # optimized versions for other platforms on our OS.
388            echo "../../gmp-${1}/configure --build=${2}-${BUILD_OS} --with-pic && return 0"
389            ../../gmp-${1}/configure --build=${2}-${BUILD_OS} --with-pic && return 0
390        fi
391
392        cd ..
393       
394        rm -R "$2"
395        printf "\n\nSorry, ${3}${5}${2} is not supported on your build environment.\a"
396        sleep 10
397        return 1
398}
399
400build_file () {
401        configure_file "$1" "$2" "$3" "$4" "$5" "$6"  && make_file "$1" "$2" "$3" "$4" "$5" "$6" && make_static "$1" "$2" "$3" "$4" "$5" "$6" && return 0
402        printf "\n\n\nError building static!\n\n\a"
403        sleep 10
404        return 1
405}
406
407
408if [ ! -d bin ]; then
409        mkdir bin
410fi
411
412if [ ! -d lib/net/i2p/util ]; then
413        mkdir -p lib/net/i2p/util
414fi
415
416for x in $PLATFORM_LIST
417do
418  (
419    if [ ! -d bin/$x ]; then
420      mkdir bin/$x
421      cd bin/$x
422    else
423      cd bin/$x
424      rm -Rf *
425    fi
426    build_file "$GMP_VER" "$x" "$NAME" "$TYPE" "-$TARGET-" "$SUFFIX"
427  )
428done
429
430echo "Success!"
431exit 0
432
433# vim:fenc=utf-8:ai:si:ts=4:sw=4:et:nu
Note: See TracBrowser for help on using the repository browser.