Skip to content

Commit c90b17e

Browse files
committed
Patch #1161914: Add python-config.
1 parent adcd25e commit c90b17e

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎Makefile.pre.in‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,11 @@ libainstall: all
826826
$(INSTALL_DATA) Modules/Setup.config $(DESTDIR)$(LIBPL)/Setup.config
827827
$(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
828828
$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
829+
# Substitution happens here, as the completely-expanded BINDIR
830+
# is not available in configure
831+
sed -e "s,@BINDIR@,$(BINDIR)," < $(srcdir)/Misc/python-config.in >python-config
832+
$(INSTALL_SCRIPT) python-config $(BINDIR)/python-config
833+
rm python-config
829834
@if [ -s Modules/python.exp -a \
830835
"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
831836
echo; echo "Installing support files for building shared extension modules on AIX:"; \

‎Misc/NEWS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Library
8282
Build
8383
-----
8484

85+
- Patch #1161914: Add a python-config script.
8586
- Patch #1324762:Remove ccpython.cc; replace --with-cxx with
8687
--with-cxx-main. Link with C++ compiler only if --with-cxx-main was
8788
specified. (Can be overridden by explicitly setting LINKCC.) Decouple

‎Misc/python-config.in‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!@BINDIR@/python
2+
3+
import sys
4+
import os
5+
import getopt
6+
from distutils import sysconfig
7+
8+
valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
9+
'ldflags', 'help']
10+
11+
def exit_with_usage(code=1):
12+
print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0],
13+
'|'.join('--'+opt for opt in valid_opts))
14+
sys.exit(code)
15+
16+
try:
17+
opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
18+
except getopt.error:
19+
exit_with_usage()
20+
21+
if not opts:
22+
exit_with_usage()
23+
24+
opt = opts[0][0]
25+
26+
pyver = sysconfig.get_config_var('VERSION')
27+
getvar = sysconfig.get_config_var
28+
29+
if opt == '--help':
30+
exit_with_usage(0)
31+
32+
elif opt == '--prefix':
33+
print sysconfig.PREFIX
34+
35+
elif opt == '--exec-prefix':
36+
print sysconfig.EXEC_PREFIX
37+
38+
elif opt in ('--includes', '--cflags'):
39+
flags = ['-I'+dir for dir in getvar('INCLDIRSTOMAKE').split()]
40+
if opt == '--cflags':
41+
flags.extend(getvar('CFLAGS').split())
42+
print ' '.join(flags)
43+
44+
elif opt in ('--libs', '--ldflags'):
45+
libs = sysconfig.get_config_var('LIBS').split()
46+
libs.append('-lpython'+pyver)
47+
if opt == '--ldflags':
48+
libs.insert(0, '-L' + getvar('LIBPL'))
49+
print ' '.join(libs)
50+

0 commit comments

Comments
 (0)