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

View File

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

View File

@ -89,6 +89,8 @@ Tools/Demos
Build Build
- On Unix, a shared libpython2.3.so can be created with --enable-shared.
- References to the CACHE_HASH and INTERN_STRINGS preprocessor symbols - References to the CACHE_HASH and INTERN_STRINGS preprocessor symbols
were eliminated. They were always defined, and the internal features were eliminated. They were always defined, and the internal features
they enabled stopped being experimental long ago. 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) (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 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) AC_SUBST(VERSION)
VERSION=2.3 VERSION=2.3
AC_SUBST(SOVERSION)
SOVERSION=1.0
# Arguments passed to configure. # Arguments passed to configure.
AC_SUBST(CONFIG_ARGS) AC_SUBST(CONFIG_ARGS)
CONFIG_ARGS="$ac_configure_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, # (defined in the Makefiles). On Cygwin LDLIBRARY is the import library,
# DLLLIBRARY is the shared (i.e., DLL) 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(LDLIBRARY)
AC_SUBST(DLLLIBRARY) AC_SUBST(DLLLIBRARY)
AC_SUBST(BLDLIBRARY) AC_SUBST(BLDLIBRARY)
AC_SUBST(LDLIBRARYDIR) AC_SUBST(LDLIBRARYDIR)
AC_SUBST(INSTSONAME)
AC_SUBST(RUNSHARED)
LDLIBRARY="$LIBRARY" LDLIBRARY="$LIBRARY"
BLDLIBRARY='$(LDLIBRARY)' BLDLIBRARY='$(LDLIBRARY)'
INSTSONMAE='$(LDLIBRARY)'
DLLLIBRARY='' DLLLIBRARY=''
LDLIBRARYDIR='' LDLIBRARYDIR=''
RUNSHARED=''
# LINKCC is the command that links the python executable -- default is $(CC). # 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 # If CXX is set, and if it is needed to link a main function that was
@ -301,22 +312,18 @@ then
fi fi
AC_MSG_RESULT($LINKCC) 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 if test -z "$enable_shared"
case $MACHDEP in then
dguxR4) enable_shared="no"
LDLIBRARY='libpython$(VERSION).so' fi
OPT="$OPT -pic" AC_MSG_RESULT($enable_shared)
;;
beos*)
LDLIBRARY='libpython$(VERSION).so' AC_MSG_CHECKING(LDLIBRARY)
;;
cygwin*)
LDLIBRARY='libpython$(VERSION).dll.a'
DLLLIBRARY='libpython$(VERSION).dll'
;;
esac
# MacOSX framework builds need more magic. LDLIBRARY is the dynamic # MacOSX framework builds need more magic. LDLIBRARY is the dynamic
# library that we build, but we do not want to link against it (we # library that we build, but we do not want to link against it (we
@ -333,6 +340,47 @@ else
BLDLIBRARY='$(LDLIBRARY)' BLDLIBRARY='$(LDLIBRARY)'
fi 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_MSG_RESULT($LDLIBRARY)
AC_PROG_RANLIB AC_PROG_RANLIB
@ -861,7 +909,8 @@ then
case $ac_sys_system/$ac_sys_release in case $ac_sys_system/$ac_sys_release in
AIX*) LINKFORSHARED='-Wl,-bE:Modules/python.exp -lld';; AIX*) LINKFORSHARED='-Wl,-bE:Modules/python.exp -lld';;
hp*|HP*) 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";; BSD/OS/4*) LINKFORSHARED="-Xlinker -export-dynamic";;
Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";; Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";;
# -u libsys_s pulls in all symbols in libsys # -u libsys_s pulls in all symbols in libsys