1eda14cbcSMatt Macydnl # 2eda14cbcSMatt Macydnl # The majority of the python scripts are written to be compatible 3eda14cbcSMatt Macydnl # with Python 2.6 and Python 3.4. Therefore, they may be installed 4eda14cbcSMatt Macydnl # and used with either interpreter. This option is intended to 5eda14cbcSMatt Macydnl # to provide a method to specify the default system version, and 6eda14cbcSMatt Macydnl # set the PYTHON environment variable accordingly. 7eda14cbcSMatt Macydnl # 8eda14cbcSMatt MacyAC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYTHON], [ 9eda14cbcSMatt Macy AC_ARG_WITH([python], 107877fdebSMatt Macy AS_HELP_STRING([--with-python[=VERSION]], 11eda14cbcSMatt Macy [default system python version @<:@default=check@:>@]), 12eda14cbcSMatt Macy [with_python=$withval], 13eda14cbcSMatt Macy [with_python=check]) 14eda14cbcSMatt Macy 15eda14cbcSMatt Macy AS_CASE([$with_python], 16eda14cbcSMatt Macy [check], [AC_CHECK_PROGS([PYTHON], [python3 python2], [:])], 17eda14cbcSMatt Macy [2*], [PYTHON="python${with_python}"], 18eda14cbcSMatt Macy [*python2*], [PYTHON="${with_python}"], 19eda14cbcSMatt Macy [3*], [PYTHON="python${with_python}"], 20eda14cbcSMatt Macy [*python3*], [PYTHON="${with_python}"], 21eda14cbcSMatt Macy [no], [PYTHON=":"], 22eda14cbcSMatt Macy [AC_MSG_ERROR([Unknown --with-python value '$with_python'])] 23eda14cbcSMatt Macy ) 24eda14cbcSMatt Macy 25eda14cbcSMatt Macy dnl # 26eda14cbcSMatt Macy dnl # Minimum supported Python versions for utilities: 27eda14cbcSMatt Macy dnl # Python 2.6 or Python 3.4 28eda14cbcSMatt Macy dnl # 29eda14cbcSMatt Macy AM_PATH_PYTHON([], [], [:]) 30eda14cbcSMatt Macy AS_IF([test -z "$PYTHON_VERSION"], [ 31*dae17134SMartin Matuska PYTHON_VERSION=$(echo ${PYTHON##*/} | tr -cd 0-9.) 32eda14cbcSMatt Macy ]) 33eda14cbcSMatt Macy PYTHON_MINOR=${PYTHON_VERSION#*\.} 34eda14cbcSMatt Macy 35eda14cbcSMatt Macy AS_CASE([$PYTHON_VERSION], 36eda14cbcSMatt Macy [2.*], [ 37eda14cbcSMatt Macy AS_IF([test $PYTHON_MINOR -lt 6], 38eda14cbcSMatt Macy [AC_MSG_ERROR("Python >= 2.6 is required")]) 39eda14cbcSMatt Macy ], 40eda14cbcSMatt Macy [3.*], [ 41eda14cbcSMatt Macy AS_IF([test $PYTHON_MINOR -lt 4], 42eda14cbcSMatt Macy [AC_MSG_ERROR("Python >= 3.4 is required")]) 43eda14cbcSMatt Macy ], 44eda14cbcSMatt Macy [:|2|3], [], 45eda14cbcSMatt Macy [PYTHON_VERSION=3] 46eda14cbcSMatt Macy ) 47eda14cbcSMatt Macy 48eda14cbcSMatt Macy AM_CONDITIONAL([USING_PYTHON], [test "$PYTHON" != :]) 49eda14cbcSMatt Macy AM_CONDITIONAL([USING_PYTHON_2], [test "x${PYTHON_VERSION%%\.*}" = x2]) 50eda14cbcSMatt Macy AM_CONDITIONAL([USING_PYTHON_3], [test "x${PYTHON_VERSION%%\.*}" = x3]) 51eda14cbcSMatt Macy 52eda14cbcSMatt Macy AM_COND_IF([USING_PYTHON_2], 53eda14cbcSMatt Macy [AC_SUBST([PYTHON_SHEBANG], [python2])], 54eda14cbcSMatt Macy [AC_SUBST([PYTHON_SHEBANG], [python3])]) 55eda14cbcSMatt Macy 56eda14cbcSMatt Macy dnl # 57eda14cbcSMatt Macy dnl # Request that packages be built for a specific Python version. 58eda14cbcSMatt Macy dnl # 59eda14cbcSMatt Macy AS_IF([test "x$with_python" != xcheck], [ 60eda14cbcSMatt Macy PYTHON_PKG_VERSION=$(echo $PYTHON_VERSION | tr -d .) 61eda14cbcSMatt Macy DEFINE_PYTHON_PKG_VERSION='--define "__use_python_pkg_version '${PYTHON_PKG_VERSION}'"' 62eda14cbcSMatt Macy DEFINE_PYTHON_VERSION='--define "__use_python '${PYTHON}'"' 63eda14cbcSMatt Macy ], [ 64eda14cbcSMatt Macy DEFINE_PYTHON_VERSION='' 65eda14cbcSMatt Macy DEFINE_PYTHON_PKG_VERSION='' 66eda14cbcSMatt Macy ]) 67eda14cbcSMatt Macy 68eda14cbcSMatt Macy AC_SUBST(DEFINE_PYTHON_VERSION) 69eda14cbcSMatt Macy AC_SUBST(DEFINE_PYTHON_PKG_VERSION) 70eda14cbcSMatt Macy]) 71