Newer
Older
Handbook / configuration / include / ac_path_jarfile.m4
dnl
dnl $Id$
dnl
dnl @synopsis AC_PATH_JARFILE
dnl
dnl AC_PATH_JARFILE returns the absolute path to a jar file given the base
dnl name. It searches for files in the directories specified in the PATH
dnl argument.
dnl
dnl Based on the macro IT_FIND_OPTIONAL_JAR from the IcedTea-Web distribution,
dnl written by Omair Majid <omajid at redhat.com>, 2011-03-08.
dnl http://icedtea.classpath.org/
dnl
dnl @category Java
dnl @author Nigel Stanger <nstanger at infoscience.otago.ac.nz>
dnl @version 2012-04-17
dnl @license AllPermissive

#
# AC_PATH_JARFILE
# --------------------
# Find an optional jar required for building and running
#
# $1 : jar base name (i.e., without suffix)
# $2 : variable name used to set $2_JAR and WITH_$2
# $3 (optional) : used to specify additional file paths for searching
#
# Sets $2_JAR to the jar location (or blank if not found)
# Defines WITH_$2 if jar is found
# Sets $2_AVAILABLE to "true" if jar is found (or "false" if not)
#
AC_DEFUN([AC_PATH_JARFILE],
[
  AC_MSG_CHECKING([for $1.jar])
  AC_ARG_WITH([$1],
              [AS_HELP_STRING(--with-$1,specify location of the $1 jar)],
  [
    case "${withval}" in
      yes)
        $2_JAR=yes
        ;;
      no)
        $2_JAR=no
        ;;
      *)
        if test -f "${withval}"; then
          $2_JAR="${withval}"
        elif test -z "${withval}"; then
          $2_JAR=yes
        else
          AC_MSG_RESULT([not found])
          AC_MSG_ERROR("The $1 jar ${withval} was not found.")
        fi
        ;;
    esac
  ],
  [
    $2_JAR=yes
  ])
  it_extra_paths_$1="$3"
  if test "x${$2_JAR}" = "xyes"; then
    for path in ${it_extra_paths_$1}; do
      # Make sure we only get the first one if multiple occurrences are found
      # under the current path. Supress errors for missing paths as well.
      found_jar=`find ${path} -name $1.jar 2> /dev/null | sed 1q`
      if test -n "${found_jar}"; then
        $2_JAR=${found_jar}
        break
      fi
    done
  fi
  if test x"${$2_JAR}" = "xyes"; then
    if test -f "/usr/share/java/$1.jar"; then
      $2_JAR=/usr/share/java/$1.jar
    fi
  fi
  if test x"${$2_JAR}" = "xyes"; then
    $2_JAR=no
  fi
  AC_MSG_RESULT(${$2_JAR})
  AM_CONDITIONAL(WITH_$2, test x"${$2_JAR}" != "xno")
  # Clear $2_JAR if it doesn't contain a valid filename
  if test x"${$2_JAR}" = "xno"; then
    $2_JAR=
  fi
  if test -n "${$2_JAR}" ; then
    $2_AVAILABLE=true
  else
    $2_AVAILABLE=false
  fi
  AC_SUBST($2_JAR)
  AC_SUBST($2_AVAILABLE)
])