Imported Upstream version 3.0.3
[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         # For Fedora Core 5 and 6, see ticket:39 in Trac
32         if test -f '/etc/redhat-release'; then
33                 if  (echo $pyexecdir | grep -q lib64); then
34                         pythondir="$pyexecdir"
35                 fi
36         fi
37
38         # Check for Python include path
39         AC_MSG_CHECKING([for Python include path])
40         if test -z "$PYTHON" ; then
41                 AC_MSG_ERROR([cannot find Python path])
42         fi
43
44         # ask distutils which include path we should use
45         python_cmd='
46 import distutils.sysconfig
47 import os
48 path = distutils.sysconfig.get_python_inc(plat_specific=False)
49 if os.sep == "\\":
50   path = path.replace("\\", "/")
51 print path
52 '
53         python_path=`$PYTHON -c "$python_cmd"`
54         AC_MSG_RESULT([$python_path])
55         if test -z "$python_path" ; then
56                 AC_MSG_ERROR([cannot find Python include path])
57         fi
58
59         AC_SUBST(PYTHON_CPPFLAGS,[-I$python_path])
60
61         # Check for Python headers usability
62         python_save_CPPFLAGS=$CPPFLAGS
63         CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
64         AC_CHECK_HEADERS([Python.h], [],
65                         [AC_MSG_ERROR([cannot find usable Python headers])])
66         CPPFLAGS="$python_save_CPPFLAGS"
67
68         # Only set this on mingw and cygwin hosts, (only implemented
69         # for mingw host, for crosscompiling you need to trick this)
70
71         PYTHON_LDFLAGS=""
72         case $host_os in
73              *mingw* | *cygwin* )
74           AC_MSG_CHECKING([for Python LDFLAGS])
75
76         python_cmd='
77 import distutils.sysconfig
78 import os
79 path = distutils.sysconfig.get_config_var("LIBPL")
80 if path == None:
81   path = distutils.sysconfig.PREFIX + "/libs"
82 if os.sep == "\\":
83   path = path.replace("\\", "/")
84 print path
85 '      
86           python_stdlib_path=`$PYTHON -c "$python_cmd"`
87
88           python_version_nodot=`echo $PYTHON_VERSION | sed "s,\.,,"`
89           libpython_name="python$PYTHON_VERSION"
90
91           # Standard install of python for win32 has libpython24.a
92           # instead of libpython2.4.a so we check for the library
93           # without the dot in the version number.
94
95           python_stdlib_filename=`find $python_stdlib_path -type f -name libpython$python_version_nodot.* -print | sed "1q"`
96           if test -n "$python_stdlib_filename" ; then
97                 libpython_name="python$python_version_nodot"
98           fi
99
100           PYTHON_LDFLAGS="-L$python_stdlib_path -l$libpython_name"
101           AC_MSG_RESULT($PYTHON_LDFLAGS) 
102           # Replace all backslashes in PYTHON Paths with forward slashes
103           pythondir=`echo $pythondir |sed 's,\\\\,/,g'`
104           pkgpythondir=`echo $pkgpythondir |sed 's,\\\\,/,g'`
105           pyexecdir=`echo $pyexecdir |sed 's,\\\\,/,g'`
106           pkgpyexecdir=`echo $pkgpyexecdir |sed 's,\\\\,/,g'`
107           ;;
108         esac
109
110         AC_SUBST([PYTHON_LDFLAGS])
111 ])