Merge branch 'new-frag-attribs'
[mesa.git] / bin / mklib
index b21658797a016b9256ce43ffff58a3dbb919846f..db97087c0a614c24ef9ee90b600a193173bf1466 100755 (executable)
--- a/bin/mklib
+++ b/bin/mklib
@@ -43,7 +43,7 @@ ARCH="auto"
 ARCHOPT=""
 NOPREFIX=0
 EXPORTS=""
-
+ID=""
 
 #
 # Parse arguments
@@ -61,7 +61,8 @@ do
            echo '  -minor N      specifies minor version number (default is 0)'
            echo '  -patch N      specifies patch version number (default is 0)'
            echo '  -lLIBRARY     specifies a dependency on LIBRARY'
-           echo '  -LDIR         search in DIR for library dependencies'
+           echo '  -LDIR         search in DIR for library dependencies at build time'
+           echo '  -RDIR         search in DIR for library dependencies at run time'
            echo '  -linker L     explicity specify the linker program to use (eg: gcc, g++)'
            echo '                Not observed on all systems at this time.'
            echo '  -ldflags OPT  specify any additional linker flags in OPT'
@@ -74,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
            ;;
@@ -107,6 +109,12 @@ do
        -L*)
            DEPS="$DEPS $1"
            ;;
+       -R*)
+           DEPS="$DEPS $1"
+           ;;
+       -Wl*)
+            DEPS="$DEPS $1"
+            ;;
        -pthread)
            # this is a special case (see bugzilla 10876)
            DEPS="$DEPS $1"
@@ -146,6 +154,10 @@ do
            shift 1;
            EXPORTS=$1
            ;;
+       '-id')
+           shift 1;
+           ID=$1
+           ;;
        -*)
            echo "mklib: Unknown option: " $1 ;
            exit 1
@@ -164,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
 #
@@ -189,6 +218,7 @@ if [  ]  ; then
     echo PATCH is $PATCH
     echo DEPS are $DEPS
     echo "EXPORTS in" $EXPORTS
+    echo ID is $ID
     echo "-----------------"
 fi
 
@@ -198,7 +228,7 @@ fi
 #
 case $ARCH in
 
-    'Linux' | 'OpenBSD' | 'GNU' | GNU/*)
+    'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*)
        # we assume gcc
 
        if [ "x$LINK" = "x" ] ; then
@@ -247,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
@@ -264,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
@@ -333,7 +388,7 @@ case $ARCH in
                        # use g++
                        LINK="g++"
                    else
-                       echo "mklib: warning: can't find C++ comiler, trying CC."
+                       echo "mklib: warning: can't find C++ compiler, trying CC."
                        LINK="CC"
                    fi
                else
@@ -359,27 +414,55 @@ 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}
-           SPARCV9=`file $1 | grep SPARCV9`
-           if [ "${SPARCV9}" ] ; then
-               OPTS="${OPTS} -xarch=v9"
+           if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
+               SPARCV9=`file $1 | grep SPARCV9`
+               if [ "${SPARCV9}" ] ; then
+                   OPTS="${OPTS} -xarch=v9"
+               fi
            fi
             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} ${OBJECTS} ${DEPS}
+               ${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
        ;;
 
@@ -621,22 +704,42 @@ 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
-            LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
-            LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
+
+            LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
+            LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
+            LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
 
            # examine first object to determine ABI
            set ${OBJECTS}
-           ABI_PPC=`file $1 | grep 'object ppc'`
-           ABI_I386=`file $1 | grep 'object i386'`
-           if [ "${ABI_PPC}" ] ; then
-               OPTS="${OPTS} -arch ppc"
-           fi
-           if [ "${ABI_I386}" ] ; then
-               OPTS="${OPTS} -arch i386"
-           fi
+            ABI_PPC=`file $1 | grep ' ppc'`
+            ABI_I386=`file $1 | grep ' i386'`
+            ABI_PPC64=`file $1 | grep ' ppc64'`
+            ABI_X86_64=`file $1 | grep ' x86_64'`
+            if [ "${ABI_PPC}" ] ; then
+                OPTS="${OPTS} -arch ppc"
+            fi
+            if [ "${ABI_I386}" ] ; then
+                OPTS="${OPTS} -arch i386"
+            fi
+            if [ "${ABI_PPC64}" ] ; then
+                OPTS="${OPTS} -arch ppc64"
+            fi
+            if [ "${ABI_X86_64}" ] ; then
+                OPTS="${OPTS} -arch x86_64"
+            fi
 
             if [ "${ALTOPTS}" ] ; then
                 OPTS=${ALTOPTS}
@@ -653,9 +756,11 @@ case $ARCH in
            fi
 
             echo "mklib: Making Darwin shared library: " ${LIBNAME}
+
             ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
             ln -s ${LIBNAME} ${LINKNAME}
-            FINAL_LIBS="${LIBNAME} ${LINKNAME}"
+            ln -s ${LIBNAME} ${LINKNAME2}
+            FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
         fi
         ;;
 
@@ -780,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"
 
@@ -796,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++"
@@ -809,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
 
@@ -822,6 +939,7 @@ case $ARCH in
            # special case for installing in bin
             FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
         fi
+        fi
        ;;
 
     'example')
@@ -853,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