Dynamically-linked version of Python-2.1 for linux

R. Timothy Edwards tim at stravinsky.jhuapl.edu
Wed Jun 13 18:26:26 CEST 2001


To the python developers:

I am the author of "xcircuit", into which I embedded python for use
as a scripting language (very successfully, I might add).  The only
problem I had with Python was that the source always compiled a
static ".a" library, and this would enlarge the size of the xcircuit
executable from 1.5MB to more like 4.5MB---i.e., the python
interpreter was twice the size of the program it was embedded in!
Because I am a traditional programmer who actually believes in
saving disk space and removing redundancy where warranted, I worked
out how to get a libpython2.1.so under linux, and made some
reasonable effort to make sure that this would not affect other
architectures.  Would someone please check my code and make sure
that it doesn't break the compile process on other OS's (including
Linux versions other than RedHat)?  Thanks.
						Regards,
						Tim Edwards

------------------------------------------------------------------
Source version: Python-2.1c2

Summary of changes:

1) Add LDCONFIG to the makefile so that the install process can
   update the ld.so cache (LDCONFIG = /bin/true on non-linux
   systems.  Do any other systems use an ld.so cache?).

2) Export LD_LIBRARY_PATH to python during the build process so
   that it will link correctly before doing make install

3) Change LDLIBRARY to libpython$(VERSION).so for Linux

4) Add a rule to generate libpython$(VERSION).so for Linux
   (is the same as for unixware)

5) Add a few lines to the make install process to check for
   /etc/ld.so.conf, and if it exists, append $(LIBRARY) to it
   and run LDCONFIG to rebuild /etc/ld.so.cache.

6) The install process currently installs LDLIBRARY into LIBPL
   and then runs RANLIB on it;  this would appear to be an error
   based on the fact that most systems set LDLIBRARY to be the
   same as LIBRARY, so that it is actually a static library.
   I would argue that this install should be changed to LIBRARY,
   not LDLIBRARY, so that it really is the static library that
   is installed here, and therefore it is not an error to run
   RANLIB on it.  It is around here, though, that I get a bit
   fuzzy on the intended use of the directory structure created
   by the install process, so there may be a difference of
   opinion.  But I am confused why the library needs to be
   installed both in $(LIBDIR) and in $(LIBPL), which is a
   subdirectory of $(LIBDIR).  One would think that one or the
   other would suffice. 

Patch files (diff -c original_file new_file)
------------------------------------------------------------------
1) Changes to Makefile.pre.in
------------------------------------------------------------------

*** Makefile.pre.in.orig	Sat Apr 14 13:57:07 2001
--- Makefile.pre.in	Tue Jun 12 16:12:30 2001
***************
*** 94,99 ****
--- 94,100 ----
  # Symbols used for using shared libraries
  SO=		@SO@
  LDSHARED=	@LDSHARED@
+ LDCONFIG=	@LDCONFIG@
  BLDSHARED=	@BLDSHARED@
  DESTSHARED=	$(BINLIBDEST)/lib-dynload
  
***************
*** 282,288 ****
  
  # Build the shared modules
  sharedmods: $(PYTHON)
! 	PYTHONPATH= ./$(PYTHON) $(srcdir)/setup.py build
  
  # buildno should really depend on something like LIBRARY_SRC
  buildno: $(PARSER_OBJS) \
--- 283,290 ----
  
  # Build the shared modules
  sharedmods: $(PYTHON)
! 	PYTHONPATH=export LD_LIBRARY_PATH; LD_LIBRARY_PATH=$(srcdir); \
! 	./$(PYTHON) $(srcdir)/setup.py build
  
  # buildno should really depend on something like LIBRARY_SRC
  buildno: $(PARSER_OBJS) \
***************
*** 309,315 ****
  	$(AR) cr $@ $(MODOBJS)
  	$(RANLIB) $@
  
! # This rule is only here for DG/UX, UnixWare, and BeOS!!!
  libpython$(VERSION).so:	$(LIBRARY)
  	case `uname -s | tr -d '/ ' | tr '[A-Z]' '[a-z]'` in \
  	*dgux*) \
--- 311,317 ----
  	$(AR) cr $@ $(MODOBJS)
  	$(RANLIB) $@
  
