merge of '4b614ea9dfb14d8f67ed00b35c59a2f23b49e2da'
[vuplus_openembedded] / classes / java.bbclass
1 # Defines the commonly used target directories and provides a convenience
2 # function to install jar files.
3 #
4 # All the default directory locations herein resemble locations chosen in
5 # the Debian distribution.
6
7 # Jar location on target
8 datadir_java ?= ${datadir}/java
9
10 # JNI library location on target
11 libdir_jni ?= ${libdir}/jni
12
13 # JVM bundle location on target
14 libdir_jvm ?= ${libdir}/jvm
15
16 STAGING_DATADIR_JAVA ?= ${STAGING_DATADIR}/java
17 STAGING_LIBDIR_JNI ?= ${STAGING_LIBDIR}/jni
18 STAGING_LIBDIR_JVM ?= ${STAGING_LIBDIR}/jvm
19
20 oe_jarinstall() {
21   # Purpose: Install a jar file and create all the given symlinks to it.
22   # Example:
23   # oe_jarinstall foo-1.3.jar foo.jar
24   # Installs foo-1.3.jar and creates symlink foo.jar.
25   #
26   # oe_jarinstall -s foo-1.3.jar foo.jar
27   # Installs foo-1.3.jar to staging and creates symlink foo.jar.
28   #
29   # oe_jarinstall -r foo-1.3.jar foo_1_3.jar foo.jar
30   # Installs foo_1_3.jar as foo-1.3.jar and creates a symlink to this.
31   #
32   dir=${D}${datadir_java}
33   destname=""
34   while [ "$#" -gt 0 ]; do
35     case "$1" in
36     -s)
37       dir=${STAGING_DATADIR_JAVA}
38       ;;
39     -r)
40       shift
41       destname=$1
42       ;;
43     -*)
44       oefatal "oe_jarinstall: unknown option: $1"
45       ;;
46     *)
47       break;
48       ;;
49     esac
50     shift
51   done
52
53   jarname=$1
54   destname=${destname:-`basename $jarname`}
55   shift
56
57   install -d $dir
58   install -m 0644 $jarname $dir/$destname
59
60   # Creates symlinks out of the remaining arguments.
61   while [ "$#" -gt 0 ]; do
62     if [ -e $dir/$1 ]; then
63       oewarn "file was in the way. removing:" $dir/$1
64       rm $dir/$1
65     fi
66     ln -s $destname $dir/$1
67     shift
68   done
69 }
70
71 oe_makeclasspath() {
72   # Purpose: Generate a classpath variable from the given Jar file names
73   # where the ".jar" has been omitted. The string is stored in the script
74   # variable whose name is given in the first argument to this function.
75   #
76   # oe_makeclasspath cp foo baz bar
77   # Stores ${datadir_java}/foo.jar:${datadir_java}/baz.jar:${datadir_java}/bar.jar
78         # in variable "cp".
79   #
80   # oe_makeclasspath bootcp -s foo baz bar
81   # Stores ${STAGING_DATADIR_JAVA}/foo.jar:${STAGING_DATADIR_JAVA}/baz.jar:${STAGING_DATADIR_JAVA}/bar.jar
82         # in variable "bootcp".
83         # 
84   # Provide the -s at the beginning otherwise strange things happen.
85         # If -s is given the function checks whether the requested jar file exists
86         #       and exits with an error message if it cannot be found.
87         #
88   dir=${datadir_java}
89         classpath=
90         delimiter=
91         retval=$1
92
93         shift
94
95   while [ "$#" -gt 0 ]; do
96     case "$1" in
97     -s)
98       dir=${STAGING_DATADIR_JAVA}
99       ;;
100     -*)
101       oefatal "oe_makeclasspath: unknown option: $1"
102       ;;
103     *)
104       file=$dir/$1.jar
105
106                         if [ -z "$dir" -a ! -f $file ]; then
107                                 oefatal "oe_makeclasspath: Jar file for '$1' not found at $file"
108                         fi
109
110       classpath=$classpath$delimiter$file
111       delimiter=":"
112       ;;
113     esac
114     shift
115   done
116
117         eval $retval="$classpath"
118 }
119
120 # Creates a simple wrapper script for your Java program.
121 # The script is written to ${PN} by default. 
122 #
123 # Parameters are as follows:
124 # [options] <output file> <main class> [jar files ...]
125 #
126 # Options are
127 # -o <name> where name is the output file name
128 #
129 # It can only take jar files from ${datadir_java}!
130 oe_java_simple_wrapper() {
131   delimiter=
132   mainclass=
133   classpath=
134   output=${PN}
135
136   while [ "$#" -gt 0 ]; do
137     case "$1" in
138     -o)
139       shift
140       output=$1
141       ;;
142     -*)
143       oefatal "oe_java_simple_wrapper: unknown option: $1"
144       ;;
145     *)
146       if [ $mainclass ]
147       then
148         classpath=$classpath$delimiter${datadir_java}/$1
149         delimiter=":"
150       else
151         mainclass=$1
152       fi
153       ;;
154     esac
155     shift
156   done
157
158   oenote "Creating simple Java wrapper script"
159   oenote "Output File: $output"
160   oenote "Main Class: $mainclass"
161   oenote "Classpath: $classpath"
162
163   echo "#!/bin/sh" > $output
164   echo "# This file is autogenerated by the oe_java_simple_wrapper function of OpenEmbedded" >> $output
165   echo >> $output
166   echo "# You can provide additional VM arguments by setting the VMARGS environment variable." >> $output
167   echo "CLASSPATH_ARG=\"-cp $classpath\"" >> $output
168   echo >> $output
169   echo "MAIN_CLASS=$mainclass" >> $output
170   echo >> $output
171   echo "# Allows overriding the VM by setting the JAVA environment variable." >> $output
172   echo "if [ x\${JAVA} = x ]" >> $output
173   echo "then" >> $output
174   echo "  JAVA=java" >> $output
175   echo "fi" >> $output
176   echo >> $output
177   echo "exec \${JAVA} \${VMARGS} \${CLASSPATH_ARG} \${MAIN_CLASS} \${@}" >> $output
178 }