~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to libraries/libapparmor/m4/ac_python_devel.m4

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
AC_DEFUN([AC_PYTHON_DEVEL],[
 
2
        #
 
3
        # Allow the use of a (user set) custom python version
 
4
        #
 
5
        AC_ARG_VAR([PYTHON_VERSION],[The installed Python
 
6
                version to use, for example '2.3'. This string
 
7
                will be appended to the Python interpreter
 
8
                canonical name.])
 
9
 
 
10
        AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
 
11
        if test -z "$PYTHON"; then
 
12
           AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path])
 
13
           PYTHON_VERSION=""
 
14
        fi
 
15
 
 
16
        #
 
17
        # Check for a version of Python >= 2.1.0
 
18
        #
 
19
        AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
 
20
        ac_supports_python_ver=`$PYTHON -c "import sys, string; \
 
21
                ver = string.split(sys.version)[[0]]; \
 
22
                print ver >= '2.1.0'"`
 
23
        if test "$ac_supports_python_ver" != "True"; then
 
24
                if test -z "$PYTHON_NOVERSIONCHECK"; then
 
25
                        AC_MSG_RESULT([no])
 
26
                        AC_MSG_FAILURE([
 
27
This version of the AC@&t@_PYTHON_DEVEL macro
 
28
doesn't work properly with versions of Python before
 
29
2.1.0. You may need to re-run configure, setting the
 
30
variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
 
31
PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
 
32
Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
 
33
to something else than an empty string.
 
34
])
 
35
                else
 
36
                        AC_MSG_RESULT([skip at user request])
 
37
                fi
 
38
        else
 
39
                AC_MSG_RESULT([yes])
 
40
        fi
 
41
 
 
42
        #
 
43
        # if the macro parameter ``version'' is set, honour it
 
44
        #
 
45
        if test -n "$1"; then
 
46
                AC_MSG_CHECKING([for a version of Python $1])
 
47
                ac_supports_python_ver=`$PYTHON -c "import sys, string; \
 
48
                        ver = string.split(sys.version)[[0]]; \
 
49
                        print ver $1"`
 
50
                if test "$ac_supports_python_ver" = "True"; then
 
51
                   AC_MSG_RESULT([yes])
 
52
                else
 
53
                        AC_MSG_RESULT([no])
 
54
                        AC_MSG_ERROR([this package requires Python $1.
 
55
If you have it installed, but it isn't the default Python
 
56
interpreter in your system path, please pass the PYTHON_VERSION
 
57
variable to configure. See ``configure --help'' for reference.
 
58
])
 
59
                        PYTHON_VERSION=""
 
60
                fi
 
61
        fi
 
62
 
 
63
        #
 
64
        # Check if you have distutils, else fail
 
65
        #
 
66
        AC_MSG_CHECKING([for the distutils Python package])
 
67
        ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
 
68
        if test -z "$ac_distutils_result"; then
 
69
                AC_MSG_RESULT([yes])
 
70
        else
 
71
                AC_MSG_RESULT([no])
 
72
                AC_MSG_ERROR([cannot import Python module "distutils".
 
73
Please check your Python installation. The error was:
 
74
$ac_distutils_result])
 
75
                PYTHON_VERSION=""
 
76
        fi
 
77
 
 
78
        #
 
79
        # Check for Python include path
 
80
        #
 
81
        AC_MSG_CHECKING([for Python include path])
 
82
        if test -z "$PYTHON_CPPFLAGS"; then
 
83
                python_path=`$PYTHON -c "import distutils.sysconfig; \
 
84
                        print distutils.sysconfig.get_python_inc();"`
 
85
                if test -n "${python_path}"; then
 
86
                        python_path="-I$python_path"
 
87
                fi
 
88
                PYTHON_CPPFLAGS=$python_path
 
89
        fi
 
90
        AC_MSG_RESULT([$PYTHON_CPPFLAGS])
 
91
        AC_SUBST([PYTHON_CPPFLAGS])
 
92
 
 
93
        #
 
94
        # Check for Python library path
 
95
        #
 
96
        AC_MSG_CHECKING([for Python library path])
 
