Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,52 @@ def _print_dict(title, data):
print('\t%s = "%s"' % (key, value))


def _generate_config_file(filename, template = None):
if not filename:
filename = '-'
if not template:
template = filename == '-' and filename or filename + '.in'
if not filename == '-' and filename == template:
raise ValueError(
"output filename '%s' must be different from input filename '%s'"
% (filename, template))

# build regex "@prefix@|@libdir@|@LIBPL@|..."
import re
rexstr = ''
sep = ''
vars = get_config_vars()
for k, v in vars.items():
rexstr += sep + '@'+k+'@'
sep = '|'
rex = re.compile(rexstr)

with filename == '-' and sys.stdout or open(filename, 'w') as outfile:
with template == '-' and sys.stdin or open(template, 'r') as infile:
for line in infile:
while True:
found = rex.search(line)
if not found:
outfile.write(line)
break
value = vars.get(found.group(0)[1:-1])
outfile.write(line[:found.span()[0]] + str(value))
line = line[found.span()[1]:]
pass


def _main():
"""Display all information sysconfig detains."""
if '--generate-posix-vars' in sys.argv:
_generate_posix_vars()
return
if '--generate-config-file' in sys.argv:
for arg in sys.argv:
param, sep, value = arg.partition('=')
if param == '--file': # see config.status --help
file, sep, template = value.partition(':')
_generate_config_file(file, template)
return
print('Platform: "%s"' % get_platform())
print('Python version: "%s"' % get_python_version())
print('Current installation scheme: "%s"' % _get_default_scheme())
Expand Down
58 changes: 36 additions & 22 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ LDLAST= @LDLAST@
SGI_ABI= @SGI_ABI@
CCSHARED= @CCSHARED@
LINKFORSHARED= @LINKFORSHARED@
BLINKFORSHARED= @BLINKFORSHARED@
LINKFORMODULE= @LINKFORMODULE@
BLINKFORMODULE= @BLINKFORMODULE@
ARFLAGS= @ARFLAGS@
# Extra C flags added for building the interpreter object files.
CFLAGSFORSHARED=@CFLAGSFORSHARED@
Expand Down Expand Up @@ -337,6 +340,11 @@ ASDLGEN= $(PYTHON_FOR_GEN) $(srcdir)/Parser/asdl_c.py
##########################################################################
# Python

PYCONFIGFILES = \
Misc/python.pc \
Misc/python-config.sh \
Misc/python-config

OPCODETARGETS_H= \
Python/opcode_targets.h

Expand Down Expand Up @@ -472,7 +480,7 @@ DTRACE_DEPS = \

# Default target
all: @DEF_MAKE_ALL_RULE@
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed $(PYCONFIGFILES)

# Compile a binary with profile guided optimization.
profile-opt:
Expand Down Expand Up @@ -566,7 +574,7 @@ clinic: $(BUILDPYTHON) $(srcdir)/Modules/_blake2/blake2s_impl.c

# Build the interpreter
$(BUILDPYTHON): Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
$(LINKCC) $(PY_LDFLAGS) $(BLINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)

platform: $(BUILDPYTHON) pybuilddir.txt
$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))' >platform
Expand Down Expand Up @@ -638,7 +646,7 @@ libpython$(LDVERSION).dylib: $(LIBRARY_OBJS)


libpython$(VERSION).sl: $(LIBRARY_OBJS)
$(LDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
$(BLDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)

# Copy up the gdb python hooks into a position where they can be automatically
# loaded by gdb during Lib/test/test_gdb.py
Expand Down Expand Up @@ -677,7 +685,7 @@ $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
# for a shared core library; otherwise, this rule is a noop.
$(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS)
if test -n "$(DLLLIBRARY)"; then \
$(LDSHARED) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
$(BLDSHARED) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
$(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST); \
else true; \
fi
Expand Down Expand Up @@ -712,7 +720,7 @@ Modules/Setup: $(srcdir)/Modules/Setup.dist
fi

Programs/_testembed: Programs/_testembed.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
$(LINKCC) $(PY_LDFLAGS) $(BLINKFORSHARED) -o $@ Programs/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)

