Changes for new BeOS port by Chris Herborth
diff --git a/BeOS/README b/BeOS/README
index c801afb..a4d6aee 100644
--- a/BeOS/README
+++ b/BeOS/README
@@ -1,19 +1,12 @@
-Python 1.5.1 for BeOS
+Python 1.5.x (x > 1) for BeOS
 
 This directory contains several useful things to help you build your own
 version of Python for BeOS.
 
-At this time, Python only supports BeOS on the PowerPC platform; if you'd
-like to help me port it to the x86 platform, please let me know (I only
-have limited access to BeOS on an x86 system).  If you'd like to lend
-me an x86 laptop running BeOS to do the port, _definitely_ let me know! :-)
-I'll even give it back when I'm done.
-
 What's Here?
 
-ar-1.1 - An "ar" command with a POSIX 1003.2 interface; you'll need
-         this for building the Python libraries under BeOS
-         (/bin/ar just won't cut it).
+ar-fake - A shell script used by the build process to emulate a "real"
+          POSIX ar command; helps to build the Python shared library.
 
 linkcc - A shell script used by the build process to build the Python
          shared library.
@@ -41,100 +34,59 @@
 
 Compiling Your Own Version
 
-To compile your own version of Python 1.5.1 for BeOS (with any luck,
-Python 1.6 will compile "out of the box" on BeOS), try this:
+To compile your own version of Python 1.5.x for BeOS (with any luck,
+Python 1.5.2 and later will compile "out of the box" on BeOS), try this:
 
-1) Get the Python 1.5.1 source code from ftp.python.org.
+1) Get the latest Python source code from ftp.python.org.
 
-2) Get the Python 1.5.1 diffs from my web pages 
-   (http://www.qnx.com/~chrish/Be/software/); if you can't get them through
-   a web browser, send me email and I'll mail them back to you.  These
-   diffs should also be available at ftp.python.org along with the BeOS
-   binary archive.
-   
-   Run autoconf.  If you don't have autoconf, you can get a precompiled
-   version from GeekGadgets (ftp://ftp.ninemoons.com/pub/geekgadgets/...).
+2) Configure with:
 
-3) Compile and install the POSIX ar from the ar-1.1 directory; see the
-   README in there for details.
-
-4) Configure with:
-
-   AR=ar-posix RANLIB=: ./configure --verbose --without-gcc \
+   AR=$(pwd)/BeOS/ar-fake RANLIB=: ./configure --verbose --without-gcc \
    --prefix=/boot/home/config --with-thread
    
-   The only strange thing that happens during the configure is that
-   we fail the "genuine getopt()" test; this is odd because we've got
-   a real live GNU getopt() in the system libs.  Other packages built
-   using configure (such as all of the goodies in GeekGadgets) suffer
-   the same fate though, so it's not a Python problem.
+3) Copy Modules/Setup.in to Modules/Setup.
 
-5) Copy Modules/Setup.in to Modules/Setup.
+4) Edit Modules/Setup to turn on all the modules you want built.
 
-6) Edit Modules/Setup to turn on all the modules you want built.  I've
-   personally built the following modules:
-
-   array, audioop, binascii, cPickle, cStringIO, cmath, crypt, curses,
-   errno, fcntl, gdbm, grp, imageop, math, md5, new, operator, parser,
-   pcre, posix, pwd, readline, regex, reop, rgbimg, rotor, select,
-   signal, socket, soundex, strop, struct, syslog, termios, thread,
-   time, timing, zlib
-
-   Newly compiled/tested with 1.5.1:
-   
-   _locale
-
-   You can get precompiled gdbm, ncurses, and zlib libraries from the
-   GeekGadgets repository (ftp://ftp.ninemoons.com/pub/geekgadgets/...).
-   
    Make sure you use _socket instead of socket for the name of the
    socketmodule on BeOS.
 
-7) Make:
+   If you want the modules to be built as shared libraries, instead of as
+   part of the Python shared library, be sure to uncomment the #*shared*
+   line.
 
-   make
-   
-   or, if you feel the need for speed:
-   
-   make OPT="-O7 -opt schedule604"
-   
-   You can safely ignore any warnings you see during the build (and you'll
-   see several if you use full warnings; I compiled the distribution with
-   -w9 -ansi strict and cleaned up any errors...).
+5) Make sure Modules/Makefile.pre has REALLIBRARY set to:
 
-8) Test:
+   REALLIBRARY=../libpython$(VERSION).so
 
