View | Details | Raw Unified
Collapse All | Expand All

(-) /usr/portage/eclass/java-utils-2.eclass (-2 / +397 lines)
 Lines 23-29    Link Here 
#
#
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
inherit eutils versionator multilib
inherit check-reqs eutils flag-o-matic multilib versionator
IUSE="elibc_FreeBSD"
IUSE="elibc_FreeBSD"
 Lines 175-180    Link Here 
JAVA_PKG_QA_VIOLATIONS=0
JAVA_PKG_QA_VIOLATIONS=0
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# @variable-internal JAVA_PKG_NATIVE_CLASSMAP
#
# Explicitly set classmap.gcjdb database file
# This is set by java-pkg_native_init_ once the libgcj ABI is known.
# Previously, it was externally configurable and defaulted to
#	JAVA_PKG_NATIVE_CLASSMAP="/usr/share/java/classmap.gcjdb"
# -----------------------------------------------------------------------------
JAVA_PKG_NATIVE_CLASSMAP=""
# -----------------------------------------------------------------------------
# @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 set by java-pkg_native_init_
# -----------------------------------------------------------------------------
JAVA_PKG_NATIVE_BIN_FLAGS=""
# -----------------------------------------------------------------------------
# @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
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
 Lines 291-296    Link Here 
	done
	done
	java-pkg_do_write_
	java-pkg_do_write_
	java-pkg_cachejar_
}
}
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
 Lines 1604-1610    Link Here 
	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
 Lines 2569-2574    Link Here 
}
}
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# @internal-function java-pkg_gcjflags
#
# sanitze CFLAGS for GCJ native.
# ------------------------------------------------------------------------------
java-pkg_gcjflags() {
	OPTIMIZE_CFLAGS=${CFLAGS}
	strip-flags
	filter-flags "-ftree-loop-distribution -ftree-vectorize"
	replace-flags "-O?" "-O0"
	append-flags -w
	filter-ldflags -Wl,--as-needed --as-needed
}
# ------------------------------------------------------------------------------
# @internal-function java-pkg_native_init_
#
# Check for issues, set default classmap db depending upon ABI
#
# @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
	# The libgcj ABI has a habbit of changing incompatibly between versions,
	# if the current java-jdk is set to gcj-jdk, compare the ABI version
	# with the current gcc libgcj ABI version, if it differs use the gcj
	# from the java-jdk version, otherwise use the most recent installed
	# gcj
	local gccversion=$(gcc-config -c)
	local gccbin=$(gcc-config -B)
	local tc_libgcj_soversion=$(ls -l $(${gccbin}/gcj -print-file-name=libgcj.so) | sed -r 's:.*\.so\.([0-9]*).*$:\1:')
	local jkd_libgcj_soversion=${tc_libgcj_soversion}
	local gcj_java_home=$(java-config -O)
        local libarch="${ARCH}"
        [ ${ARCH} == x86 ] && libarch="i386"
        [ ${ARCH} == x86_64 ] && libarch="amd64"
 
	if [[ $(echo "$(java-config -f)" | grep 'gcj-jdk') ]]; then
		jdk_libgcj_soversion=$(java-config -O | sed -r 's:.*-([0-9]*)$:\1:')
 		if [[ "${tc_libgcj_soversion}" != "${jdk_libgcj_soversion}" ]]; then
			local gccversion_=${gccversion}
			gccversion=${CHOST}-$($(java-config -J) -version | grep libgcj | sed -r 's:.*version (.*[0-9]).*$:\1:g')
			gccbin=$(gcc-config -B ${gccversion})
			einfo "The selected gcj-jdk uses a different ABI version (${jdk_libgcj_soversion})"
			einfo "than the currently selected gcc (${gccversion_}; ABI version ${tc_libgcj_soversion})."
			einfo ""
		fi
	else
		if ! [[ $(echo "$(java-config -L)" | grep 'gcj-jdk') ]]; then
			ewarn "gcj-jdk must be installed to use gcc/gcj as a JDK";
			ewarn "and to compile java packages to native binaries.";
			return 1
		fi
		for gccversion in $(ls -1r /etc/env.d/gcc/${CHOST}-*); do
			gccbin=$(gcc-config -B ${gccversion})
			if ( [[ -x ${gccbin}/gcj ]] &&
			  [[ -x ${gccbin}/gcj-dbtool ]] ); then
				jdk_libgcj_soversion=$(ls -l $(${gccbin}/gcj \
				  -print-file-name=libgcj.so) \
				  | sed -r 's#.*\.so\.([0-9]*).*$#\1#')
				gcj_java_home=$(java-config --select-vm gcj-jdk -O)
				break
			fi
		done
		einfo "The Java JDK is not set to gcj-jdk."
	fi
	# The ABI for libgcj must match the native binary/library
	JAVA_PKG_NATIVE_CLASSMAP="/usr/share/java/classmap.gcjdb.${jdk_libgcj_soversion}"
	JAVA_PKG_NATIVE_BIN_FLAGS="-Wl,-rpath ${gcj_java_home}/lib/${libarch} \
		-Wl,-Bsymbolic -findirect-dispatch -fjni"
	gcj="${gccbin}/gcj"
	gcj_dbtool="${gccbin}/gcj-dbtool"
	if [[ ( ! -x "$(which ${gcj})" ) || ( ! -x "$(which ${gcj_dbtool})" ) ]] ; then
		# Do we want to die here?
		ewarn "java native tools unusable!"
		return 1
	fi
	einfo "Using ${gccversion} to build native pkg..."
	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 ${OPTIMIZE_CFLAGS} -Wno-deprecated \
			${JAVA_PKG_NATIVE_INC} ${file} -o ${file/\.java/.o}
		${gcj} -c -g0 ${OPTIMIZE_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 ${OPTIMIZE_CFLAGS} -Wno-deprecated \
			--resource ${file} ${file} -o ${file}.o
		${gcj} -c -g0 ${OPTIMIZE_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