source: core/c/jcpuid/build.sh @ 8807787

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

remove alert character output from build script printfs

  • Property mode set to 100755
File size: 4.3 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;;
23esac
24
25
26if [ -z $BITS ]; then
27  UNAME="$(uname -a)"
28  if test "${UNAME#*x86_64}" != "x86_&4"; then
29    BITS=64
30  elif test "${UNAME#*i386}" != "i386"; then
31    BITS=32
32  elif test "${UNAME#*i686}" != "i686"; then
33    BITS=32
34  elif test "${UNAME#*armv6}" != "armv6"; then
35    BITS=32
36  elif test "${UNAME#*armv7}" != "armv7"; then
37    BITS=32
38  elif test "${UNAME#*aarch32}" != "aarch32"; then
39    BITS=32
40  elif test "${UNAME#*aarch64}" != "aarch64"; then
41    BITS=64
42  else
43 
44    echo "Unable to detect default setting for BITS variable"
45    exit
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
58if [ $BITS -eq 32 ]; then
59  export ABI=32
60  export CFLAGS="-m32 -mtune=i686 -march=i686"
61  export LDFLAGS="-m32"
62elif [ $BITS -eq 64 ]; then
63  export ABI=64
64  export CFLAGS="-m64 -mtune=generic"
65  export LDFLAGS="-m64"
66else
67  printf "BITS value \"$BITS\" not valid, please select 32 or 64\n" >&2
68  exit 1
69fi
70
71[ -z $ARCH ] && case `uname -m` in
72    x86_64*|amd64)
73        if [ $BITS -eq 64 ]; then
74          ARCH="x86_64"
75        else
76          ARCH="x86"
77        fi
78        ;;
79    ia64*)
80        ARCH="ia64";;
81    i?86*)
82        ARCH="x86";;
83    # Solaris x86
84    i86pc)
85        if [ $BITS -eq 64 ]; then
86          ARCH="x86_64"
87        else
88          ARCH="x86"
89        fi
90        ;;
91    *)
92        echo "Unsupported build environment. jcpuid is only used on x86 systems."
93        exit 0;;
94esac
95
96
97case $TARGET in
98    MINGW*|CYGWIN*|windows*)
99        [ -z $JAVA_HOME ] && JAVA_HOME="/c/software/j2sdk1.4.2_05"
100        CFLAGS="${CFLAGS} -Wall"
101        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/$HOST/"
102        LDFLAGS="${LDFLAGS} -shared -static -static-libgcc -Wl,--kill-at"
103        LIBFILE="lib/freenet/support/CPUInformation/jcpuid-${ARCH}-windows.dll";;
104    Darwin*)
105        JAVA_HOME=$(/usr/libexec/java_home)
106        CFLAGS="${CFLAGS} -fPIC -Wall -arch x86_64 -arch i386"
107        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/dawrin/"
108        LDFLAGS="${LDFLAGS} -dynamiclib -framework JavaVM"
109        LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-darwin.jnilib";;
110    Linux*|OpenBSD*|NetBSD*|*FreeBSD*|SunOS*)
111        KFREEBSD=0
112        UNIXTYPE="`uname -s | tr [A-Z] [a-z]`"
113        if [ ${UNIXTYPE} = "sunos" ]; then
114            UNIXTYPE="solaris"
115        elif [ ${UNIXTYPE} = "gnu/kfreebsd" ]; then
116            UNIXTYPE="linux"
117            KFREEBSD=1
118        fi
119        # If JAVA_HOME isn't set, try to figure it out on our own
120        [ -z $JAVA_HOME ] && . ../find-java-home
121        # JAVA_HOME being set doesn't guarantee that it's usable
122        if [ ! -f "$JAVA_HOME/include/jni.h" ]; then
123            echo "Please ensure you have a Java SDK installed" >&2
124            echo "and/or set JAVA_HOME then re-run this script." >&2
125            exit 1
126        fi
127
128        LDFLAGS="${LDFLAGS} -shared -Wl,-soname,libjcpuid-${ARCH}-${UNIXTYPE}.so"
129        if [ $KFREEBSD -eq 1 ]; then
130            LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-${ARCH}-kfreebsd.so"
131        else
132            LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-${ARCH}-${UNIXTYPE}.so"
133        fi
134        CFLAGS="${CFLAGS} -fPIC -Wall"
135        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include -I${JAVA_HOME}/include/${UNIXTYPE}";;
136esac
137
138echo "CC_PREFIX:$CC_PREFIX"
139echo "TARGET:$TARGET"
140echo "HOST:$HOST"
141echo "ARCH:$ARCH"
142echo "CFLAGS:$CFLAGS"
143echo "LDFLAGS:$LDFLAGS"
144echo ""
145
146echo "Compiling C code..."
147rm -f ${LIBFILE}
148${CC_PREFIX}${CC} ${CFLAGS} ${LDFLAGS} ${INCLUDES} src/*.c -o ${LIBFILE} || (echo "Failed to compile ${LIBFILE}"; exit 1)
149${CC_PREFIX}strip ${LIBFILE} || (echo "Failed to strip ${LIBFILE}" ; exit 1)
150echo Built `dirname $0`/${LIBFILE}
Note: See TracBrowser for help on using the repository browser.