Check for numpy in configure.ac
[oscopy.git] / m4 / ipython.m4
blobe4b96f163db8168953df3778c2164013525d9a9a
1 ## ipython.m4 - Check for IPython version on a system. -*-Autoconf-*-
2 ## Copyright (C) 2013 Arnaud Gardelein.
3 ## Author: Arnaud Gardelein <arnaud@oscopy.org
4 ##
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.
9 ##
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.
33 # check also matplotlib, numpy, dbus, xdg, gtk
34 AC_DEFUN([AM_PATH_IPYTHON],
35  [
36   dnl Find a IPYTHON interpreter.
37   m4_define_default([_AM_IPYTHON_INTERPRETER_LIST],
38 [ipython])
40   AC_ARG_VAR([IPYTHON], [the IPython interpreter])
42   m4_if([$1],[],[
43     dnl No version check is needed.
44     # Find any IPython interpreter.
45     if test -z "$IPYTHON"; then
46       AC_PATH_PROGS([IPYTHON], _AM_IPYTHON_INTERPRETER_LIST, :)
47     fi
48     am_display_IPYTHON=IPython
49   ], [
50     dnl A version check is needed.
51     if test -n "$IPYTHON"; then
52       # If the user set $IPYTHON, use it and don't search something else.
53       AC_MSG_CHECKING([whether $IPYTHON version >= $1])
54       AM_IPYTHON_CHECK_VERSION([$IPYTHON], [$1],
55                               [AC_MSG_RESULT(yes)],
56                               [AC_MSG_ERROR(too old)])
57       am_display_IPYTHON=$IPYTHON
58     else
59       # Otherwise, try each interpreter until we find one that satisfies
60       # VERSION.
61       AC_CACHE_CHECK([for a IPython interpreter with version >= $1],
62         [am_cv_pathless_IPYTHON],[
63         for am_cv_pathless_IPYTHON in _AM_IPYTHON_INTERPRETER_LIST none; do
64           test "$am_cv_pathless_IPYTHON" = none && break
65           AM_IPYTHON_CHECK_VERSION([$am_cv_pathless_IPYTHON], [$1], [break])
66         done])
67       # Set $IPYTHON to the absolute path of $am_cv_pathless_IPYTHON.
68       if test "$am_cv_pathless_IPYTHON" = none; then
69         IPYTHON=:
70       else
71         AC_PATH_PROG([IPYTHON], [$am_cv_pathless_IPYTHON])
72       fi
73       am_display_IPYTHON=$am_cv_pathless_IPYTHON
74     fi
75   ])
77   if test "$IPYTHON" = :; then
78   dnl Run any user-specified action, or abort.
79     m4_default([$3], [AC_MSG_ERROR([no suitable IPython interpreter found])])
80   else
82   dnl Query IPYTHON for its version number.
84   AC_CACHE_CHECK([for $am_display_IPYTHON version], [am_cv_ipython_version],
85     [am_cv_ipython_version=`$IPYTHON -c "import IPython,sys; sys.stdout.write(IPython.release.version if hasattr(IPython, 'release') else IPython.Release.version)"`])
86   AC_SUBST([IPYTHON_VERSION], [$am_cv_ipython_version])
88   dnl Use the values of $prefix and $exec_prefix for the corresponding
89   dnl values of IPYTHON_PREFIX and IPYTHON_EXEC_PREFIX.  These are made
90   dnl distinct variables so they can be overridden if need be.  However,
91   dnl general consensus is that you shouldn't need this ability.
93   dnl AC_SUBST([IPYTHON_PREFIX], ['${prefix}'])
94   dnl AC_SUBST([IPYTHON_EXEC_PREFIX], ['${exec_prefix}'])
96   dnl At times (like when building shared libraries) you may want
97   dnl to know which OS platform IPYTHON thinks this is.
99   dnl AC_CACHE_CHECK([for $am_display_IPYTHON platform], [am_cv_IPYTHON_platform],
100   dnl  [am_cv_IPYTHON_platform=`$IPYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
101   dnl AC_SUBST([IPYTHON_PLATFORM], [$am_cv_IPYTHON_platform])
102   dnl Run any user-specified action.
103   $2
104   fi
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
122     # First check whether the program exists
123     # Probably /dev/null is not portable ouside linux systems...
124    which `echo $1 | cut -d ' ' -f 1` > /dev/null
125    if test "$?" = 1; then
126       ac_status=1
127       (exit $ac_status);
128    else
129       ac_status=`$*`
130       echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
131       (exit $ac_status);
132    fi
133  }])