Patch #527027: Allow building python as shared library.

This commit is contained in:
Martin v. Löwis 2002-03-29 16:28:31 +00:00
parent eddd68d56c
commit 1142de3f5b
6 changed files with 651 additions and 533 deletions

View File

@ -108,6 +108,9 @@ PYTHONFRAMEWORKDIR= @PYTHONFRAMEWORKDIR@
PYTHONFRAMEWORKPREFIX= @PYTHONFRAMEWORKPREFIX@
PYTHONFRAMEWORKINSTALLDIR= @PYTHONFRAMEWORKINSTALLDIR@
# Environment to run shared python without installed libraries
RUNSHARED= @RUNSHARED@
# Modes for directories, executables and data files created by the
# install process. Default to user-only-writable for all file types.
DIRMODE= 755
@ -136,6 +139,7 @@ LDLIBRARY= @LDLIBRARY@
BLDLIBRARY= @BLDLIBRARY@
DLLLIBRARY= @DLLLIBRARY@
LDLIBRARYDIR= @LDLIBRARYDIR@
INSTSONAME= @INSTSONAME@
LIBS= @LIBS@
@ -292,20 +296,20 @@ LIBRARY_OBJS= \
all: $(BUILDPYTHON) oldsharedmods sharedmods
# Build the interpreter
$(BUILDPYTHON): Modules/$(MAINOBJ) $(LDLIBRARY)
$(BUILDPYTHON): Modules/$(MAINOBJ) $(LIBRARY) $(LDLIBRARY)
$(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \
Modules/$(MAINOBJ) \
$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
platform: $(BUILDPYTHON)
./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform
$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform
# Build the shared modules
sharedmods: $(BUILDPYTHON)
case $$MAKEFLAGS in \
*-s*) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
*) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
*-s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
esac
# buildno should really depend on something like LIBRARY_SRC
@ -333,18 +337,11 @@ $(LIBRARY): $(LIBRARY_OBJS)
$(AR) cr $@ $(MODOBJS)
$(RANLIB) $@
# This rule is only here for DG/UX and BeOS!!!
libpython$(VERSION).so: $(LIBRARY)
case `uname -s | tr -d '/ ' | tr '[A-Z]' '[a-z]'` in \
*dgux*) \
test -d dgux || mkdir dgux; \
(cd dgux;ar x ../$^;ld -G -o ../$@ * ); \
/bin/rm -rf ./dgux \
;; \
beos) \
$(AR) so $(LIBRARY) $@ \
;; \
esac
libpython$(VERSION).so: $(LIBRARY_OBJS)
$(LDSHARED) -o $@ $(LIBRARY_OBJS) $(LIBC) $(LIBM)
libpython$(VERSION).sl: $(LIBRARY_OBJS)
$(LDSHARED) -o $@ $(LIBRARY_OBJS) $(LIBC) $(LIBM)
# This rule is here for OPENSTEP/Rhapsody/MacOSX
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): $(LIBRARY) $(PYTHONFRAMEWORKDIR)
@ -420,10 +417,10 @@ Parser/metagrammar.o: $(srcdir)/Parser/metagrammar.c
Python/compile.o Python/symtable.o: $(GRAMMAR_H)
Python/getplatform.o: $(srcdir)/Python/getplatform.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
Python/importdl.o: $(srcdir)/Python/importdl.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
Objects/unicodectype.o: $(srcdir)/Objects/unicodectype.c \
$(srcdir)/Objects/unicodetype_db.h
@ -486,7 +483,7 @@ $(LIBRARY_OBJS) $(MODOBJS) Modules/$(MAINOBJ): $(PYTHON_HEADERS)
# Test the interpreter (twice, once without .pyc files, once with)
TESTOPTS= -l
TESTPROG= $(srcdir)/Lib/test/regrtest.py
TESTPYTHON= ./$(BUILDPYTHON) -E -tt
TESTPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) -E -tt
test: all platform
-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
-$(TESTPYTHON) $(TESTPROG) $(TESTOPTS)
@ -556,8 +553,8 @@ altbininstall: $(BUILDPYTHON)
fi; \
done
$(INSTALL_PROGRAM) $(BUILDPYTHON) $(BINDIR)/python$(VERSION)$(EXE)
if test -f libpython$(VERSION).so; then \
$(INSTALL_DATA) libpython$(VERSION).so $(LIBDIR); \
if test -f libpython$(VERSION)$(SO); then \
$(INSTALL_SHARED) libpython$(VERSION)$(SO) $(LIBDIR)/$(INSTSONAME); \
else true; \
fi
if test -f "$(DLLLIBRARY)"; then \
@ -640,10 +637,10 @@ libinstall: $(BUILDPYTHON) $(srcdir)/Lib/$(PLATDIR)
done; \
done
$(INSTALL_DATA) $(srcdir)/LICENSE $(LIBDEST)/LICENSE.txt
PYTHONPATH=$(LIBDEST) \
PYTHONPATH=$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -tt $(LIBDEST)/compileall.py -x badsyntax \
$(LIBDEST)
PYTHONPATH=$(LIBDEST) \
PYTHONPATH=$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -O $(LIBDEST)/compileall.py -x badsyntax $(LIBDEST)
# Create the PLATDIR source directory, if one wasn't distributed..
@ -686,12 +683,12 @@ libainstall: all
else true; \
fi; \
done
@if test -d $(LDLIBRARY); then :; else \
@if test -d $(LIBRARY); then :; else \
if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
$(INSTALL_DATA) $(LDLIBRARY) $(LIBPL)/$(LDLIBRARY) ; \
$(RANLIB) $(LIBPL)/$(LDLIBRARY) ; \
$(INSTALL_DATA) $(LIBRARY) $(LIBPL)/$(LIBRARY) ; \
$(RANLIB) $(LIBPL)/$(LIBRARY) ; \
else \
echo Skip install of $(LDLIBRARY) - use make frameworkinstall; \
echo Skip install of $(LIBRARY) - use make frameworkinstall; \
fi; \
fi
$(INSTALL_DATA) Modules/config.c $(LIBPL)/config.c
@ -733,7 +730,8 @@ libainstall: all
# Install the dynamically loadable modules
# This goes into $(exec_prefix)
sharedinstall:
./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
--prefix=$(prefix) \
--install-scripts=$(BINDIR) \
--install-platlib=$(DESTSHARED)

