if building 32-bit objects in 64-bit environment, use -m32 flag
[mesa.git] / bin / mklib
index 2f6beff7c86543266a53b4f4b03001a786cd657c..1e2a1649c8cc3e7e7fd9b515a4a420e4d4df4fb7 100755 (executable)
--- a/bin/mklib
+++ b/bin/mklib
@@ -21,6 +21,7 @@
 #   -arch ARCH    override using `uname` to determine architecture
 #   -archopt OPT  specify an extra achitecture-specific option OPT
 #   -noprefix     don't prefix library name with "lib" or any suffix
+#   -exports FILE only export the symbols listed in FILE
 #
 # The library name should just be "GL" or "GLU", etc.  The 'lib' prefix
 # will be added here if needed, as well as the ".so" or ".a" suffix,
@@ -48,6 +49,7 @@ INSTALLDIR="."
 ARCH="auto"
 ARCHOPT=""
 NOPREFIX=0
+EXPORTS=""
 
 
 #
@@ -68,6 +70,7 @@ do
        '-arch')      shift 1; ARCH=$1;;
        '-archopt')   shift 1; ARCHOPT=$1;;
        '-noprefix')  NOPREFIX=1;;
+       '-exports')   shift 1; EXPORTS=$1;;
        -*)           echo "mklib: Unknown option: " $1 ; exit 1;;
        *) break
     esac
@@ -104,6 +107,7 @@ if [  ]  ; then
     echo MINOR is $MINOR
     echo PATCH is $PATCH
     echo DEPS are $DEPS
+    echo "EXPORTS in" $EXPORTS
     echo "-----------------"
 fi
 
@@ -114,7 +118,7 @@ fi
 case $ARCH in
 
     'Linux' | 'OpenBSD')
-       # GCC-based environment
+       # we assume gcc
 
        # Set default compilers if env vars not set
        if [ "x$CXX" = "x" ] ; then
@@ -157,6 +161,27 @@ case $ARCH in
            else
                OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
            fi
+           if [ $EXPORTS ] ; then
+               #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
+               # Make the 'exptmp' file for --version-script option
+               echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
+               echo "global:" >> exptmp
+               sed 's/$/;/' ${EXPORTS} >> exptmp
+               echo "local:" >> exptmp
+               echo "*;" >> exptmp
+               echo "};" >> exptmp
+               OPTS="${OPTS} -Xlinker --version-script=exptmp"
+               # exptmp is removed below
+           fi
+
+           # Check if objects are 32-bit and we're running in 64-bit
+           # environment.  If so, pass -m32 flag to linker.
+           set ${OBJECTS}
+           ABI32=`file $1 | grep 32-bit`
+           if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
+               OPTS="-m32 ${OPTS}"
+           fi
+
            if [ x${PATCH} = "x" ] ; then
                VERSION="${MAJOR}.${MINOR}"
            else
@@ -183,6 +208,7 @@ case $ARCH in
             ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
             # finish up
             FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
+#          rm -f exptmp
         fi
        ;;
 
@@ -339,53 +365,27 @@ case $ARCH in
        fi
        ;;
 
-    'AIX')
-        if [ $STATIC = 1 ] ; then
-            LIBNAME="lib${LIBNAME}.a"
-            echo "mklib: Making AIX static library: " ${LIBNAME}
-            ar -ruv ${LIBNAME} ${OBJECTS}
-            FINAL_LIBS=${LIBNAME}
-        else
-           EXPFILE="lib${LIBNAME}.exp"
-           OFILE=shr.o  #Want to be consistent with the IBM libGL.a
-           LIBNAME="lib${LIBNAME}.a"  # shared objects are still stored in the .a libraries
-           OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry"
-           rm -f ${EXPFILE} ${OFILE}
-           NM="/bin/nm -eC"
-           echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
-           ${NM} ${OBJECTS} | awk '{
-           if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
-           && ( substr($1,1,1) != ".")) {
-                   if (substr ($1, 1, 7) != "__sinit" &&
-                           substr ($1, 1, 7) != "__sterm") {
-                           if (substr ($1, 1, 5) == "__tf1")
-                               print (substr ($1, 7))
-                           else if (substr ($1, 1, 5) == "__tf9")
-                               print (substr ($1, 15))
-                           else
-                               print $1
-                       }
-               }
-           }' | sort -u >> ${EXPFILE}
-           cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
-           ar -r ${LIBNAME} ${OFILE}
-            FINAL_LIBS="${LIBNAME}"
-        fi
-        ;;
+    'AIX' | 'AIX64')
+       if [ $ARCH = "AIX64" ] ; then
+           X64="-X64"
+       fi
 
-    'AIX64')
         if [ $STATIC = 1 ] ; then
             LIBNAME="lib${LIBNAME}.a"
             echo "mklib: Making AIX static library: " ${LIBNAME}
-            ar -X64 -ruv ${LIBNAME} ${OBJECTS}
+            ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
             FINAL_LIBS=${LIBNAME}
         else
            EXPFILE="lib${LIBNAME}.exp"
            OFILE=shr.o  #Want to be consistent with the IBM libGL.a
            LIBNAME="lib${LIBNAME}.a"  # shared objects are still stored in the .a libraries
-           OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry -q64"
+           if [ $ARCH = "AIX64" ] ; then
+               OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry -q64"
+           else
+               OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry"
+           fi
            rm -f ${EXPFILE} ${OFILE}
-           NM="/bin/nm -eC -X64"
+           NM="/bin/nm -eC ${X64}"
            echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
            ${NM} ${OBJECTS} | awk '{
            if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
@@ -402,7 +402,7 @@ case $ARCH in
                }
            }' | sort -u >> ${EXPFILE}
            cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
-           ar -X64 -r ${LIBNAME} ${OFILE}
+           ar ${X64} -r ${LIBNAME} ${OFILE}
             FINAL_LIBS="${LIBNAME}"
         fi
         ;;
@@ -425,8 +425,13 @@ case $ARCH in
            VERSION="${MAJOR}.${MINOR}"
            LIBNAME="lib${LIBNAME}.so"
            echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
+           if [ $CPLUSPLUS = 1 ] ; then
+               LINK=$CXX
+           else
+               LINK=$CC
+           fi
            rm -f ${LIBNAME}.${VERSION}
-           ld -o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
+           ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
            ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
            FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
        fi