-   make test
+6) Make:
+
+   make AR=$(pwd)/BeOS/ar-fake RANLIB=: OPT=-DUSE_DL_EXPORT \
+   CCSHARED=-UUSE_DL_EXPORT
+   
+7) Test:
+
+   make AR=$(pwd)/BeOS/ar-fake RANLIB=: OPT=-DUSE_DL_EXPORT \
+   CCSHARED=-UUSE_DL_EXPORT test
 
    Expect the following errors:
 
-   test_builtin failed -- round(1000000000.0)
-   test_fcntl skipped -- an optional feature could not be imported
    test_grp crashed -- exceptions.KeyError : getgrnam(): name not found
    test_pwd failed -- Writing: 'fakename', expected: 'caught e'
    test_socket crashed -- exceptions.AttributeError : SOCK_RAW
 
    These are all due to either partial support for certain things (like
-   sockets), or valid differences between systems (like the round()
-   error; different CPUs represent floating point numbers differently,
-   which can cause minor rounding errors).
+   sockets), or valid differences between systems.
 
-9) Install:
+   NOTE: On R4/x86, the pause() function is broken; expect the signal
+         module test to crash Python!
 
-   make install
+8) Install:
 
-10) Enjoy!
+   make AR=$(pwd)/BeOS/ar-fake RANLIB=: OPT=-DUSE_DL_EXPORT \
+   CCSHARED=-UUSE_DL_EXPORT install
 
-NOTE
-
-If you're going to build your own C/C++-based Python modules, link them
-against the libpython1.5.so shared library (in /boot/home/config/lib)
-instead of the libpython1.5.a (in /boot/home/config/lib/python1.5/config),
-unless you're building a statically-linked python interpreter (then you
-could try linking against _APP_ instead).
-
-Mixing modules linked against the shared library with a statically-linked
-interpreter is a bad idea (and it'll fail in _interesting_ ways).
+9) Enjoy!
 
 - Chris Herborth (chrish@qnx.com)
-  April 25, 1998
+  December 17, 1998
diff --git a/BeOS/linkcc b/BeOS/linkcc
index 9b95635..e3708c1 100755
--- a/BeOS/linkcc
+++ b/BeOS/linkcc
@@ -24,23 +24,20 @@
 # For BeOS we should set $(LINKCC) to this in configure (similar to the
 # AIX situation):
 #
-# $(srcdir)../BeOS/linkcc $(LIBRARY) $(PURIFY) $(CC) -nodup $(OPT)
+# $(srcdir)../BeOS/linkcc $(LIBRARY) $(PURIFY) $(CC) $(OPT)
 #
 # -L.. -lpython$(VERSION) will automagically pick up the shared library.
-
-# Check to make sure we know what we're doing.
-system="`uname -m`"
-if [ "$system" != "BeMac" ] && [ "$system" != "BeBox" ] ; then
-	echo "Sorry, BeOS Python doesn't support x86 yet."
-	exit 1
-fi
+#
+# As of Python 1.5.2, this isn't strictly necessary, but it makes me
+# feel safer.  It makes sure we've got all the BeOS-specific libraries,
+# and it creates the "lib" symlink that we'll need for chance of running
+# "make test" successfully.
 
 LIBRARY="$1"; shift
 
 # What we want to end up with.
-EXPORTS=${LIBRARY%.a}.exp
 DYNAMIC=${LIBRARY%.a}.so
-LINK_DYNAMIC="-l`echo ${DYNAMIC%.so} | sed -e s,\\\.\\\./,, -e s,lib,,`"
+LINK_DYNAMIC="-l$(basename ${DYNAMIC%.so} | sed -e s,lib,,)"
 
 # Grab the rest of the args and build them into the command used to
 # link the python binary.  Make sure we link against the shared lib
@@ -52,6 +49,7 @@
 			LINK_CMD="$LINK_CMD -L.. $LINK_DYNAMIC"
 			shift
 			;;
+
 		*)
 			LINK_CMD="$LINK_CMD $1"
 			shift
@@ -59,42 +57,12 @@
 	esac
 done
 
-# The shared libraries and glue objects we need to link against.
+# The shared libraries and glue objects we need to link against; this is
+# a little overkill, but it'll be OK.
 LIBS="-lbe -lnet -lroot"
-GLUE="/boot/develop/lib/ppc/glue-noinit.a /boot/develop/lib/ppc/init_term_dyn.o"
 
