1 ## ipython.m4 - Check for IPython version on a system. -*-Autoconf-*-
2 ## Copyright (C) 2013 Arnaud Gardelein.
3 ## Author: Arnaud Gardelein <arnaud@oscopy.org
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 2 of the License, or
8 ## (at your option) any later version.
10 ## This program is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 ## As a special exception to the GNU General Public License, if you
20 ## distribute this file as part of a program that contains a
21 ## configuration script generated by Autoconf, you may include it under
22 ## the same distribution terms that you use for the rest of that program.
24 # AM_PATH_IPYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
25 # ---------------------------------------------------------------------------
26 # Adds support for distributing IPYTHON modules and packages.
28 # If the MINIMUM-VERSION argument is passed, AM_PATH_IPYTHON will
29 # cause an error if the version of IPYTHON installed on the system
30 # doesn't meet the requirement. MINIMUM-VERSION should consist of
31 # numbers and dots only.
32 AC_DEFUN([AM_PATH_IPYTHON],
34 dnl Find a IPYTHON interpreter.
35 m4_define_default([_AM_IPYTHON_INTERPRETER_LIST],
38 AC_ARG_VAR([IPYTHON], [the IPython interpreter])
41 dnl No version check is needed.
42 # Find any IPython interpreter.
43 if test -z "$IPYTHON"; then
44 AC_PATH_PROGS([IPYTHON], _AM_IPYTHON_INTERPRETER_LIST, :)
46 am_display_IPYTHON=IPython
48 dnl A version check is needed.
49 if test -n "$IPYTHON"; then
50 # If the user set $IPYTHON, use it and don't search something else.
51 AC_MSG_CHECKING([whether $IPYTHON version >= $1])
52 AM_IPYTHON_CHECK_VERSION([$IPYTHON], [$1],
54 [AC_MSG_ERROR(too old)])
55 am_display_IPYTHON=$IPYTHON
57 # Otherwise, try each interpreter until we find one that satisfies
59 AC_CACHE_CHECK([for a IPython interpreter with version >= $1],
60 [am_cv_pathless_IPYTHON],[
61 for am_cv_pathless_IPYTHON in _AM_IPYTHON_INTERPRETER_LIST none; do
62 test "$am_cv_pathless_IPYTHON" = none && break
63 AM_IPYTHON_CHECK_VERSION([$am_cv_pathless_IPYTHON], [$1], [break])
65 # Set $IPYTHON to the absolute path of $am_cv_pathless_IPYTHON.
66 if test "$am_cv_pathless_IPYTHON" = none; then
69 AC_PATH_PROG([IPYTHON], [$am_cv_pathless_IPYTHON])
71 am_display_IPYTHON=$am_cv_pathless_IPYTHON
75 if test "$IPYTHON" = :; then
76 dnl Run any user-specified action, or abort.
77 m4_default([$3], [AC_MSG_ERROR([no suitable IPython interpreter found])])
80 dnl Query IPYTHON for its version number.
82 AC_CACHE_CHECK([for $am_display_IPYTHON version], [am_cv_ipython_version],
83 [am_cv_ipython_version=`$IPYTHON -c "import IPython,sys; sys.stdout.write(IPython.release.version if hasattr(IPython, 'release') else IPython.Release.version)"`])
84 AC_SUBST([IPYTHON_VERSION], [$am_cv_ipython_version])
86 dnl Use the values of $prefix and $exec_prefix for the corresponding
87 dnl values of IPYTHON_PREFIX and IPYTHON_EXEC_PREFIX. These are made
88 dnl distinct variables so they can be overridden if need be. However,
89 dnl general consensus is that you shouldn't need this ability.
91 dnl AC_SUBST([IPYTHON_PREFIX], ['${prefix}'])
92 dnl AC_SUBST([IPYTHON_EXEC_PREFIX], ['${exec_prefix}'])
94 dnl At times (like when building shared libraries) you may want
95 dnl to know which OS platform IPYTHON thinks this is.
97 dnl AC_CACHE_CHECK([for $am_display_IPYTHON platform], [am_cv_IPYTHON_platform],
98 dnl [am_cv_IPYTHON_platform=`$IPYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
99 dnl AC_SUBST([IPYTHON_PLATFORM], [$am_cv_IPYTHON_platform])
100 dnl Run any user-specified action.
107 # AM_IPYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
108 # ---------------------------------------------------------------------------
109 # Run ACTION-IF-TRUE if the IPYTHON interpreter PROG has version >= VERSION.
110 # Run ACTION-IF-FALSE otherwise.
111 AC_DEFUN([AM_IPYTHON_CHECK_VERSION],
112 [prog="import sys, IPython;minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]];ver = list(map(int, (IPython.release.version if hasattr(IPython, 'release') else IPython.Release.version).split('.'))) + [[0, 0, 0]];minverhex = sum([[minver[i]<<((4-i)*8) for i in range(0, 4)]]);verhex = sum([[ver[i]<<((4-i)*8) for i in range(0, 4)]]);sys.stdout.write('1' if verhex < minverhex else '0');"
113 AS_IF([AM_RUN_LOG_IPYTHON([$1 -c "$prog"])], [$3], [$4])])
115 # AM_RUN_LOG_IPYTHON(COMMAND)
116 # -------------------
117 # Run COMMAND, save the output in ac_status, and log it.
118 # (This has been adapted from Python's AM_RUN_LOG macro.)
119 AC_DEFUN([AM_RUN_LOG_IPYTHON],
120 [{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD
121 # ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
123 echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
124 (exit $ac_status); }])