Skip to content

Commit c0d057f

Browse files
Alexpuxlazka
authored andcommitted
msys cygwin semi native build sysconfig
Co-authored-by: Алексей <alexey.pawlow@gmail.com>
1 parent 5512707 commit c0d057f

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

Lib/sysconfig.py

+8
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,14 @@ def _parse_makefile(filename, vars=None, keep_unresolved=True):
441441
if isinstance(v, str):
442442
done[k] = v.strip()
443443

444+
# any keys that have one with the same name suffixed with _b2h
445+
# need to be replaced with the value of the _b2h key.
446+
# This converts from MSYS*/Cygwin paths to Windows paths.
447+
for k, v in dict(done).items():
448+
if isinstance(k, str):
449+
if k.endswith("_b2h"):
450+
done[k[:-4]]=v
451+
444452
# save the results in the global dictionary
445453
vars.update(done)
446454
return vars

Makefile.pre.in

+7
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ exec_prefix= @exec_prefix@
141141
# Install prefix for data files
142142
datarootdir= @datarootdir@
143143

144+
# Locations needed for semi-native fixup of sysconfig.
145+
srcdir_b2h= @srcdir_b2h@
146+
VPATH_b2h= @VPATH_b2h@
147+
abs_srcdir_b2h= @abs_srcdir_b2h@
148+
abs_builddir_b2h= @abs_builddir_b2h@
149+
prefix_b2h= @prefix_b2h@
150+
144151
# Expanded directories
145152
BINDIR= @bindir@
146153
LIBDIR= @libdir@

configure.ac

+59
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,65 @@ then
738738
AC_DEFINE(_INCLUDE__STDC_A1_SOURCE, 1, Define to include mbstate_t for mbrtowc)
739739
fi
740740

741+
# On 'semi-native' build systems (MSYS*/Cygwin targeting MinGW-w64)
742+
# _sysconfigdata.py will contain paths that are correct only in the
743+
# build environment. This means external modules will fail to build
744+
# without setting up the same env and also that the build of Python
745+
# itself will fail as the paths are not correct for the host tools.
746+
#
747+
# Also, getpath.c uses GetModuleFileNameW (replacing \ with /) and
748+
# compares that with the define VPATH (passed in via command-line)
749+
# to determine whether it's the build- or the installed-Python.
750+
#
751+
# To work around these issues a set of _b2h variables are created:
752+
# VPATH_b2h, prefix_b2h, srcdir_b2h, abs_srcdir_b2h
753+
# and abs_builddir_b2h
754+
# .. where b2h stands for build to host. sysconfig.py replaces path
755+
# prefixes matching the non-b2h versions with the b2h equivalents.
756+
#
757+
# (note this assumes the host compilers are native and *not* cross
758+
# - in the 'semi-native' scenario only that is.)
759+
760+
AC_DEFUN([ABS_PATH_HOST],
761+
[$1=$(cd $$2 && pwd)
762+
case $build_os in
763+
mingw*)
764+
case $host_os in
765+
mingw*) $1=$(cd $$2 && pwd -W) ;;
766+
*) ;;
767+
esac
768+
;;
769+
cygwin*)
770+
case $host_os in
771+
mingw*) $1=$(cygpath -w -m $$2) ;;
772+
*) ;;
773+
esac
774+
;;
775+
esac
776+
AC_SUBST([$1])
777+
])
778+
779+
AC_MSG_CHECKING(absolute host location of VPATH)
780+
ABS_PATH_HOST([VPATH_b2h],[srcdir])
781+
AC_MSG_RESULT([$VPATH_b2h])
782+
783+
AC_MSG_CHECKING(absolute host location of prefix)
784+
ABS_PATH_HOST([prefix_b2h],[prefix])
785+
AC_MSG_RESULT([$prefix_b2h])
786+
787+
AC_MSG_CHECKING(absolute host location of srcdir)
788+
ABS_PATH_HOST([srcdir_b2h],[srcdir])
789+
AC_MSG_RESULT([$srcdir_b2h])
790+
791+
AC_MSG_CHECKING(absolute host location of abs_srcdir)
792+
ABS_PATH_HOST([abs_srcdir_b2h],[srcdir])
793+
AC_MSG_RESULT([$abs_srcdir_b2h])
794+
795+
my_builddir=.
796+
AC_MSG_CHECKING(Absolute host location of abs_builddir)
797+
ABS_PATH_HOST([abs_builddir_b2h],[my_builddir])
798+
AC_MSG_RESULT([$abs_builddir_b2h])
799+
741800
AC_MSG_CHECKING([for init system calls])
742801
AC_SUBST(INITSYS)
743802
case $host in

0 commit comments

Comments
 (0)