############################################################################
# Importlib
Expand Down Expand Up @@ -1341,18 +1349,18 @@ libinstall: build_all $(srcdir)/Modules/xxmodule.c
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
$(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/PatternGrammar.txt

python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh
@ # Substitution happens here, as the completely-expanded BINDIR
@ # is not available in configure
sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py
@ # Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR}
LC_ALL=C sed -e 's,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g' < Misc/python-config.sh >python-config
@ # On Darwin, always use the python version of the script, the shell
@ # version doesn't use the compiler customizations that are provided
@ # in python (_osx_support.py).
@if test `uname -s` = Darwin; then \
cp python-config.py python-config; \
fi
Misc/python.pc: $(srcdir)/Misc/python.pc.in
Misc/python-config: $(srcdir)/Misc/python-config.in
Misc/python-config.sh: $(srcdir)/Misc/python-config.sh.in

# Besides a common subset, both sysconfig and config.status provide variables
# not known to the other. While config.status provides the configured values,
# sysconfig provides values with variable-references resolved already:
# Substitute sysconfig values first, and remaining ones with config.status.
$(PYCONFIGFILES): $(BUILDPYTHON) pybuilddir.txt
$(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig \
--generate-config-file --file=-:$(srcdir)/[email protected] | \
$(SHELL) config.status --file=$@:-


# Install the include files
Expand Down Expand Up @@ -1380,7 +1388,7 @@ LIBPL= @LIBPL@
# pkgconfig directory
LIBPC= $(LIBDIR)/pkgconfig

libainstall: all python-config
libainstall: all $(PYCONFIGFILES)
@for i in $(LIBDIR) $(LIBPL) $(LIBPC); \
do \
if test ! -d $(DESTDIR)$$i; then \
Expand Down Expand Up @@ -1411,8 +1419,14 @@ libainstall: all python-config
$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
$(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
$(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py
$(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config
$(INSTALL_SCRIPT) Misc/python-config $(DESTDIR)$(LIBPL)/python-config.py
$(INSTALL_SCRIPT) Misc/python-config.sh $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config
# On Darwin, always use the python version of the script, the shell
# version doesn't use the compiler customizations that are provided
# in python (_osx_support.py).
if test `uname -s` = Darwin; then \
$(INSTALL_SCRIPT) Misc/python-config $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config; \
fi
@if [ -s Modules/python.exp -a \
"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
echo; echo "Installing support files for building shared extension modules on AIX:"; \
Expand Down Expand Up @@ -1616,7 +1630,7 @@ clobber: clean profile-removal
config.cache config.log pyconfig.h Modules/config.c
-rm -rf build platform
-rm -rf $(PYTHONFRAMEWORKDIR)
-rm -f python-config.py python-config
-rm -f $(PYCONFIGFILES)

# Make things extra clean, before making a distribution:
# remove all generated files, even Makefile[.pre]
Expand All @@ -1627,7 +1641,7 @@ distclean: clobber
done
-rm -f core Makefile Makefile.pre config.status \
Modules/Setup Modules/Setup.local Modules/Setup.config \
Modules/ld_so_aix Modules/python.exp Misc/python.pc
Modules/ld_so_aix Modules/python.exp
-rm -f python*-gdb.py
# Issue #28258: set LC_ALL to avoid issues with Estonian locale.
# Expansion is performed here by shell (spawned by make) itself before
Expand Down
13 changes: 3 additions & 10 deletions Misc/python-config.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!@EXENAME@
#!@BINDIR@/python@LDVERSION@@EXE@
# -*- python -*-

# Keep this script in sync with python-config.sh.in
Expand Down Expand Up @@ -47,16 +47,9 @@ for opt in opt_flags:
print(' '.join(flags))

elif opt in ('--libs', '--ldflags'):
libs = ['-lpython' + pyver + sys.abiflags]
libs += getvar('LIBS').split()
libs += getvar('SYSLIBS').split()
# add the prefix/lib/pythonX.Y/config dir, but only if there is no
# shared library in prefix/lib/.
# no libs for modules
if opt == '--ldflags':
if not getvar('Py_ENABLE_SHARED'):
libs.insert(0, '-L' + getvar('LIBPL'))
if not getvar('PYTHONFRAMEWORK'):
libs.extend(getvar('LINKFORSHARED').split())
libs.extend(getvar('LINKFORMODULE').split())
print(' '.join(libs))

elif opt == '--extension-suffix':
Expand Down
15 changes: 3 additions & 12 deletions Misc/python-config.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ LIBM="@LIBM@"
LIBC="@LIBC@"
SYSLIBS="$LIBM $LIBC"
ABIFLAGS="@ABIFLAGS@"
LIBS="-lpython${VERSION}${ABIFLAGS} @LIBS@ $SYSLIBS"
BASECFLAGS="@BASECFLAGS@"
LDLIBRARY="@LDLIBRARY@"
LINKFORSHARED="@LINKFORSHARED@"
LINKFORMODULE="@LINKFORMODULE@"
OPT="@OPT@"
PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
LDVERSION="@LDVERSION@"
Expand Down Expand Up @@ -85,18 +84,10 @@ do
echo "$INCDIR $PLATINCDIR $BASECFLAGS $CFLAGS $OPT"
;;
--libs)
echo "$LIBS"
# no libs for modules
;;
--ldflags)
LINKFORSHAREDUSED=
if [ -z "$PYTHONFRAMEWORK" ] ; then
LINKFORSHAREDUSED=$LINKFORSHARED
fi
LIBPLUSED=
if [ "$PY_ENABLE_SHARED" = "0" ] ; then
LIBPLUSED="-L$LIBPL"
fi
echo "$LIBPLUSED -L$libdir $LIBS $LINKFORSHAREDUSED"
echo "$LINKFORMODULE"
;;
--extension-suffix)
echo "$SO"
Expand Down
2 changes: 1 addition & 1 deletion Misc/python.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Description: Python library
Requires:
Version: @VERSION@
Libs.private: @LIBS@
Libs: -L${libdir} -lpython@VERSION@@ABIFLAGS@
Libs: -L${libdir} -lpython@VERSION@@ABIFLAGS@ @LINKFORSHARED@
Cflags: -I${includedir}/python@VERSION@@ABIFLAGS@
Loading