diff options
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/java-library.bbclass | 58 | ||||
| -rw-r--r-- | classes/java-native.bbclass | 9 | ||||
| -rw-r--r-- | classes/java.bbclass | 184 |
3 files changed, 251 insertions, 0 deletions
diff --git a/classes/java-library.bbclass b/classes/java-library.bbclass new file mode 100644 index 0000000..4396bb3 --- /dev/null +++ b/classes/java-library.bbclass | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | # Inherit this bbclass for each java recipe that builds a Java library (jar file[s]). | ||
| 2 | # | ||
| 3 | # It automatically adds important build dependencies, defines JPN (Java Package Name) | ||
| 4 | # a package named ${JPN} whose contents are those of ${datadir}/java (the jar location). | ||
| 5 | # | ||
| 6 | # The JPN is basically lib${PN}-java but takes care of the fact that ${PN} already | ||
| 7 | # starts with "lib" and/or ends with "-java". In case the "lib" prefix is part of | ||
| 8 | # your package's normal name (e.g. liberator) the guessing is wrong and you have | ||
| 9 | # to set JPN manually! | ||
| 10 | |||
| 11 | inherit java | ||
| 12 | |||
| 13 | # use java_stage for native packages | ||
| 14 | JAVA_NATIVE_STAGE_INSTALL = "1" | ||
| 15 | |||
| 16 | def java_package_name(d): | ||
| 17 | import bb; | ||
| 18 | |||
| 19 | pre="" | ||
| 20 | post="" | ||
| 21 | |||
| 22 | pn = bb.data.getVar('PN', d, 1) | ||
| 23 | if not pn.startswith("lib"): | ||
| 24 | pre='lib' | ||
| 25 | |||
| 26 | if not pn.endswith("-java"): | ||
| 27 | post='-java' | ||
| 28 | |||
| 29 | return pre + pn + post | ||
| 30 | |||
| 31 | JPN ?= "${@java_package_name(d)}" | ||
| 32 | |||
| 33 | DEPENDS_prepend = "virtual/javac-native fastjar-native " | ||
| 34 | |||
| 35 | PACKAGES = "${JPN}" | ||
| 36 | |||
| 37 | PACKAGE_ARCH_${JPN} = "all" | ||
| 38 | |||
| 39 | FILES_${JPN} = "${datadir_java}" | ||
| 40 | |||
| 41 | # File name of the libraries' main Jar file | ||
| 42 | JARFILENAME = "${BP}.jar" | ||
| 43 | |||
| 44 | # Space-separated list of alternative file names. | ||
| 45 | ALTJARFILENAMES = "${BPN}.jar" | ||
| 46 | |||
| 47 | # Java "source" distributions often contain precompiled things | ||
| 48 | # we want to delete first. | ||
| 49 | do_removebinaries() { | ||
| 50 | find ${WORKDIR} -name "*.jar" -exec rm {} \; | ||
| 51 | find ${WORKDIR} -name "*.class" -exec rm {} \; | ||
| 52 | } | ||
| 53 | |||
| 54 | addtask removebinaries after do_unpack before do_patch | ||
| 55 | |||
| 56 | do_install() { | ||
| 57 | oe_jarinstall ${JARFILENAME} ${ALTJARFILENAMES} | ||
| 58 | } | ||
diff --git a/classes/java-native.bbclass b/classes/java-native.bbclass new file mode 100644 index 0000000..cade7b1 --- /dev/null +++ b/classes/java-native.bbclass | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # This is to be used by recipes which rely on java-library.bbclass | ||
| 2 | # infrastructure and are a *-native recipe which needs to install | ||
| 3 | # jar files into staging. | ||
| 4 | # | ||
| 5 | # This class has nothing to do with Java's JNI. | ||
| 6 | |||
| 7 | inherit native | ||
| 8 | |||
| 9 | NATIVE_INSTALL_WORKS = "1" | ||
diff --git a/classes/java.bbclass b/classes/java.bbclass new file mode 100644 index 0000000..6a45065 --- /dev/null +++ b/classes/java.bbclass | |||
| @@ -0,0 +1,184 @@ | |||
| 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 -r foo-1.3.jar foo_1_3.jar foo.jar | ||
| 31 | # Installs foo_1_3.jar as foo-1.3.jar and creates a symlink to this. | ||
| 32 | # | ||
| 33 | dir=${D}${datadir_java} | ||
| 34 | destname="" | ||
| 35 | while [ "$#" -gt 0 ]; do | ||
| 36 | case "$1" in | ||
| 37 | -r) | ||
| 38 | shift | ||
| 39 | destname=$1 | ||
| 40 | ;; | ||
| 41 | -*) | ||
| 42 | oefatal "oe_jarinstall: unknown option: $1" | ||
| 43 | ;; | ||
| 44 | *) | ||
| 45 | break; | ||
| 46 | ;; | ||
| 47 | esac | ||
| 48 | shift | ||
| 49 | done | ||
| 50 | |||
| 51 | jarname=$1 | ||
| 52 | destname=${destname:-`basename $jarname`} | ||
| 53 | shift | ||
| 54 | |||
| 55 | install -d $dir | ||
| 56 | install -m 0644 $jarname $dir/$destname | ||
| 57 | |||
| 58 | # Creates symlinks out of the remaining arguments. | ||
| 59 | while [ "$#" -gt 0 ]; do | ||
| 60 | if [ -e $dir/$1 -o -h $dir/$1 ]; then | ||
| 61 | oewarn "file was in the way. removing:" $dir/$1 | ||
| 62 | rm $dir/$1 | ||
| 63 | fi | ||
| 64 | ln -s $destname $dir/$1 | ||
| 65 | shift | ||
| 66 | done | ||
| 67 | } | ||
| 68 | |||
| 69 | oe_makeclasspath() { | ||
| 70 | # Purpose: Generate a classpath variable from the given Jar file names | ||
| 71 | # where the ".jar" has been omitted. The string is stored in the script | ||
| 72 | # variable whose name is given in the first argument to this function. | ||
| 73 | # | ||
| 74 | # oe_makeclasspath cp foo baz bar | ||
| 75 | # Stores ${datadir_java}/foo.jar:${datadir_java}/baz.jar:${datadir_java}/bar.jar | ||
| 76 | # in variable "cp". | ||
| 77 | # | ||
| 78 | # oe_makeclasspath bootcp -s foo baz bar | ||
| 79 | # Stores ${STAGING_DATADIR_JAVA}/foo.jar:${STAGING_DATADIR_JAVA}/baz.jar:${STAGING_DATADIR_JAVA}/bar.jar | ||
| 80 | # in variable "bootcp". | ||
| 81 | # | ||
| 82 | # Provide the -s at the beginning otherwise strange things happen. | ||
| 83 | # If -s is given the function checks whether the requested jar file exists | ||
| 84 | # and exits with an error message if it cannot be found. | ||
| 85 | # | ||
| 86 | # Note: In order to encourage usage of the DEPENDS variable, the function | ||
| 87 | # can accept recipe names. If a recipe has no corresponding Jar file it | ||
| 88 | # is ignored. Be careful with recipes where the recipe name is different | ||
| 89 | # from the the Jar file name! | ||
| 90 | dir=${datadir_java} | ||
| 91 | classpath= | ||
| 92 | delimiter= | ||
| 93 | retval=$1 | ||
| 94 | |||
| 95 | shift | ||
| 96 | |||
| 97 | while [ "$#" -gt 0 ]; do | ||
| 98 | case "$1" in | ||
| 99 | -s) | ||
| 100 | # take jar files from native staging if this is a -native recipe | ||
| 101 | if [ ${PACKAGE_ARCH} = ${BUILD_ARCH} ]; then | ||
| 102 | dir=${STAGING_DATADIR_JAVA_NATIVE} | ||
| 103 | else | ||
| 104 | dir=${STAGING_DATADIR_JAVA} | ||
| 105 | fi | ||
| 106 | ;; | ||
| 107 | -*) | ||
| 108 | oefatal "oe_makeclasspath: unknown option: $1" | ||
| 109 | ;; | ||
| 110 | *) | ||
| 111 | file=$dir/$1.jar | ||
| 112 | |||
| 113 | if [ -e $file ]; then | ||
| 114 | classpath=$classpath$delimiter$file | ||
| 115 | delimiter=":" | ||
| 116 | fi | ||
| 117 | |||
| 118 | ;; | ||
| 119 | esac | ||
| 120 | shift | ||
| 121 | done | ||
| 122 | |||
| 123 | eval $retval="$classpath" | ||
| 124 | } | ||
| 125 | |||
| 126 | # Creates a simple wrapper script for your Java program. | ||
| 127 | # The script is written to ${PN} by default. | ||
| 128 | # | ||
| 129 | # Parameters are as follows: | ||
| 130 | # [options] <output file> <main class> [jar files ...] | ||
| 131 | # | ||
| 132 | # Options are | ||
| 133 | # -o <name> where name is the output file name | ||
| 134 | # | ||
| 135 | # It can only take jar files from ${datadir_java}! | ||
| 136 | oe_java_simple_wrapper() { | ||
| 137 | delimiter= | ||
| 138 | mainclass= | ||
| 139 | classpath= | ||
| 140 | output=${PN} | ||
| 141 | |||
| 142 | while [ "$#" -gt 0 ]; do | ||
| 143 | case "$1" in | ||
| 144 | -o) | ||
| 145 | shift | ||
| 146 | output=$1 | ||
| 147 | ;; | ||
| 148 | -*) | ||
| 149 | oefatal "oe_java_simple_wrapper: unknown option: $1" | ||
| 150 | ;; | ||
| 151 | *) | ||
| 152 | if [ $mainclass ] | ||
| 153 | then | ||
| 154 | classpath=$classpath$delimiter${datadir_java}/$1 | ||
| 155 | delimiter=":" | ||
| 156 | else | ||
| 157 | mainclass=$1 | ||
| 158 | fi | ||
| 159 | ;; | ||
| 160 | esac | ||
| 161 | shift | ||
| 162 | done | ||
| 163 | |||
| 164 | oenote "Creating simple Java wrapper script" | ||
| 165 | oenote "Output File: $output" | ||
| 166 | oenote "Main Class: $mainclass" | ||
| 167 | oenote "Classpath: $classpath" | ||
| 168 | |||
| 169 | echo "#!/bin/sh" > $output | ||
| 170 | echo "# This file is autogenerated by the oe_java_simple_wrapper function of OpenEmbedded" >> $output | ||
| 171 | echo >> $output | ||
| 172 | echo "# You can provide additional VM arguments by setting the VMARGS environment variable." >> $output | ||
| 173 | echo "CLASSPATH_ARG=\"-cp $classpath\"" >> $output | ||
| 174 | echo >> $output | ||
| 175 | echo "MAIN_CLASS=$mainclass" >> $output | ||
| 176 | echo >> $output | ||
| 177 | echo "# Allows overriding the VM by setting the JAVA environment variable." >> $output | ||
| 178 | echo "if [ x\${JAVA} = x ]" >> $output | ||
| 179 | echo "then" >> $output | ||
| 180 | echo " JAVA=java" >> $output | ||
| 181 | echo "fi" >> $output | ||
| 182 | echo >> $output | ||
| 183 | echo "exec \${JAVA} \${VMARGS} \${CLASSPATH_ARG} \${MAIN_CLASS} \${@}" >> $output | ||
| 184 | } | ||
