merge of '07a342693675fe2b1daacf0eb62302579d9fade3'
[org.openembedded.dev.git] / classes / java.bbclass
blobe51b0d71dad1b0d4616f114a432fc62ae93acd30
1 # Defines the commonly used target directories and provides a convenience
2 # function to install jar files.
4 # Jar location on target
5 datadir_java ?= ${datadir}/java
7 # JNI library location on target
8 libdir_jni ?= ${libdir}/jni
10 STAGING_DATADIR_JAVA ?= ${STAGING_DATADIR}/java
11 STAGING_LIBDIR_JNI ?= ${STAGING_LIBDIR}/jni
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
46   jarname=$1
47   destname=${destname:-`basename $jarname`}
48   shift
50   install -d $dir
51   install -m 0644 $jarname $dir/$destname
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
64 oe_makeclasspath() {
65   # Purpose: Generate a classpath variable from the given Jar file names
66   # where the ".jar" has been omitted.
67   #
68   # oe_makeclasspath foo baz bar
69   # Prints ${datadir_java}/foo.jar:${datadir_java}/baz.jar:${datadir_java}/bar.jar
70   #
71   # oe_makeclasspath -s foo baz bar
72   # Prints ${STAGING_DATADIR_JAVA}/foo.jar:${STAGING_DATADIR_JAVA}/baz.jar:${STAGING_DATADIR_JAVA}/bar.jar
73   #
74   # Provide the -s at the beginning otherwise strange things happen.
75   #
76   dir=${datadir_java}
77         classpath=
78         delimiter=
80   while [ "$#" -gt 0 ]; do
81     case "$1" in
82     -s)
83       dir=${STAGING_DATADIR_JAVA}
84       ;;
85     -*)
86       oefatal "oe_makeclasspath: unknown option: $1"
87       ;;
88     *)
89       classpath=$classpath$delimiter$dir/$1.jar
90       delimiter=":"
91       ;;
92     esac
93     shift
94   done
96         echo $classpath
99 # Creates a simple wrapper script for your Java program.
100 # The script is written to ${PN} by default. 
102 # Parameters are as follows:
103 # [options] <output file> <main class> [jar files ...]
105 # Options are
106 # -o <name> where name is the output file name
108 # It can only take jar files from ${datadir_java}!
109 oe_java_simple_wrapper() {
110   delimiter=
111   mainclass=
112   classpath=
113   output=${PN}
115   while [ "$#" -gt 0 ]; do
116     case "$1" in
117     -o)
118       shift
119       output=$1
120       ;;
121     -*)
122       oefatal "oe_java_simple_wrapper: unknown option: $1"
123       ;;
124     *)
125       if [ $mainclass ]
126       then
127         classpath=$classpath$delimiter${datadir_java}/$1
128         delimiter=":"
129       else
130         mainclass=$1
131       fi
132       ;;
133     esac
134     shift
135   done
137   oenote "Creating simple Java wrapper script"
138   oenote "Output File: $output"
139   oenote "Main Class: $mainclass"
140   oenote "Classpath: $classpath"
142   echo "#!/bin/sh" > $output
143   echo "# This file is autogenerated by the oe_java_simple_wrapper function of OpenEmbedded" >> $output
144   echo >> $output
145   echo "# You can provide additional VM arguments by setting the VMARGS environment variable." >> $output
146   echo "CLASSPATH_ARG=\"-cp $classpath\"" >> $output
147   echo >> $output
148   echo "MAIN_CLASS=$mainclass" >> $output
149   echo >> $output
150   echo "# Allows overriding the VM by setting the JAVA environment variable." >> $output
151   echo "if [ x\${JAVA} = x ]" >> $output
152   echo "then" >> $output
153   echo "  JAVA=java" >> $output
154   echo "fi" >> $output
155   echo >> $output
156   echo "exec \${JAVA} \${VMARGS} \${CLASSPATH_ARG} \${MAIN_CLASS} \${@}" >> $output