]> oss.titaniummirror.com Git - tinyos-2.x.git/blob - tools/tinyos/misc/tos-locate-jre
Fixed some bugs with the tinyos-tools that have crept in due to incompatibilities...
[tinyos-2.x.git] / tools / tinyos / misc / tos-locate-jre
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)
8
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
13
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
23 fi
24
25 rpmlocate () {
26 javarpm=$1
27 javapath=`rpm -ql $1 2>/dev/null | grep "bin/$2$"`
28 }
29
30 pathlocate () {
31 javapath=`which $1 2>/dev/null`
32 while [ -n "$javapath" -a -h "$javapath" ]; do
33 javapath=`readlink -q $javapath`
34 done
35 test -n "$javapath"
36 }
37
38 case `uname` in
39 CYGWIN*)
40 # Hopefully this will always work on cygwin with Sun's Java
41 jversion=`regtool -q -w get '\\HKLM\\SOFTWARE\\JavaSoft\\Java Development Kit\\CurrentVersion'`
42 if [ $? != 0 ]; then
43 exit 1
44 fi
45 jhome=`regtool -q get '\\HKLM\SOFTWARE\\JavaSoft\\Java Development Kit\\'$jversion'\\JavaHome'`
46 if [ $? != 0 ]; then
47 exit 1
48 fi
49 jhome=`cygpath -u "$jhome"`
50 ;;
51
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
55 ;;
56
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; }
64 fi
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; }
73
74 if [ -z "$javapath" ]; then
75 # lastly, check for a weirdly named IBMJava2
76 name=`rpm -qa | grep IBMJava2 | head -1`
77 if [ -n "$name" ]; then
78 rpmlocate $name javac
79 fi
80 fi
81 fi
82 if [ -z "$javapath" ]; then
83 exit 1
84 fi
85 jbin=`dirname "$javapath"`
86 jhome=`dirname "$jbin"`
87 ;;
88
89 FreeBSD)
90 # We check the path first, on the assumption that that's the preferred
91 # version.
92 pathlocate javac || { test -z "$javac" && pathlocate java; }
93 if [ -n "$javapath" ]; then
94 jbin=`dirname "$javapath"`
95 else
96 if [ -f /usr/local/jdk1.4*/bin/java ]; then
97 jbin=/usr/local/jdk1.4*/bin
98 else
99 exit 1
100 fi
101 fi
102 jhome=`dirname $jbin`
103 ;;
104 esac
105
106 # These are correct for Sun and IBM's x86 Java versions
107 if [ "$jni" = "yes" ]; then
108 jnilocate () {
109 dir="$1"
110 test -d "$1"
111 }
112
113 # Look for a likely JNI directory
114 # Windows, and IBM Java: in jre/bin
115 # Sun Java on Linux: in jre/lib/i386
116 if [ `uname` = "Darwin" ]; then
117 jnilocate "/Library/java/Extensions"
118 elif "$jhome/bin/java" -version 2>&1 | grep -q IBM || cygpath -w / >/dev/null 2>/dev/null; then
119 jnilocate "$jhome/jre/bin" || jnilocate "$jhome/bin"
120 else
121 arch=`uname -m`
122 jnilocate "$jhome/jre/lib/$arch" || \
123 jnilocate "$jhome/jre/lib/i386" || \
124 jnilocate "$jhome/jre/lib/amd64" || \
125 jnilocate "$jhome/lib/$arch" || \
126 jnilocate "$jhome/lib/i386" || \
127 jnilocate "$jhome/lib/amd64"
128 fi
129 elif [ "$javac" = "yes" ]; then
130 if [ `uname` = "Darwin" ]; then
131 dir="$jhome/Commands"
132 else
133 dir="$jhome/bin"
134 fi
135 elif [ "$java" = "yes" ]; then
136 if [ `uname` = "Darwin" ]; then
137 dir="$jhome/Commands"
138 else
139 dir="$jhome/bin"
140 fi
141 fi
142
143 # Check that what we found actually exists
144 if [ -d "$dir" ]; then
145 echo $dir
146 else
147 exit 1
148 fi