Guido van Rossum | d8eb211 | 1998-08-04 17:57:28 +0000 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | # |
| 3 | # linkcc for Python |
| 4 | # Chris Herborth (chrish@qnx.com) |
| 5 | # |
| 6 | # This is covered by the same copyright/licensing terms as the rest of |
| 7 | # Python. |
| 8 | # |
| 9 | # Shell script to build the Python shared library properly; if we haven't |
| 10 | # already built the export list, we'll need to link twice (argh...) so we |
| 11 | # can eliminate some unwatnted global symbols from the system glue/init |
| 12 | # objects. |
| 13 | # |
| 14 | # This is called by the Modules/Makefile as part of $(LINKCC): |
| 15 | # |
| 16 | # $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) $(MAINOBJ) \ |
| 17 | # -L.. -lpython$(VERSION) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python $(LDLAST) |
| 18 | # |
| 19 | # In 1.5.1 this changed to: |
| 20 | # |
| 21 | # $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) $(MAINOBJ) \ |
| 22 | # $(LIBRARY) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python $(LDLAST) |
| 23 | # |
| 24 | # For BeOS we should set $(LINKCC) to this in configure (similar to the |
| 25 | # AIX situation): |
| 26 | # |
| 27 | # $(srcdir)../BeOS/linkcc $(LIBRARY) $(PURIFY) $(CC) -nodup $(OPT) |
| 28 | # |
| 29 | # -L.. -lpython$(VERSION) will automagically pick up the shared library. |
| 30 | |
| 31 | # Check to make sure we know what we're doing. |
| 32 | system="`uname -m`" |
| 33 | if [ "$system" != "BeMac" ] && [ "$system" != "BeBox" ] ; then |
| 34 | echo "Sorry, BeOS Python doesn't support x86 yet." |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | LIBRARY="$1"; shift |
| 39 | |
| 40 | # What we want to end up with. |
| 41 | EXPORTS=${LIBRARY%.a}.exp |
| 42 | DYNAMIC=${LIBRARY%.a}.so |
| 43 | LINK_DYNAMIC="-l`echo ${DYNAMIC%.so} | sed -e s,\\\.\\\./,, -e s,lib,,`" |
| 44 | |
| 45 | # Grab the rest of the args and build them into the command used to |
| 46 | # link the python binary. Make sure we link against the shared lib |
| 47 | # and not the static lib. |
| 48 | LINK_CMD="" |
| 49 | while [ "$#" != "0" ] ; do |
| 50 | case "$1" in |
| 51 | $LIBRARY) |
| 52 | LINK_CMD="$LINK_CMD -L.. $LINK_DYNAMIC" |
| 53 | shift |
| 54 | ;; |
| 55 | *) |
| 56 | LINK_CMD="$LINK_CMD $1" |
| 57 | shift |
| 58 | ;; |
| 59 | esac |
| 60 | done |
| 61 | |
| 62 | # The shared libraries and glue objects we need to link against. |
| 63 | LIBS="-lbe -lnet -lroot" |
| 64 | GLUE="/boot/develop/lib/ppc/glue-noinit.a /boot/develop/lib/ppc/init_term_dyn.o" |
| 65 | |
| 66 | # Unwanted symbols we need to eliminate; these are regular expressions |
| 67 | # passed to egrep. |
| 68 | SYMS="opterr optind optarg getopt __.* longjmp _.*_" |
| 69 | |
| 70 | # Check to see if we've already got an exports file, and delete it if |
| 71 | # it's older than the lib. |
| 72 | if [ -e $EXPORTS ] && [ $LIBRARY -nt $EXPORTS ] ; then |
| 73 | echo "Deleting old exports file for $DYNAMIC..." |
| 74 | rm -f $EXPORTS |
| 75 | fi |
| 76 | |
| 77 | if [ ! -e $EXPORTS ] ; then |
| 78 | # First link; create the exports file with the unwanted global symbols |
| 79 | # in it. It's a pity we don't have "nm" or something like that... |
| 80 | rm -f temp-exports.exp |
| 81 | mwcc -xms -f temp-exports.exp -o $DYNAMIC $LIBRARY $GLUE $LIBS -nodup |
| 82 | |
| 83 | # Now clean out those bad symbols. |
| 84 | for sym in $SYMS ; do |
| 85 | rm -f temp-exports.exp2 |
| 86 | egrep -v "^$sym$" < temp-exports.exp > temp-exports.exp2 |
| 87 | mv -f temp-exports.exp2 temp-exports.exp |
| 88 | done |
| 89 | |
| 90 | rm -f temp-exports.exp2 |
| 91 | mv -f temp-exports.exp $EXPORTS |
| 92 | fi |
| 93 | |
| 94 | # Now link against the clean exports file. |
| 95 | mwcc -xms -f $EXPORTS -o $DYNAMIC $LIBRARY $GLUE $LIBS -nodup |
| 96 | |
| 97 | # We'll need this or the python binary won't load libpython.so... |
| 98 | ( cd .. ; ln -sf `pwd` lib ) |
| 99 | |
| 100 | # Now build the python binary. |
| 101 | echo "Link command: $LINK_CMD" |
| 102 | $LINK_CMD |