Kaydet (Commit) 0f48d98b authored tarafından Martin v. Löwis's avatar Martin v. Löwis

Patch #1324762: Change --with-cxx to --with-cxx-main.

üst 15be5ec1
......@@ -30,6 +30,7 @@ VPATH= @srcdir@
CC= @CC@
CXX= @CXX@
MAINCC= @MAINCC@
LINKCC= @LINKCC@
AR= @AR@
RANLIB= @RANLIB@
......@@ -157,7 +158,6 @@ LIBC= @LIBC@
SYSLIBS= $(LIBM) $(LIBC)
SHLIBS= @SHLIBS@
MAINOBJ= @MAINOBJ@
THREADOBJ= @THREADOBJ@
DLINCLDIR= @DLINCLDIR@
DYNLOADFILE= @DYNLOADFILE@
......@@ -326,9 +326,9 @@ LIBRARY_OBJS= \
all: $(BUILDPYTHON) oldsharedmods sharedmods
# Build the interpreter
$(BUILDPYTHON): Modules/$(MAINOBJ) $(LIBRARY) $(LDLIBRARY)
$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY)
$(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \
Modules/$(MAINOBJ) \
Modules/python.o \
$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
platform: $(BUILDPYTHON)
......@@ -448,8 +448,8 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
-DVPATH='"$(VPATH)"' \
-o $@ $(srcdir)/Modules/getpath.c
Modules/ccpython.o: $(srcdir)/Modules/ccpython.cc
$(CXX) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/ccpython.cc
Modules/python.o: $(srcdir)/Modules/python.c
$(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
......@@ -537,7 +537,7 @@ PYTHON_HEADERS= \
Include/weakrefobject.h \
pyconfig.h
$(LIBRARY_OBJS) $(MODOBJS) Modules/$(MAINOBJ): $(PYTHON_HEADERS)
$(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS)
######################################################################
......@@ -813,7 +813,7 @@ libainstall: all
fi; \
fi
$(INSTALL_DATA) Modules/config.c $(DESTDIR)$(LIBPL)/config.c
$(INSTALL_DATA) Modules/$(MAINOBJ) $(DESTDIR)$(LIBPL)/$(MAINOBJ)
$(INSTALL_DATA) Modules/python.o $(DESTDIR)$(LIBPL)/python.o
$(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in
$(INSTALL_DATA) Makefile $(DESTDIR)$(LIBPL)/Makefile
$(INSTALL_DATA) Modules/Setup $(DESTDIR)$(LIBPL)/Setup
......
......@@ -82,6 +82,11 @@ Library
Build
-----
- Patch #1324762:Remove ccpython.cc; replace --with-cxx with
--with-cxx-main. Link with C++ compiler only if --with-cxx-main was
specified. (Can be overriden by explicitly setting LINKCC.) Decouple
CXX from --with-cxx-main, see description in README.
- Patch #1429775: Link extension modules with the shared libpython.
C API
......
/* Minimal main program -- everything is loaded from the library */
#include "Python.h"
extern "C"
DL_EXPORT(int) Py_Main( int argc, char *argv[] );
int main( int argc, char *argv[] )
{
return Py_Main(argc, argv);
}
......@@ -1045,13 +1045,35 @@ Modules/getpath.o.
--with-libs='libs': Add 'libs' to the LIBS that the python interpreter
is linked against.
--with-cxx=<compiler>: Some C++ compilers require that main() is
compiled with the C++ if there is any C++ code in the application.
Specifically, g++ on a.out systems may require that to support
construction of global objects. With this option, the main() function
of Python will be compiled with <compiler>; use that only if you
plan to use C++ extension modules, and if your compiler requires
compilation of main() as a C++ program.
--with-cxx-main=<compiler>: If you plan to use C++ extension modules,
then -- on some platforms -- you need to compile python's main()
function with the C++ compiler. With this option, make will use
<compiler> to compile main() *and* to link the python executable.
It is likely that the resulting executable depends on the C++
runtime library of <compiler>. (The default is --without-cxx-main.)
There are platforms that do not require you to build Python
with a C++ compiler in order to use C++ extension modules.
E.g., x86 Linux with ELF shared binaries and GCC 3.x, 4.x is such
a platform. We recommend that you configure Python
--without-cxx-main on those platforms because a mismatch
between the C++ compiler version used to build Python and to
build a C++ extension module is likely to cause a crash at
runtime.
The Python installation also stores the variable CXX that
determines, e.g., the C++ compiler distutils calls by default
to build C++ extensions. If you set CXX on the configure command
line to any string of non-zero length, then configure won't
change CXX. If you do not preset CXX but pass
--with-cxx-main=<compiler>, then configure sets CXX=<compiler>.
In all other cases, configure looks for a C++ compiler by
some common names (c++, g++, gcc, CC, cxx, cc++, cl) and sets
CXX to the first compiler it finds. If it does not find any
C++ compiler, then it sets CXX="".
Similarly, if you want to change the command used to link the
python executable, then set LINKCC on the configure command line.
--with-pydebug: Enable additional debugging code to help track down
......
This diff is collapsed.
......@@ -313,64 +313,69 @@ AC_ARG_WITH(gcc,
esac])
AC_MSG_RESULT($without_gcc)
# If the user switches compilers, we can't believe the cache
if test ! -z "$ac_cv_prog_CC" -a ! -z "$CC" -a "$CC" != "$ac_cv_prog_CC"
then
AC_MSG_ERROR([cached CC is different -- throw away $cache_file
(it is also a good idea to do 'make clean' before compiling)])
fi
AC_PROG_CC
AC_SUBST(CXX)
AC_SUBST(MAINOBJ)
MAINOBJ=python.o
AC_MSG_CHECKING(for --with-cxx=<compiler>)
AC_ARG_WITH(cxx,
AC_HELP_STRING(--with-cxx=<compiler>, enable C++ support),
AC_SUBST(MAINCC)
AC_MSG_CHECKING(for --with-cxx-main=<compiler>)
AC_ARG_WITH(cxx_main,
AC_HELP_STRING([--with-cxx-main=<compiler>],
[compile main() and link python executable with C++ compiler]),
[
check_cxx=no
case $withval in
no) CXX=
with_cxx=no;;
*) CXX=$withval
MAINOBJ=ccpython.o
with_cxx=$withval;;
no) with_cxx_main=no
MAINCC='$(CC)';;
yes) with_cxx_main=yes
MAINCC='$(CXX)';;
*) with_cxx_main=yes
MAINCC=$withval
if test -z "$CXX"
then
CXX=$withval
fi;;
esac], [
with_cxx=no
check_cxx=yes
with_cxx_main=no
MAINCC='$(CC)'
])
AC_MSG_RESULT($with_cxx)
AC_MSG_RESULT($with_cxx_main)
if test "$with_cxx" = "yes"
preset_cxx="$CXX"
if test -z "$CXX"
then
AC_MSG_ERROR([must supply a compiler when using --with-cxx])
case "$CC" in
gcc) AC_PATH_PROG(CXX, [g++], [g++], [notfound]) ;;
cc) AC_PATH_PROG(CXX, [c++], [c++], [notfound]) ;;
esac
if test "$CXX" = "notfound"
then
CXX=""
fi
fi
dnl The following fragment works similar to AC_PROG_CXX.
dnl It does not fail if CXX is not found, and it is not executed if
dnl --without-cxx was given.
dnl Finally, it does not test whether CXX is g++.
dnl Autoconf 2.5x does not have AC_PROG_CXX_WORKS anymore
ifdef([AC_PROG_CXX_WORKS],[],
[AC_DEFUN([AC_PROG_CXX_WORKS],
[AC_LANG_PUSH(C++)dnl
_AC_COMPILER_EXEEXT
AC_LANG_POP()
]
)])
if test "$check_cxx" = "yes"
if test -z "$CXX"
then
AC_CHECK_PROGS(CXX, $CCC c++ g++ gcc CC cxx cc++ cl, notfound)
if test "$CXX" = "notfound"
then
CXX=
else
AC_PROG_CXX_WORKS
CXX=""
fi
fi
# If the user switches compilers, we can't believe the cache
if test ! -z "$ac_cv_prog_CC" -a ! -z "$CC" -a "$CC" != "$ac_cv_prog_CC"
if test "$preset_cxx" != "$CXX"
then
AC_MSG_ERROR([cached CC is different -- throw away $cache_file
(it is also a good idea to do 'make clean' before compiling)])
AC_MSG_WARN([
By default, distutils will build C++ extension modules with "$CXX".
If this is not intended, then set CXX on the configure command line.
])
fi
AC_PROG_CC
# checks for UNIX variants that set C preprocessor variables
AC_AIX
......@@ -480,22 +485,7 @@ AC_SUBST(LINKCC)
AC_MSG_CHECKING(LINKCC)
if test -z "$LINKCC"
then
if test -z "$CXX"; then
LINKCC="\$(PURIFY) \$(CC)"
else
echo 'extern "C" void foo();int main(){foo();}' > conftest_a.cc
$CXX -c conftest_a.cc # 2>&5
echo 'void foo(){}' > conftest_b.$ac_ext
$CC -c conftest_b.$ac_ext # 2>&5
if $CC -o conftest$ac_exeext conftest_a.$ac_objext conftest_b.$ac_objext 2>&5 \
&& test -s conftest$ac_exeext && ./conftest$ac_exeext
then
LINKCC="\$(PURIFY) \$(CC)"
else
LINKCC="\$(PURIFY) \$(CXX)"
fi
rm -fr conftest*
fi
LINKCC='$(PURIFY) $(MAINCC)'
case $ac_sys_system in
AIX*)
exp_extra="\"\""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment