--- mklib.freebsd.orig	Tue Oct 21 18:34:34 1997
+++ mklib.freebsd	Fri Sep 17 13:50:59 1999
@@ -34,7 +34,11 @@
 
 #--platform------------------------------------------------------------
 
-VERSION=$MAJOR.$MINOR
+if [ "${PORTOBJFORMAT}" = "elf" ]; then
+    VERSION=$MAJOR
+else
+    VERSION=$MAJOR.$MINOR
+fi
 
 BASENAME=`echo ${LIBRARY} | sed "s/\.a//g"`
 SHLIB=${BASENAME}.so.${VERSION}
@@ -44,6 +48,26 @@
 
 ar cq ${STLIB} ${OBJECTS}
 ranlib ${STLIB}
-ld -Bshareable -o ${SHLIB} ${OBJECTS}
 
-mv ${SHLIB} ../lib
+if [ "${PORTOBJFORMAT}" = "elf" ]; then
+    # This is a bit of a kludge, but... (see mklib.irix6-n32)
+    if test ${BASENAME} = "libMesaGL" ; then
+        # Add Xext & X11 to MesaGL.so's NEEDED .so list.
+        # If MesaGL is dloaded, the dependent .so's must be dloaded as well.  
+        # Dependent .so info is necessary when Mesa is loaded dynamically 
+        # by extensible interpreters (e.g. Python) where the interpreter 
+        # can't/shouldn't know all the dependent libraries that an 
+        # interpreter extension module may need to link with.  Shared libs 
+        # should be built to indicate what they need via NEEDED and RPATH. 
+        # For example, see:     objdump -x libXt.so.6 | egrep 'NEEDED|RPATH'
+	OBJECTS="${OBJECTS} -L${X11BASE}/lib -rpath ${X11BASE}/lib"
+	OBJECTS="${OBJECTS} -lXext -lX11 -lm"
+    fi
+
+    ld -shared -soname ${SHLIB} -o ${SHLIB} ${OBJECTS}
+    ln -sf ${SHLIB} ${BASENAME}.so
+    mv ${SHLIB} ${BASENAME}.so ../lib
+else
+    ld -Bshareable -o ${SHLIB} ${OBJECTS}
+    mv ${SHLIB} ../lib
+fi
