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