3 # Make a shared library.
4 # This script should be useful for projects other than Mesa.
5 # Improvements/fixes are welcome.
8 # Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
10 # Permission is hereby granted, free of charge, to any person obtaining a
11 # copy of this software and associated documentation files (the "Software"),
12 # to deal in the Software without restriction, including without limitation
13 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 # and/or sell copies of the Software, and to permit persons to whom the
15 # Software is furnished to do so, subject to the following conditions:
17 # The above copyright notice and this permission notice shall be included
18 # in all copies or substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 # BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 # Clear CDPATH as the 'cd' command will echo stuff
29 # to stdout if it is set
32 # Given a list of files, look for .a archives and unpack them.
33 # Return the original list of files minus the .a files plus the unpacked files.
34 # first param: name of a temp directory (to be deleted when finished)
35 # remaining params: list of .o and .a files
44 for FILE in $FILES ; do
47 # extract the .o files from this .a archive
50 *) FILE="$ORIG_DIR/$FILE" ;;
54 for MEMBER in $MEMBERS ; do
55 NEWFILES="$NEWFILES $DIR/$MEMBER"
59 # other file type, just add to list
60 NEWFILES="$NEWFILES $FILE"
69 # Make static library with 'ar'
72 # 1 or 0 to indicate if ranlib should be run
74 # list of object files
75 # Return name of library we made
76 # Example: "make_ar_static_lib -ru 1 libfoo.a foo.o bar.o"
77 make_ar_static_lib() {
86 # remove existing lib, if present
90 ar ${OPTS} ${LIBNAME} ${OBJECTS}
93 if [ ${RANLIB} = 1 ] ; then
103 echo 'Usage: mklib [options] objects'
104 echo 'Create a shared library from object files.'
105 echo ' -o LIBRARY specifies the name of the resulting library, without'
106 echo ' the leading "lib" or any suffix.'
107 echo ' (eg: "-o GL" might result in "libGL.so" being made)'
108 echo ' -major N specifies major version number (default is 1)'
109 echo ' -minor N specifies minor version number (default is 0)'
110 echo ' -patch N specifies patch version number (default is 0)'
111 echo ' -lLIBRARY specifies a dependency on LIBRARY'
112 echo ' -LDIR search in DIR for library dependencies at build time'
113 echo ' -RDIR search in DIR for library dependencies at run time'
114 echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
115 echo ' Not observed on all systems at this time.'
116 echo ' -ldflags OPT specify any additional linker flags in OPT'
117 echo ' -cplusplus link with C++ runtime'
118 echo ' -static make a static library (default is dynamic/shared)'
119 echo ' -dlopen make a shared library suitable for dynamic loading'
120 echo ' -install DIR put resulting library file(s) in DIR'
121 echo ' -arch ARCH override using `uname` to determine host system'
122 echo ' -archopt OPT specify an extra achitecture-specific option OPT'
123 echo ' -altopts OPTS alternate options to override all others'
124 echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
125 echo ' -exports FILE only export the symbols listed in FILE'
126 echo ' -id NAME Sets the id of the dylib (Darwin)'
127 echo ' -h, --help display this information and exit'
198 # this is a special case (see bugzilla 10876)
202 DEPS="$DEPS -pthread"
241 echo "mklib: Unknown option: " $1 ;
245 # This should be the first object file, stop parsing
253 if [ ${ARCH} = "auto" ] ; then
258 if [ $STATIC = 1 ]; then
259 # filter out linker options inside object list
261 for OBJ in $OBJECTS ; do
264 echo "mklib: warning: ignoring $OBJ for static library"
267 NEWOBJECTS="$NEWOBJECTS $OBJ"
278 if [ "x${LIBNAME}" = "x" ] ; then
279 echo "mklib: Error: no library name specified (-h for help)"
282 if [ "x${OBJECTS}" = "x" ] ; then
283 echo "mklib: Error: no object files specified (-h for help)"
292 echo "-----------------"
294 echo LIBNAME is $LIBNAME
299 echo "EXPORTS in" $EXPORTS
301 echo "-----------------"
306 # OK, make the library now
310 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*)
313 if [ "x$LINK" = "x" ] ; then
314 # -linker was not specified so set default link command now
315 if [ $CPLUSPLUS = 1 ] ; then
322 if [ $NOPREFIX = 1 ] ; then
323 # No "lib" or ".so" part
324 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
325 case $ARCH in 'Linux' | 'GNU' | GNU/*)
326 OPTS="-Xlinker -Bsymbolic -shared"
333 # Check if objects are 32-bit and we're running in 64-bit
334 # environment. If so, pass -m32 flag to linker.
336 ABI32=`file $1 | grep 32-bit`
337 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
341 if [ "${ALTOPTS}" ] ; then
347 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
349 FINAL_LIBS="${LIBNAME}"
350 elif [ $STATIC = 1 ] ; then
351 # make a static .a library
352 LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
353 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
355 if [ "${ALTOPTS}" ] ; then
359 # expand .a into .o files
360 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
363 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
365 # remove temporary extracted .o files
366 rm -rf ${LIBNAME}.obj
368 # make dynamic library
369 LIBNAME="lib${LIBNAME}" # prefix with "lib"
370 case $ARCH in 'Linux' | 'GNU' | GNU/*)
371 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
374 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
377 if [ $EXPORTS ] ; then
378 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
379 # Make the 'exptmp' file for --version-script option
381 echo "global:" >> exptmp
382 sed 's/$/;/' ${EXPORTS} >> exptmp
383 echo "local:" >> exptmp
386 OPTS="${OPTS} -Xlinker --version-script=exptmp"
387 # exptmp is removed below
390 # Check if objects are 32-bit and we're running in 64-bit
391 # environment. If so, pass -m32 flag to linker.
393 ABI32=`file $1 | grep 32-bit`
394 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
397 if [ "${ALTOPTS}" ] ; then
401 if [ x${PATCH} = "x" ] ; then
402 VERSION="${MAJOR}.${MINOR}"
404 VERSION="${MAJOR}.${MINOR}.${PATCH}"
407 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
410 rm -f ${LIBNAME}.so.${VERSION}
411 rm -f ${LIBNAME}.so.${MAJOR}
415 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
416 # make usual symlinks
417 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
418 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
420 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
426 if [ $STATIC = 1 ] ; then
427 LIBNAME="lib${LIBNAME}.a"
428 echo "mklib: Making SunOS static library: " ${LIBNAME}
429 FINAL_LIBS=`make_ar_static_lib -ruc 0 ${LIBNAME} ${OBJECTS}`
431 if [ $NOPREFIX = 0 ] ; then
432 LIBNAME="lib${LIBNAME}.so"
434 echo "mklib: Making SunOS shared library: " ${LIBNAME}
436 if [ "x$LINK" = "x" ] ; then
437 # -linker was not specified, choose default linker now
438 if [ $CPLUSPLUS = 1 ] ; then
439 # determine linker and options for C++ code
440 if [ `which c++` ] ; then
443 elif [ `type g++` ] ; then
447 echo "mklib: warning: can't find C++ compiler, trying CC."
451 # use native Sun linker for C code
457 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
458 # SunOS tools, -G to make shared libs
462 # Check if objects are 32-bit and we're running in 64-bit
463 # environment. If so, pass -m32 flag to linker.
465 ABI32=`file $1 | grep 32-bit`
466 if [ "${ABI32}" ] ; then
467 OPTS="-m32 -shared -Wl,-Bdynamic"
469 OPTS="-m64 -shared -Wl,-Bdynamic"
473 # If using Sun C++ compiler, need to tell it not to add runpaths
474 # that are specific to the build machine
475 if [ ${LINK} = "CC" ] ; then
476 OPTS="${OPTS} -norunpath"
479 # Solaris linker requires explicitly listing the Standard C & C++
480 # libraries in the link path when building shared objects
481 if [ ${LINK} = "CC" ] ; then
482 DEPS="${DEPS} -lCrun"
486 if [ $EXPORTS ] ; then
487 # Make the 'mapfile.scope' linker mapfile
488 echo "{" > mapfile.scope
489 echo "global:" >> mapfile.scope
490 sed 's/$/;/' ${EXPORTS} >> mapfile.scope
491 echo "local:" >> mapfile.scope
492 echo " *;" >> mapfile.scope
493 echo "};" >> mapfile.scope
494 OPTS="${OPTS} -Wl,-Mmapfile.scope"
497 # Check if objects are 64-bit
498 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
500 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
501 ABI64=`file $1 | grep "ELF 64-bit"`
502 if [ "${ABI64}" ] ; then
504 sparc) OPTS="${OPTS} -xarch=v9" ;;
505 i386) OPTS="${OPTS} -xarch=amd64" ;;
509 if [ "${ALTOPTS}" ] ; then
514 #echo "mklib: linker is" ${LINK} ${OPTS}
515 if [ $NOPREFIX = 1 ] ; then
517 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
518 FINAL_LIBS="${LIBNAME}"
520 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
521 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
522 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
523 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
531 if [ "x$LINK" = "x" ] ; then
532 # -linker was not specified so set default link command now
533 if [ $CPLUSPLUS = 1 ] ; then
540 if [ $NOPREFIX = 1 ] ; then
541 # No "lib" or ".so" part
542 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
544 if [ "${ALTOPTS}" ] ; then
548 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
549 FINAL_LIBS=${LIBNAME}
550 elif [ $STATIC = 1 ] ; then
551 # make a static .a library
552 STLIB="lib${LIBNAME}.a"
553 echo "mklib: Making FreeBSD static library: " ${STLIB}
555 # expand .a into .o files
556 NEW_OBJECTS=`expand_archives ${STLIB}.obj $OBJECTS`
558 FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
560 # remove temporary extracted .o files
563 # make dynamic library
564 SHLIB="lib${LIBNAME}.so.${MAJOR}"
565 OPTS="-shared -Wl,-soname,${SHLIB}"
566 if [ "${ALTOPTS}" ] ; then
569 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
571 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
572 ln -sf ${SHLIB} "lib${LIBNAME}.so"
573 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
578 if [ $STATIC = 1 ] ; then
579 LIBNAME="lib${LIBNAME}_pic.a"
580 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
581 FINAL_LIBS=`make_ar_static_lib cq 1 ${LIBNAME} ${OBJECTS}`
583 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
584 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
586 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
587 FINAL_LIBS=${LIBNAME}
592 if [ $STATIC = 1 ] ; then
593 LIBNAME="lib${LIBNAME}.a"
594 FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
596 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
598 # examine first object to determine ABI
600 ABI_O32=`file $1 | grep 'ELF 32-bit'`
601 ABI_N32=`file $1 | grep 'ELF N32'`
602 ABI_N64=`file $1 | grep 'ELF 64-bit'`
603 if [ "${ABI_O32}" ] ; then
604 OPTS="-32 -shared -all"
606 elif [ "${ABI_N32}" ] ; then
607 OPTS="-n32 -shared -all"
609 elif [ "${ABI_N64}" ] ; then
610 OPTS="-64 -shared -all"
613 echo "Error: Unexpected IRIX ABI!"
617 if [ "${ALTOPTS}" ] ; then
621 if [ $CPLUSPLUS = 1 ] ; then
627 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
628 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
629 FINAL_LIBS=${LIBNAME}
634 LIBNAME="lib${LIBNAME}.a"
635 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
637 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
638 FINAL_LIBS=${LIBNAME}
642 if [ $STATIC = 1 ] ; then
643 LIBNAME="lib${LIBNAME}.a"
644 echo "mklib: Making HP-UX static library: " ${LIBNAME}
645 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
647 # HP uses a .2 for their current GL/GLU libraries
648 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
651 RUNLIB="lib${LIBNAME}.${MAJOR}"
652 DEVLIB="lib${LIBNAME}.sl"
653 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
654 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
655 ln -s ${RUNLIB} ${DEVLIB}
656 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
661 # examine first object to determine ABI
663 ABI_64=`file $1 | grep '64-bit'`
664 if [ "${ABI_64}" ] ; then
669 OFILE=shr.o #Want to be consistent with the IBM libGL.a
672 if [ $STATIC = 1 ] ; then
673 LIBNAME="lib${LIBNAME}.a"
674 echo "mklib: Making AIX static library: " ${LIBNAME}
675 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
677 EXPFILE="lib${LIBNAME}.exp"
678 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
679 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
680 rm -f ${EXPFILE} ${OFILE}
681 NM="/bin/nm -eC ${X64}"
682 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
683 ${NM} ${OBJECTS} | awk '{
684 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
685 && ( substr($1,1,1) != ".")) {
686 if (substr ($1, 1, 7) != "__sinit" &&
687 substr ($1, 1, 7) != "__sterm") {
688 if (substr ($1, 1, 5) == "__tf1")
689 print (substr ($1, 7))
690 else if (substr ($1, 1, 5) == "__tf9")
691 print (substr ($1, 15))
696 }' | sort -u >> ${EXPFILE}
698 if [ "${ALTOPTS}" ] ; then
702 # On AIX a shared library is linked differently when
703 # you want to dlopen the file
704 if [ $DLOPEN = "1" ] ; then
705 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
707 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
708 ar ${X64} -r ${LIBNAME} ${OFILE}
711 FINAL_LIBS="${LIBNAME}"
716 LIBNAME="lib${LIBNAME}.a"
717 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
718 libtool -static -o ${LIBNAME} - ${OBJECTS}
719 FINAL_LIBS=${LIBNAME}
723 if [ $STATIC = 1 ] ; then
724 LIBNAME="lib${LIBNAME}.a"
725 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
726 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
728 VERSION="${MAJOR}.${MINOR}"
729 LIBNAME="lib${LIBNAME}.so"
730 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
731 if [ "x$LINK" = "x" ] ; then
732 if [ $CPLUSPLUS = 1 ] ; then
738 rm -f ${LIBNAME}.${VERSION}
739 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
740 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
741 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
746 if [ $STATIC = 1 ] ; then
747 LIBNAME="lib${LIBNAME}.a"
748 echo "mklib: Making Darwin static library: " ${LIBNAME}
750 if [ "${ALTOPTS}" ] ; then
754 # expand .a into .o files
755 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
758 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
760 # remove temporary extracted .o files
761 rm -rf ${LIBNAME}.obj
763 FINAL_LIBS=${LIBNAME}
765 # On Darwin a .bundle is used for a library that you want to dlopen
766 if [ $DLOPEN = "1" ] ; then
768 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
771 if [ -z "$ID" ] ; then
772 ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
774 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
777 if [ ${EXPORTS} ] ; then
778 if [ -f ${EXPORTS}".darwin" ] ; then
779 EXPORTS=$EXPORTS".darwin"
781 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
784 LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
785 LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
786 LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
788 # examine first object to determine ABI
790 ABIS=`lipo -info $1 | sed s/.*://`
792 OPTS="${OPTS} -arch ${ABI}"
795 if [ "${ALTOPTS}" ] ; then
799 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
803 if [ $CPLUSPLUS = 1 ] ; then
809 echo "mklib: Making Darwin shared library: " ${LIBNAME}
811 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
812 ln -s ${LIBNAME} ${LINKNAME}
813 ln -s ${LIBNAME} ${LINKNAME2}
814 FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
819 LIBNAME="lib${LIBNAME}.a"
820 echo "mklib: Making LynxOS static library: " ${LIBNAME}
821 FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
825 if [ $STATIC = 1 ] ; then
826 LIBNAME="lib${LIBNAME}.a"
827 echo "mklib: Making BeOS static library: " ${LIBNAME}
828 FINAL_LIBS=`make_ar_static_lib -cru 0 ${LIBNAME} ${OBJECTS}`
830 LIBNAME="lib${LIBNAME}.so"
831 echo "mklib: Making BeOS shared library: " ${LIBNAME}
832 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
833 mimeset -f "${LIBNAME}"
834 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
835 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
837 FINAL_LIBS=${LIBNAME}
841 LIBNAME="lib${LIBNAME}.a"
842 echo "mklib: Making QNX library: " ${LIBNAME}
843 wlib ${LIBNAME} ${OBJECTS}
844 FINAL_LIBS=${LIBNAME}
848 LIBNAME="lib${LIBNAME}.a"
849 echo "mklib: Making MorphOS library: " ${LIBNAME}
850 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
851 FINAL_LIBS="${LIBNAME}"
854 'icc' | 'icc-istatic')
856 # This should get merged into the Linux code, above, since this isn't
857 # really a different architecture.
858 LIBNAME="lib${LIBNAME}" # prefix with "lib"
860 if [ $STATIC = 1 ] ; then
861 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
864 if [ "${ALTOPTS}" ] ; then
868 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
870 FINAL_LIBS="${LIBNAME}.a"
872 if [ $ARCH = icc-istatic ] ; then
873 OPTS="-shared -i-static -cxxlib-icc"
877 if [ "${ALTOPTS}" ] ; then
880 VERSION="${MAJOR}.${MINOR}.${PATCH}"
881 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
883 if [ $CPLUSPLUS = 1 ] ; then
889 rm -f ${LIBNAME}.so.${VERSION}
890 rm -f ${LIBNAME}.so.${MAJOR}
893 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
894 # make usual symlinks
895 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
896 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
898 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
904 if [ $STATIC = 1 ] ; then
905 LIBNAME="lib${LIBNAME}.a"
906 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
907 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
909 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
910 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
914 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
915 # NOTE: the application linking with this library must specify
916 # the -Wl,-brtl flags to gcc
917 FINAL_LIBS=${LIBNAME}
923 if [ $STATIC = 0 ] ; then
924 echo "mklib: Warning shared libs not supported on Ultrix"
926 LIBNAME="lib${LIBNAME}.a"
927 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
928 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
932 # GCC-based environment
934 if [ "x$LINK" = "x" ] ; then
935 # -linker was not specified so set default link command now
936 if [ $CPLUSPLUS = 1 ] ; then
943 if [ $NOPREFIX = 1 ] ; then
944 # No "lib" or ".so" part
945 echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
946 OPTS="-shared -Wl,--enable-auto-image-base"
947 if [ "${ALTOPTS}" ] ; then
951 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} || exit $?
952 FINAL_LIBS=${LIBNAME}
954 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
955 LIBNAME="lib${LIBNAME}" # prefix with "lib"
957 if [ $STATIC = 1 ] ; then
959 echo "mklib: Making CYGWIN static library: " ${LIBNAME}
961 if [ "${ALTOPTS}" ] ; then
965 # expand .a into .o files
966 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
968 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
970 # remove temporary extracted .o files
971 rm -rf ${LIBNAME}.obj
973 OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
974 if [ "${ALTOPTS}" ] ; then
977 echo "mklib: Making CYGWIN shared library: " ${CYGNAME}-${MAJOR}.dll
980 rm -f ${CYGNAME}-${MAJOR}.dll
981 rm -f ${LIBNAME}-${MAJOR}.dll.a
982 rm -f ${LIBNAME}.dll.a
986 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} || exit $?
987 # make usual symlinks
988 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
990 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
991 # special case for installing in bin
992 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
998 # If you're adding support for a new architecture, you can
1000 if [ $STATIC = 1 ] ; then
1001 LIBNAME="lib${LIBNAME}.a"
1002 echo "mklib: Making static library for example arch: " ${LIBNAME}
1003 FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
1005 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
1006 echo "mklib: Making shared library for example arch: " ${LIBNAME}
1007 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
1008 FINAL_LIBS="${LIBNAME}"
1013 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
1014 echo "mklib: Please add necessary commands to mklib script."
1020 # Put library files into installation directory if specified.
1022 if [ ${INSTALLDIR} != "." ] ; then
1023 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
1024 test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
1025 mv ${FINAL_LIBS} ${INSTALLDIR}/
1027 if [ "x${FINAL_BINS}" != "x" ] ; then
1028 echo "mklib: Installing" ${FINAL_BINS} "in" ${INSTALLDIR}
1029 mv ${FINAL_BINS} ${INSTALLDIR}/