97
        if test -z "$PYTHON_LDFLAGS"; then
 
98
                # (makes two attempts to ensure we've got a version number
 
99
                # from the interpreter)
 
100
                py_version=`$PYTHON -c "from distutils.sysconfig import *; \
 
101
                        from string import join; \
 
102
                        print join(get_config_vars('VERSION'))"`
 
103
                if test "$py_version" == "[None]"; then
 
104
                        if test -n "$PYTHON_VERSION"; then
 
105
                                py_version=$PYTHON_VERSION
 
106
                        else
 
107
                                py_version=`$PYTHON -c "import sys; \
 
108
                                        print sys.version[[:3]]"`
 
109
                        fi
 
110
                fi
 
111
 
 
112
                PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
 
113
                        from string import join; \
 
114
                        print '-L' + get_python_lib(0,1), \
 
115
                        '-lpython';"`$py_version
 
116
        fi
 
117
        AC_MSG_RESULT([$PYTHON_LDFLAGS])
 
118
        AC_SUBST([PYTHON_LDFLAGS])
 
119
 
 
120
        #
 
121
        # Check for site packages
 
122
        #
 
123
        AC_MSG_CHECKING([for Python site-packages path])
 
124
        if test -z "$PYTHON_SITE_PKG"; then
 
125
                PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
 
126
                        print distutils.sysconfig.get_python_lib(0,0);"`
 
127
        fi
 
128
        AC_MSG_RESULT([$PYTHON_SITE_PKG])
 
129
        AC_SUBST([PYTHON_SITE_PKG])
 
130
 
 
131
        #
 
132
        # libraries which must be linked in when embedding
 
133
        #
 
134
        AC_MSG_CHECKING(python extra libraries)
 
135
        if test -z "$PYTHON_EXTRA_LIBS"; then
 
136
           PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
 
137
                conf = distutils.sysconfig.get_config_var; \
 
138
                print conf('LOCALMODLIBS'), conf('LIBS')"`
 
139
        fi
 
140
        AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
 
141
        AC_SUBST(PYTHON_EXTRA_LIBS)
 
142
 
 
143
        #
 
144
        # linking flags needed when embedding
 
145
        #
 
146
        AC_MSG_CHECKING(python extra linking flags)
 
147
        if test -z "$PYTHON_EXTRA_LDFLAGS"; then
 
148
                PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
 
149
                        conf = distutils.sysconfig.get_config_var; \
 
150
                        print conf('LINKFORSHARED')"`
 
151
        fi
 
152
        AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
 
153
        AC_SUBST(PYTHON_EXTRA_LDFLAGS)
 
154
 
 
155
        #
 
156
        # final check to see if everything compiles alright
 
157
        #
 
158
        AC_MSG_CHECKING([consistency of all components of python development environment])
 
159
        AC_LANG_PUSH([C])
 
160
        # save current global flags
 
161
        LIBS="$ac_save_LIBS $PYTHON_LDFLAGS"
 
162
        CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
 
163
        AC_TRY_LINK([
 
164
                #include <Python.h>
 
165
        ],[
 
166
                Py_Initialize();
 
167
        ],[pythonexists=yes],[pythonexists=no])
 
168
 
 
169
        AC_MSG_RESULT([$pythonexists])
 
170
 
 
171
        if test ! "$pythonexists" = "yes"; then
 
172
           AC_MSG_ERROR([
 
173
  Could not link test program to Python. Maybe the main Python library has been
 
174
  installed in some non-standard library path. If so, pass it to configure,
 
175
  via the LDFLAGS environment variable.
 
176
  Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
 
177
  ============================================================================
 
178
   ERROR!
 
179
   You probably have to install the development version of the Python package
 
180
   for your distribution.  The exact name of this package varies among them.
 
181
  ============================================================================
 
182
           ])
 
183
          PYTHON_VERSION=""
 
184
        fi
 
185
        AC_LANG_POP
 
186
        # turn back to default flags
 
187
        CPPFLAGS="$ac_save_CPPFLAGS"
 
188
        LIBS="$ac_save_LIBS"
 
189
 
 
190
        #
 
191
        # all done!
 
192
        #
 
193
])