Clarify portability and main program.
[python/dscho.git] / BeOS / linkcc
blob9b956355373849e4679437273b96bfbf900c30d8
1 #! /bin/sh
3 # linkcc for Python
4 # Chris Herborth (chrish@qnx.com)
6 # This is covered by the same copyright/licensing terms as the rest of
7 # Python.
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.
14 # This is called by the Modules/Makefile as part of $(LINKCC):
16 # $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) $(MAINOBJ) \
17 # -L.. -lpython$(VERSION) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python $(LDLAST)
19 # In 1.5.1 this changed to:
21 # $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) $(MAINOBJ) \
22 # $(LIBRARY) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python $(LDLAST)
24 # For BeOS we should set $(LINKCC) to this in configure (similar to the
25 # AIX situation):
27 # $(srcdir)../BeOS/linkcc $(LIBRARY) $(PURIFY) $(CC) -nodup $(OPT)
29 # -L.. -lpython$(VERSION) will automagically pick up the shared library.
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
38 LIBRARY="$1"; shift
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,,`"
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
56 LINK_CMD="$LINK_CMD $1"
57 shift
59 esac
60 done
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"
66 # Unwanted symbols we need to eliminate; these are regular expressions
67 # passed to egrep.
68 SYMS="opterr optind optarg getopt __.* longjmp _.*_"
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
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
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
90 rm -f temp-exports.exp2
91 mv -f temp-exports.exp $EXPORTS
94 # Now link against the clean exports file.
95 mwcc -xms -f $EXPORTS -o $DYNAMIC $LIBRARY $GLUE $LIBS -nodup
97 # We'll need this or the python binary won't load libpython.so...
98 ( cd .. ; ln -sf `pwd` lib )
100 # Now build the python binary.
101 echo "Link command: $LINK_CMD"
102 $LINK_CMD