Imported Upstream version 3.0
[debian/gnuradio] / config / gr_python.m4
1 dnl
2 dnl Copyright 2003,2004,2005 Free Software Foundation, Inc.
3 dnl 
4 dnl This file is part of GNU Radio
5 dnl 
6 dnl GNU Radio is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 2, or (at your option)
9 dnl any later version.
10 dnl 
11 dnl GNU Radio is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 dnl GNU General Public License for more details.
15 dnl 
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with GNU Radio; see the file COPYING.  If not, write to
18 dnl the Free Software Foundation, Inc., 51 Franklin Street,
19 dnl Boston, MA 02110-1301, USA.
20 dnl 
21
22 # PYTHON_DEVEL()
23 #
24 # Checks for Python and tries to get the include path to 'Python.h'.
25 # It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LDFLAGS) output variables.
26 #
27 AC_DEFUN([PYTHON_DEVEL],[
28         AC_REQUIRE([AM_PATH_PYTHON])
29         AC_REQUIRE([AC_CANONICAL_HOST])
30
31         # Check for Python include path
32         AC_MSG_CHECKING([for Python include path])
33         if test -z "$PYTHON" ; then
34                 AC_MSG_ERROR([cannot find Python path])
35         fi
36
37         # ask distutils which include path we should use
38         python_cmd='
39 import distutils.sysconfig
40 import os
41 path = distutils.sysconfig.get_python_inc(plat_specific=False)
42 if os.sep == "\\":
43   path = path.replace("\\", "/")
44 print path
45 '
46         python_path=`$PYTHON -c "$python_cmd"`
47         AC_MSG_RESULT([$python_path])
48         if test -z "$python_path" ; then
49                 AC_MSG_ERROR([cannot find Python include path])
50         fi
51
52         AC_SUBST(PYTHON_CPPFLAGS,[-I$python_path])
53
54         # Check for Python headers usability
55         python_save_CPPFLAGS=$CPPFLAGS
56         CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
57         AC_CHECK_HEADERS([Python.h], [],
58                         [AC_MSG_ERROR([cannot find usable Python headers])])
59         CPPFLAGS="$python_save_CPPFLAGS"
60
61         # Only set this on mingw and cygwin hosts, (only implemented
62         # for mingw host, for crosscompiling you need to trick this)
63
64         PYTHON_LDFLAGS=""
65         case $host_os in
66              *mingw* | *cygwin* )
67           AC_MSG_CHECKING([for Python LDFLAGS])
68
69         python_cmd='
70 import distutils.sysconfig
71 import os
72 path = distutils.sysconfig.get_config_var("LIBPL")
73 if path == None:
74   path = distutils.sysconfig.PREFIX + "/libs"
75 if os.sep == "\\":
76   path = path.replace("\\", "/")
77 print path
78 '      
79           python_stdlib_path=`$PYTHON -c "$python_cmd"`
80
81           python_version_nodot=`echo $PYTHON_VERSION | sed "s,\.,,"`
82           libpython_name="python$PYTHON_VERSION"
83
84           # Standard install of python for win32 has libpython24.a
85           # instead of libpython2.4.a so we check for the library
86           # without the dot in the version number.
87
88           python_stdlib_filename=`find $python_stdlib_path -type f -name libpython$python_version_nodot.* -print | sed "1q"`
89           if test -n "$python_stdlib_filename" ; then
90                 libpython_name="python$python_version_nodot"
91           fi
92
93           PYTHON_LDFLAGS="-L$python_stdlib_path -l$libpython_name"
94           AC_MSG_RESULT($PYTHON_LDFLAGS) 
95           # Replace all backslashes in PYTHON Paths with forward slashes
96           AC_MSG_CHECKING([for pythondir])
97           pythondir=`echo $pythondir |sed 's,\\\\,/,g'`
98           AC_MSG_RESULT($pythondir)
99           AC_SUBST([pythondir])
100           AC_MSG_CHECKING([for pkgpythondir])
101           pkgpythondir=`echo $pkgpythondir |sed 's,\\\\,/,g'`
102           AC_MSG_RESULT($pkgpythondir)
103           AC_SUBST([pkgpythondir])
104           AC_MSG_CHECKING([for pyexecdir])
105           pyexecdir=`echo $pyexecdir |sed 's,\\\\,/,g'`
106           AC_MSG_RESULT($pyexecdir)
107           AC_SUBST([pyexecdir])
108           AC_MSG_CHECKING([for pkgpyexecdir])
109           pkgpyexecdir=`echo $pkgpyexecdir |sed 's,\\\\,/,g'`
110           AC_MSG_RESULT($pkgpyexecdir)
111           AC_SUBST([pkgpyexecdir])
112           ;;
113         esac
114
115         AC_SUBST([PYTHON_LDFLAGS])
116 ])