View File

@ -335,6 +335,7 @@ Todd R. Palmer
Dan Parisien
Harri Pasanen
Randy Pausch
Ondrej Palkovsky
Marcel van der Peijl
Samuele Pedroni
Steven Pemberton

View File

@ -89,6 +89,8 @@ Tools/Demos
Build
- On Unix, a shared libpython2.3.so can be created with --enable-shared.
- References to the CACHE_HASH and INTERN_STRINGS preprocessor symbols
were eliminated. They were always defined, and the internal features
they enabled stopped being experimental long ago.

9
README
View File

@ -558,6 +558,15 @@ Linker (ld) libraries and flags for threads
(jph@emilia.engr.sgi.com)
Building a shared libpython
---------------------------
Starting with Python 2.3, the majority of the interpreter can be built
into a shared library, which can then be used by the interpreter
executable, and by applications embedding Python. To enable this feature,
configure with --enable-shared.
Configuring additional built-in modules
---------------------------------------

1037
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,9 @@ AC_CONFIG_HEADER(pyconfig.h)
AC_SUBST(VERSION)
VERSION=2.3
AC_SUBST(SOVERSION)
SOVERSION=1.0
# Arguments passed to configure.
AC_SUBST(CONFIG_ARGS)
CONFIG_ARGS="$ac_configure_args"
@ -257,14 +260,22 @@ AC_MSG_RESULT($LIBRARY)
# (defined in the Makefiles). On Cygwin LDLIBRARY is the import library,
# DLLLIBRARY is the shared (i.e., DLL) library.
#
# RUNSHARED is used to run shared python without installed libraries
#
# INSTSONAME is the name of the shared library that will be use to install
# on the system - some systems like version suffix, others don't
AC_SUBST(LDLIBRARY)
AC_SUBST(DLLLIBRARY)
AC_SUBST(BLDLIBRARY)
AC_SUBST(LDLIBRARYDIR)
AC_SUBST(INSTSONAME)
AC_SUBST(RUNSHARED)
LDLIBRARY="$LIBRARY"
BLDLIBRARY='$(LDLIBRARY)'
INSTSONMAE='$(LDLIBRARY)'
DLLLIBRARY=''
LDLIBRARYDIR=''
RUNSHARED=''
# LINKCC is the command that links the python executable -- default is $(CC).
# If CXX is set, and if it is needed to link a main function that was
@ -301,22 +312,18 @@ then
fi
AC_MSG_RESULT($LINKCC)
AC_MSG_CHECKING(LDLIBRARY)
AC_MSG_CHECKING(for --enable-shared)
AC_ARG_ENABLE(shared,
[ --enable-shared disable/enable building shared python library])
# DG/UX requires some fancy ld contortions to produce a .so from an .a
case $MACHDEP in
dguxR4)
LDLIBRARY='libpython$(VERSION).so'
OPT="$OPT -pic"
;;
beos*)
LDLIBRARY='libpython$(VERSION).so'
;;
cygwin*)
LDLIBRARY='libpython$(VERSION).dll.a'
DLLLIBRARY='libpython$(VERSION).dll'
;;
esac
if test -z "$enable_shared"
then
enable_shared="no"
fi
AC_MSG_RESULT($enable_shared)
AC_MSG_CHECKING(LDLIBRARY)
# MacOSX framework builds need more magic. LDLIBRARY is the dynamic
# library that we build, but we do not want to link against it (we
@ -333,6 +340,47 @@ else
BLDLIBRARY='$(LDLIBRARY)'
fi
# Other platforms follow
if test $enable_shared = "yes"; then
case $ac_sys_system in
BeOS*)
LDLIBRARY='libpython$(VERSION).so'
;;
CYGWIN*)
LDLIBRARY='libpython$(VERSION).dll.a'
DLLLIBRARY='libpython$(VERSION).dll'
;;
SunOS*)
LDLIBRARY='libpython$(VERSION).so'
BLDLIBRARY='-Wl,-rpath,$(LIBDIR) -L. -lpython$(VERSION)'
RUNSHARED=LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
;;
Linux*)
LDLIBRARY='libpython$(VERSION).so'
BLDLIBRARY='-L. -lpython$(VERSION)'
RUNSHARED=LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
INSTSONAME="$LDLIBRARY".$SOVERSION
;;
hp*|HP*)
LDLIBRARY='libpython$(VERSION).sl'
BLDLIBRARY='-Wl,+b,$(LIBDIR) -L. -lpython$(VERSION)'
RUNSHARED=SHLIB_PATH=`pwd`:$SHLIB_PATH
;;
OSF*)
LDLIBRARY='libpython$(VERSION).so'
BLDLIBRARY='-rpath $(LIBDIR) -L. -lpython$(VERSION)'
RUNSHARED=LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
;;
esac
# DG/UX requires some fancy ld contortions to produce a .so from an .a
case $MACHDEP in
dguxR4)
LDLIBRARY='libpython$(VERSION).so'
OPT="$OPT -pic"
;;
esac
fi
AC_MSG_RESULT($LDLIBRARY)
AC_PROG_RANLIB
@ -861,7 +909,8 @@ then
case $ac_sys_system/$ac_sys_release in
AIX*) LINKFORSHARED='-Wl,-bE:Modules/python.exp -lld';;
hp*|HP*)
LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
LINKFORSHARED="-Wl,-E -Wl,+s";;
# LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
BSD/OS/4*) LINKFORSHARED="-Xlinker -export-dynamic";;
Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";;
# -u libsys_s pulls in all symbols in libsys