source: core/c/jbigi/mbuild-all.sh @ 5c56de7

Last change on this file since 5c56de7 was 5c56de7, checked in by dev <dev@…>, 6 years ago

Add x86 and x86_64 targets.

  • Property mode set to 100755
File size: 10.2 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#BITS=32
11
12#
13# look in configure file in gmp source for supported host CPUs, at about line 5000
14#
15
16# FIXME Is this all?
17DARWIN_PLATFORMS="core2 corei"
18MISC_DARWIN_PLATFORMS="powerpc powerpc64 powerpc64le powerpcle"
19
20# Note: You will have to add the CPU ID for the platform in the CPU ID code
21# for a new CPU. Just adding them here won't let I2P use the code!
22
23#
24# If you know of other platforms i2p on linux works on,
25# please add them here.
26# Do NOT add any X86 platforms, do that below in the x86 platform list.
27#
28MISC_LINUX_PLATFORMS="hppa2.0 alphaev56 mips64el itanium itanium2 ultrasparc2 ultrasparc2i alphaev6 powerpc970 powerpc7455 powerpc7447"
29
30#
31# If you know of other platforms i2p on *BSD works on,
32# please add them here.
33# Do NOT add any X86 platforms, do that below in the x86 platform list.
34#
35MISC_FREEBSD_PLATFORMS="alphaev56 ultrasparc2i"
36MISC_NETBSD_PLATFORMS="armv5tel mips64el ultrasparc2i sgi hppa2.0 alphaev56 powerpc powerpc64 powerpc64le powerpcle atari amiga m68knommu" # and many, many more
37MISC_OPENBSD_PLATFORMS="alphaev56 ultrasparc2i sgi powerpc powerpc64 hppa2.0 alphaev56 armv5tel mips64el"
38
39#
40# MINGW/Windows??
41#
42MISC_MINGW_PLATFORMS=""
43
44#
45# ARM
46#
47# These platforms exist as of GMP 6.0.0.
48# Some of them will be renamed in the next version of GMP.
49ARM_PLATFORMS="armv5 armv6 armv7a armcortex8 armcortex9 armcortex15"
50# Rename output of armv7a to armv7 since that's what NBI expects.
51# This is due to versions after GMP 6.0.0 changing the target name.
52TRANSLATE_NAME_armv7a="armv7"
53
54#
55# X86_64
56#
57# Are there any other X86 platforms that work on i2p? Add them here.
58#
59# Note! these build on 32bit as 32bit when operating as 32bit...
60# starting with k10 added for 6.0.0
61# As of GMP 6.0.0, libgmp 3,
62X86_64_PLATFORMS="coreisbr coreihwl coreibwl bobcat jaguar bulldozer piledriver steamroller excavator atom athlon64 core2 corei nano pentium4 k10 x86_64"
63TRANSLATE_NAME_x86_64="x86" # The _64 tag will be appended to the filename at another place.
64
65# Note! these are 32bit _ONLY_ (after the 64 bit ones)
66X86_PLATFORMS="${X86_64_PLATFORMS} pentium pentiummmx pentium2 pentium3 pentiumm k6 k62 k63 athlon geode viac3 viac32 x86"
67
68MINGW_PLATFORMS="${X86_PLATFORMS} ${MISC_MINGW_PLATFORMS}"
69LINUX_PLATFORMS="${X86_PLATFORMS} ${MISC_LINUX_PLATFORMS}"
70FREEBSD_PLATFORMS="${X86_PLATFORMS} ${MISC_FREEBSD_PLATFORMS}"
71# As they say, "Of course it runs NetBSD!"
72NETBSD_PLATFORMS="${FREEBSD_PLATFORMS} ${MISC_LINUX_PLATFORMS} ${MISC_NETBSD_PLATFORMS}"
73OPENBSD_PLATFORM="${X86_PLATFORMS} ${MISC_OPENBSD_PLATFORMS}"
74
75#
76# You should not need to edit anything below this comment.
77#
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 [ ! $(which m4)  ]; then
88    printf "\aWARNING: \`m4\` not found. If this process fails to complete, install m4 " >&2
89    printf "and re-run this script.\n\n\n\a" >&2
90    sleep 10
91fi
92
93
94# Allow TARGET to be overridden (e.g. for use with cross compilers)
95[ -z $TARGET ] && TARGET=$(uname -s |tr "[A-Z]" "[a-z]")
96
97
98# Set the version to 5.0.2 for OSX because AFAIK there are only 64bit capable CPUs for the Intel Macs
99# FIXME do this without sed (and tail) (= portably)
100if [ `echo $TARGET|grep darwin` ]; then
101        VER=5.0.2
102elif [ `echo $TARGET|grep sunos` ]; then
103        VER=$(echo gmp-*.tar.bz2 | sed -e "s/\(.*-\)\(.*\)\(.*.tar.bz2\)$/\2/" | /usr/xpg4/bin/tail -n 1)
104else
105        VER=$(echo gmp-*.tar.bz2 | sed -e "s/\(.*-\)\(.*\)\(.*.tar.bz2\)$/\2/" | tail -n 1)
106fi
107
108if [ "$VER" = "" ] ; then
109        echo "ERROR! Can't find gmp source tarball."
110        exit 1
111fi
112
113# If the BITS variable isn't set above we'll proceed without setting the *FLAGS
114# variables ourselves.
115[ -z $BITS ] && BITS=0
116
117if [ $BITS -eq 32 ]; then
118    export CC="gcc -m32"
119    export CFLAGS="-m32"
120    export LDFLAGS="-m32"
121    SUFFIX=
122elif [ $BITS -eq 64 ]; then
123    export CC="gcc -m64"
124    export CFLAGS="-m64"
125fi
126
127case "$TARGET" in
128mingw*)
129        PLATFORM_LIST="${MINGW_PLATFORMS}"
130        NAME="jbigi"
131        TYPE="dll"
132        TARGET="windows"
133        echo "Building windows .dlls for all architectures";;
134darwin*)
135        PLATFORM_LIST="${DARWIN_PLATFORMS}"
136        NAME="libjbigi"
137        TYPE="jnilib"
138        TARGET="osx"
139        echo "Building ${TARGET} .jnilibs for all architectures";;
140sunos*)
141        PLATFORM_LIST="${X86_64_PLATFORMS}"
142        NAME="libjbigi"
143        TYPE="so"
144        UNIXTYPE="solaris"
145        TARGET="${UNIXTYPE}"
146        if $(echo "$CFLAGS" | grep -q "\-m64") ; then
147            [ -z $SUFFIX ] && SUFFIX="_64"
148            PLATFORM_LIST="${X86_PLATFORMS}"
149        else
150            PLATFORM_LIST="${X86_PLATFORMS}"
151        fi
152        echo "Building ${TARGET} .sos for all architectures";;
153linux*|*kfreebsd)
154        NAME="libjbigi"
155        TYPE="so"
156        PLATFORM_LIST=""
157        case "$TARGET" in
158            *kfreebsd)
159                TARGET="kfreebsd"
160                ;;
161            *)
162                TARGET="linux"
163                ;;
164        esac
165        arch=$(uname -m | cut -f1 -d" ")
166        case ${arch} in
167                i[3-6]86)
168                        arch="x86";;
169        esac
170        case ${arch} in
171                x86_64 | amd64)
172                        PLATFORM_LIST="${X86_64_PLATFORMS}"
173                        if [ $BITS -ne 32 ]; then
174                            [ -z $SUFFIX ] && SUFFIX="_64"
175                        fi
176                        ;;
177                #ia64)
178                #        PLATFORM_LIST="${X86_64_PLATFORMS}"
179                #        TARGET="$TARGET-ia64";;
180                x86)
181                        PLATFORM_LIST="${X86_PLATFORMS}";;
182                arm*)
183                        PLATFORM_LIST="${ARM_PLATFORMS}";;
184                *)
185                        PLATFORM_LIST="${LINUX_PLATFORMS}";;
186        esac
187        echo "Building ${TARGET} .sos for ${arch}";;
188netbsd*|freebsd*|openbsd*)
189        NAME="libjbigi"
190        TYPE="so"
191        PLATFORM_LIST=
192        arch=$(uname -m | cut -f1 -d" ")
193        case ${arch} in
194                i[3-6]86)
195                        arch="x86";;
196        esac
197        case ${arch} in
198                x86_64|amd64)
199                        PLATFORM_LIST="${X86_64_PLATFORMS}"
200                       [ -z $SUFFIX ] && SUFFIX="_64";;
201                #ia64)
202                #        PLATFORM_LIST="${X86_64_PLATFORMS}"
203                #        SUFFIX="{SYS}-ia64";;
204                x86)
205                        PLATFORM_LIST="${X86_PLATFORMS}";;
206                *)
207                        case ${TARGET} in
208                                netbsd)
209                                        PLATFORM_LIST="${NETBSD_PLATFORMS}";;
210                                openbsd)
211                                        PLATFORM_LIST="${OPENBSD_PLATFORMS}";;
212                                freebsd)
213                                        PLATFORM_LIST="${FREEBSD_PLATFORMS}";;
214                                *)
215                                        echo "Unsupported build environment"
216                                        exit 1;;
217                        esac
218        esac
219        echo "Building ${TARGET} .sos for ${arch}";;
220*)
221        echo "Unsupported build environment"
222        exit;;
223esac
224
225#####################
226# In the below functions:
227# $1 = gmp version
228# $2 = platform: such as athlon64
229# $3 = basename: "jbigi" on Windows, "libjbigi" everywhere else
230# $4 = type/extension: windows = "dll". osx = "jnilib". Everything else = "so"
231# $5 = target: "linux", "freebsd", "kfreebsd", "osx", "windows", etc.
232# $6 = suffix: null if 32bit, _64 if 64bit
233
234make_static () {
235        echo "Attempting .${4} creation for ${3}${5}${2}${6}"
236        ../../build_jbigi.sh static || return 1
237        PLATFORM="${2}"
238        eval TRANSLATED_NAME=\$TRANSLATE_NAME_$PLATFORM
239        if [ -n "$TRANSLATED_NAME" ]; then
240            PLATFORM="${TRANSLATED_NAME}"
241        fi
242        cp ${3}.${4} ../../lib/net/i2p/util/${3}${5}${PLATFORM}${6}.${4}
243        return 0
244}
245
246make_file () {
247        # Nonfatal bail out on Failed build.
248        echo "Attempting build for ${3}${5}${2}"
249        make -j && return 0
250        cd ..
251        rm -R "$2"
252        printf "\n\nFAILED! ${3}${5}${2} not made.\a"
253        sleep 10
254        return 1
255}
256
257configure_file () {
258        printf "\n\n\nAttempting configure for ${3}${5}${2}${6}\n\n\n"
259        if [ $BITS -eq 32 ] && [ "$2"  = "none" ]; then
260            unset ABI
261        elif [ $BITS -eq 32 ] && [ "$2" != "none" ]; then
262            export ABI=32
263        fi
264
265        # Nonfatal bail out on unsupported platform.
266        (cd ../../gmp-${1}; make clean)
267        if [ $(echo $TARGET| grep -q osx) ]; then
268                ../../gmp-${1}/configure --build=${2}-apple-darwin --with-pic && return 0
269        else
270                ../../gmp-${1}/configure --build=${2} --with-pic && return 0
271        fi
272        cd ..
273        rm -R "$2"
274        printf "\n\nSorry, ${3}${5}${2} is not supported on your build environment.\a"
275        sleep 10
276        return 1
277}
278
279build_file () {
280        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
281        printf "\n\n\nError building static!\n\n\a"
282        sleep 10
283        return 1
284}
285
286if [ ! -d gmp-$VER ]; then
287  echo "Extracting GMP Version $VER ..."
288  if [ -e gmp-$VER.tar.bz2 ]; then
289    tar -xjf gmp-$VER.tar.bz2 || ( echo "Error in tarball file!" >&2 ; exit 1 )
290  else
291    echo "ERROR: gmp tarball not found in current directory" >&2
292    exit 1
293  fi
294fi
295
296if [ ! -d bin ]; then
297        mkdir bin
298fi
299if [ ! -d lib/net/i2p/util ]; then
300        mkdir -p lib/net/i2p/util
301fi
302
303
304for x in $PLATFORM_LIST
305do
306        (
307                if [ ! -d bin/$x ]; then
308                        mkdir bin/$x
309                        cd bin/$x
310                else
311                        cd bin/$x
312                        rm -Rf *
313                fi
314
315                build_file "$VER" "$x" "$NAME" "$TYPE" "-$TARGET-" "$SUFFIX"
316        )
317done
318
319echo "Success!"
320exit 0
321
322# vim:fenc=utf-8:ai:si:ts=4:sw=4:et:nu
Note: See TracBrowser for help on using the repository browser.