Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 21477 | Differences between
and this patch

Collapse All | Expand All

(-)/usr/portage/eclass/java-utils-2.eclass (-2 / +397 lines)
Lines 23-29 Link Here
23
#
23
#
24
# -----------------------------------------------------------------------------
24
# -----------------------------------------------------------------------------
25
25
26
inherit eutils versionator multilib
26
inherit check-reqs eutils flag-o-matic multilib versionator
27
27
28
IUSE="elibc_FreeBSD"
28
IUSE="elibc_FreeBSD"
29
29
Lines 175-180 Link Here
175
JAVA_PKG_QA_VIOLATIONS=0
175
JAVA_PKG_QA_VIOLATIONS=0
176
176
177
# -----------------------------------------------------------------------------
177
# -----------------------------------------------------------------------------
178
# @variable-internal JAVA_PKG_NATIVE_CLASSMAP
179
#
180
# Explicitly set classmap.gcjdb database file
181
# This is set by java-pkg_native_init_ once the libgcj ABI is known.
182
# Previously, it was externally configurable and defaulted to
183
#	JAVA_PKG_NATIVE_CLASSMAP="/usr/share/java/classmap.gcjdb"
184
# -----------------------------------------------------------------------------
185
JAVA_PKG_NATIVE_CLASSMAP=""
186
187
# -----------------------------------------------------------------------------
188
# @variable-internal JAVA_PKG_NATIVE_CACHE_FLAGS
189
#
190
# Required flags for native library
191
# -----------------------------------------------------------------------------
192
JAVA_PKG_NATIVE_CACHE_FLAGS="-shared -Wl,-Bsymbolic -fPIC -findirect-dispatch -fjni"
193
194
# -----------------------------------------------------------------------------
195
# @variable-internal JAVA_PKG_NATIVE_BIN_FLAGS
196
#
197
# Required ldflags for native binary set by java-pkg_native_init_
198
# -----------------------------------------------------------------------------
199
JAVA_PKG_NATIVE_BIN_FLAGS=""
200
201
# -----------------------------------------------------------------------------
202
# @variable-internal JAVA_PKG_NATIVE_INC
203
#
204
# Set include files (jar) to compile native code
205
# This is generated by java-pkg_gen-native-cp
206
# -----------------------------------------------------------------------------
207
JAVA_PKG_NATIVE_INC=""
208
209
# -----------------------------------------------------------------------------
210
# @variable-internal JAVA_PKG_NATIVE_LIB
211
#
212
# Set library files (jar.so) to link native code
213
# This is generated by java-pkg_gen-native-cp
214
# -----------------------------------------------------------------------------
215
JAVA_PKG_NATIVE_LIB=""
216
217
# -----------------------------------------------------------------------------
218
# @variable-internal JAVA_PKG_NATIVE_SKIP
219
#
220
# Jar files that match pattern will be skipped.
221
#
222
# @example
223
#	java-pkg_skip-cachejar org.eclipse.jdt.core_ org.eclipse.jdt.apt
224
#	java-pkg_skip-cachejar 2000 org.eclipse.jdt.ui_
225
#
226
# param $1 - optional: memory size to check
227
# param $@ - pattern of Jar files to skip
228
# -----------------------------------------------------------------------------
229
JAVA_PKG_NATIVE_SKIP=""
230
231
# -----------------------------------------------------------------------------
178
# @section-end variables
232
# @section-end variables
179
# -----------------------------------------------------------------------------
233
# -----------------------------------------------------------------------------
180
234
Lines 291-296 Link Here
291
	done
345
	done
292
346
293
	java-pkg_do_write_
347
	java-pkg_do_write_
348
	java-pkg_cachejar_
294
}
349
}
295
350
296
# ------------------------------------------------------------------------------
351
# ------------------------------------------------------------------------------
Lines 1604-1610 Link Here
1604
	else
1659
	else
1605
		# for everything else, try to determine from an env file
1660
		# for everything else, try to determine from an env file
1606
1661
1607
		local compiler_env="/usr/share/java-config-2/compiler/${compiler}"
1662
		local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1608
		if [[ -f ${compiler_env} ]]; then
1663
		if [[ -f ${compiler_env} ]]; then
1609
			local old_javac=${JAVAC}
1664
			local old_javac=${JAVAC}