-# Unwanted symbols we need to eliminate; these are regular expressions
-# passed to egrep.
-SYMS="opterr optind optarg getopt __.* longjmp _.*_"
-
-# Check to see if we've already got an exports file, and delete it if
-# it's older than the lib.
-if [ -e $EXPORTS ] && [ $LIBRARY -nt $EXPORTS ] ; then
-	echo "Deleting old exports file for $DYNAMIC..."
-	rm -f $EXPORTS
-fi
-
-if [ ! -e $EXPORTS ] ; then
-	# First link; create the exports file with the unwanted global symbols
-	# in it.  It's a pity we don't have "nm" or something like that...
-	rm -f temp-exports.exp
-	mwcc -xms -f temp-exports.exp -o $DYNAMIC $LIBRARY $GLUE $LIBS -nodup
-
-	# Now clean out those bad symbols.
-	for sym in $SYMS ; do 
-		rm -f temp-exports.exp2
-		egrep -v "^$sym$" < temp-exports.exp > temp-exports.exp2
-		mv -f temp-exports.exp2 temp-exports.exp
-	done
-
-	rm -f temp-exports.exp2
-	mv -f temp-exports.exp $EXPORTS
-fi
-
-# Now link against the clean exports file.
-mwcc -xms -f $EXPORTS -o $DYNAMIC $LIBRARY $GLUE $LIBS -nodup
-
-# We'll need this or the python binary won't load libpython.so...
+# We'll need this or the python binary won't load libpython.so... handy
+# for testing.
 ( cd .. ; ln -sf `pwd` lib )
 
 # Now build the python binary.
diff --git a/BeOS/linkmodule b/BeOS/linkmodule
index f0a6f9f..575f2bd 100755
--- a/BeOS/linkmodule
+++ b/BeOS/linkmodule
@@ -4,12 +4,11 @@
 # Chris Herborth (chrish@qnx.com)
 #
 # This is covered by the same copyright/licensing terms as the rest of
-# Python
+# Python.
 #
-# Shell script to build shared library versions of the modules; the
-# idea is to build an export list containing only the init*() function
-# for the module.  We _could_ assume for foomodule.o it was initfoo, but
-# that's asking for trouble... this is a little less efficient but correct.
+# Shell script to build shared library versions of the modules; since
+# the change to the *ahem* "proper" import/export mechanism, this script
+# is much simpler.  It handles PowerPC and x86, too.
 #
 # This is called by the Modules/Makefile as $(LDSHARED):
 #
@@ -19,13 +18,8 @@
 #
 # $(LDSHARED)  readline.o  -L/boot/home/config/lib -lreadline -ltermcap \
 # -o readline$(SO)
-
-# Check to make sure we know what we're doing.
-system="`uname -m`"
-if [ "$system" != "BeMac" ] && [ "$system" != "BeBox" ] ; then
-	echo "Sorry, BeOS Python doesn't support x86 yet."
-	exit 1
-fi
+#
+# so we need to preserve the arguments, sort of.
 
 # Make sure we got reasonable arguments.
 TARGET=""
@@ -45,26 +39,37 @@
 	echo
 	echo "Where:"
 	echo
-	echo "	[args]	normal mwcc arguments"
+	echo "	[args]	normal compiler arguments"
 	exit 1
 fi
 
-EXPORTS=${TARGET%.so}.exp
-
 # The shared libraries and glue objects we need to link against; these
 # libs are overkill for most of the standard modules, but it makes life
 # in this shell script easier.
 LIBS="-L.. -lpython1.5 -lbe -lnet -lroot"
-GLUE="/boot/develop/lib/ppc/glue-noinit.a /boot/develop/lib/ppc/init_term_dyn.o"
 
-# Check to see if we've already got an exports file; we don't need to
-# update this once we've got it because we only ever want to export
-# one symbol.
-if [ ! -e $EXPORTS ] ; then
-	# The init*() function has to be related to the module's .so name
-	# for importdl to work.
-	echo init${TARGET%.so} | sed -e s/module// > $EXPORTS
-fi
+case $BE_HOST_CPU in
+	ppc)
+		# Boy, do we need a lot of crap...
+		GLUE_LOC=/boot/develop/lib/ppc
+		GLUE="${GLUE_LOC}/glue-noinit.a ${GLUE_LOC}/init_term_dyn.o"
+		CC="mwcc -xms -export pragma -nodup"
+		;;
 
-# Now link against the clean exports file.
-mwcc -xms -f $EXPORTS -o $TARGET $ARGS $GLUE $LIBS -nodup
+	x86)
+		# We don't need as much crap here...
+		GLUE=""
+		CC="gcc -nostart -Wl,-soname=${TARGET}"
+		;;
+
+	*)
+		# What the?!?
+		echo "$0 doesn't support $BE_HOST_CPU systems..."
+		echo "You're on your own... I'd be surprised if this works."
+		GLUE=""
+		CC="cc"
+		;;
+esac
+
+# Now link that shared lib...
+$CC -o $TARGET $ARGS $GLUE $LIBS