-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcit_python.m4
468 lines (410 loc) · 14.8 KB
/
cit_python.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# -*- Autoconf -*-
## --------------------------- ##
## Autoconf macros for Python. ##
## --------------------------- ##
# CIT_PYTHON_INCDIR
# -----------------
# Determine the directory containing <Python.h> using distutils.
AC_DEFUN([CIT_PYTHON_INCDIR], [
# $Id$
AC_REQUIRE([AM_PATH_PYTHON])
AC_CACHE_CHECK([for $am_display_PYTHON include directory],
[_cv_PYTHON_INCDIR],
[_cv_PYTHON_INCDIR=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_inc())" 2>/dev/null ||
echo "$PYTHON_PREFIX/include/python$PYTHON_VERSION"`])
AC_SUBST([PYTHON_INCDIR], [$_cv_PYTHON_INCDIR])
])dnl CIT_PYTHON_INCDIR
# CIT_CHECK_PYTHON_HEADER
# -----------------------
# Checking the existence of Python.h
AC_DEFUN([CIT_CHECK_PYTHON_HEADER], [
# $Id$
AC_REQUIRE([CIT_PYTHON_INCDIR])
cit_save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="-I$PYTHON_INCDIR $cit_save_CPPFLAGS"
AC_CHECK_HEADER([Python.h], [], [
AC_MSG_ERROR([Header file 'Python.h' not found; maybe you don't have the python development package, e.g. 'python-dev', installed?])
])
CPPFLAGS=$cit_save_CPPFLAGS
])dnl CIT_CHECK_PYTHON_HEADER
# CIT_CHECK_PYTHON_SHARED
# -----------------------
# Check whether -lpythonX.X is a shared library.
AC_DEFUN([CIT_CHECK_PYTHON_SHARED], [
# $Id$
AC_REQUIRE([CIT_PYTHON_CONFIG])
AC_MSG_CHECKING([whether -lpython$PYTHON_VERSION is a shared library])
cit_save_CPPFLAGS=$CPPFLAGS
cit_save_LDFLAGS=$LDFLAGS
cit_save_LIBS=$LIBS
CPPFLAGS="$PYTHON_CPPFLAGS $cit_save_CPPFLAGS"
LDFLAGS="$PYTHON_LDFLAGS $cit_save_LDFLAGS"
LIBS="$PYTHON_LIBS $cit_save_LIBS"
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include "Python.h"
]], [[
int status;
Py_Initialize();
status = PyRun_SimpleString("import binascii") != 0;
Py_Finalize();
return status;
]])], [
AC_MSG_RESULT(yes)
], [
AC_MSG_RESULT(no)
AC_MSG_ERROR([-lpython$PYTHON_VERSION is not a shared library])
])
CPPFLAGS=$cit_save_CPPFLAGS
LDFLAGS=$cit_save_LDFLAGS
LIBS=$cit_save_LIBS
])dnl CIT_CHECK_PYTHON_SHARED
# CIT_PYTHON_CONFIG
# -----------------
AC_DEFUN([CIT_PYTHON_CONFIG], [
# $Id$
AC_REQUIRE([AM_PATH_PYTHON])
AC_MSG_CHECKING([$am_display_PYTHON config])
cat >python-config.py <<END_OF_PYTHON
[
# This is based upon the pythonX.X-config utility that ships with
# Python 2.4 and later.
from distutils import sysconfig
pyver = sysconfig.get_config_var('VERSION')
getvar = sysconfig.get_config_var
cppflags = ['-I' + sysconfig.get_python_inc(),
'-I' + sysconfig.get_python_inc(plat_specific=True)]
print('PYTHON_CPPFLAGS="%s"' % ' '.join(cppflags))
ldflags = ['-L' + getvar('LIBDIR'), '-L' + getvar('LIBPL')]
print('PYTHON_LDFLAGS="%s"' % ' '.join(ldflags))
libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
libs.append('-lpython'+pyver)
print('PYTHON_LIBS="%s"' % ' '.join(libs))
]
END_OF_PYTHON
eval `$PYTHON python-config.py 2>/dev/null`
if test -n "$PYTHON_CPPFLAGS"; then
AC_MSG_RESULT(ok)
else
AC_MSG_ERROR(["failed
Run '$PYTHON python-config.py' to see what went wrong.
"])
fi
rm -f python-config.py
AC_SUBST([PYTHON_CPPFLAGS], [$PYTHON_CPPFLAGS])
AC_SUBST([PYTHON_LDFLAGS], [$PYTHON_LDFLAGS])
AC_SUBST([PYTHON_LIBS], [$PYTHON_LIBS])
])dnl CIT_PYTHON_CONFIG
# CIT_PYTHON_SYSCONFIG
# --------------------
AC_DEFUN([CIT_PYTHON_SYSCONFIG], [
# $Id$
AC_REQUIRE([AM_PATH_PYTHON])
AC_MSG_CHECKING([$am_display_PYTHON sysconfig])
cat >local_sysconfig.py <<END_OF_PYTHON
[import os, sys
from distutils import sysconfig
def cygpath(wpath):
s = os.popen('cygpath -u "%s"' % wpath)
path = s.read().strip()
s.close()
return path
incdir = sysconfig.get_python_inc()
keys = (
'BLDLIBRARY',
'LDFLAGS',
'LDLAST',
'LDLIBRARY',
'LIBDIR',
'LIBP',
'LIBPL',
'LIBS',
'LINKFORSHARED',
'MODLIBS',
'SYSLIBS',
'LA_LDFLAGS',
)
if os.name == "nt":
# We are running under Python for Windows (the real one...
# not Cygwin Python, under which 'os.name' is 'posix').
# We assume that we are still in the Cygwin POSIX environment,
# however (this is 'configure', after all); so we convert
# all Windows pathnames to POSIX pathnames using 'cygpath'.
incdir = cygpath(incdir)
vars = {}
libs = os.path.join(sys.prefix, "libs")
libs = cygpath(libs)
version = sysconfig.get_python_version()
version = version.replace('.', '')
vars['BLDLIBRARY'] = "-L%s -lpython%s" % (libs, version)
else:
vars = sysconfig.get_config_vars()
# transform AIX's python.exp
vars['LINKFORSHARED'] = vars['LINKFORSHARED'].replace('Modules',vars['LIBPL'])
if vars['LDLIBRARY'] == vars['LIBRARY']:
# "On systems without shared libraries, LDLIBRARY is the same as LIBRARY"
vars['BLDLIBRARY'] = "-L%(LIBPL)s -lpython%(VERSION)s" % vars
elif vars['BLDLIBRARY']:
# The 'mpicc' wrapper for LAM/MPI isn't very smart about "-L"
# options. Adding "-L/usr/lib" can cause "-lmpi" to be found in /usr/lib
# instead of LAM's 'lib' directory. Of course, avoiding "-L/usr/lib"
# doesn't really fix the problem, but it does make it much less likely;
# and "-L/usr/lib" is redundant and potentially problematic anyway.
# Python 2.4 and later puts a symlink to libpython.so in LIBPL
# (/usr/lib/python2.x/config), which makes adding "-L$LIBDIR"
# (in addition to "-L$LIBPL") completely redundant.
# But we still support Python 2.3, and we prefer shared to static,
# so we still add "-L$LIBDIR" when Python is installed in a non-standard
# location. Note that the linker will still prefer shared over static
# with only "-L/usr/lib/python2.3/config" on the link line.
libdir = ""
if vars['LIBDIR'] != "/usr/lib":
libdir = "-L%(LIBDIR)s "
# Important: on Cygwin, the import library for libpython.dll is
# nested inside Python's 'config' directory (see Issue39). This means
# that the linker always needs help finding "-lpython2.x" (in the form
# of "-L$LIBPL"), even for the "system" Python installed under /usr.
vars['BLDLIBRARY'] = (libdir + "-L%(LIBPL)s -lpython%(VERSION)s") % vars
else:
# "On Mac OS X frameworks, BLDLIBRARY is blank"
# See also Issue39.
framework = "%(PYTHONFRAMEWORKDIR)s/Versions/%(VERSION)s/%(PYTHONFRAMEWORK)s" % vars
PYTHONFRAMEWORK = vars.get('PYTHONFRAMEWORK', 'Python')
# Setting LINKFORSHARED and LA_LDFLAGS causes problems with linking on macOS with a Python
# virtual environment. This may also be true in general.
#vars['LINKFORSHARED'] = vars['LINKFORSHARED'].replace(framework, "-framework " + PYTHONFRAMEWORK)
#vars['LA_LDFLAGS'] = "-Wl,-framework,%s" % PYTHONFRAMEWORK
vars['LDFLAGS'] = '' # only causes trouble (e.g., "-arch i386 -arch ppc" on Mac) -- see issue97
print('PYTHON_INCDIR="%s"' % incdir)
for key in keys:
print('PYTHON_%s="%s"' % (key, vars.get(key, '')))
]
END_OF_PYTHON
eval `$PYTHON local_sysconfig.py 2>/dev/null`
if test -n "$PYTHON_INCDIR"; then
AC_MSG_RESULT(ok)
else
AC_MSG_ERROR(["failed
Run '$PYTHON local_sysconfig.py' to see what went wrong.
"])
fi
rm -f local_sysconfig.py
AC_SUBST([PYTHON_INCDIR], [$PYTHON_INCDIR])
AC_SUBST([PYTHON_BLDLIBRARY], [$PYTHON_BLDLIBRARY])
AC_SUBST([PYTHON_LDFLAGS], [$PYTHON_LDFLAGS])
AC_SUBST([PYTHON_LDLAST], [$PYTHON_LDLAST])
AC_SUBST([PYTHON_LDLIBRARY], [$PYTHON_LDLIBRARY])
AC_SUBST([PYTHON_LIBDIR], [$PYTHON_LIBDIR])
AC_SUBST([PYTHON_LIBP], [$PYTHON_LIBP])
AC_SUBST([PYTHON_LIBPL], [$PYTHON_LIBPL])
AC_SUBST([PYTHON_LIBS], [$PYTHON_LIBS])
AC_SUBST([PYTHON_LINKFORSHARED], [$PYTHON_LINKFORSHARED])
AC_SUBST([PYTHON_MODLIBS], [$PYTHON_MODLIBS])
AC_SUBST([PYTHON_SYSLIBS], [$PYTHON_SYSLIBS])
AC_SUBST([PYTHON_LA_LDFLAGS], [$PYTHON_LA_LDFLAGS])
])dnl CIT_PYTHON_SYSCONFIG
# CIT_PYTHON_SITE
# ---------------
AC_DEFUN([CIT_PYTHON_SITE], [
# $Id$
AC_REQUIRE([AM_PATH_PYTHON])
AC_MSG_CHECKING([whether we are installing to Python's prefix])
cit_python_prefix=`$PYTHON -c "import sys; print(sys.prefix)"`
if test "$cit_python_prefix" = "$prefix"; then
AC_MSG_RESULT(yes)
cit_cond_python_site=true
else
AC_MSG_RESULT(no)
cit_cond_python_site=false
fi
AC_MSG_CHECKING([whether we are installing to Python's exec prefix])
cit_python_exec_prefix=`$PYTHON -c "import sys; print(sys.exec_prefix)"`
cit_exec_prefix=$exec_prefix
test "x$cit_exec_prefix" = xNONE && cit_exec_prefix=$prefix
if test "$cit_python_exec_prefix" = "$cit_exec_prefix"; then
AC_MSG_RESULT(yes)
cit_cond_pyexec_site=true
else
AC_MSG_RESULT(no)
cit_cond_pyexec_site=false
fi
AM_CONDITIONAL([COND_PYTHON_SITE], [$cit_cond_python_site])
AM_CONDITIONAL([COND_PYEXEC_SITE], [$cit_cond_pyexec_site])
])dnl CIT_PYTHON_SITE
# CIT_CHECK_PYTHON_EGG(REQUIREMENT,
# [ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]])
# --------------------------------------------------------------
# Check for REQUIREMENT using pkg_resources.require(). If the
# corresponding distribution is found, execute ACTION-IF-FOUND.
# Otherwise, execute ACTION-IF-NOT-FOUND.
AC_DEFUN([CIT_CHECK_PYTHON_EGG], [
# $Id$
AC_MSG_CHECKING([for "$1"])
cat >check_python_egg.py <<END_OF_PYTHON
[
import sys
try:
from pkg_resources import require
require("$1")
except Exception, e:
sys.stderr.write("%s\n" % e)
print("cit_egg_status=1")
else:
print("cit_egg_status=0")
]
END_OF_PYTHON
AS_IF([AC_TRY_COMMAND([$PYTHON check_python_egg.py >conftest.sh 2>&AS_MESSAGE_LOG_FD])],
[],
[AC_MSG_RESULT(failed)
AC_MSG_FAILURE([cannot check for Python eggs])])
eval `cat conftest.sh`
rm -f conftest.sh check_python_egg.py
if test "$cit_egg_status" == 0; then
AC_MSG_RESULT(yes)
$2
else
AC_MSG_RESULT(no)
m4_default([$3], [AC_MSG_ERROR([required Python package not found: $1])])
fi
])dnl CIT_CHECK_PYTHON_EGG
# CIT_PYTHON_EGG_SETUP
# --------------------
AC_DEFUN([CIT_PYTHON_EGG_SETUP], [
# $Id$
AC_REQUIRE([AM_PATH_PYTHON])
cit_builddir=`pwd`
cit_save_PYTHONPATH="$PYTHONPATH"
PYTHONPATH="$cit_builddir/python:$PYTHONPATH"; export PYTHONPATH
cd $srcdir
#AC_MSG_NOTICE([downloading missing Python dependencies])
#AS_IF([AC_TRY_COMMAND([$PYTHON setup.py install_deps -f $cit_builddir/deps -zmxd $cit_builddir/deps >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD])],
# [],
# [AC_MSG_FAILURE([cannot download missing Python dependencies])])
#
#AC_MSG_NOTICE([building Python dependencies])
#AS_IF([AC_TRY_COMMAND([$PYTHON setup.py develop -H None -f $cit_builddir/deps -x -d $cit_builddir/python >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD])],
# [],
# [AC_MSG_FAILURE([building Python dependencies])])
AC_MSG_NOTICE([Generating Python egg info])
AS_IF([AC_TRY_COMMAND([$PYTHON setup.py egg_info >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD])],
[],
[AC_MSG_FAILURE([generating Python egg info])])
AC_MSG_CHECKING([for egg-related flags])
AS_IF([AC_TRY_COMMAND([$PYTHON setup.py egg_flags >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD])],
[AC_MSG_RESULT(ok)
. ./egg-flags.sh
rm -f egg-flags.sh
],
[AC_MSG_RESULT(failed)
AC_MSG_FAILURE([cannot scan Python eggs for flags])])
cd $cit_builddir
PYTHONPATH="$cit_save_PYTHONPATH"
PYTHONPATH="${pythondir}:${pyexecdir}${cit_save_PYTHONPATH:+:${cit_save_PYTHONPATH}}"
AC_SUBST(PYTHONPATH)
AC_SUBST(PYTHON_EGG_CFLAGS)
AC_SUBST(PYTHON_EGG_CPPFLAGS)
AC_SUBST(PYTHON_EGG_LDFLAGS)
AC_SUBST(PYTHON_EGG_LIBS)
AC_SUBST(PYTHON_EGG_PYXFLAGS)
])dnl CIT_PYTHON_EGG_SETUP
# CIT_PROG_PYCONFIG
# -----------------
# Provide a simple Python script which generates a Python module to
# expose our package configuration, similar to Python's
# distutils.sysconfig.
AC_DEFUN([CIT_PROG_PYCONFIG], [
# $Id$
PYCONFIG='$(top_builddir)/pyconfig'
AC_SUBST(PYCONFIG)
ofile=pyconfig
cfgfile="${ofile}T"
trap "rm \"$cfgfile\"; exit 1" 1 2 15
rm -f "$cfgfile"
AC_MSG_NOTICE([creating $ofile])
cat >"$cfgfile" <<END_OF_PYTHON
[#!/usr/bin/env python
from getopt import getopt, GetoptError
from sys import argv, exit
from getopt import getopt
from distutils.sysconfig import parse_config_h, parse_makefile, expand_makefile_vars
def printUsage():
print("Usage: %s -h HEADER -m MAKEFILE -o OUTPUT" % argv[0])
try:
(opts, args) = getopt(argv[1:], "h:m:o:")
except GetoptError, error:
print("%s: %s" % (argv[0], error))
printUsage()
exit(1)
header = '';
makefile = '';
output = '';
for option, parameter in opts:
if option == '-h':
header = parameter
elif option == '-m':
makefile = parameter
elif option == '-o':
output = parameter
if not (header and makefile and output):
printUsage()
exit(1)
f = open(header)
config_vars = parse_config_h(f)
f.close()
makefile_vars = parse_makefile(makefile)
keys = makefile_vars.keys()
for key in keys:
makefile_vars[key] = expand_makefile_vars(makefile_vars[key], makefile_vars)
with open(output, 'w') as f:
f.write("#!/usr/bin/env python\n\n")
f.write("config = %s\n\n\n" % config_vars)
f.write("makefile = %s\n\n" % makefile_vars)
f.write("# end of file\n")
# end of file]
END_OF_PYTHON
mv -f "$cfgfile" "$ofile" || \
(rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
chmod +x "$ofile"
])dnl CIT_PROG_PYCONFIG
# CIT_PATH_NEMESIS
# -----------------
AC_DEFUN([CIT_PATH_NEMESIS], [
# $Id$
AC_BEFORE([$0], [AM_PATH_PYTHON])
AC_PATH_PROG(PYTHON, nemesis, no)
if test "$PYTHON" = no; then
AC_MSG_ERROR([program 'nemesis' not found])
fi
])dnl CIT_PATH_NEMESIS
# CIT_PYTHON_MODULE(name, version)
# -----------------
# Determine whether module is available.
AC_DEFUN([CIT_PYTHON_MODULE],[
AC_REQUIRE([AM_PATH_PYTHON])
AC_MSG_CHECKING(for python module $1)
$PYTHON -c "import $1" 2>/dev/null
if test $? == 0; then
eval s=`$PYTHON -c "import $1; print($1.__""file__)"`
AC_MSG_RESULT([found $s])
else
AC_MSG_FAILURE(not found)
fi
if test -n "$2" ; then
AC_MSG_CHECKING([for $1 version])
[eval `$PYTHON -c "import $1; print($1.__version__)" | sed 's/\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)/avail_major=\1; avail_minor=\2; avail_patch=\3/'`]
[eval `echo $2 | sed 's/\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)/req_major=\1; req_minor=\2; req_patch=\3/' 2>/dev/null`]
if test -n "$avail_major" -a -n "$avail_minor" -a -n "$avail_patch"; then
if test $avail_major -lt $req_major ; then
AC_MSG_FAILURE([$1 version >= $2 is required. You have $avail_major.$avail_minor.$avail_patch.])
elif test $avail_major -eq $req_major -a $avail_minor -lt $req_minor; then
AC_MSG_FAILURE([$1 version >= $2 is required. You have $avail_major.$avail_minor.$avail_patch.])
elif test $avail_major -eq $req_major -a $avail_minor -eq $req_minor -a $avail_patch -lt $req_patch; then
AC_MSG_FAILURE([$1 version >= $2 is required. You have $avail_major.$avail_minor.$avail_patch.])
else
AC_MSG_RESULT([$avail_major.$avail_minor.$avail_patch])
fi
else
AC_MSG_FAILURE([Could not determine version of module $1. Version >= $2 is required.])
fi
fi
]) dnl CIT_PYTHON_MODULE
dnl end of file