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