From b0ce258925cc9542ca0214f5a848a85e8c417d11 Mon Sep 17 00:00:00 2001 From: kytv Date: Tue, 27 Sep 2011 08:25:32 +0000 Subject: [PATCH] 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 --- core/c/jcpuid/build.sh | 131 +++++++++++++++++++++++++--------------- core/c/jcpuid/mbuild.sh | 90 --------------------------- core/c/mbuild.sh | 13 +++- 3 files changed, 94 insertions(+), 140 deletions(-) delete mode 100755 core/c/jcpuid/mbuild.sh diff --git a/core/c/jcpuid/build.sh b/core/c/jcpuid/build.sh index 836ea73d0..77c262a4a 100755 --- a/core/c/jcpuid/build.sh +++ b/core/c/jcpuid/build.sh @@ -1,61 +1,96 @@ -#/bin/sh +#!/bin/sh + +cd `dirname $0` case `uname -sr` in -MINGW*) - echo "Building windows .dll's";; -SunOS*) - echo "Building solaris .so's";; -CYGWIN*) - echo "Building windows .dll's";; -Linux*) - echo "Building linux .so's";; -FreeBSD*) - echo "Building freebsd .so's";; -*kFreeBSD*) - echo "Building kFreebsd .so's";; -*) - echo "Unsupported build environment" - exit;; + MINGW*|CYGWIN*) + echo "Building windows .dlls";; + SunOS*) + echo "Building solaris .sos";; + Darwin*) + echo "Building Darwin jnilibs";; + Linux*|NetBSD*|OpenBSD*|*FreeBSD*) + echo "Building `uname -s |tr [A-Z] [a-z]` .sos";; + *) + echo "Unsupported build environment" + exit;; esac rm -rf lib -mkdir lib -mkdir lib/freenet -mkdir lib/freenet/support -mkdir lib/freenet/support/CPUInformation +mkdir -p lib/freenet/support/CPUInformation CC="gcc" case `uname -sr` in -MINGW*) - JAVA_HOME="/c/software/j2sdk1.4.2_05" - COMPILEFLAGS="-Wall" - INCLUDES="-I. -Iinclude -I$JAVA_HOME/include/ -I$JAVA_HOME/include/win32/" - LINKFLAGS="-shared -static -static-libgcc -Wl,--kill-at" - LIBFILE="lib/freenet/support/CPUInformation/jcpuid-x86-windows.dll";; -SunOS*) + MINGW*|CYGWIN*) + JAVA_HOME="/c/software/j2sdk1.4.2_05" COMPILEFLAGS="-Wall" - INCLUDES="-I. -Iinclude -I$JAVA_HOME/include/ -I$JAVA_HOME/include/solaris/" - LINKFLAGS="-shared -static -Wl,-soname,libjcpuid-x86-solaris.so" - LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-solaris.so";; -FreeBSD*) - COMPILEFLAGS="-Wall" - INCLUDES="-I. -Iinclude -I$JAVA_HOME/include/ -I$JAVA_HOME/include/freebsd/" - LINKFLAGS="-shared -static -Wl,-soname,libjcpuid-x86-freebsd.so" - LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-freebsd.so";; -*kFreeBSD*|Linux*) - COMPILEFLAGS="-fPIC -Wall" - INCLUDES="-I. -Iinclude -I$JAVA_HOME/include -I$JAVA_HOME/include/linux" - LINKFLAGS="-shared -Wl,-soname,libjcpuid-x86-linux.so" - LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-linux.so";; + INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/win32/" + LINKFLAGS="-shared -static -static-libgcc -Wl,--kill-at" + LIBFILE="lib/freenet/support/CPUInformation/jcpuid-x86-windows.dll";; + Darwin*) + JAVA_HOME=$(/usr/libexec/java_home) + COMPILEFLAGS="-fPIC -Wall -arch x86_64 -arch i386" + INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/" + LINKFLAGS="-dynamiclib -framework JavaVM" + LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-darwin.jnilib";; + Linux*|OpenBSD*|NetBSD*|*FreeBSD*|SunOS*) + UNIXTYPE="`uname -s | tr [A-Z] [a-z]`" + if [ ${UNIXTYPE} = "sunos" ]; then + UNIXTYPE="solaris" + elif [ ${UNIXTYPE} = "kfreebsd" ]; then + UNIXTYPE="linux" + fi + + # If JAVA_HOME is set elsewhere, obey it. Otherwise we'll try to + # deduce its location ourselves. + if [ -z "${JAVA_HOME}" ]; then + if [ ${UNIXTYPE} = "freebsd" ]; then + if [ -d /usr/local/openjdk6 ]; then + JAVA_HOME="/usr/local/openjdk6" + elif [ -d /usr/local/openjdk7 ]; then + JAVA_HOME="/usr/local/openjdk7" + fi + elif [ ${UNIXTYPE} = "openbsd" ]; then # The default in 4.9 + if [ -d /usr/local/jdk-1.7.0 ]; then + JAVA_HOME="/usr/local/jdk-1.7.0" + fi + elif [ ${UNIXTYPE} = "netbsd" ]; then + if [ -d /usr/pkg/java/openjdk7 ]; then + JAVA_HOME="/usr/pkg/java/openjdk7" + fi + elif [ ${UNIXTYPE} = "linux" -a -e /etc/debian_version ]; then + if [ -d /usr/lib/jvm/default-java ]; then + JAVA_HOME="/usr/lib/jvm/default-java" + fi + fi + fi + case `uname -m` in + x86_64*|amd64) + ARCH="x86_64";; + ia64*) + ARCH="ia64";; + i?86*) + ARCH="x86";; + *) + echo "Unsupported build environment. jcpuid is only used on x86 systems." + exit 1;; + esac + + # JAVA_HOME being set doesn't guarantee that it's usable + if [ ! -r ${JAVA_HOME}/include/jni.h ]; then + echo "Please ensure you have a Java SDK installed" + echo "and/or set JAVA_HOME then re-run this script." + exit 1 + fi + LINKFLAGS="-shared -Wl,-soname,libjcpuid-${ARCH}-${UNIXTYPE}.so" + LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-${ARCH}-${UNIXTYPE}.so" + COMPILEFLAGS="-fPIC -Wall" + INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include -I${JAVA_HOME}/include/${UNIXTYPE}";; esac echo "Compiling C code..." -rm -f $LIBFILE -$CC $COMPILEFLAGS $LINKFLAGS $INCLUDES src/*.c -o $LIBFILE -strip $LIBFILE -echo Built $LIBFILE - -#g++ -shared -static -static-libgcc -Iinclude -I$JAVA_HOME/include \ -# -I$JAVA_HOME/include/linux src/*.cpp \ -# -o lib/freenet/support/CPUInformation/libjcpuid-x86-linux.so +rm -f ${LIBFILE} +${CC} ${COMPILEFLAGS} ${LINKFLAGS} ${INCLUDES} src/*.c -o ${LIBFILE} || (echo "Failed to compile ${LIBFILE}"; exit 1) +strip ${LIBFILE} || (echo "Failed to strip ${LIBFILE}" ; exit 1) +echo Built `dirname $0`/${LIBFILE} diff --git a/core/c/jcpuid/mbuild.sh b/core/c/jcpuid/mbuild.sh deleted file mode 100755 index 14dec0309..000000000 --- a/core/c/jcpuid/mbuild.sh +++ /dev/null @@ -1,90 +0,0 @@ -#/bin/sh - -case `uname -sr` in -MINGW*) - echo "Building windows .dlls";; -CYGWIN*) - echo "Building windows .dlls";; -Linux*) - echo "Building linux .sos";; -NetBSD*|OpenBSD*|FreeBSD*) - echo "Building `uname -s |tr [A-Z] [a-z]` .sos";; -Darwin*) - echo "Building OSX jnilibs";; -*) - echo "Unsupported build environment" - exit;; -esac - -rm -rf lib -#mkdir lib -#mkdir lib/freenet -#mkdir lib/freenet/support -mkdir -p lib/freenet/support/CPUInformation - -CC="gcc" - -case `uname -sr` in -MINGW*) - JAVA_HOME="/c/software/j2sdk1.4.2_05" - COMPILEFLAGS="-Wall" - INCLUDES="-I. -Iinclude -I$JAVA_HOME/include/ -I$JAVA_HOME/include/win32/" - LINKFLAGS="-shared -static -static-libgcc -Wl,--kill-at" - LIBFILE="lib/freenet/support/CPUInformation/jcpuid-x86-windows.dll";; -Darwin*) - JAVA_HOME=$(/usr/libexec/java_home) - COMPILEFLAGS="-fPIC -Wall -arch x86_64 -arch i386" - INCLUDES="-I. -Iinclude -I$JAVA_HOME/include/" - LINKFLAGS="-dynamiclib -framework JavaVM" - LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-darwin.jnilib";; -Linux*|OpenBSD*|NetBSD*|FreeBSD*|SunOS*) - UNIXTYPE="`uname -s | tr [A-Z] [a-z]`" - if [ $UNIXTYPE = "sunos" ]; then - UNIXTYPE="solaris" - elif [ $UNIXTYPE = "freebsd" ]; then - if [ -d /usr/local/openjdk6 ]; then - JAVA_HOME="/usr/local/openjdk6" - elif [ -d /usr/local/openjdk7 ]; then - JAVA_HOME="/usr/local/openjdk7" - fi - elif [ $UNIXTYPE = "openbsd" ]; then - if [ -d /usr/local/jdk-1.7.0 ]; then - JAVA_HOME="/usr/local/jdk-1.7.0" - fi - elif [ $UNIXTYPE = "netbsd" ]; then - if [ -d /usr/pkg/java/openjdk7 ]; then - JAVA_HOME="/usr/pkg/java/openjdk7" - fi - elif [ $UNIXTYPE = "linux" -a -e /etc/debian_version ]; then - if [ -d /usr/lib/jvm/default-java ]; then - JAVA_HOME="/usr/lib/jvm/default-java" - fi - fi - case `uname -m` in - x86_64*|amd64) - LINKFLAGS="-shared -Wl,-soname,libjcpuid-x86_64-${UNIXTYPE}.so" - LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86_64-${UNIXTYPE}.so";; - ia64*) - LINKFLAGS="-shared -Wl,-soname,libjcpuid-x86-${UNIXTYPE}.so" - LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-ia64-${UNIXTYPE}.so";; - i?86*) - LINKFLAGS="-shared -Wl,-soname,libjcpuid-x86-${UNIXTYPE}.so" - LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-${UNIXTYPE}.so";; - *) - echo "Unsupported build environment" - exit;; - esac - COMPILEFLAGS="-fPIC -Wall" - INCLUDES="-I. -Iinclude -I$JAVA_HOME/include -I$JAVA_HOME/include/${UNIXTYPE}";; - -esac - -echo "Compiling C code..." -rm -f $LIBFILE -$CC $COMPILEFLAGS $LINKFLAGS $INCLUDES src/*.c -o $LIBFILE -strip $LIBFILE -echo Built $LIBFILE - -#g++ -shared -static -static-libgcc -Iinclude -I$JAVA_HOME/include \ -# -I$JAVA_HOME/include/linux src/*.cpp \ -# -o lib/freenet/support/CPUInformation/libjcpuid-x86-linux.so diff --git a/core/c/mbuild.sh b/core/c/mbuild.sh index c81c3929b..e57fc75b4 100755 --- a/core/c/mbuild.sh +++ b/core/c/mbuild.sh @@ -1,7 +1,16 @@ -#/usr/bin/env bash +#!/bin/sh +##/usr/bin/env bash # Automatic build of so files, ignores failed builds. # Place latest gmp tarball in the jbigi dir, and exec this script. +if [ -z "$BASH_VERSION" ]; then + echo "This script needs to be run with Bash." + echo + echo "Please install bash and then run this script with" + echo "bash $0" + exit 1 +fi + #JBIGI=../../../installer/lib/jbigi/jbigi.jar #if [ -f jbigi.jarx ] ; then @@ -10,7 +19,7 @@ rm -f t/* jcpuid/lib/freenet/support/CPUInformation/* jbigi/lib/net/i2p/util/* -( cd jcpuid ; ./mbuild.sh ) +( cd jcpuid ; ./build.sh ) ( cd jbigi ; ./mbuild-all.sh ) rm -Rf t