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 |
|
2663 |
if [[ $(echo "$(java-config -f)" | grep 'gcj-jdk') ]]; then |
2664 |
local jdk_libgcj_soversion=$(java-config -O | sed -r 's:.*-([0-9]*)$:\1:') |
2665 |
|
2666 |
if [[ "${tc_libgcj_soversion}" != "${jdk_libgcj_soversion}" ]]; then |
2667 |
local gccversion_=${gccversion} |
2668 |
gccversion=${CHOST}-$(java-config -O | sed -r 's:.*gcj-(.*)-[0-9]*$:\1:') |
2669 |
gccbin=$(gcc-config -B ${gccversion}) |
2670 |
einfo "The selected gcj-jdk uses a different ABI version (${jdk_libgcj_soversion})" |
2671 |
einfo "than the currently selected gcc (${gccversion_}; ABI version ${tc_libgcj_soversion})." |
2672 |
einfo "" |
2673 |
fi |
2674 |
else |
2675 |
if ! [[ $(echo "$(java-config -L)" | grep 'gcj-jdk') ]]; then |
2676 |
ewarn "gcj-jdk must be installed to use gcc/gcj as a JDK"; |
2677 |
ewarn "and to compile java packages to native binaries."; |
2678 |
return 1 |
2679 |
fi |
2680 |
for gccversion in $(ls -1r /etc/env.d/gcc/${CHOST}-*); do |
2681 |
gccbin=$(gcc-config -B ${gccversion}) |
2682 |
if ( [[ -x ${gccbin}/gcj ]] && |
2683 |
[[ -x ${gccbin}/gcj-dbtool ]] ); then |
2684 |
local jdk_libgcj_soversion=$(ls -l $(${gccbin}/gcj \ |
2685 |
-print-file-name=libgcj.so) \ |
2686 |
| sed -r 's#.*\.so\.([0-9]*).*$#\1#') |
2687 |
break |
2688 |
fi |
2689 |
done |
2690 |
einfo "The Java JDK is not set to gcj-jdk." |
2691 |
fi |
2692 |
|
2693 |
# The ABI for libgcj must match the native binary/library |
2694 |
JAVA_PKG_NATIVE_CLASSMAP="/usr/share/java/classmap.gcjdb.${jdk_libgcj_soversion}" |
2695 |
JAVA_PKG_NATIVE_BIN_FLAGS="-Wl,-rpath,$(gcc-config -L ${gccversion} | \ |
2696 |
awk -F: '{ print $1 }') \ |
2697 |
-Wl,-Bsymbolic -findirect-dispatch -fjni" |
2698 |
|
2699 |
gcj="${gccbin}/gcj" |
2700 |
gcj_dbtool="${gccbin}/gcj-dbtool" |
2701 |
|
2702 |
if [[ ( ! -x "$(which ${gcj})" ) || ( ! -x "$(which ${gcj_dbtool})" ) ]] ; then |
2703 |
# Do we want to die here? |
2704 |
ewarn "java native tools unusable!" |
2705 |
return 1 |
2706 |
fi |
2707 |
|
2708 |
einfo "Using ${gccversion} to build native pkg..." |
2709 |
|
2710 |
java-pkg_gcjflags |
2711 |
|
2712 |
return 0 |
2713 |
} |
2714 |
|
2715 |
# ------------------------------------------------------------------------------ |
2716 |
# @ebuild-function java-pkg_gen-native-cp |
2717 |
# |
2718 |
# Set include and library paths for native build. |
2719 |
# |
2720 |
# Example: |
2721 |
# java-pkg_gen-native-cp junit gnu-crypto ... |
2722 |
# |
2723 |
# @param $@ - space-separated list of packages |
2724 |
# ------------------------------------------------------------------------------ |
2725 |
java-pkg_gen-native-cp() { |
2726 |
java-pkg_native_init_ || return 0 |
2727 |
|
2728 |
local pkg cp item lib |
2729 |
for pkg in ${@} ; do |
2730 |
cp="$(java-config --classpath=${pkg})" |
2731 |
for item in ${cp//:/ } ; do |
2732 |
if [[ ( -f "${item}" ) && ( ".jar" == "${item: -4:4}" ) ]] ; then |
2733 |
lib="$(dirname ${item})/lib$(basename ${item}).so" |
2734 |
[ ! -f "${lib}" ] && die "Native library ${lib} from ${pkg} missing!" |
2735 |
JAVA_PKG_NATIVE_INC="${JAVA_PKG_NATIVE_INC} -I${item}" |
2736 |
JAVA_PKG_NATIVE_LIB="${JAVA_PKG_NATIVE_LIB} ${lib}" |
2737 |
fi |
2738 |
done |
2739 |
done |
2740 |
} |
2741 |
|
2742 |
# ------------------------------------------------------------------------------ |
2743 |
# @ebuild-function java-pkg_donative |
2744 |
# |
2745 |
# Compile Java source to native. |
2746 |
# |
2747 |
# Example: |
2748 |
# java-pkg_donative src/java/* ... |
2749 |
# Where '*' is org or com et cetera |
2750 |
# |
2751 |
# @param $@ - path to java source(s) |
2752 |
# ------------------------------------------------------------------------------ |
2753 |
java-pkg_donative() { |
2754 |
java-pkg_native_init_ || return 0 |
2755 |
einfo "Compile Java source to native ..." |
2756 |
|
2757 |
local buildpath="${S}/build/native" |
2758 |
mkdir -p "${buildpath}" |
2759 |
|
2760 |
local path |
2761 |
for path in ${@} ; do |
2762 |
cp -a "${path}" "${buildpath}" |
2763 |
done |
2764 |
|
2765 |
pushd "${buildpath}" >/dev/null || die "no native build there!" |
2766 |
|
2767 |
local file |
2768 |
for file in $(find -type f -name '*.java' | cut -c3-) ; do |
2769 |
echo ${gcj} -c -g0 ${OPTIMIZE_CFLAGS} -Wno-deprecated \ |
2770 |
${JAVA_PKG_NATIVE_INC} ${file} -o ${file/\.java/.o} |
2771 |
${gcj} -c -g0 ${OPTIMIZE_CFLAGS} -Wno-deprecated \ |
2772 |
${JAVA_PKG_NATIVE_INC} ${file} -o ${file/\.java/.o} \ |
2773 |
|| die "java native compile failed! (${file})" |
2774 |
done |
2775 |
|
2776 |
# Any other resource formats out there? |
2777 |
# .properties, .rsc, .xml |
2778 |
|
2779 |
for file in $(find -type f \( -name '*.properties' -o -name '*.rsc' -o -name '*.xml' \) | cut -c3-) ; do |
2780 |
echo ${gcj} -c -g0 ${OPTIMIZE_CFLAGS} -Wno-deprecated \ |
2781 |
--resource ${file} ${file} -o ${file}.o |
2782 |
${gcj} -c -g0 ${OPTIMIZE_CFLAGS} -Wno-deprecated \ |
2783 |
--resource ${file} ${file} -o ${file}.o \ |
2784 |
|| die "java native compile failed! (${file})" |
2785 |
done |
2786 |
|
2787 |
popd >/dev/null |
2788 |
} |
2789 |
|
2790 |
# ------------------------------------------------------------------------------ |
2791 |
# @ebuild-function java-pkg_donative-bin |
2792 |
# |
2793 |
# Create native binary. |
2794 |
# |
2795 |
# Example: |
2796 |
# java-pkg_donative-bin com.example.my.Main <name of native binary> |
2797 |
# java-pkg_donative-bin com.example.my.Main <path to jar file> |
2798 |
# |
2799 |
# @param $1 - main function to call on execution of the native binary |
2800 |
# @param $2 - optional: the name of resulting binary |
2801 |
# path to jar file to turn native |
2802 |
# ------------------------------------------------------------------------------ |
2803 |
java-pkg_donative-bin() { |
2804 |
java-pkg_native_init_ || return 0 |
2805 |
[ -z "${1}" ] && die "set the main function to call for the binary!" |
2806 |
|
2807 |
if [ ".jar" == "${2: -4:4}" ] ; then |
2808 |
pushd "${S}" >/dev/null |
2809 |
|
2810 |
echo ${gcj} --main=${1} -o ${2/\.jar} ${2} \ |
2811 |
${JAVA_PKG_NATIVE_BIN_FLAGS} ${CFLAGS} ${LDFLAGS} \ |
2812 |
${JAVA_PKG_NATIVE_INC} ${JAVA_PKG_NATIVE_LIB} |
2813 |
${gcj} --main=${1} -o ${2/\.jar} ${2} \ |
2814 |
${JAVA_PKG_NATIVE_BIN_FLAGS} ${CFLAGS} ${LDFLAGS} \ |
2815 |
${JAVA_PKG_NATIVE_INC} ${JAVA_PKG_NATIVE_LIB} \ |
2816 |
|| die "build of native binary failed! (from jar)" |
2817 |
else |
2818 |
pushd "${S}/build/native" >/dev/null || die "no native build there!" |
2819 |
|
2820 |
local file files |
2821 |
for file in $(find -type f -name '*.o' | cut -c3-) ; do |
2822 |
files="${files} ${file}" |
2823 |
done |
2824 |
|
2825 |
local bin="" |
2826 |
if [ -n "${2}" ] ; then |
2827 |
bin="${2}" |
2828 |
elif [[ ( -n "${SLOT}" ) && ( "${SLOT}" != "0" ) ]] ; then |
2829 |
bin="${PN}-native-${SLOT}" |
2830 |
else |
2831 |
bin="${PN}-native" |
2832 |
fi |
2833 |
|
2834 |
echo ${gcj} ${JAVA_PKG_NATIVE_BIN_FLAGS} \ |
2835 |
--main=${1} -o ../${bin} ${LDFLAGS} \ |
2836 |
${JAVA_PKG_NATIVE_LIB} ... |
2837 |
${gcj} ${JAVA_PKG_NATIVE_BIN_FLAGS} \ |
2838 |
--main=${1} -o ../${bin} ${LDFLAGS} \ |
2839 |
${JAVA_PKG_NATIVE_LIB} ${files} \ |
2840 |
|| die "build of native binary failed! (from source)" |
2841 |
fi |
2842 |
|
2843 |
popd >/dev/null |
2844 |
} |
2845 |
|
2846 |
# ------------------------------------------------------------------------------ |
2847 |
# @ebuild-function java-pkg_skip-cachejar |
2848 |
# |
2849 |
# Skip caching of Jar files that match pattern. |
2850 |
# |
2851 |
# Example: |
2852 |
# java-pkg_skip-cachejar org.eclipse.jdt.core_ org.eclipse.jdt.apt |
2853 |
# java-pkg_skip-cachejar 2000 org.eclipse.jdt.ui_ |
2854 |
# |
2855 |
# param $1 - optional: memory size to check |
2856 |
# param $@ - pattern of Jar files to skip |
2857 |
# ------------------------------------------------------------------------------ |
2858 |
java-pkg_skip-cachejar() { |
2859 |
java-pkg_native_init_ || return 0 |
2860 |
|
2861 |
if [[ ${1} =~ ^[0-9]+$ ]] ; then |
2862 |
CHECKREQS_MEMORY="${1}" |
2863 |
check_reqs_conditional && return 0 |
2864 |
shift |
2865 |
fi |
2866 |
|
2867 |
JAVA_PKG_NATIVE_SKIP="${JAVA_PKG_NATIVE_SKIP} ${@}" |
2868 |
} |
2869 |
|
2870 |
# ------------------------------------------------------------------------------ |
2871 |
# @ebuild-function java-pkg_cachejar |
2872 |
# |
2873 |
# Create native library from jar. |
2874 |
# For packages not using java-pkg_dojar. |
2875 |
# |
2876 |
# Example: |
2877 |
# use gcj && java-pkg_cachejar |
2878 |
# |
2879 |
# @param $@ - none |
2880 |
# ------------------------------------------------------------------------------ |
2881 |
java-pkg_cachejar() { |
2882 |
java-pkg_native_init_ || return 0 |
2883 |
pushd "${D}" >/dev/null || die "This function is for src_install!" |
2884 |
|
2885 |
local jars jar |
2886 |
for jar in $(find -type f -name '*.jar' | cut -c2-) ; do |
2887 |
jars="${jars} ${jar}" |
2888 |
done |
2889 |
|
2890 |
java-pkg_cachejar_ "${jars}" |
2891 |
|
2892 |
popd >/dev/null |
2893 |
} |
2894 |
|
2895 |
# ------------------------------------------------------------------------------ |
2896 |
# @internal-function java-pkg_cachejar_ |
2897 |
# |
2898 |
# Create native library from jar |
2899 |
# ------------------------------------------------------------------------------ |
2900 |
java-pkg_cachejar_() { |
2901 |
java-pkg_native_init_ || return 0 |
2902 |
|
2903 |
local jars |
2904 |
[ ${#} -lt 1 ] \ |
2905 |
&& jars="${JAVA_PKG_CLASSPATH//:/ }" \ |
2906 |
|| jars="${@}" |
2907 |
|
2908 |
local item jar to |
2909 |
for jar in ${jars} ; do |
2910 |
for item in ${JAVA_PKG_NATIVE_SKIP} ; do |
2911 |
if [[ ${jar} =~ ${item} ]] ; then |
2912 |
ewarn "skip: ${jar}" |
2913 |
jar="no_native_lib" |
2914 |
break |
2915 |
fi |
2916 |
done |
2917 |
|
2918 |
to="$(dirname ${jar})/lib$(basename ${jar}).so" |
2919 |
if [[ ( -f "${D}${jar}" ) && ( ".jar" == "${jar: -4:4}" ) && ( ! -e "${D}${to}" ) ]] ; then |
2920 |
echo ${gcj} ${JAVA_PKG_NATIVE_CACHE_FLAGS} \ |
2921 |
-g0 ${CFLAGS} -o ${to} ${jar} |
2922 |
if ! ${gcj} ${JAVA_PKG_NATIVE_CACHE_FLAGS} \ |
2923 |
-g0 ${CFLAGS} -o ${D}${to} ${D}${jar} ; then |
2924 |
ewarn "${to} build failed -> skipping" |
2925 |
fi |
2926 |
fi |
2927 |
done |
2928 |
} |
2929 |
|
2930 |
# ------------------------------------------------------------------------------ |
2931 |
# @internal-function java-pkg_reg-cachejar_ |
2932 |
# |
2933 |
# Register native library |
2934 |
# ------------------------------------------------------------------------------ |
2935 |
java-pkg_reg-cachejar_() { |
2936 |
java-pkg_native_init_ || return 0 |
2937 |
[ -z "${JAVA_PKG_CLASSPATH}" ] && return 0 |
2938 |
|
2939 |
# Create new database? |
2940 |
if [ ! -e "${JAVA_PKG_NATIVE_CLASSMAP}" ] ; then |
2941 |
einfo "Create new database ..." |
2942 |
[ -d "$(dirname ${JAVA_PKG_NATIVE_CLASSMAP})" ] \ |
2943 |
|| mkdir -p "$(dirname ${JAVA_PKG_NATIVE_CLASSMAP})" |
2944 |
${gcj_dbtool} -n ${JAVA_PKG_NATIVE_CLASSMAP} |
2945 |
fi |
2946 |
|
2947 |
einfo "Register native library in database (${JAVA_PKG_NATIVE_CLASSMAP}) ..." |
2948 |
|
2949 |
local jar to |
2950 |
for jar in ${JAVA_PKG_CLASSPATH//:/ } ; do |
2951 |
to="$(dirname ${jar})/lib$(basename ${jar}).so" |
2952 |
if [[ ( -f "${jar}" ) && ( ".jar" == "${jar: -4:4}" ) && ( -f "${to}" ) ]] ; then |
2953 |
einfo "library: ${to}" |
2954 |
${gcj_dbtool} -a ${JAVA_PKG_NATIVE_CLASSMAP} ${jar} ${to} \ |
2955 |
|| die "failed to register jar file" |
2956 |
fi |
2957 |
done |
2958 |
} |
2959 |
|
2960 |
# ------------------------------------------------------------------------------ |
2572 |
# @internal-function java-pkg_die |
2961 |
# @internal-function java-pkg_die |
2573 |
# |
2962 |
# |
2574 |
# Enhanced die for Java packages, which displays some information that may be |
2963 |
# Enhanced die for Java packages, which displays some information that may be |