Merge commit 'origin'
[wizzardx.tinyos2.x.git] / tools / tinyos / misc / tos-locate-jre
blobb55298a96fd1bb305d266be9d57ac4d392ddf5b3
1 #!/bin/sh
2 # This script attempts to locate the jre directory of the current
3 # Java installation, even when java is not in the path
4 # It works with the following rpm files:
5 # Sun's Java Software Development Kit (Linux/Windows)
6 # Sun's Java Runtime Environment (Linux)
7 # IBM's Java Software Development Kit (linux)
9 # We require an option to specify which directory is desired:
10 # --java: directory with java executable
11 # --javac: directory with javac executable
12 # --jni: directory where JNI code is placed
14 if [ "$1" = "--jni" ]; then
15 jni=yes
16 elif [ "$1" = "--java" ]; then
17 java=yes
18 elif [ "$1" = "--javac" ]; then
19 javac=yes
20 else
21 echo "Usage: tos-locate-jre --java|--javac|--jni" >&2
22 exit 2
25 rpmlocate () {
26 javarpm=$1
27 javapath=`rpm -ql $1 2>/dev/null | grep "bin/$2$"`
30 pathlocate () {
31 javapath=`which $1 2>/dev/null`
32 while [ -n "$javapath" -a -h "$javapath" ]; do
33 javapath=`readlink -f -q $javapath`
34 done
35 test -n "$javapath"
38 case `uname` in
39 CYGWIN*)
40 # Hopefully this will always work on cygwin with Sun's Java
41 jversion=`regtool -q get '\\HKLM\\SOFTWARE\\JavaSoft\\Java Development Kit\\CurrentVersion'`
42 if [ $? != 0 ]; then
43 exit 1
45 jhome=`regtool -q get '\\HKLM\SOFTWARE\\JavaSoft\\Java Development Kit\\'$jversion'\\JavaHome'`
46 if [ $? != 0 ]; then
47 exit 1
49 jhome=`cygpath -u "$jhome"`
52 Darwin)
53 #Just statically typed in, uses default location of installation for XTools. May need to be fixed
54 jhome=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
57 Linux)
58 # Check gentoo java configuration
59 javapath=`java-config -c 2>/dev/null`
60 # We check the path first, on the assumption that that's the preferred
61 # version.
62 if [ -z "$javapath" ]; then
63 pathlocate javac || { test -z "$javac" && pathlocate java; }
65 if [ -z "$javapath" ]; then
66 # We try a bunch of standard names, before resorting to rpm -qa
67 rpmlocate IBMJava2-SDK javac || \
68 rpmlocate IBMJava2-142-ia32-SDK javac || \
69 rpmlocate j2sdk javac || \
70 rpmlocate jdk javac || \
71 { test -z "$javac" && rpmlocate j2re java; } || \
72 { test -z "$javac" && rpmlocate jre java; }
74 if [ -z "$javapath" ]; then
75 # lastly, check for a weirdly named IBMJava2
76 if [ `which rpm 2>/dev/null` ]; then
77 name=`rpm -qa | grep IBMJava2 | head -1`
78 if [ -n "$name" ]; then
79 rpmlocate $name javac
84 if [ -z "$javapath" ]; then
85 exit 1
87 jbin=`dirname "$javapath"`
88 jhome=`dirname "$jbin"`
91 FreeBSD)
92 # We check the path first, on the assumption that that's the preferred
93 # version.
94 pathlocate javac || { test -z "$javac" && pathlocate java; }
95 if [ -n "$javapath" ]; then
96 jbin=`dirname "$javapath"`
97 else
98 if [ -f /usr/local/jdk1.4*/bin/java ]; then
99 jbin=/usr/local/jdk1.4*/bin
100 else
101 exit 1
104 jhome=`dirname $jbin`
106 esac
108 # These are correct for Sun and IBM's x86 Java versions
109 if [ "$jni" = "yes" ]; then
110 jnilocate () {
111 dir="$1"
112 test -d "$1"
115 # Look for a likely JNI directory
116 # Windows, and IBM Java: in jre/bin
117 # Sun Java on Linux: in jre/lib/i386
118 if [ `uname` = "Darwin" ]; then
119 jnilocate "/Library/java/Extensions"
120 elif "$jhome/bin/java" -version 2>&1 | grep -q IBM || cygpath -w / >/dev/null 2>/dev/null; then
121 jnilocate "$jhome/jre/bin" || jnilocate "$jhome/bin"
122 else
123 arch=`uname -m`
124 jnilocate "$jhome/jre/lib/$arch" || \
125 jnilocate "$jhome/jre/lib/i386" || \
126 jnilocate "$jhome/jre/lib/amd64" || \
127 jnilocate "$jhome/lib/$arch" || \
128 jnilocate "$jhome/lib/i386" || \
129 jnilocate "$jhome/lib/amd64"
131 elif [ "$javac" = "yes" ]; then
132 if [ `uname` = "Darwin" ]; then
133 dir="$jhome/Commands"
134 else
135 dir="$jhome/bin"
137 elif [ "$java" = "yes" ]; then
138 if [ `uname` = "Darwin" ]; then
139 dir="$jhome/Commands"
140 else
141 dir="$jhome/bin"
145 # Check that what we found actually exists
146 if [ -d "$dir" ]; then
147 echo $dir
148 else
149 exit 1