merge of '3381ae4a99275c36eccde0920ee34b936bb7d58c'
[vuplus_openembedded] / classes / java.bbclass
1 # Defines the commonly used target directories and provides a convenience
2 # function to install jar files.
3
4 # Jar location on target
5 datadir_java ?= ${datadir}/java
6
7 # JNI library location on target
8 libdir_jni ?= ${libdir}/jni
9
10 STAGING_DATADIR_JAVA ?= ${STAGING_DATADIR}/java
11 STAGING_LIBDIR_JNI ?= ${STAGING_LIBDIR}/jni
12
13 oe_jarinstall() {
14   # Purpose: Install a jar file and create all the given symlinks to it.
15   # Example:
16   # oe_jarinstall foo-1.3.jar foo.jar
17   # Installs foo-1.3.jar and creates symlink foo.jar.
18   #
19   # oe_jarinstall -s foo-1.3.jar foo.jar
20   # Installs foo-1.3.jar to staging and creates symlink foo.jar.
21   #
22   # oe_jarinstall -r foo-1.3.jar foo_1_3.jar foo.jar
23   # Installs foo_1_3.jar as foo-1.3.jar and creates a symlink to this.
24   #
25   dir=${D}${datadir_java}
26   destname=""
27   while [ "$#" -gt 0 ]; do
28     case "$1" in
29     -s)
30       dir=${STAGING_DATADIR_JAVA}
31       ;;
32     -r)
33       shift
34       destname=$1
35       ;;
36     -*)
37       oefatal "oe_jarinstall: unknown option: $1"
38       ;;
39     *)
40       break;
41       ;;
42     esac
43     shift
44   done
45
46   jarname=$1
47   destname=${destname:-`basename $jarname`}
48   shift
49
50   install -d $dir
51   install -m 0644 $jarname $dir/$destname
52
53   # Creates symlinks out of the remaining arguments.
54   while [ "$#" -gt 0 ]; do
55     if [ -e $dir/$1 ]; then
56       oewarn "file was in the way. removing:" $dir/$1
57       rm $dir/$1
58     fi
59     ln -s $destname $dir/$1
60     shift
61   done
62 }
63
64 # Creates a simple wrapper script for your Java program.
65 # The script is written to ${PN} by default. 
66 #
67 # Parameters are as follows:
68 # [options] <output file> <main class> [jar files ...]
69 #
70 # Options are
71 # -o <name> where name is the output file name
72 #
73 # It can only take jar files from ${datadir_java}!
74 oe_java_simple_wrapper() {
75   delimiter=
76   mainclass=
77   classpath=
78   output=${PN}
79
80   while [ "$#" -gt 0 ]; do
81     case "$1" in
82     -o)
83       shift
84       output=$1
85       ;;
86     -*)
87       oefatal "oe_java_simple_wrapper: unknown option: $1"
88       ;;
89     *)
90       if [ $mainclass ]
91       then
92         classpath=$classpath$delimiter${datadir_java}/$1
93         delimiter=":"
94       else
95         mainclass=$1
96       fi
97       ;;
98     esac
99     shift
100   done
101
102   oenote "Creating simple Java wrapper script"
103   oenote "Output File: $output"
104   oenote "Main Class: $mainclass"
105   oenote "Classpath: $classpath"
106
107   echo "#!/bin/sh" > $output
108   echo "# This file is autogenerated by the oe_java_simple_wrapper function of OpenEmbedded" >> $output
109   echo >> $output
110   echo "# You can provide additional VM arguments by setting the VMARGS environment variable." >> $output
111   echo "CLASSPATH_ARG=\"-cp $classpath\"" >> $output
112   echo >> $output
113   echo "MAIN_CLASS=$mainclass" >> $output
114   echo >> $output
115   echo "# Allows overriding the VM by setting the JAVA environment variable." >> $output
116   echo "if [ x\${JAVA} = x ]" >> $output
117   echo "then" >> $output
118   echo "  JAVA=java" >> $output
119   echo "fi" >> $output
120   echo >> $output
121   echo "exec \${JAVA} \${VMARGS} \${CLASSPATH_ARG} \${MAIN_CLASS} \${@}" >> $output
122 }