source: core/c/jbigi/mbuild-all.sh @ 63272d3

Last change on this file since 63272d3 was 63272d3, checked in by zzz <zzz@…>, 4 years ago

mbuild-all script fixes

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