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

Last change on this file since b0ce258 was b0ce258, checked in by kytv <kytv@…>, 9 years ago

jcpuid build scripts:

  • merge x64 improvements from mbuild.sh into build.sh
  • drop mbuild.sh
  • add logic to determine the location of JAVA_HOME if not defined.
  • update core/c/mbuild to call jcpuid/build.sh
  • Property mode set to 100755
File size: 3.5 KB
Line 
1#!/bin/sh
2
3cd `dirname $0`
4
5case `uname -sr` in
6    MINGW*|CYGWIN*)
7        echo "Building windows .dlls";;
8    SunOS*)
9        echo "Building solaris .sos";;
10    Darwin*)
11        echo "Building Darwin jnilibs";;
12    Linux*|NetBSD*|OpenBSD*|*FreeBSD*)
13        echo "Building `uname -s |tr [A-Z] [a-z]` .sos";;
14    *)
15        echo "Unsupported build environment"
16        exit;;
17esac
18
19rm -rf lib
20mkdir -p lib/freenet/support/CPUInformation
21
22CC="gcc"
23
24case `uname -sr` in
25    MINGW*|CYGWIN*)
26        JAVA_HOME="/c/software/j2sdk1.4.2_05"
27        COMPILEFLAGS="-Wall"
28        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/win32/"
29        LINKFLAGS="-shared -static -static-libgcc -Wl,--kill-at"
30        LIBFILE="lib/freenet/support/CPUInformation/jcpuid-x86-windows.dll";;
31    Darwin*)
32        JAVA_HOME=$(/usr/libexec/java_home)
33        COMPILEFLAGS="-fPIC -Wall -arch x86_64 -arch i386"
34        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/"
35        LINKFLAGS="-dynamiclib -framework JavaVM"
36        LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-darwin.jnilib";;
37    Linux*|OpenBSD*|NetBSD*|*FreeBSD*|SunOS*)
38        UNIXTYPE="`uname -s | tr [A-Z] [a-z]`"
39        if [ ${UNIXTYPE} = "sunos" ]; then
40            UNIXTYPE="solaris"
41        elif [ ${UNIXTYPE} = "kfreebsd" ]; then
42            UNIXTYPE="linux"
43        fi
44
45        # If JAVA_HOME is set elsewhere, obey it. Otherwise we'll try to
46        # deduce its location ourselves.
47        if [ -z "${JAVA_HOME}" ]; then
48            if [ ${UNIXTYPE} = "freebsd" ]; then
49                if [ -d /usr/local/openjdk6 ]; then
50                    JAVA_HOME="/usr/local/openjdk6"
51                elif [ -d /usr/local/openjdk7 ]; then
52                    JAVA_HOME="/usr/local/openjdk7"
53                fi
54            elif [ ${UNIXTYPE} = "openbsd" ]; then # The default in 4.9
55                if [ -d /usr/local/jdk-1.7.0 ]; then
56                    JAVA_HOME="/usr/local/jdk-1.7.0"
57                fi
58            elif [ ${UNIXTYPE} = "netbsd" ]; then
59                if [ -d /usr/pkg/java/openjdk7 ]; then
60                    JAVA_HOME="/usr/pkg/java/openjdk7"
61                fi
62            elif [ ${UNIXTYPE} = "linux" -a -e /etc/debian_version ]; then
63                if [ -d /usr/lib/jvm/default-java ]; then
64                    JAVA_HOME="/usr/lib/jvm/default-java"
65                fi
66            fi
67        fi
68        case `uname -m` in
69            x86_64*|amd64)
70                ARCH="x86_64";;
71            ia64*)
72                ARCH="ia64";;
73            i?86*)
74                ARCH="x86";;
75            *)
76                echo "Unsupported build environment. jcpuid is only used on x86 systems."
77                exit 1;;
78        esac
79
80        # JAVA_HOME being set doesn't guarantee that it's usable
81        if [ ! -r ${JAVA_HOME}/include/jni.h ]; then
82            echo "Please ensure you have a Java SDK installed"
83            echo "and/or set JAVA_HOME then re-run this script."
84            exit 1
85        fi
86        LINKFLAGS="-shared -Wl,-soname,libjcpuid-${ARCH}-${UNIXTYPE}.so"
87        LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-${ARCH}-${UNIXTYPE}.so"
88        COMPILEFLAGS="-fPIC -Wall"
89        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include -I${JAVA_HOME}/include/${UNIXTYPE}";;
90esac
91
92echo "Compiling C code..."
93rm -f ${LIBFILE}
94${CC} ${COMPILEFLAGS} ${LINKFLAGS} ${INCLUDES} src/*.c -o ${LIBFILE} || (echo "Failed to compile ${LIBFILE}"; exit 1)
95strip ${LIBFILE} || (echo "Failed to strip ${LIBFILE}" ; exit 1)
96echo Built `dirname $0`/${LIBFILE}
Note: See TracBrowser for help on using the repository browser.