Blame | Last modification | View Log | Download | RSS feed
#!/bin/shif test -z "${R_HOME}"; thenecho "This command can be executed via R CMD only!"exit 1fiSED=sedtools_classpath=${R_SHARE_DIR}/javausage="Usage: R CMD javareconf [options]Detect current Java setup and update the corresponding configuration in R.Options:-h, --help print short help message and exit-n, --dry-run perform Java detection, but don't touch anyconfigurations filesxxx=yyy evaluate the corresponding expression(e.g. JAVA_HOME=/usr/lib/java)Environment variables that can be used to influence the detection:JAVA path to a Java interpreter executableBy default first 'java' command found on the PATHis taken (unless JAVA_HOME is also specified).JAVA_HOME home of the Java environment. If not specified,it will be detected automatically from the Javainterpreter.Report bugs to <r-bugs@r-project.org>."dry_run=nowhile test -n "${1}"; docase ${1} in-help | --help | -h) echo "${usage}"; exit 0 ;;-n | --dry-run) dry_run=yes ;;*=*) eval ${1} ;;esacshiftdone## find java compiler binariesif test -z "${JAVA_HOME}" ; thenJAVA_PATH=${PATH}elseif test ! -e "${JAVA_HOME}"; thenecho "*** JAVA_HOME is not a valid path, ignoring"JAVA_HOME=fi## try jre/bin first just in case we don't have full JDKJAVA_PATH=${JAVA_HOME}:${JAVA_HOME}/jre/bin:${JAVA_HOME}/bin:${PATH}fi## if 'java' is not on the PATH or JAVA_HOME, add some guesses as of## where java could liveJAVA_PATH=${JAVA_PATH}:/usr/java/bin:/usr/jdk/bin:/usr/lib/java/bin:/usr/lib/jdk/bin:/usr/local/java/bin:/usr/local/jdk\/bin:/usr/local/lib/java/bin:/usr/local/lib/jdk/binif test -z "$JAVA"; thensave_IFS=$IFS; IFS=:for dir in ${JAVA_PATH}; doif test -f "$dir/java"; thenJAVA="$dir/java"breakfidoneIFS=${save_IFS}fiif test -z "$JAVA"; thenecho "~*** Cannot find any Java interpreter~*** Please make sure 'java' is on you PATH or set JAVA_HOME correspondingly"|${SED} -e 'y/~/\n/' >&2exit 1fiecho "Java interpreter : $JAVA"jires=`$JAVA -classpath ${tools_classpath} getsp -test`if test "$jires" != "Test1234OK"; thenecho "$jires"echo "~*** Java interpreter doesn't work properly.~"|${SED} -e 'y/~/\n/' >&2exit 1fiif test -z "${JAVA_HOME}"; thenJAVA_HOME=`$JAVA -classpath ${tools_classpath} getsp java.home`fiif test -z "${JAVA_HOME}"; thenecho "~*** Cannot find Java environemnt.~*** Please set JAVA_HOME correspondingly.~"|${SED} -e 'y/~/\n/' >&2exit 1fiecho "Java version : `$JAVA -classpath ${tools_classpath} getsp java.version 2>/dev/null`"echo "Java home path : ${JAVA_HOME}"hostos=`uname 2>/dev/null`case "$hostos" inDarwin*)JAVA_LD_LIBRARY_PATH=JAVA_LIBS="-framework JavaVM";;*)## we need to reset LD_LIBRARY_PATH, because Java automatically## adds all LD_LIBRARY_PATH to Java pathsave_LDLP=${LD_LIBRARY_PATH}LD_LIBRARY_PATH=export LD_LIBRARY_PATH# remove trailing : (if any) and replace occurrences of JAVA_HOME# with $(JAVA_HOME)JAVA_LD_LIBRARY_PATH=`$JAVA -classpath ${tools_classpath} getsp java.library.path| ${SED} -e s:${JAVA_HOME}:\$\(JAVA_HOME\):g -e 's/:$//'`LD_LIBRARY_PATH=${save_LDLP}export LD_LIBRARY_PATH# build JAVA_LIBS from the detected pathJAVA_LIBS=`echo ${JAVA_LD_LIBRARY_PATH}|${SED} -e 's|:| -L|g'`if test -n "${JAVA_LIBS}"; then JAVA_LIBS="-L${JAVA_LIBS}"; fiJAVA_LIBS="${JAVA_LIBS} -ljvm"# create shell-version to be used in scriptsJAVA_LD_LIBRARY_PATH_SH=`echo ${JAVA_LD_LIBRARY_PATH}|${SED} -e 's:$(JAVA_HOME):\$\{JAVA_HOME\}:g'`;;esacecho "Java library path: ${JAVA_LD_LIBRARY_PATH}"echo "JNI linker flags : ${JAVA_LIBS}"echo ""if test "${dry_run}" = yes; then exit 0; fiecho "Updating Java configuration in ${R_HOME}"files="${R_HOME}/etc${R_ARCH}/Makeconf ${R_HOME}/etc${R_ARCH}/ldpaths"for file in $files; do${SED} -e "s|JAVA =.\{0,\}|JAVA = $JAVA|" -e "s|JAVA_HOME =.\{0,\}|JAVA_HOME = ${JAVA_HOME}|" -e "s|: \${JAVA_HOME=.\{1,\}|: \${JAVA_HOME=${JAVA_HOME}}|" -e "s|: \${R_JAVA_LD_LIBRARY_PATH=.\{1,\}|: \${R_JAVA_LD_LIBRARY_PATH=${JAVA_LD_LIBRARY_PATH_SH}}|" -e "s|JAVA_LIBS =.\{0,\}|JAVA_LIBS = ${JAVA_LIBS}|g" -e "s|JAVA_LD_LIBRARY_PATH =.\{0,\}|JAVA_LD_LIBRARY_PATH = ${JAVA_LD_LIBRARY_PATH}|" "$file" > "${file}.new"if test -f "${file}.new"; thenmv "${file}" "${file}.old"mv "${file}.new" "${file}"elseecho "*** cannot create ${file}.new~*** Please run as root if required.~" | ${SED} -e 'y/~/\n/' >&2exit 1fidoneecho "Done."