Changeset c9818e6 for core/c


Ignore:
Timestamp:
Jan 26, 2016 12:06:39 AM (5 years ago)
Author:
dev <dev@…>
Branches:
master
Children:
eb696c8
Parents:
305f45fb
Message:

Improved jcpuid build script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/c/jcpuid/build.sh

    r305f45fb rc9818e6  
    22
    33cd `dirname $0`
     4rm -rf lib
     5mkdir -p lib/freenet/support/CPUInformation
    46
    5 case `uname -s` in
    6     MINGW*|CYGWIN*)
     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*)
    713        echo "Building windows .dlls";;
    814    SunOS*)
     
    1723esac
    1824
    19 rm -rf lib
    20 mkdir -p lib/freenet/support/CPUInformation
    2125
    22 [ -z $CC ] && CC="gcc"
     26if [ -z $BITS ]; then
     27  BITS=64
     28  printf "\aBITS variable not set, defaulting to $BITS\n\a" >&2
     29fi
    2330
    24 case `uname -s` 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";;
     31if [ -z $CC ]; then
     32  export CC="gcc"
     33  printf "\aCC variable not set, defaulting to $CC\n\a" >&2
     34fi
     35
     36
     37if [ $BITS -eq 32 ]; then
     38  export ABI=32
     39  export CFLAGS="-m32"
     40  export LDFLAGS="-m32"
     41elif [ $BITS -eq 64 ]; then
     42  export ABI=64
     43  export CFLAGS="-m64"
     44  export LDFLAGS="-m64"
     45else
     46  printf "\aBITS value \"$BITS\" not valid, please select 32 or 64\n\a" >&2
     47  exit 1
     48fi
     49
     50[ -z $ARCH ] && case `uname -m` in
     51    x86_64*|amd64)
     52        if [ $BITS -eq 64 ]; then
     53          ARCH="x86_64"
     54        else
     55          ARCH="x86"
     56        fi
     57        ;;
     58    ia64*)
     59        ARCH="ia64";;
     60    i?86*)
     61        ARCH="x86";;
     62    # Solaris x86
     63    i86pc)
     64        if [ $BITS -eq 64 ]; then
     65          ARCH="x86_64"
     66        else
     67          ARCH="x86"
     68        fi
     69        ;;
     70    *)
     71        echo "Unsupported build environment. jcpuid is only used on x86 systems."
     72        exit 0;;
     73esac
     74
     75
     76case $TARGET in
     77    MINGW*|CYGWIN*|windows*)
     78        [ -z $JAVA_HOME ] && JAVA_HOME="/c/software/j2sdk1.4.2_05"
     79        CFLAGS="${CFLAGS} -Wall"
     80        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/$HOST/"
     81        LDFLAGS="${LDFLAGS} -shared -static -static-libgcc -Wl,--kill-at"
     82        LIBFILE="lib/freenet/support/CPUInformation/jcpuid-${ARCH}-windows.dll";;
    3183    Darwin*)
    3284        JAVA_HOME=$(/usr/libexec/java_home)
    33         COMPILEFLAGS="-fPIC -Wall -arch x86_64 -arch i386"
     85        CFLAGS="${CFLAGS} -fPIC -Wall -arch x86_64 -arch i386"
    3486        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include/"
    35         LINKFLAGS="-dynamiclib -framework JavaVM"
     87        LDFLAGS="${LDFLAGS} -dynamiclib -framework JavaVM"
    3688        LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-x86-darwin.jnilib";;
    3789    Linux*|OpenBSD*|NetBSD*|*FreeBSD*|SunOS*)
     
    53105        fi
    54106
    55         # Abort script on uncaught errors
    56         set -e
    57 
    58         case `uname -m` in
    59             x86_64*|amd64)
    60                 ARCH="x86_64";;
    61             ia64*)
    62                 ARCH="ia64";;
    63             i?86*)
    64                 ARCH="x86";;
    65             # Solaris x86
    66             i86pc)
    67                 if $(echo $CC | grep -q '\-m64') ; then
    68                     ARCH="x86_64"
    69                 else
    70                     ARCH="x86"
    71                 fi
    72                 ;;
    73             *)
    74                 echo "Unsupported build environment. jcpuid is only used on x86 systems."
    75                 exit 0;;
    76         esac
    77 
    78         LINKFLAGS="-shared -Wl,-soname,libjcpuid-${ARCH}-${UNIXTYPE}.so"
     107        LDFLAGS="${LDFLAGS} -shared -Wl,-soname,libjcpuid-${ARCH}-${UNIXTYPE}.so"
    79108        if [ $KFREEBSD -eq 1 ]; then
    80109            LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-${ARCH}-kfreebsd.so"
     
    82111            LIBFILE="lib/freenet/support/CPUInformation/libjcpuid-${ARCH}-${UNIXTYPE}.so"
    83112        fi
    84         COMPILEFLAGS="-fPIC -Wall"
     113        CFLAGS="${CFLAGS} -fPIC -Wall"
    85114        INCLUDES="-I. -Iinclude -I${JAVA_HOME}/include -I${JAVA_HOME}/include/${UNIXTYPE}";;
    86115esac
    87116
     117echo "CC_PREFIX:$CC_PREFIX"
     118echo "TARGET:$TARGET"
     119echo "HOST:$HOST"
     120echo "ARCH:$ARCH"
     121
    88122echo "Compiling C code..."
    89123rm -f ${LIBFILE}
    90 ${CC} ${COMPILEFLAGS} ${LINKFLAGS} ${INCLUDES} src/*.c -o ${LIBFILE} || (echo "Failed to compile ${LIBFILE}"; exit 1)
    91 strip ${LIBFILE} || (echo "Failed to strip ${LIBFILE}" ; exit 1)
     124${CC_PREFIX}${CC} ${CFLAGS} ${LDFLAGS} ${INCLUDES} src/*.c -o ${LIBFILE} || (echo "Failed to compile ${LIBFILE}"; exit 1)
     125${CC_PREFIX}strip ${LIBFILE} || (echo "Failed to strip ${LIBFILE}" ; exit 1)
    92126echo Built `dirname $0`/${LIBFILE}
Note: See TracChangeset for help on using the changeset viewer.