Merge branch 'softpipe-opt'
[mesa.git] / bin / mklib
index 0dc3135d50f89270834b5b6a1d86be0c1e2c2f39..db97087c0a614c24ef9ee90b600a193173bf1466 100755 (executable)
--- a/bin/mklib
+++ b/bin/mklib
@@ -43,7 +43,7 @@ ARCH="auto"
 ARCHOPT=""
 NOPREFIX=0
 EXPORTS=""
-
+ID=""
 
 #
 # Parse arguments
@@ -75,6 +75,7 @@ do
            echo '  -altopts OPTS alternate options to override all others'
            echo "  -noprefix     don't prefix library name with 'lib' nor add any suffix"
            echo '  -exports FILE only export the symbols listed in FILE'
+           echo '  -id NAME      Sets the id of the dylib (Darwin)'
            echo '  -h, --help    display this information and exit'
            exit 1
            ;;
@@ -153,6 +154,10 @@ do
            shift 1;
            EXPORTS=$1
            ;;
+       '-id')
+           shift 1;
+           ID=$1
+           ;;
        -*)
            echo "mklib: Unknown option: " $1 ;
            exit 1
@@ -171,6 +176,23 @@ if [ ${ARCH} = "auto" ] ; then
 fi
 
 
+if [ $STATIC = 1 ]; then
+    # filter out linker options inside object list
+    NEWOBJECTS=""
+    for OBJ in $OBJECTS ; do
+       case $OBJ in
+           -Wl,*)
+               echo "mklib: warning: ignoring $OBJ for static library"
+               ;;
+           *)
+               NEWOBJECTS="$NEWOBJECTS $OBJ"
+               ;;
+       esac
+    done
+    OBJECTS=$NEWOBJECTS
+fi
+
+
 #
 # Error checking
 #
@@ -196,6 +218,7 @@ if [  ]  ; then
     echo PATCH is $PATCH
     echo DEPS are $DEPS
     echo "EXPORTS in" $EXPORTS
+    echo ID is $ID
     echo "-----------------"
 fi
 
@@ -254,9 +277,34 @@ case $ARCH in
                 OPTS=${ALTOPTS}
             fi
             rm -f ${LIBNAME}
+
+           # expand any .a objects into constituent .o files.
+           NEWOBJECTS=""
+           DELETIA=""
+           for OBJ in $OBJECTS ; do
+               case $OBJ in
+                   *.a)
+                       # extract the .o files from this .a archive
+                       FILES=`ar t $OBJ`
+                       ar x $OBJ
+                       NEWOBJECTS="$NEWOBJECTS $FILES"
+                       # keep track of temporary .o files and delete them below
+                       DELETIA="$DELETIA $FILES"
+                       ;;
+                   *)
+                       # ordinary .o file
+                       NEWOBJECTS="$NEWOBJECTS $OBJ"
+                       ;;
+               esac
+           done
+
             # make lib
-            ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
+            ${LINK} ${OPTS} ${LIBNAME} ${NEWOBJECTS}
             ranlib ${LIBNAME}
+
+           # remove temporary extracted .o files
+           rm -f ${DELETIA}
+
             # finish up
             FINAL_LIBS=${LIBNAME}
         else
@@ -271,7 +319,7 @@ case $ARCH in
            if [ $EXPORTS ] ; then
                #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
                # Make the 'exptmp' file for --version-script option
-               echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
+               echo "{" > exptmp
                echo "global:" >> exptmp
                sed 's/$/;/' ${EXPORTS} >> exptmp
                echo "local:" >> exptmp
@@ -366,6 +414,30 @@ case $ARCH in
                fi
            fi
 
+           # If using Sun C++ compiler, need to tell it not to add runpaths
+           # that are specific to the build machine
+           if [ ${LINK} = "CC" ] ; then
+               OPTS="${OPTS} -norunpath"
+           fi
+
+           # Solaris linker requires explicitly listing the Standard C & C++
+           # libraries in the link path when building shared objects
+           if [ ${LINK} = "CC" ] ; then
+               DEPS="${DEPS} -lCrun"
+           fi
+           DEPS="${DEPS} -lc"
+
+           if [ $EXPORTS ] ; then
+               # Make the 'mapfile.scope' linker mapfile
+               echo "{" > mapfile.scope
+               echo "global:" >> mapfile.scope
+               sed 's/$/;/' ${EXPORTS} >> mapfile.scope
+               echo "local:" >> mapfile.scope
+               echo "    *;" >> mapfile.scope
+               echo "};" >> mapfile.scope
+               OPTS="${OPTS} -Wl,-Mmapfile.scope"
+           fi
+
            # Check if objects are SPARC v9
            # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
            set ${OBJECTS}
@@ -378,17 +450,19 @@ case $ARCH in
             if [ "${ALTOPTS}" ] ; then
                 OPTS=${ALTOPTS}
             fi
+
            # for debug:
            #echo "mklib: linker is" ${LINK} ${OPTS}
            if [ $NOPREFIX = 1 ] ; then
                rm -f ${LIBNAME}
                ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
+               FINAL_LIBS="${LIBNAME}"
            else
                rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
                ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
                ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
+               FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
            fi
-           FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
        fi
        ;;
 
@@ -630,13 +704,19 @@ case $ARCH in
                 LIBSUFFIX="bundle"
                 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
             else
-               LIBSUFFIX="dylib"
-                OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
+                LIBSUFFIX="dylib"
+                if [ -z "$ID" ] ; then
+                    ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
+                fi
+                OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
             fi
 
             if [ ${EXPORTS} ] ; then
+                if [ -f ${EXPORTS}".darwin" ] ; then
+                    EXPORTS=$EXPORTS".darwin"
+                fi
                 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
-            fi 
+            fi
 
             LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
             LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
@@ -805,6 +885,17 @@ case $ARCH in
 
      CYGWIN*)
        # GCC-based environment
+       if [ $NOPREFIX = 1 ] ; then
+           # No "lib" or ".so" part
+           echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
+           OPTS="-shared -Wl,--enable-auto-image-base"
+            if [ "${ALTOPTS}" ] ; then
+                OPTS=${ALTOPTS}
+            fi
+           rm -f ${LIBNAME}
+           ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
+           FINAL_LIBS=${LIBNAME}
+        else
        CYGNAME="cyg${LIBNAME}"     # prefix with "cyg"
        LIBNAME="lib${LIBNAME}"     # prefix with "lib"
 
@@ -821,11 +912,11 @@ case $ARCH in
             # finish up
             FINAL_LIBS=${LIBNAME}.a
         else
-           OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
+           OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
             if [ "${ALTOPTS}" ] ; then
                 OPTS=${ALTOPTS}
             fi
-            echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
+            echo "mklib: Making" $ARCH "shared library: " ${CYGNAME}-${MAJOR}.dll
 
             if [ $CPLUSPLUS = 1 ] ; then
                 LINK="g++"
@@ -834,7 +925,8 @@ case $ARCH in
             fi
 
             # rm any old libs
-            rm -f ${LIBNAME}-${MAJOR}.dll
+            rm -f ${CYGNAME}-${MAJOR}.dll
+            rm -f ${LIBNAME}-${MAJOR}.dll.a
             rm -f ${LIBNAME}.dll.a
             rm -f ${LIBNAME}.a
 
@@ -847,6 +939,7 @@ case $ARCH in
            # special case for installing in bin
             FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
         fi
+        fi
        ;;
 
     'example')
@@ -878,5 +971,6 @@ esac
 #
 if [ ${INSTALLDIR} != "." ] ; then
     echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
+    test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
     mv ${FINAL_LIBS} ${INSTALLDIR}/
 fi