source: core/c/jcpuid/build.sh @ 1412dbd

Last change on this file since 1412dbd was 3abc777, checked in by zzz <zzz@…>, 3 years ago

Debian: Fix builds for x32 (ticket #2076)
Incorporate patches 2 and 3 into build scripts

  • Property mode set to 100755
File size: 4.8 KB
Line 
1#!/bin/sh
2
3cd `dirname $0`
4rm -rf lib
5mkdir -p lib/freenet/support/CPUInformation
6
7[ -z $CC_PREFIX ] && CC_PREFIX=""
8[ -z $TARGET ] && TARGET="$(uname -s)"
9[ -z $HOST ] && HOST="$(uname -s | tr '[:upper:]' '[:lower:]')"
10
11case $TARGET in
12    MINGW*|CYGWIN*|windows*)
13        echo "Building windows .dlls";;
14    SunOS*)
15        echo "Building solaris .sos";;
16    Darwin*)
17        echo "Building Darwin jnilibs";;
18    Linux*|NetBSD*|OpenBSD*|*FreeBSD*)
19        echo "Building `uname -s |tr [A-Z] [a-z]` .sos";;
20    *)
21        echo "Unsupported build environment"
22        exit 1;;
23esac
24
25
26if [ -z $BITS ]; then
27  UNAME="$(uname -m)"
28  if test "${UNAME#*x86_64}" != "$UNAME"; then
29    BITS=64
30  elif test "${UNAME#*i386}" != "$UNAME"; then
31    BITS=32
32  elif test "${UNAME#*i686}" != "$UNAME"; then
33    BITS=32
34  elif test "${UNAME#*armv6}" != "$UNAME"; then
35    BITS=32
36  elif test "${UNAME#*armv7}" != "$UNAME"; then
37    BITS=32
38  elif test "${UNAME#*aarch32}" != "$UNAME"; then
39    BITS=32
40  elif test "${UNAME#*aarch64}" != "$UNAME"; then
41    BITS=64
42  else
43 
44    echo "Unable to detect default setting for BITS variable"
45    exit 1
46  fi
47
48  printf "BITS variable not set, $BITS bit system detected\n" >&2
49fi
50
51
52if [ -z $CC ]; then
53  export CC="gcc"
54  printf "CC variable not set, defaulting to $CC\n" >&2
55fi
56
57
58# Debian builds are presumed to be native, we don't need the -mxx flag unless cross-compile,
59# and this breaks the x32 build
60if [ -z "$DEBIANVERSION" ] ; then
61    if [ $BITS -eq 32 ]; then
62      export ABI=32
63      export CFLAGS="-m32 -mtune=i686 -march=i686"
64      export LDFLAGS="-m32"
65    elif [ $BITS -eq 64 ]; then
66      export ABI=64
67      export CFLAGS="-m64 -mtune=generic"
68      export LDFLAGS="-m64"
69    else
70      printf "BITS value \"$BITS\" not valid, please select 32 or 64\n" >&2
71      exit 1
72    fi
73fi
74
75[ -z $ARCH ] && case `uname -m` in
76    x86_64*|amd64)
77        if [ $BITS -eq 64 ]; then
78          ARCH="x86_64"
79        else
80          ARCH="x86"
81        fi
82        ;;
83    ia64*)
84        ARCH="ia64";;
85    i?86*)
86        ARCH="x86";;
87    # Solaris x86
88    i86pc)
89        if [ $BITS -eq 64 ]; then
90          ARCH="x86_64"
91        else
92          ARCH="x86"
93        fi
94        ;;
95    *)
96        echo "Unsupported build environment. jcpuid is only used on x86 systems."
97        exit 0;;
98esac
99
100
101case $TARGET in
102    MINGW*|CYGWIN*|windows*)
103        [ -z $JAVA_HOME ] && JAVA_HOME="/c/software/j2sdk1.4.2_05"
104        CFLAGS="${CFLAGS} -Wall"
105        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/$HOST/"
106        LDFLAGS="${LDFLAGS} -shared -static -static-libgcc -Wl,--kill-at"
107        LIBFILE="lib/freenet/support/CPUInformation/jcpuid-${ARCH}-windows.dll";;
108    Darwin*)
109        JAVA_HOME=$(/usr/libexec/java_home)
110        CFLAGS="${CFLAGS} -fPIC -Wall -arch x86_64 -arch i386"
111        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/darwin/"
112        LDFLAGS="${LDFLAGS} -dynamiclib -framework JavaVM"
113        LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86_64-osx.jnilib";;
114    Linux*|OpenBSD*|NetBSD*|*FreeBSD*|SunOS*)
115        KFREEBSD=0
116        UNIXTYPE="`uname -s | tr [A-Z] [a-z]`"
117        if [ ${UNIXTYPE} = "sunos" ]; then
118            UNIXTYPE="solaris"
119        elif [ ${UNIXTYPE} = "gnu/kfreebsd" ]; then
120            UNIXTYPE="linux"
121            KFREEBSD=1
122        fi
123        # If JAVA_HOME isn't set, try to figure it out on our own
124        [ -z $JAVA_HOME ] && . ../find-java-home
125        # JAVA_HOME being set doesn't guarantee that it's usable
126        if [ ! -f "$JAVA_HOME/include/jni.h" ]; then
127            echo "Please ensure you have a Java SDK installed" >&2
128            echo "and/or set JAVA_HOME then re-run this script." >&2
129            exit 1
130        fi
131
132        # rename jcpuid, formerly 0003-rename-jcpuid.patch
133        if [ "$DEBIANVERSION" ] ; then
134            LDFLAGS="${LDFLAGS} -shared -Wl,-soname,libjcpuid.so"
135            LIBFILE="../jbigi/libjcpuid.so"
136        else
137            LDFLAGS="${LDFLAGS} -shared -Wl,-soname,libjcpuid-${ARCH}-${UNIXTYPE}.so"
138            if [ $KFREEBSD -eq 1 ]; then
139                LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-${ARCH}-kfreebsd.so"
140            else
141                LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-${ARCH}-${UNIXTYPE}.so"
142            fi
143        fi
144        CFLAGS="${CFLAGS} -fPIC -Wall"
145        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include -I${JAVA_HOME}/include/${UNIXTYPE}";;
146esac
147
148echo "CC_PREFIX:$CC_PREFIX"
149echo "TARGET:$TARGET"
150echo "HOST:$HOST"
151echo "ARCH:$ARCH"
152echo "CFLAGS:$CFLAGS"
153echo "LDFLAGS:$LDFLAGS"
154echo ""
155
156echo "Compiling C code..."
157rm -f ${LIBFILE}
158${CC_PREFIX}${CC} ${CFLAGS} ${LDFLAGS} ${INCLUDES} src/*.c -o ${LIBFILE} || (echo "Failed to compile ${LIBFILE}"; exit 1)
159${CC_PREFIX}strip ${LIBFILE} || (echo "Failed to strip ${LIBFILE}" ; exit 1)
160echo Built `dirname $0`/${LIBFILE}
Note: See TracBrowser for help on using the repository browser.