! # This rule is here for DG/UX, UnixWare, Linux, and BeOS
  libpython$(VERSION).so:	$(LIBRARY)
  	case `uname -s | tr -d '/ ' | tr '[A-Z]' '[a-z]'` in \
  	*dgux*) \
***************
*** 320,325 ****
--- 322,330 ----
  	unixware*) \
  	    $(LDSHARED) -o $@ $(LIBRARY_OBJS) \
  	    ;; \
+ 	linux*) \
+ 	    $(LDSHARED) -o $@ $(LIBRARY_OBJS) \
+ 	    ;; \
  	beos) \
  	    $(AR) so $(LIBRARY) $@ \
  	    ;; \
***************
*** 534,539 ****
--- 539,548 ----
  	$(INSTALL_PROGRAM) $(PYTHON) $(BINDIR)/python$(VERSION)$(EXE)
  	if test -f libpython$(VERSION).so; then \
  		$(INSTALL_DATA) libpython$(VERSION).so $(LIBDIR); \
+ 		if test -z `grep $(LIBDIR) /etc/ld.so.conf | uniq`; then \
+ 		   echo $(LIBDIR) >> /etc/ld.so.conf; \
+ 		fi; \
+ 		$(LDCONFIG) $(LIBDIR); \
  	else	true; \
  	fi
  	if test -f "$(DLLLIBRARY)"; then \
***************
*** 659,667 ****
  		else	true; \
  		fi; \
  	done
! 	@if test -d $(LDLIBRARY); then :; else \
! 		$(INSTALL_DATA) $(LDLIBRARY) $(LIBPL)/$(LDLIBRARY) ; \
! 		$(RANLIB) $(LIBPL)/$(LDLIBRARY) ; \
  	fi
  	$(INSTALL_DATA) Modules/config.c $(LIBPL)/config.c
  	$(INSTALL_DATA) Modules/$(MAINOBJ) $(LIBPL)/$(MAINOBJ)
--- 668,676 ----
  		else	true; \
  		fi; \
  	done
! 	@if test -d $(LIBRARY); then :; else \
! 		$(INSTALL_DATA) $(LIBRARY) $(LIBPL)/$(LIBRARY) ; \
! 		$(RANLIB) $(LIBPL)/$(LIBRARY) ; \
  	fi
  	$(INSTALL_DATA) Modules/config.c $(LIBPL)/config.c
  	$(INSTALL_DATA) Modules/$(MAINOBJ) $(LIBPL)/$(MAINOBJ)

------------------------------------------------------------------
2) Changes to configure.in for autoconf
------------------------------------------------------------------

*** configure.in.orig	Wed Apr 11 16:56:19 2001
--- configure.in	Tue Jun 12 16:09:58 2001
***************
*** 273,278 ****
--- 273,281 ----
        LDLIBRARY='libpython$(VERSION).dll.a'
        DLLLIBRARY='libpython$(VERSION).dll'
        ;;
+ linux*)
+       LDLIBRARY='libpython$(VERSION).so'
+       ;;
  unixware*)
        LDLIBRARY='libpython$(VERSION).so'
        ;;
***************
*** 546,551 ****
--- 549,555 ----
  # Set info about shared libraries.
  AC_SUBST(SO)
  AC_SUBST(LDSHARED)
+ AC_SUBST(LDCONFIG)
  AC_SUBST(BLDSHARED)
  AC_SUBST(CCSHARED)
  AC_SUBST(LINKFORSHARED)
***************
*** 561,566 ****
--- 565,583 ----
  	esac
  fi
  AC_MSG_RESULT($SO)
+ # LDCONFIG is the command used to create the ld.so cache in
+ # /etc/ld.so.cache.  Linux only.
+ AC_MSG_CHECKING(LDCONFIG)
+ if test -z "$LDCONFIG"
+ then
+ 	case $ac_sys_system/$ac_sys_release in
+ 	Linux*)
+ 		LDCONFIG="ldconfig";;
+ 	*)
+ 		LDCONFIG="/bin/true";;
+ 	esac
+ fi
+ AC_MSG_RESULT($LDCONFIG)
  # LDSHARED is the ld *command* used to create shared library
  # -- "ld" on SunOS 4.x.x, "ld -G" on SunOS 5.x, "ld -shared" on IRIX 5
  # (Shared libraries in this instance are shared modules to be loaded into




More information about the Python-list mailing list