xf86-video-omapfb: pandora: handle cycle/forcer events better
[openembedded.git] / 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_DIR_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 -o -h $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   # Note: In order to encourage usage of the DEPENDS variable, the function
98   # can accept recipe names. If a recipe has no corresponding Jar file it
99   # is ignored. Be careful with recipes where the recipe name is different
100   # from the the Jar file name!
101   dir=${datadir_java}
102   classpath=
103   delimiter=
104   retval=$1
105
106   shift
107
108   while [ "$#" -gt 0 ]; do
109       case "$1" in
110           -s)
111               # take jar files from native staging if this is a -native recipe
112               if [ ${PACKAGE_ARCH} = ${BUILD_ARCH} ]; then
113                   dir=${STAGING_DATADIR_JAVA_NATIVE}
114               else
115                   dir=${STAGING_DATADIR_JAVA}
116               fi
117               ;;
118           -*)
119               oefatal "oe_makeclasspath: unknown option: $1"
120               ;;
121           *)
122               file=$dir/$1.jar
123
124               if [ -e $file ]; then
125                   classpath=$classpath$delimiter$file
126                   delimiter=":"
127               fi
128
129           ;;
130       esac
131       shift
132   done
133
134   eval $retval="$classpath"
135 }
136
137 # Creates a simple wrapper script for your Java program.
138 # The script is written to ${PN} by default. 
139 #
140 # Parameters are as follows:
141 # [options] <output file> <main class> [jar files ...]
142 #
143 # Options are
144 # -o <name> where name is the output file name
145 #
146 # It can only take jar files from ${datadir_java}!
147 oe_java_simple_wrapper() {
148   delimiter=
149   mainclass=
150   classpath=
151   output=${PN}
152
153   while [ "$#" -gt 0 ]; do
154     case "$1" in
155     -o)
156       shift
157       output=$1
158       ;;
159     -*)
160       oefatal "oe_java_simple_wrapper: unknown option: $1"
161       ;;
162     *)
163       if [ $mainclass ]
164       then
165         classpath=$classpath$delimiter${datadir_java}/$1
166         delimiter=":"
167       else
168         mainclass=$1
169       fi
170       ;;
171     esac
172     shift
173   done
174
175   oenote "Creating simple Java wrapper script"
176   oenote "Output File: $output"
177   oenote "Main Class: $mainclass"
178   oenote "Classpath: $classpath"
179
180   echo "#!/bin/sh" > $output
181   echo "# This file is autogenerated by the oe_java_simple_wrapper function of OpenEmbedded" >> $output
182   echo >> $output
183   echo "# You can provide additional VM arguments by setting the VMARGS environment variable." >> $output
184   echo "CLASSPATH_ARG=\"-cp $classpath\"" >> $output
185   echo >> $output
186   echo "MAIN_CLASS=$mainclass" >> $output
187   echo >> $output
188   echo "# Allows overriding the VM by setting the JAVA environment variable." >> $output
189   echo "if [ x\${JAVA} = x ]" >> $output
190   echo "then" >> $output
191   echo "  JAVA=java" >> $output
192   echo "fi" >> $output
193   echo >> $output
194   echo "exec \${JAVA} \${VMARGS} \${CLASSPATH_ARG} \${MAIN_CLASS} \${@}" >> $output
195 }