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 / +338 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-external JAVA_PKG_NATIVE_CLASSMAP
179
#
180
# Explicitly set classmap.gcjdb database file
181
#
182
# @example for /etc/make.conf
183
#	JAVA_PKG_NATIVE_CLASSMAP="/usr/share/java/classmap.gcjdb"
184
# -----------------------------------------------------------------------------
185
JAVA_PKG_NATIVE_CLASSMAP=${JAVA_PKG_NATIVE_CLASSMAP:="/usr/share/java/classmap.gcjdb"}
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
198
# -----------------------------------------------------------------------------
199
JAVA_PKG_NATIVE_BIN_FLAGS="-Wl,-Bsymbolic -findirect-dispatch -fjni"
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 1604-1610 Link Here
1604
	else
1660
	else
1605
		# for everything else, try to determine from an env file
1661
		# for everything else, try to determine from an env file
1606
1662
1607
		local compiler_env="/usr/share/java-config-2/compiler/${compiler}"
1663
		local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1608
		if [[ -f ${compiler_env} ]]; then
1664
		if [[ -f ${compiler_env} ]]; then
1609
			local old_javac=${JAVAC}
1665
			local old_javac=${JAVAC}
1610
			unset JAVAC
1666
			unset JAVAC
Lines 2569-2574 Link Here
2569
}
2618
}
2570
2619
2571
# ------------------------------------------------------------------------------
2620
# ------------------------------------------------------------------------------
2621
# @internal-function java-pkg_gcjflags
2622
#
2623
# sanitze CFLAGS for GCJ native.
2624
# ------------------------------------------------------------------------------
2625
java-pkg_gcjflags() {
2626
	strip-flags
2627
	filter-flags "-ftree-loop-distribution -ftree-vectorize"
2628
	replace-flags "-O?" "-Os"
2629
	append-flags -w
2630
2631
	filter-ldflags -Wl,--as-needed --as-needed
2632
}
2633
2634
# ------------------------------------------------------------------------------
2635
# @internal-function java-pkg_native_init_
2636
#
2637
# Check for issues.
2638
#
2639
# @return 0 - procede with native build
2640
# @return 1 - skip native build
2641
# ------------------------------------------------------------------------------
2642
java-pkg_native_init_() {
2643
	if ! has gcj "${IUSE}" || ! use gcj ; then
2644
		return 1
2645
	fi
2646
	if [[ ( ! -x "$(which gcj)" ) || ( ! -x "$(which gcj-dbtool)" ) ]] ; then
2647
		# Do we want to die here?
2648
		ewarn "java native tools unusable!"
2649
		return 1
2650
	fi
2651
2652
	java-pkg_gcjflags
2653
2654
	return 0
2655
}
2656
2657
# ------------------------------------------------------------------------------
2658
# @ebuild-function java-pkg_gen-native-cp
2659
#
2660
# Set include and library paths for native build.
2661
#
2662
# Example:
2663
#	java-pkg_gen-native-cp junit gnu-crypto ...
2664
#
2665
# @param $@ - space-separated list of packages
2666
# ------------------------------------------------------------------------------
2667
java-pkg_gen-native-cp() {
2668
	java-pkg_native_init_ || return 0
2669
2670
	local pkg cp item lib
2671
	for pkg in ${@} ; do
2672
		cp="$(java-config --classpath=${pkg})"
2673
		for item in ${cp//:/ } ; do
2674
			if [[ ( -f "${item}" ) && ( ".jar" == "${item: -4:4}" ) ]] ; then
2675
				lib="$(dirname ${item})/lib$(basename ${item}).so"
2676
				[ ! -f "${lib}" ] && die "Native library ${lib} from ${pkg} missing!"
2677
				JAVA_PKG_NATIVE_INC="${JAVA_PKG_NATIVE_INC} -I${item}"
2678
				JAVA_PKG_NATIVE_LIB="${JAVA_PKG_NATIVE_LIB} ${lib}"
2679
			fi
2680
		done
2681
	done
2682
}
2683
2684
# ------------------------------------------------------------------------------
2685
# @ebuild-function java-pkg_donative
2686
#
2687
# Compile Java source to native.
2688
#
2689
# Example:
2690
#	java-pkg_donative src/java/* ...
2691
#		Where '*' is org or com et cetera
2692
#
2693
# @param $@ - path to java source(s)
2694
# ------------------------------------------------------------------------------
2695
java-pkg_donative() {
2696
	java-pkg_native_init_ || return 0
2697
	einfo "Compile Java source to native ..."
2698
2699
	local buildpath="${S}/build/native"
2700
	mkdir -p "${buildpath}"
2701
2702
	local path
2703
	for path in ${@} ; do
2704
		cp -a "${path}" "${buildpath}"
2705
	done
2706
2707
	pushd "${buildpath}" >/dev/null || die "no native build there!"
2708
2709
	local file
2710
	for file in $(find -type f -name '*.java' | cut -c3-) ; do
2711
		echo gcj -c -g0 ${CFLAGS} -Wno-deprecated \
2712
			${JAVA_PKG_NATIVE_INC} ${file} -o ${file/\.java/.o}
2713
		gcj -c -g0 ${CFLAGS} -Wno-deprecated \
2714
			${JAVA_PKG_NATIVE_INC} ${file} -o ${file/\.java/.o} \
2715
			|| die "java native compile failed! (${file})"
2716
	done
2717
2718
	# Any other resource formats out there?
2719
	# .properties, .rsc, .xml
2720
2721
	for file in $(find -type f \( -name '*.properties' -o -name '*.rsc' -o -name '*.xml' \) | cut -c3-) ; do
2722
		echo gcj -c -g0 ${CFLAGS} -Wno-deprecated \
2723
			--resource ${file} ${file} -o ${file}.o
2724
		gcj -c -g0 ${CFLAGS} -Wno-deprecated \
2725
			--resource ${file} ${file} -o ${file}.o \
2726
			|| die "java native compile failed! (${file})"
2727
	done
2728
2729
	popd >/dev/null
2730
}
2731
2732
# ------------------------------------------------------------------------------
2733
# @ebuild-function java-pkg_donative-bin
2734
#
2735
# Create native binary.
2736
#
2737
# Example:
2738
#	java-pkg_donative-bin com.example.my.Main <name of native binary>
2739
#	java-pkg_donative-bin com.example.my.Main <path to jar file>
2740
#
2741
# @param $1 - main function to call on execution of the native binary
2742
# @param $2 - optional: the name of resulting binary
2743
#						path to jar file to turn native
2744
# ------------------------------------------------------------------------------
2745
java-pkg_donative-bin() {
2746
	java-pkg_native_init_ || return 0
2747
	[ -z "${1}" ] && die "set the main function to call for the binary!"
2748
2749
	if [ ".jar" == "${2: -4:4}" ] ; then
2750
		pushd "${S}" >/dev/null
2751
2752
		echo gcj --main=${1} -o ${2/\.jar} ${2} \
2753
			${JAVA_PKG_NATIVE_BIN_FLAGS} ${CFLAGS} ${LDFLAGS} \
2754
			${JAVA_PKG_NATIVE_INC} ${JAVA_PKG_NATIVE_LIB}
2755
		gcj --main=${1} -o ${2/\.jar} ${2} \
2756
			${JAVA_PKG_NATIVE_BIN_FLAGS} ${CFLAGS} ${LDFLAGS} \
2757
			${JAVA_PKG_NATIVE_INC} ${JAVA_PKG_NATIVE_LIB} \
2758
			|| die "build of native binary failed! (from jar)"
2759
	else
2760
		pushd "${S}/build/native" >/dev/null || die "no native build there!"
2761
2762
		local file files
2763
		for file in $(find -type f -name '*.o' | cut -c3-) ; do
2764
			files="${files} ${file}"
2765
		done
2766
2767
		local bin=""
2768
		if [ -n "${2}" ] ; then
2769
			bin="${2}"
2770
		elif [[ ( -n "${SLOT}" ) && ( "${SLOT}" != "0" ) ]] ; then
2771
			bin="${PN}-native-${SLOT}"
2772
		else
2773
			bin="${PN}-native"
2774
		fi
2775
2776
		echo gcj ${JAVA_PKG_NATIVE_BIN_FLAGS} \
2777
			--main=${1} -o ../${bin} ${LDFLAGS} \
2778
			${JAVA_PKG_NATIVE_LIB} ...
2779
		gcj ${JAVA_PKG_NATIVE_BIN_FLAGS} \
2780
			--main=${1} -o ../${bin} ${LDFLAGS} \
2781
			${JAVA_PKG_NATIVE_LIB} ${files} \
2782
			|| die "build of native binary failed! (from source)"
2783
	fi
2784
2785
	popd >/dev/null
2786
}
2787
2788
# ------------------------------------------------------------------------------
2789
# @ebuild-function java-pkg_skip-cachejar
2790
#
2791
# Skip caching of Jar files that match pattern.
2792
#
2793
# Example:
2794
#	java-pkg_skip-cachejar org.eclipse.jdt.core_ org.eclipse.jdt.apt
2795
#	java-pkg_skip-cachejar 2000 org.eclipse.jdt.ui_
2796
#
2797
# param $1 - optional: memory size to check
2798
# param $@ - pattern of Jar files to skip
2799
# ------------------------------------------------------------------------------
2800
java-pkg_skip-cachejar() {
2801
	java-pkg_native_init_ || return 0
2802
2803
	if [[ ${1} =~ ^[0-9]+$ ]] ; then
2804
		CHECKREQS_MEMORY="${1}"
2805
		check_reqs_conditional && return 0
2806
		shift
2807
	fi
2808
2809
	JAVA_PKG_NATIVE_SKIP="${JAVA_PKG_NATIVE_SKIP} ${@}"
2810
}
2811
2812
# ------------------------------------------------------------------------------
2813
# @ebuild-function java-pkg_cachejar
2814
#
2815
# Create native library from jar.
2816
# For packages not using java-pkg_dojar.
2817
#
2818
# Example:
2819
#	use gcj && java-pkg_cachejar
2820
#
2821
# @param $@ - none
2822
# ------------------------------------------------------------------------------
2823
java-pkg_cachejar() {
2824
	java-pkg_native_init_ || return 0
2825
	pushd "${D}" >/dev/null || die "This function is for src_install!"
2826
2827
	local jars jar
2828
	for jar in $(find -type f -name '*.jar' | cut -c2-) ; do
2829
		jars="${jars} ${jar}"
2830
	done
2831
2832
	java-pkg_cachejar_ "${jars}"
2833
2834
	popd >/dev/null
2835
}
2836
2837
# ------------------------------------------------------------------------------
2838
# @internal-function java-pkg_cachejar_
2839
#
2840
# Create native library from jar
2841
# ------------------------------------------------------------------------------
2842
java-pkg_cachejar_() {
2843
	java-pkg_native_init_ || return 0
2844
2845
	local jars
2846
	[ ${#} -lt 1 ] \
2847
		&& jars="${JAVA_PKG_CLASSPATH//:/ }" \
2848
		|| jars="${@}"
2849
2850
	local item jar to
2851
	for jar in ${jars} ; do
2852
		for item in ${JAVA_PKG_NATIVE_SKIP} ; do
2853
			if [[ ${jar} =~ ${item} ]] ; then
2854
				ewarn "skip: ${jar}"
2855
				jar="no_native_lib"
2856
				break
2857
			fi
2858
		done
2859
2860
		to="$(dirname ${jar})/lib$(basename ${jar}).so"
2861
		if [[ ( -f "${D}${jar}" ) && ( ".jar" == "${jar: -4:4}" ) && ( ! -e "${D}${to}" ) ]] ; then
2862
			echo gcj ${JAVA_PKG_NATIVE_CACHE_FLAGS} \
2863
				-g0 ${CFLAGS} -o ${to} ${jar}
2864
			if ! gcj ${JAVA_PKG_NATIVE_CACHE_FLAGS} \
2865
				-g0 ${CFLAGS} -o ${D}${to} ${D}${jar} ; then
2866
				ewarn "${to} build failed -> skipping"
2867
			fi
2868
		fi
2869
	done
2870
}
2871
2872
# ------------------------------------------------------------------------------
2873
# @internal-function java-pkg_reg-cachejar_
2874
#
2875
# Register native library
2876
# ------------------------------------------------------------------------------
2877
java-pkg_reg-cachejar_() {
2878
	java-pkg_native_init_ || return 0
2879
	[ -z "${JAVA_PKG_CLASSPATH}" ] && return 0
2880
2881
	# Create new database?
2882
	if [ ! -e "${JAVA_PKG_NATIVE_CLASSMAP}" ] ; then
2883
		einfo "Create new database ..."
2884
		[ -d "$(dirname ${JAVA_PKG_NATIVE_CLASSMAP})" ] \
2885
			|| mkdir -p "$(dirname ${JAVA_PKG_NATIVE_CLASSMAP})"
2886
		gcj-dbtool -n ${JAVA_PKG_NATIVE_CLASSMAP}
2887
	fi
2888
2889
	einfo "Register native library in database (${JAVA_PKG_NATIVE_CLASSMAP}) ..."
2890
2891
	local jar to
2892
	for jar in ${JAVA_PKG_CLASSPATH//:/ } ; do
2893
		to="$(dirname ${jar})/lib$(basename ${jar}).so"
2894
		if [[ ( -f "${jar}" ) && ( ".jar" == "${jar: -4:4}" ) && ( -f "${to}" ) ]] ; then
2895
			einfo "library: ${to}"
2896
			gcj-dbtool -a ${JAVA_PKG_NATIVE_CLASSMAP} ${jar} ${to} \
2897
				|| die "failed to register jar file"
2898
		fi
2899
	done
2900
}
2901
2902
# ------------------------------------------------------------------------------
2572
# @internal-function java-pkg_die
2903
# @internal-function java-pkg_die
2573
#
2904
#
2574
# Enhanced die for Java packages, which displays some information that may be
2905
# Enhanced die for Java packages, which displays some information that may be

Return to bug 21477