|
|
# | # |
# ----------------------------------------------------------------------------- | # ----------------------------------------------------------------------------- |
| |
inherit eutils versionator multilib |
inherit check-reqs eutils flag-o-matic multilib versionator |
| |
IUSE="elibc_FreeBSD" | IUSE="elibc_FreeBSD" |
| |
|
|
JAVA_PKG_QA_VIOLATIONS=0 | JAVA_PKG_QA_VIOLATIONS=0 |
| |
# ----------------------------------------------------------------------------- | # ----------------------------------------------------------------------------- |
|
# @variable-external JAVA_PKG_NATIVE_CLASSMAP |
|
# |
|
# Explicitly set classmap.gcjdb database file |
|
# |
|
# @example for /etc/make.conf |
|
# JAVA_PKG_NATIVE_CLASSMAP="/usr/share/java/classmap.gcjdb" |
|
# ----------------------------------------------------------------------------- |
|
JAVA_PKG_NATIVE_CLASSMAP=${JAVA_PKG_NATIVE_CLASSMAP:="/usr/share/java/classmap.gcjdb"} |
|
|
|
# ----------------------------------------------------------------------------- |
|
# @variable-internal JAVA_PKG_NATIVE_CACHE_FLAGS |
|
# |
|
# Required flags for native library |
|
# ----------------------------------------------------------------------------- |
|
JAVA_PKG_NATIVE_CACHE_FLAGS="-shared -Wl,-Bsymbolic -fPIC -findirect-dispatch -fjni" |
|
|
|
# ----------------------------------------------------------------------------- |
|
# @variable-internal JAVA_PKG_NATIVE_BIN_FLAGS |
|
# |
|
# Required ldflags for native binary |
|
# ----------------------------------------------------------------------------- |
|
JAVA_PKG_NATIVE_BIN_FLAGS="-Wl,-Bsymbolic -findirect-dispatch -fjni" |
|
|
|
# ----------------------------------------------------------------------------- |
|
# @variable-internal JAVA_PKG_NATIVE_INC |
|
# |
|
# Set include files (jar) to compile native code |
|
# This is generated by java-pkg_gen-native-cp |
|
# ----------------------------------------------------------------------------- |
|
JAVA_PKG_NATIVE_INC="" |
|
|
|
# ----------------------------------------------------------------------------- |
|
# @variable-internal JAVA_PKG_NATIVE_LIB |
|
# |
|
# Set library files (jar.so) to link native code |
|
# This is generated by java-pkg_gen-native-cp |
|
# ----------------------------------------------------------------------------- |
|
JAVA_PKG_NATIVE_LIB="" |
|
|
|
# ----------------------------------------------------------------------------- |
|
# @variable-internal JAVA_PKG_NATIVE_SKIP |
|
# |
|
# Jar files that match pattern will be skipped. |
|
# |
|
# @example |
|
# java-pkg_skip-cachejar org.eclipse.jdt.core_ org.eclipse.jdt.apt |
|
# java-pkg_skip-cachejar 2000 org.eclipse.jdt.ui_ |
|
# |
|
# param $1 - optional: memory size to check |
|
# param $@ - pattern of Jar files to skip |
|
# ----------------------------------------------------------------------------- |
|
JAVA_PKG_NATIVE_SKIP="" |
|
|
|
# ----------------------------------------------------------------------------- |
# @section-end variables | # @section-end variables |
# ----------------------------------------------------------------------------- | # ----------------------------------------------------------------------------- |
| |
|
|
else | else |
# for everything else, try to determine from an env file | # for everything else, try to determine from an env file |
| |
local compiler_env="/usr/share/java-config-2/compiler/${compiler}" |
local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" |
if [[ -f ${compiler_env} ]]; then | if [[ -f ${compiler_env} ]]; then |
local old_javac=${JAVAC} | local old_javac=${JAVAC} |
unset JAVAC | unset JAVAC |
|
|
} | } |
| |
# ------------------------------------------------------------------------------ | # ------------------------------------------------------------------------------ |
|
# @internal-function java-pkg_gcjflags |
|
# |
|
# sanitze CFLAGS for GCJ native. |
|
# ------------------------------------------------------------------------------ |
|
java-pkg_gcjflags() { |
|
strip-flags |
|
filter-flags "-ftree-loop-distribution -ftree-vectorize" |
|
replace-flags "-O?" "-Os" |
|
append-flags -w |
|
|
|
filter-ldflags -Wl,--as-needed --as-needed |
|
} |
|
|
|
# ------------------------------------------------------------------------------ |
|
# @internal-function java-pkg_native_init_ |
|
# |
|
# Check for issues. |
|
# |
|
# @return 0 - procede with native build |
|
# @return 1 - skip native build |
|
# ------------------------------------------------------------------------------ |
|
java-pkg_native_init_() { |
|
if ! has gcj "${IUSE}" || ! use gcj ; then |
|
return 1 |
|
fi |
|
if [[ ( ! -x "$(which gcj)" ) || ( ! -x "$(which gcj-dbtool)" ) ]] ; then |
|
# Do we want to die here? |
|
ewarn "java native tools unusable!" |
|
return 1 |
|
fi |
|
|
|
java-pkg_gcjflags |
|
|
|
return 0 |
|
} |
|
|
|
# ------------------------------------------------------------------------------ |
|
# @ebuild-function java-pkg_gen-native-cp |
|
# |
|
# Set include and library paths for native build. |
|
# |
|
# Example: |
|
# java-pkg_gen-native-cp junit gnu-crypto ... |
|
# |
|
# @param $@ - space-separated list of packages |
|
# ------------------------------------------------------------------------------ |
|
java-pkg_gen-native-cp() { |
|
java-pkg_native_init_ || return 0 |
|
|
|
local pkg cp item lib |
|
for pkg in ${@} ; do |
|
cp="$(java-config --classpath=${pkg})" |
|
for item in ${cp//:/ } ; do |
|
if [[ ( -f "${item}" ) && ( ".jar" == "${item: -4:4}" ) ]] ; then |
|
lib="$(dirname ${item})/lib$(basename ${item}).so" |
|
[ ! -f "${lib}" ] && die "Native library ${lib} from ${pkg} missing!" |
|
JAVA_PKG_NATIVE_INC="${JAVA_PKG_NATIVE_INC} -I${item}" |
|
JAVA_PKG_NATIVE_LIB="${JAVA_PKG_NATIVE_LIB} ${lib}" |
|
fi |
|
done |
|
done |
|
} |
|
|
|
# ------------------------------------------------------------------------------ |
|
# @ebuild-function java-pkg_donative |
|
# |
|
# Compile Java source to native. |
|
# |
|
# Example: |
|
# java-pkg_donative src/java/* ... |
|
# Where '*' is org or com et cetera |
|
# |
|
# @param $@ - path to java source(s) |
|
# ------------------------------------------------------------------------------ |
|
java-pkg_donative() { |
|
java-pkg_native_init_ || return 0 |
|
einfo "Compile Java source to native ..." |
|
|
|
local buildpath="${S}/build/native" |
|
mkdir -p "${buildpath}" |
|
|
|
local path |
|
for path in ${@} ; do |
|
cp -a "${path}" "${buildpath}" |
|
done |
|
|
|
pushd "${buildpath}" >/dev/null || die "no native build there!" |
|
|
|
local file |
|
for file in $(find -type f -name '*.java' | cut -c3-) ; do |
|
echo gcj -c -g0 ${CFLAGS} -Wno-deprecated \ |
|
${JAVA_PKG_NATIVE_INC} ${file} -o ${file/\.java/.o} |
|
gcj -c -g0 ${CFLAGS} -Wno-deprecated \ |
|
${JAVA_PKG_NATIVE_INC} ${file} -o ${file/\.java/.o} \ |
|
|| die "java native compile failed! (${file})" |
|
done |
|
|
|
# Any other resource formats out there? |
|
# .properties, .rsc, .xml |
|
|
|
for file in $(find -type f \( -name '*.properties' -o -name '*.rsc' -o -name '*.xml' \) | cut -c3-) ; do |
|
echo gcj -c -g0 ${CFLAGS} -Wno-deprecated \ |
|
--resource ${file} ${file} -o ${file}.o |
|
gcj -c -g0 ${CFLAGS} -Wno-deprecated \ |
|
--resource ${file} ${file} -o ${file}.o \ |
|
|| die "java native compile failed! (${file})" |
|
done |
|
|
|
popd >/dev/null |
|
} |
|
|
|
# ------------------------------------------------------------------------------ |
|
# @ebuild-function java-pkg_donative-bin |
|
# |
|
# Create native binary. |
|
# |
|
# Example: |
|
# java-pkg_donative-bin com.example.my.Main <name of native binary> |
|
# java-pkg_donative-bin com.example.my.Main <path to jar file> |
|
# |
|
# @param $1 - main function to call on execution of the native binary |
|
# @param $2 - optional: the name of resulting binary |
|
# path to jar file to turn native |
|
# ------------------------------------------------------------------------------ |
|
java-pkg_donative-bin() { |
|
java-pkg_native_init_ || return 0 |
|
[ -z "${1}" ] && die "set the main function to call for the binary!" |
|
|
|
if [ ".jar" == "${2: -4:4}" ] ; then |
|
pushd "${S}" >/dev/null |
|
|
|
echo gcj --main=${1} -o ${2/\.jar} ${2} \ |
|
${JAVA_PKG_NATIVE_BIN_FLAGS} ${CFLAGS} ${LDFLAGS} \ |
|
${JAVA_PKG_NATIVE_INC} ${JAVA_PKG_NATIVE_LIB} |
|
gcj --main=${1} -o ${2/\.jar} ${2} \ |
|
${JAVA_PKG_NATIVE_BIN_FLAGS} ${CFLAGS} ${LDFLAGS} \ |
|
${JAVA_PKG_NATIVE_INC} ${JAVA_PKG_NATIVE_LIB} \ |
|
|| die "build of native binary failed! (from jar)" |
|
else |
|
pushd "${S}/build/native" >/dev/null || die "no native build there!" |
|
|
|
local file files |
|
for file in $(find -type f -name '*.o' | cut -c3-) ; do |
|
files="${files} ${file}" |
|
done |
|
|
|
local bin="" |
|
if [ -n "${2}" ] ; then |
|
bin="${2}" |
|
elif [[ ( -n "${SLOT}" ) && ( "${SLOT}" != "0" ) ]] ; then |
|
bin="${PN}-native-${SLOT}" |
|
else |
|
bin="${PN}-native" |
|
fi |
|
|
|
echo gcj ${JAVA_PKG_NATIVE_BIN_FLAGS} \ |
|
--main=${1} -o ../${bin} ${LDFLAGS} \ |
|
${JAVA_PKG_NATIVE_LIB} ... |
|
gcj ${JAVA_PKG_NATIVE_BIN_FLAGS} \ |
|
--main=${1} -o ../${bin} ${LDFLAGS} \ |
|
${JAVA_PKG_NATIVE_LIB} ${files} \ |
|
|| die "build of native binary failed! (from source)" |
|
fi |
|
|
|
popd >/dev/null |
|
} |
|
|
|
# ------------------------------------------------------------------------------ |
|
# @ebuild-function java-pkg_skip-cachejar |
|
# |
|
# Skip caching of Jar files that match pattern. |
|
# |
|
# Example: |
|
# java-pkg_skip-cachejar org.eclipse.jdt.core_ org.eclipse.jdt.apt |
|
# java-pkg_skip-cachejar 2000 org.eclipse.jdt.ui_ |
|
# |
|
# param $1 - optional: memory size to check |
|
# param $@ - pattern of Jar files to skip |
|
# ------------------------------------------------------------------------------ |
|
java-pkg_skip-cachejar() { |
|
java-pkg_native_init_ || return 0 |
|
|
|
if [[ ${1} =~ ^[0-9]+$ ]] ; then |
|
CHECKREQS_MEMORY="${1}" |
|
check_reqs_conditional && return 0 |
|
shift |
|
fi |
|
|
|
JAVA_PKG_NATIVE_SKIP="${JAVA_PKG_NATIVE_SKIP} ${@}" |
|
} |
|
|
|
# ------------------------------------------------------------------------------ |
|
# @ebuild-function java-pkg_cachejar |
|
# |
|
# Create native library from jar. |
|
# For packages not using java-pkg_dojar. |
|
# |
|
# Example: |
|
# use gcj && java-pkg_cachejar |
|
# |
|
# @param $@ - none |
|
# ------------------------------------------------------------------------------ |
|
java-pkg_cachejar() { |
|
java-pkg_native_init_ || return 0 |
|
pushd "${D}" >/dev/null || die "This function is for src_install!" |
|
|
|
local jars jar |
|
for jar in $(find -type f -name '*.jar' | cut -c2-) ; do |
|
jars="${jars} ${jar}" |
|
done |
|
|
|
java-pkg_cachejar_ "${jars}" |
|
|
|
popd >/dev/null |
|
} |
|
|
|
# ------------------------------------------------------------------------------ |
|
# @internal-function java-pkg_cachejar_ |
|
# |
|
# Create native library from jar |
|
# ------------------------------------------------------------------------------ |
|
java-pkg_cachejar_() { |
|
java-pkg_native_init_ || return 0 |
|
|
|
local jars |
|
[ ${#} -lt 1 ] \ |
|
&& jars="${JAVA_PKG_CLASSPATH//:/ }" \ |
|
|| jars="${@}" |
|
|
|
local item jar to |
|
for jar in ${jars} ; do |
|
for item in ${JAVA_PKG_NATIVE_SKIP} ; do |
|
if [[ ${jar} =~ ${item} ]] ; then |
|
ewarn "skip: ${jar}" |
|
jar="no_native_lib" |
|
break |
|
fi |
|
done |
|
|
|
to="$(dirname ${jar})/lib$(basename ${jar}).so" |
|
if [[ ( -f "${D}${jar}" ) && ( ".jar" == "${jar: -4:4}" ) && ( ! -e "${D}${to}" ) ]] ; then |
|
echo gcj ${JAVA_PKG_NATIVE_CACHE_FLAGS} \ |
|
-g0 ${CFLAGS} -o ${to} ${jar} |
|
if ! gcj ${JAVA_PKG_NATIVE_CACHE_FLAGS} \ |
|
-g0 ${CFLAGS} -o ${D}${to} ${D}${jar} ; then |
|
ewarn "${to} build failed -> skipping" |
|
fi |
|
fi |
|
done |
|
} |
|
|
|
# ------------------------------------------------------------------------------ |
|
# @internal-function java-pkg_reg-cachejar_ |
|
# |
|
# Register native library |
|
# ------------------------------------------------------------------------------ |
|
java-pkg_reg-cachejar_() { |
|
java-pkg_native_init_ || return 0 |
|
[ -z "${JAVA_PKG_CLASSPATH}" ] && return 0 |
|
|
|
# Create new database? |
|
if [ ! -e "${JAVA_PKG_NATIVE_CLASSMAP}" ] ; then |
|
einfo "Create new database ..." |
|
[ -d "$(dirname ${JAVA_PKG_NATIVE_CLASSMAP})" ] \ |
|
|| mkdir -p "$(dirname ${JAVA_PKG_NATIVE_CLASSMAP})" |
|
gcj-dbtool -n ${JAVA_PKG_NATIVE_CLASSMAP} |
|
fi |
|
|
|
einfo "Register native library in database (${JAVA_PKG_NATIVE_CLASSMAP}) ..." |
|
|
|
local jar to |
|
for jar in ${JAVA_PKG_CLASSPATH//:/ } ; do |
|
to="$(dirname ${jar})/lib$(basename ${jar}).so" |
|
if [[ ( -f "${jar}" ) && ( ".jar" == "${jar: -4:4}" ) && ( -f "${to}" ) ]] ; then |
|
einfo "library: ${to}" |
|
gcj-dbtool -a ${JAVA_PKG_NATIVE_CLASSMAP} ${jar} ${to} \ |
|
|| die "failed to register jar file" |
|
fi |
|
done |
|
} |
|
|
|
# ------------------------------------------------------------------------------ |
# @internal-function java-pkg_die | # @internal-function java-pkg_die |
# | # |
# Enhanced die for Java packages, which displays some information that may be | # Enhanced die for Java packages, which displays some information that may be |