-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv.sh
58 lines (49 loc) · 1.49 KB
/
env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
#
# source env.sh before running tests or compilation
OS=`uname -s | tr '[[:upper:]]' '[[:lower:]]'`
function detect_java_home {
# Use a Java snippet to detect
cat > /tmp/EchoJavaHome.java <<EOF
public class EchoJavaHome {
public static void main(String[] args) {
System.out.println(System.getProperty("java.home"));
}
}
EOF
javac /tmp/EchoJavaHome.java
export JAVA_HOME="$(java -cp /tmp EchoJavaHome)"
}
function setup {
detect_java_home
if [[ "x${OS}" = "xdarwin" ]]; then
export DYLD_LIBRARY_PATH=${JAVA_HOME}/lib/server:${DYLD_LIBRARY_PATH}
elif [[ "x${OS}" = "xlinux" ]]; then
# detect JAVA_HOME
if [[ "x${JAVA_HOME}" = "x" ]]; then
which java > /dev/null 2>&1 || {
echo "cannot find command java, aborting"
return 1
}
fi
export LD_LIBRARY_PATH=${JAVA_HOME}/lib/server:${DYLD_LIBRARY_PATH}
fi
if [[ "x${JAVA_HOME}" = "x" ]] || [[ ! -d "${JAVA_HOME}" ]]; then
echo "Canot find a valid JAVA_HOME, aborting..."
return 128
fi
if [[ "x$(echo ${PATH} | sed 's/:/\n/g' | grep ${JAVA_HOME}/bin)" = "x" ]]; then
export PATH=${JAVA_HOME}/bin:${PATH}
if [[ -d "${JAVA_HOME}/jre" ]]; then
export PATH=${JAVA_HOME}/jre/bin:${PATH}
fi
fi
if [[ -d "${JAVA_HOME}/jre" ]]; then
export CGO_LDFLAGS="-L${JAVA_HOME}/lib/amd64/server -ljvm"
else
export CGO_LDFLAGS="-L${JAVA_HOME}/lib/server -ljvm"
fi
export CGO_CFLAGS="-I${JAVA_HOME}/include -I${JAVA_HOME}/include/${OS}"
return 0
}
setup