1610
			unset JAVAC
1665
			unset JAVAC
Lines 2569-2574 Link Here
2569
}
2624
}
2570
2625
2571
# ------------------------------------------------------------------------------
2626
# ------------------------------------------------------------------------------
2627
# @internal-function java-pkg_gcjflags
2628
#
2629
# sanitze CFLAGS for GCJ native.
2630
# ------------------------------------------------------------------------------
2631
java-pkg_gcjflags() {
2632
	OPTIMIZE_CFLAGS=${CFLAGS}
2633
	strip-flags
2634
	filter-flags "-ftree-loop-distribution -ftree-vectorize"
2635
	replace-flags "-O?" "-O0"
2636
	append-flags -w
2637
2638
	filter-ldflags -Wl,--as-needed --as-needed
2639
}
2640
2641
# ------------------------------------------------------------------------------
2642
# @internal-function java-pkg_native_init_
2643
#
2644
# Check for issues, set default classmap db depending upon ABI
2645
#
2646
# @return 0 - procede with native build
2647
# @return 1 - skip native build
2648
# ------------------------------------------------------------------------------
2649
java-pkg_native_init_() {
2650
	if ! has gcj "${IUSE}" || ! use gcj ; then
2651
		return 1
2652
	fi
2653
2654
	# The libgcj ABI has a habbit of changing incompatibly between versions,
2655
	# if the current java-jdk is set to gcj-jdk, compare the ABI version
2656
	# with the current gcc libgcj ABI version, if it differs use the gcj
2657
	# from the java-jdk version, otherwise use the most recent installed
2658
	# gcj
2659
	local gccversion=$(gcc-config -c)
2660
	local gccbin=$(gcc-config -B)
2661
	local tc_libgcj_soversion=$(ls -l $(${gccbin}/gcj -print-file-name=libgcj.so) | sed -r 's:.*\.so\.([0-9]*).*$:\1:')
2662
	local jkd_libgcj_soversion=${tc_libgcj_soversion}
2663
	local gcj_java_home=$(java-config -O)
2664
        local libarch="${ARCH}"
2665
        [ ${ARCH} == x86 ] && libarch="i386"
2666
        [ ${ARCH} == x86_64 ] && libarch="amd64"
2667
 
2668
	if [[ $(echo "$(java-config -f)" | grep 'gcj-jdk') ]]; then
2669
		jdk_libgcj_soversion=$(java-config -O | sed -r 's:.*-([0-9]*)$:\1:')
2670
2671
 		if [[ "${tc_libgcj_soversion}" != "${jdk_libgcj_soversion}" ]]; then
2672
			local gccversion_=${gccversion}
2673
			gccversion=${CHOST}-$($(java-config -J) -version | grep libgcj | sed -r 's:.*version (.*[0-9]).*$:\1:g')
2674
			gccbin=$(gcc-config -B ${gccversion})
2675
2676
			einfo "The selected gcj-jdk uses a different ABI version (${jdk_libgcj_soversion})"
2677
			einfo "than the currently selected gcc (${gccversion_}; ABI version ${tc_libgcj_soversion})."
2678
			einfo ""
2679
		fi
2680
	else
2681
		if ! [[ $(echo "$(java-config -L)" | grep 'gcj-jdk') ]]; then
2682
			ewarn "gcj-jdk must be installed to use gcc/gcj as a JDK";
2683
			ewarn "and to compile java packages to native binaries.";
2684
			return 1
2685
		fi
2686
		for gccversion in $(ls -1r /etc/env.d/gcc/${CHOST}-*); do
2687
			gccbin=$(gcc-config -B ${gccversion})
2688
			if ( [[ -x ${gccbin}/gcj ]] &&
2689
			  [[ -x ${gccbin}/gcj-dbtool ]] ); then
2690
				jdk_libgcj_soversion=$(ls -l $(${gccbin}/gcj \
2691
				  -print-file-name=libgcj.so) \
2692
				  | sed -r 's#.*\.so\.([0-9]*).*$#\1#')
2693
				gcj_java_home=$(java-config --select-vm gcj-jdk -O)
2694
				break
2695
			fi
2696
		done
2697
		einfo "The Java JDK is not set to gcj-jdk."
2698
	fi
2699
2700
	# The ABI for libgcj must match the native binary/library
2701
	JAVA_PKG_NATIVE_CLASSMAP="/usr/share/java/classmap.gcjdb.${jdk_libgcj_soversion}"
2702
	JAVA_PKG_NATIVE_BIN_FLAGS="-Wl,-rpath ${gcj_java_home}/lib/${libarch} \
2703
		-Wl,-Bsymbolic -findirect-dispatch -fjni"
2704
2705
	gcj="${gccbin}/gcj"
2706
	gcj_dbtool="${gccbin}/gcj-dbtool"
2707
2708
	if [[ ( ! -x "$(which ${gcj})" ) || ( ! -x "$(which ${gcj_dbtool})" ) ]] ; then
2709
		# Do we want to die here?
2710
		ewarn "java native tools unusable!"
2711
		return 1
2712
	fi
2713
2714
	einfo "Using ${gccversion} to build native pkg..."
2715
2716
	java-pkg_gcjflags
2717
2718
	return 0
2719
}
2720
2721
# ------------------------------------------------------------------------------
2722
# @ebuild-function java-pkg_gen-native-cp
2723
#
2724
# Set include and library paths for native build.
2725
#
2726
# Example:
2727
#	java-pkg_gen-native-cp junit gnu-crypto ...
2728
#
2729
# @param $@ - space-separated list of packages
2730
# ------------------------------------------------------------------------------
2731
java-pkg_gen-native-cp() {
2732
	java-pkg_native_init_ || return 0
2733
2734
	local pkg cp item lib
2735
	for pkg in ${@} ; do
2736
		cp="$(java-config --classpath=${pkg})"
2737
		for item in ${cp//:/ } ; do
2738
			if [[ ( -f "${item}" ) && ( ".jar" == "${item: -4:4}" ) ]] ; then
2739
				lib="$(dirname ${item})/lib$(basename ${item}).so"
2740
				[ ! -f "${lib}" ] && die "Native library ${lib} from ${pkg} missing!"
2741
				JAVA_PKG_NATIVE_INC="${JAVA_PKG_NATIVE_INC} -I${item}"
2742
				JAVA_PKG_NATIVE_LIB="${JAVA_PKG_NATIVE_LIB} ${lib}"
2743
			fi
2744
		done
2745
	done
2746
}
2747
2748
# ------------------------------------------------------------------------------
2749
# @ebuild-function java-pkg_donative
2750
#
2751
# Compile Java source to native.
2752
#
2753
# Example:
2754
#	java-pkg_donative src/java/* ...
2755
#		Where '*' is org or com et cetera
2756
#
2757
# @param $@ - path to java source(s)
2758
# ------------------------------------------------------------------------------
2759
java-pkg_donative() {
2760
	java-pkg_native_init_ || return 0
2761
	einfo "Compile Java source to native ..."
2762
2763
	local buildpath="${S}/build/native"
2764
	mkdir -p "${buildpath}"
2765
2766
	local path
2767
	for path in ${@} ; do
2768
		cp -a "${path}" "${buildpath}"
2769
	done
2770
2771
	pushd "${buildpath}" >/dev/null || die "no native build there!"
2772
2773
	local file
2774
	for file in $(find -type f -name '*.java' | cut -c3-) ; do
2775
		echo ${gcj} -c -g0 ${OPTIMIZE_CFLAGS} -Wno-deprecated \
2776
			${JAVA_PKG_NATIVE_INC} ${file} -o ${file/\.java/.o}
2777
		${gcj} -c -g0 ${OPTIMIZE_CFLAGS} -Wno-deprecated \
2778
			${JAVA_PKG_NATIVE_INC} ${file} -o ${file/\.java/.o} \
2779
			|| die "java native compile failed! (${file})"
2780
	done
2781
2782
	# Any other resource formats out there?
2783
	# .properties, .rsc, .xml
2784
2785
	for file in $(find -type f \( -name '*.properties' -o -name '*.rsc' -o -name '*.xml' \) | cut -c3-) ; do
2786
		echo ${gcj} -c -g0 ${OPTIMIZE_CFLAGS} -Wno-deprecated \
2787
			--resource ${file} ${file} -o ${file}.o
2788
		${gcj} -c -g0 ${OPTIMIZE_CFLAGS} -Wno-deprecated \
2789
			--resource ${file} ${file} -o ${file}.o \
2790
			|| die "java native compile failed! (${file})"
2791
	done
2792
2793
	popd >/dev/null
2794
}
2795
2796
# ------------------------------------------------------------------------------
2797
# @ebuild-function java-pkg_donative-bin
2798
#
2799
# Create native binary.
2800
#
2801
# Example:
2802
#	java-pkg_donative-bin com.example.my.Main <name of native binary>
2803
#	java-pkg_donative-bin com.example.my.Main <path to jar file>
2804
#
2805
# @param $1 - main function to call on execution of the native binary
2806
# @param $2 - optional: the name of resulting binary
2807
#						path to jar file to turn native
2808
# ------------------------------------------------------------------------------
2809
java-pkg_donative-bin() {
2810
	java-pkg_native_init_ || return 0
2811
	[ -z "${1}" ] && die "set the main function to call for the binary!"
2812
2813
	if [ ".jar" == "${2: -4:4}" ] ; then
2814
		pushd "${S}" >/dev/null
2815
2816
		echo ${gcj} --main=${1} -o ${2/\.jar} ${2} \
2817
			${JAVA_PKG_NATIVE_BIN_FLAGS} ${CFLAGS} ${LDFLAGS} \
2818
			${JAVA_PKG_NATIVE_INC} ${JAVA_PKG_NATIVE_LIB}
2819
		${gcj} --main=${1} -o ${2/\.jar} ${2} \
2820
			${JAVA_PKG_NATIVE_BIN_FLAGS} ${CFLAGS} ${LDFLAGS} \
2821
			${JAVA_PKG_NATIVE_INC} ${JAVA_PKG_NATIVE_LIB} \
2822
			|| die "build of native binary failed! (from jar)"
2823
	else
2824
		pushd "${S}/build/native" >/dev/null || die "no native build there!"
2825
2826
		local file files
2827
		for file in $(find -type f -name '*.o' | cut -c3-) ; do
2828
			files="${files} ${file}"
2829
		done
2830
2831
		local bin=""
2832
		if [ -n "${2}" ] ; then
2833
			bin="${2}"
2834
		elif [[ ( -n "${SLOT}" ) && ( "${SLOT}" != "0" ) ]] ; then
2835
			bin="${PN}-native-${SLOT}"
2836
		else
2837
			bin="${PN}-native"
2838
		fi
2839
2840
		echo ${gcj} ${JAVA_PKG_NATIVE_BIN_FLAGS} \
2841
			--main=${1} -o ../${bin} ${LDFLAGS} \
2842
			${JAVA_PKG_NATIVE_LIB} ...
2843
		${gcj} ${JAVA_PKG_NATIVE_BIN_FLAGS} \
2844
			--main=${1} -o ../${bin} ${LDFLAGS} \
2845
			${JAVA_PKG_NATIVE_LIB} ${files} \
2846
			|| die "build of native binary failed! (from source)"
2847
	fi
2848
2849
	popd >/dev/null
2850
}
2851
2852
# ------------------------------------------------------------------------------
2853
# @ebuild-function java-pkg_skip-cachejar
2854
#
2855
# Skip caching of Jar files that match pattern.
2856
#
2857
# Example:
2858
#	java-pkg_skip-cachejar org.eclipse.jdt.core_ org.eclipse.jdt.apt
2859
#	java-pkg_skip-cachejar 2000 org.eclipse.jdt.ui_
2860
#
2861
# param $1 - optional: memory size to check
2862
# param $@ - pattern of Jar files to skip
2863
# ------------------------------------------------------------------------------
2864
java-pkg_skip-cachejar() {
2865
	java-pkg_native_init_ || return 0
2866
2867
	if [[ ${1} =~ ^[0-9]+$ ]] ; then
2868
		CHECKREQS_MEMORY="${1}"
2869
		check_reqs_conditional && return 0
2870
		shift
2871
	fi
2872
2873
	JAVA_PKG_NATIVE_SKIP="${JAVA_PKG_NATIVE_SKIP} ${@}"
2874
}
2875
2876
# ------------------------------------------------------------------------------
2877
# @ebuild-function java-pkg_cachejar
2878
#
2879
# Create native library from jar.
2880
# For packages not using java-pkg_dojar.
2881
#
2882
# Example:
2883
#	use gcj && java-pkg_cachejar
2884
#
2885
# @param $@ - none
2886
# ------------------------------------------------------------------------------
2887
java-pkg_cachejar() {
2888
	java-pkg_native_init_ || return 0
2889
	pushd "${D}" >/dev/null || die "This function is for src_install!"
2890
2891
	local jars jar
2892
	for jar in $(find -type f -name '*.jar' | cut -c2-) ; do
2893
		jars="${jars} ${jar}"
2894
	done
2895
2896
	java-pkg_cachejar_ "${jars}"
2897
2898
	popd >/dev/null
2899
}
2900
2901
# ------------------------------------------------------------------------------
2902
# @internal-function java-pkg_cachejar_
2903
#
2904
# Create native library from jar
2905
# ------------------------------------------------------------------------------
2906
java-pkg_cachejar_() {
2907
	java-pkg_native_init_ || return 0
2908
2909
	local jars
2910
	[ ${#} -lt 1 ] \
2911
		&& jars="${JAVA_PKG_CLASSPATH//:/ }" \
2912
		|| jars="${@}"
2913
2914
	local item jar to
2915
	for jar in ${jars} ; do
2916
		for item in ${JAVA_PKG_NATIVE_SKIP} ; do
2917
			if [[ ${jar} =~ ${item} ]] ; then
2918
				ewarn "skip: ${jar}"
2919
				jar="no_native_lib"
2920
				break
2921
			fi
2922
		done
2923
2924
		to="$(dirname ${jar})/lib$(basename ${jar}).so"
2925
		if [[ ( -f "${D}${jar}" ) && ( ".jar" == "${jar: -4:4}" ) && ( ! -e "${D}${to}" ) ]] ; then
2926
			echo ${gcj} ${JAVA_PKG_NATIVE_CACHE_FLAGS} \
2927
				-g0 ${CFLAGS} -o ${to} ${jar}
2928
			if ! ${gcj} ${JAVA_PKG_NATIVE_CACHE_FLAGS} \
2929
				-g0 ${CFLAGS} -o ${D}${to} ${D}${jar} ; then
2930
				ewarn "${to} build failed -> skipping"
2931
			fi
2932
		fi
2933
	done
2934
}
2935
2936
# ------------------------------------------------------------------------------
2937
# @internal-function java-pkg_reg-cachejar_
2938
#
2939
# Register native library
2940
# ------------------------------------------------------------------------------
2941
java-pkg_reg-cachejar_() {
2942
	java-pkg_native_init_ || return 0
2943
	[ -z "${JAVA_PKG_CLASSPATH}" ] && return 0
2944
2945
	# Create new database?
2946
	if [ ! -e "${JAVA_PKG_NATIVE_CLASSMAP}" ] ; then
2947
		einfo "Create new database ..."
2948
		[ -d "$(dirname ${JAVA_PKG_NATIVE_CLASSMAP})" ] \
2949
			|| mkdir -p "$(dirname ${JAVA_PKG_NATIVE_CLASSMAP})"
2950
		${gcj_dbtool} -n ${JAVA_PKG_NATIVE_CLASSMAP}
2951
	fi
2952
2953
	einfo "Register native library in database (${JAVA_PKG_NATIVE_CLASSMAP}) ..."
2954
2955
	local jar to
2956
	for jar in ${JAVA_PKG_CLASSPATH//:/ } ; do
2957
		to="$(dirname ${jar})/lib$(basename ${jar}).so"
2958
		if [[ ( -f "${jar}" ) && ( ".jar" == "${jar: -4:4}" ) && ( -f "${to}" ) ]] ; then
2959
			einfo "library: ${to}"
2960
			${gcj_dbtool} -a ${JAVA_PKG_NATIVE_CLASSMAP} ${jar} ${to} \
2961
				|| die "failed to register jar file"
2962
		fi
2963
	done
2964
}
2965
2966
# ------------------------------------------------------------------------------
2572
# @internal-function java-pkg_die
2967
# @internal-function java-pkg_die
2573
#
2968
#
2574
# Enhanced die for Java packages, which displays some information that may be
2969
# Enhanced die for Java packages, which displays some information that may be

Return to bug 21477