source: core/c/jbigi/mbuild-all.sh @ 0f633605

Last change on this file since 0f633605 was 0f633605, checked in by dev <dev@…>, 4 years ago

core/buildscripts: Added ARM support to BITS detection.

Added support for armv6/armv7/aarch32/aarch64 BITS detection
to build scripts.

  • Property mode set to 100755
File size: 12.7 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="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
70# Import gmp version variables and download gmp.
71. ./download_gmp.sh
72
73# If JAVA_HOME isn't set we'll try to figure it out
74[ -z $JAVA_HOME ] && . ../find-java-home
75if [ ! -f "$JAVA_HOME/include/jni.h" ]; then
76    echo "Cannot find jni.h! Looked in '$JAVA_HOME/include/jni.h'" >&2
77    echo "Please set JAVA_HOME to a java home that has the JNI" >&2
78    exit 1
79fi
80
81if ! command -v m4 > /dev/null; then
82    printf "\aWARNING: \`m4\` not found. If this process fails to complete, install m4 " >&2
83    printf "and re-run this script.\n\n\n\a" >&2
84    exit 1
85fi
86
87
88if [ -z $BITS ]; then
89  UNAME="$(uname -a)"
90  if test "${UNAME#*x86_64}" != "x86_&4"; then
91    BITS=64
92  elif test "${UNAME#*i386}" != "i386"; then
93    BITS=32
94  elif test "${UNAME#*i686}" != "i686"; then
95    BITS=32
96  elif test "${UNAME#*armv6}" != "armv6"; then
97    BITS=32
98  elif test "${UNAME#*armv7}" != "armv7"; then
99    BITS=32
100  elif test "${UNAME#*aarch32}" != "aarch32"; then
101    BITS=32
102  elif test "${UNAME#*aarch64}" != "aarch64"; then
103    BITS=64
104  else
105 
106    echo "Unable to detect default setting for BITS variable"
107    exit
108  fi
109
110  printf "\aBITS variable not set, $BITS bit system detected\n\a" >&2
111fi
112
113
114if [ -z $CC ]; then
115  export CC="gcc"
116  printf "\aCC variable not set, defaulting to $CC\n\a" >&2
117fi
118
119if [ $BITS -eq 32 ]; then
120  export ABI=32
121  export CFLAGS="-m32"
122  export LDFLAGS="-m32"
123elif [ $BITS -eq 64 ]; then
124  export ABI=64
125  export CFLAGS="-m64"
126  export LDFLAGS="-m64"
127else
128  printf "\aBITS value \"$BITS\" not valid, please select 32 or 64\n\a" >&2
129  exit 1
130fi
131
132if ! command -v ${CC} > /dev/null; then
133  echo "The compiler you've selected \"$CC\" does not appear to exist"
134  exit 1
135fi
136
137# Set the "_64" filname filename suffix for 64-bit builds
138if [ $BITS -ne 32 ]; then
139    [ -z $SUFFIX ] && SUFFIX="_64"
140fi
141
142# Allow TARGET to be overridden (e.g. for use with cross compilers)
143[ -z $TARGET ] && TARGET=$(uname -s |tr "[A-Z]" "[a-z]")
144
145# Note, this line does not support windows (and needs to generate a win32/win64 string for that to work)
146BUILD_OS=$(uname -s | tr "[A-Z]" "[a-z]")
147
148# Do some sanity checks for when we're cross-compiling and
149# set up host string, ARCH_VENDOR_OS. The "\$2" will be replaced
150# with the name of the arch at configuration time
151if [ "$TARGET" != "$BUILD_OS" ]; then
152  case "$TARGET" in
153  windows*)
154    HOST_CONFIGURE_FLAG="\$2-w64-mingw32"
155    case "$CC" in
156    *i*86*mingw32*gcc)
157      [ $BITS -ne 32 ] && echo "Error, 32-bit cross-compiler used with non 32-bit architecture" && exit 1
158      ;;
159    *x86_64*mingw32*gcc)
160      [ $BITS -ne 64 ] && echo "Error, 64-bit cross-compiler used with non 64-bit architecture" && exit 1
161      ;;
162    *)
163      echo "No recognized cross-compiler provided in CC env variable."
164      [ $BITS -eq 32 ] && echo "For 32-bit targets, i686-w64-mingw32-gcc is recommended"
165      [ $BITS -eq 64 ] && echo "For 64-bit targets, x86_64-w64-mingw32-gcc is recommended"
166      exit 1;
167      ;;
168    esac
169  ;;
170  freebsd*)
171    HOST_CONFIGURE_FLAG="\$2-pc-freebsd"
172  ;;
173  darwin*|osx)
174    HOST_CONFIGURE_FLAG="\$2-darwin"
175#     case "$CC" in
176#     *i*86*darwin*)
177
178
179#       [ $BITS -ne 32 ] && echo "Error, 32-bit cross-compiler used with non 32-bit architecture" && exit 1
180      ;;
181#     *x86_64*darwin*)
182#       HOST_CONFIGURE_FLAG="\$2-apple-darwin"
183#       [ $BITS -ne 64 ] && echo "Error, 64-bit cross-compiler used with non 64-bit architecture" && exit 1
184#       ;;
185#     *)
186#       echo "No recognized cross-compiler provided in CC env variable."
187#       [ $BITS -eq 32 ] && echo "For 32-bit targets, i686-apple-darwin10-gcc recommended"
188#       [ $BITS -eq 64 ] && echo "For 64-bit targets, x86_64-apple-darwin10-gcc recommended"
189#       exit 1;
190#       ;;
191#     esac
192#   ;;
193  esac
194fi
195
196case "$TARGET" in
197mingw*|windows*)
198        NAME="jbigi"
199        TYPE="dll"
200        TARGET="windows"
201        if [ $BITS -ne 32 ]; then
202                PLATFORM_LIST="${X86_64_PLATFORMS}"
203        else
204                PLATFORM_LIST="${X86_PLATFORMS}"
205        fi
206        echo "Building ${TARGET} .dlls for all architectures";;
207darwin*|osx)
208        NAME="libjbigi"
209        TYPE="jnilib"
210        TARGET="osx"
211        PLATFORM_LIST="${DARWIN_PLATFORMS}"
212        echo "Building ${TARGET} .jnilibs for all architectures";;
213sunos*)
214        NAME="libjbigi"
215        TYPE="so"
216        BUILD_OS="solaris"
217        TARGET="${BUILD_OS}"
218        if [ $BITS -eq 32 ]; then
219            PLATFORM_LIST="${X86_PLATFORMS}"
220        else
221            PLATFORM_LIST="${X86_PLATFORMS}"
222        fi
223        echo "Building ${TARGET} .sos for all architectures";;
224linux*|*kfreebsd)
225        NAME="libjbigi"
226        TYPE="so"
227        PLATFORM_LIST=""
228        case "$TARGET" in
229            *kfreebsd)
230                TARGET="kfreebsd"
231                ;;
232            *)
233                TARGET="linux"
234                ;;
235        esac
236        ARCH=$(uname -m | cut -f1 -d" ")
237
238        case ${ARCH} in
239                x86_64 | amd64 | i*86)
240                        if [ $BITS -eq 32 ]; then
241                          PLATFORM_LIST="${X86_PLATFORMS}"
242                          ARCH="x86"
243                        else
244                          PLATFORM_LIST="${X86_64_PLATFORMS}"
245                          ARCH="x86_64"
246                        fi;;
247                arm*)
248                        PLATFORM_LIST="${ARM_PLATFORMS}";;
249                *)
250                        PLATFORM_LIST="${LINUX_PLATFORMS}";;
251        esac
252        echo "Building ${TARGET} .sos for ${ARCH}";;
253netbsd*|freebsd*|openbsd*)
254        NAME="libjbigi"
255        TYPE="so"
256        PLATFORM_LIST=
257        ARCH=$(uname -m | cut -f1 -d" ")
258        case ${ARCH} in
259                x86_64 | amd64 | i*86)
260                        if [ $BITS -eq 32 ]; then
261                          PLATFORM_LIST="${X86_PLATFORMS}"
262                          ARCH="x86"
263                        else
264                          PLATFORM_LIST="${X86_64_PLATFORMS}"
265                          ARCH="x86_64"
266                        fi;;
267                *)
268                        case ${TARGET} in
269                                netbsd)
270                                        PLATFORM_LIST="${NETBSD_PLATFORMS}";;
271                                openbsd)
272                                        PLATFORM_LIST="${OPENBSD_PLATFORMS}";;
273                                freebsd)
274                                        PLATFORM_LIST="${FREEBSD_PLATFORMS}";;
275                                *)
276                                        echo "Unsupported build environment"
277                                        exit 1;;
278                        esac
279        esac
280        echo "Building ${TARGET} .sos for ${ARCH}";;
281*)
282        echo "Unsupported build environment"
283        exit;;
284esac
285
286#####################
287# In the below functions:
288# $1 = gmp version
289# $2 = platform: such as athlon64
290# $3 = basename: "jbigi" on Windows, "libjbigi" everywhere else
291# $4 = type/extension: windows = "dll". osx = "jnilib". Everything else = "so"
292# $5 = target: "linux", "freebsd", "kfreebsd", "osx", "windows", etc.
293# $6 = suffix: null if 32bit, _64 if 64bit
294
295make_static () {
296        echo "Attempting .${4} creation for ${3}${5}${2}${6}"
297        ../../build_jbigi.sh static || return 1
298        PLATFORM="${2}"
299       
300        # Some platforms have different build-time names from
301        # what java and NativeBigInteger refers to them as.
302        # Translate to the proper name here
303        eval TRANSLATED_NAME=\$TRANSLATE_NAME_$PLATFORM
304        if [ -n "$TRANSLATED_NAME" ]; then
305            PLATFORM="${TRANSLATED_NAME}"
306        fi
307       
308        cp ${3}.${4} ../../lib/net/i2p/util/${3}${5}${PLATFORM}${6}.${4}
309        return 0
310}
311
312make_file () {
313        # Nonfatal bail out on Failed build.
314        echo "Attempting build for ${3}${5}${2}"
315        make -j && return 0
316        cd ..
317        rm -R "$2"
318        printf "\n\nFAILED! ${3}${5}${2} not made.\a"
319        sleep 10
320        return 1
321}
322
323configure_file () {
324        printf "\n\n\nAttempting configure for ${3}${5}${2}${6}\n\n\n"
325        if [ $BITS -eq 32 ] && [ "$2"  = "none" ]; then
326            unset ABI
327        elif [ $BITS -eq 32 ] && [ "$2" != "none" ]; then
328            export ABI=32
329        fi
330
331        # Nonfatal bail out on unsupported platform.
332        (cd ../../gmp-${1}; make clean)
333        if [ "$TARGET" != "$BUILD_OS" ]; then
334            # We're cross-compiling, supply a --host flag
335           
336            # Here we're making sure that the platform we're target is injected into
337            # the HOST_CONFIGURE_FLAG string. The string looks somehing like this
338            # before the eval: "$2_VENDOR_OS"
339            # and this after:  "x86_VENDOR_OS"
340            eval HOST_CONFIGURE_FLAG=$HOST_CONFIGURE_FLAG
341            echo "../../gmp-${1}/configure --host=${HOST_CONFIGURE_FLAG} --with-pic && return 0"
342            ../../gmp-${1}/configure --host=${HOST_CONFIGURE_FLAG} --with-pic && return 0
343        else
344            # We're not cross-compiling, we are however building
345            # optimized versions for other platforms on our OS.
346            echo "../../gmp-${1}/configure --build=${2}-${BUILD_OS} --with-pic && return 0"
347            ../../gmp-${1}/configure --build=${2}-${BUILD_OS} --with-pic && return 0
348        fi
349
350        cd ..
351       
352        rm -R "$2"
353        printf "\n\nSorry, ${3}${5}${2} is not supported on your build environment.\a"
354        sleep 10
355        return 1
356}
357
358build_file () {
359        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
360        printf "\n\n\nError building static!\n\n\a"
361        sleep 10
362        return 1
363}
364
365
366if [ ! -d bin ]; then
367        mkdir bin
368fi
369
370if [ ! -d lib/net/i2p/util ]; then
371        mkdir -p lib/net/i2p/util
372fi
373
374for x in $PLATFORM_LIST
375do
376  (
377    if [ ! -d bin/$x ]; then
378      mkdir bin/$x
379      cd bin/$x
380    else
381      cd bin/$x
382      rm -Rf *
383    fi
384    build_file "$GMP_VER" "$x" "$NAME" "$TYPE" "-$TARGET-" "$SUFFIX"
385  )
386done
387
388echo "Success!"
389exit 0
390
391# vim:fenc=utf-8:ai:si:ts=4:sw=4:et:nu
Note: See TracBrowser for help on using the repository browser.