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 # Given a list of files, look for .a archives and unpack them.
29 # Return the original list of files minus the .a files plus the unpacked files.
33 for FILE in $FILES ; do
36 # extract the .o files from this .a archive
39 NEWFILES="$NEWFILES $MEMBERS"
42 # other file type, just add to list
43 NEWFILES="$NEWFILES $FILE"
51 # Given a list of files, look for .a archives and return a list of all objects
53 contents_of_archives() {
56 for FILE in $FILES ; do
59 # get list of members in this .a archive
61 NEWFILES="$NEWFILES $MEMBERS"
64 # skip other file types
72 # Make static library with 'ar'
75 # 1 or 0 to indicate if ranlib should be run
77 # list of object files
78 # Return name of library we made
79 # Example: "make_ar_static_lib -ru 1 libfoo.a foo.o bar.o"
80 make_ar_static_lib() {
89 # remove existing lib, if present
93 ar ${OPTS} ${LIBNAME} ${OBJECTS}
96 if [ ${RANLIB} = 1 ] ; then
106 echo 'Usage: mklib [options] objects'
107 echo 'Create a shared library from object files.'
108 echo ' -o LIBRARY specifies the name of the resulting library, without'
109 echo ' the leading "lib" or any suffix.'
110 echo ' (eg: "-o GL" might result in "libGL.so" being made)'
111 echo ' -major N specifies major version number (default is 1)'
112 echo ' -minor N specifies minor version number (default is 0)'
113 echo ' -patch N specifies patch version number (default is 0)'
114 echo ' -lLIBRARY specifies a dependency on LIBRARY'
115 echo ' -LDIR search in DIR for library dependencies at build time'
116 echo ' -RDIR search in DIR for library dependencies at run time'
117 echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
118 echo ' Not observed on all systems at this time.'
119 echo ' -ldflags OPT specify any additional linker flags in OPT'
120 echo ' -cplusplus link with C++ runtime'
121 echo ' -static make a static library (default is dynamic/shared)'
122 echo ' -dlopen make a shared library suitable for dynamic loading'
123 echo ' -install DIR put resulting library file(s) in DIR'
124 echo ' -arch ARCH override using `uname` to determine host system'
125 echo ' -archopt OPT specify an extra achitecture-specific option OPT'
126 echo ' -altopts OPTS alternate options to override all others'
127 echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
128 echo ' -exports FILE only export the symbols listed in FILE'
129 echo ' -id NAME Sets the id of the dylib (Darwin)'
130 echo ' -h, --help display this information and exit'
201 # this is a special case (see bugzilla 10876)
205 DEPS="$DEPS -pthread"
244 echo "mklib: Unknown option: " $1 ;
248 # This should be the first object file, stop parsing
256 if [ ${ARCH} = "auto" ] ; then
261 if [ $STATIC = 1 ]; then
262 # filter out linker options inside object list
264 for OBJ in $OBJECTS ; do
267 echo "mklib: warning: ignoring $OBJ for static library"
270 NEWOBJECTS="$NEWOBJECTS $OBJ"
281 if [ "x${LIBNAME}" = "x" ] ; then
282 echo "mklib: Error: no library name specified (-h for help)"
285 if [ "x${OBJECTS}" = "x" ] ; then
286 echo "mklib: Error: no object files specified (-h for help)"
295 echo "-----------------"
297 echo LIBNAME is $LIBNAME
302 echo "EXPORTS in" $EXPORTS
304 echo "-----------------"
309 # OK, make the library now
313 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*)
316 if [ "x$LINK" = "x" ] ; then
317 # -linker was not specified so set default link command now
318 if [ $CPLUSPLUS = 1 ] ; then
325 if [ $NOPREFIX = 1 ] ; then
326 # No "lib" or ".so" part
327 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
328 case $ARCH in 'Linux' | 'GNU' | GNU/*)
329 OPTS="-Xlinker -Bsymbolic -shared"
336 # Check if objects are 32-bit and we're running in 64-bit
337 # environment. If so, pass -m32 flag to linker.
339 ABI32=`file $1 | grep 32-bit`
340 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
344 if [ "${ALTOPTS}" ] ; then
350 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
352 FINAL_LIBS="${LIBNAME}"
353 elif [ $STATIC = 1 ] ; then
354 # make a static .a library
355 LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
356 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
358 if [ "${ALTOPTS}" ] ; then
362 # expand .a into .o files
363 NEW_OBJECTS=`expand_archives $OBJECTS`
366 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
368 # remove temporary extracted .o files
369 rm -f `contents_of_archives $OBJECTS`
371 # make dynamic library
372 LIBNAME="lib${LIBNAME}" # prefix with "lib"
373 case $ARCH in 'Linux' | 'GNU' | GNU/*)
374 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
377 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
380 if [ $EXPORTS ] ; then
381 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
382 # Make the 'exptmp' file for --version-script option
384 echo "global:" >> exptmp
385 sed 's/$/;/' ${EXPORTS} >> exptmp
386 echo "local:" >> exptmp
389 OPTS="${OPTS} -Xlinker --version-script=exptmp"
390 # exptmp is removed below
393 # Check if objects are 32-bit and we're running in 64-bit
394 # environment. If so, pass -m32 flag to linker.
396 ABI32=`file $1 | grep 32-bit`
397 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
400 if [ "${ALTOPTS}" ] ; then
404 if [ x${PATCH} = "x" ] ; then
405 VERSION="${MAJOR}.${MINOR}"
407 VERSION="${MAJOR}.${MINOR}.${PATCH}"
410 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
413 rm -f ${LIBNAME}.so.${VERSION}
414 rm -f ${LIBNAME}.so.${MAJOR}
418 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
419 # make usual symlinks
420 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
421 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
423 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
429 if [ $STATIC = 1 ] ; then
430 LIBNAME="lib${LIBNAME}.a"
431 echo "mklib: Making SunOS static library: " ${LIBNAME}
432 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
434 if [ $NOPREFIX = 0 ] ; then
435 LIBNAME="lib${LIBNAME}.so"
437 echo "mklib: Making SunOS shared library: " ${LIBNAME}
439 if [ "x$LINK" = "x" ] ; then
440 # -linker was not specified, choose default linker now
441 if [ $CPLUSPLUS = 1 ] ; then
442 # determine linker and options for C++ code
443 if [ `which c++` ] ; then
446 elif [ `type g++` ] ; then
450 echo "mklib: warning: can't find C++ compiler, trying CC."
454 # use native Sun linker for C code
460 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
461 # SunOS tools, -G to make shared libs
465 # Check if objects are 32-bit and we're running in 64-bit
466 # environment. If so, pass -m32 flag to linker.
468 ABI32=`file $1 | grep 32-bit`
469 if [ "${ABI32}" ] ; then
470 OPTS="-m32 -shared -Wl,-Bdynamic"
472 OPTS="-m64 -shared -Wl,-Bdynamic"
476 # If using Sun C++ compiler, need to tell it not to add runpaths
477 # that are specific to the build machine
478 if [ ${LINK} = "CC" ] ; then
479 OPTS="${OPTS} -norunpath"
482 # Solaris linker requires explicitly listing the Standard C & C++
483 # libraries in the link path when building shared objects
484 if [ ${LINK} = "CC" ] ; then
485 DEPS="${DEPS} -lCrun"
489 if [ $EXPORTS ] ; then
490 # Make the 'mapfile.scope' linker mapfile
491 echo "{" > mapfile.scope
492 echo "global:" >> mapfile.scope
493 sed 's/$/;/' ${EXPORTS} >> mapfile.scope
494 echo "local:" >> mapfile.scope
495 echo " *;" >> mapfile.scope
496 echo "};" >> mapfile.scope
497 OPTS="${OPTS} -Wl,-Mmapfile.scope"
500 # Check if objects are SPARC v9
501 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
503 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
504 SPARCV9=`file $1 | grep SPARCV9`
505 if [ "${SPARCV9}" ] ; then
506 OPTS="${OPTS} -xarch=v9"
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 $OBJECTS`
558 FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
560 # remove temporary extracted .o files
561 rm -f `contents_of_archives $OBJECTS`
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}
751 if [ "${ALTOPTS}" ] ; then
754 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
755 FINAL_LIBS=${LIBNAME}
757 # On Darwin a .bundle is used for a library that you want to dlopen
758 if [ $DLOPEN = "1" ] ; then
760 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
763 if [ -z "$ID" ] ; then
764 ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
766 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
769 if [ ${EXPORTS} ] ; then
770 if [ -f ${EXPORTS}".darwin" ] ; then
771 EXPORTS=$EXPORTS".darwin"
773 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
776 LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
777 LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
778 LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
780 # examine first object to determine ABI
782 ABIS=`lipo -info $1 | sed s/.*://`
784 OPTS="${OPTS} -arch ${ABI}"
787 if [ "${ALTOPTS}" ] ; then
791 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
795 if [ $CPLUSPLUS = 1 ] ; then
801 echo "mklib: Making Darwin shared library: " ${LIBNAME}
803 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
804 ln -s ${LIBNAME} ${LINKNAME}
805 ln -s ${LIBNAME} ${LINKNAME2}
806 FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
811 LIBNAME="lib${LIBNAME}.a"
812 echo "mklib: Making LynxOS static library: " ${LIBNAME}
813 FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
817 if [ $STATIC = 1 ] ; then
818 LIBNAME="lib${LIBNAME}.a"
819 echo "mklib: Making BeOS static library: " ${LIBNAME}
820 FINAL_LIBS=`make_ar_static_lib -cru 0 ${LIBNAME} ${OBJECTS}`
822 LIBNAME="lib${LIBNAME}.so"
823 echo "mklib: Making BeOS shared library: " ${LIBNAME}
824 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
825 mimeset -f "${LIBNAME}"
826 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
827 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
829 FINAL_LIBS=${LIBNAME}
833 LIBNAME="lib${LIBNAME}.a"
834 echo "mklib: Making QNX library: " ${LIBNAME}
835 wlib ${LIBNAME} ${OBJECTS}
836 FINAL_LIBS=${LIBNAME}
840 LIBNAME="lib${LIBNAME}.a"
841 echo "mklib: Making MorphOS library: " ${LIBNAME}
842 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
843 FINAL_LIBS="${LIBNAME}"
846 'icc' | 'icc-istatic')
848 # This should get merged into the Linux code, above, since this isn't
849 # really a different architecture.
850 LIBNAME="lib${LIBNAME}" # prefix with "lib"
852 if [ $STATIC = 1 ] ; then
853 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
856 if [ "${ALTOPTS}" ] ; then
860 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
862 FINAL_LIBS="${LIBNAME}.a"
864 if [ $ARCH = icc-istatic ] ; then
865 OPTS="-shared -i-static -cxxlib-icc"
869 if [ "${ALTOPTS}" ] ; then
872 VERSION="${MAJOR}.${MINOR}.${PATCH}"
873 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
875 if [ $CPLUSPLUS = 1 ] ; then
881 rm -f ${LIBNAME}.so.${VERSION}
882 rm -f ${LIBNAME}.so.${MAJOR}
885 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
886 # make usual symlinks
887 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
888 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
890 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
896 if [ $STATIC = 1 ] ; then
897 LIBNAME="lib${LIBNAME}.a"
898 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
899 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
901 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
902 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
906 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
907 # NOTE: the application linking with this library must specify
908 # the -Wl,-brtl flags to gcc
909 FINAL_LIBS=${LIBNAME}
915 if [ $STATIC = 0 ] ; then
916 echo "mklib: Warning shared libs not supported on Ultrix"
918 LIBNAME="lib${LIBNAME}.a"
919 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
920 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
924 # GCC-based environment
925 if [ $NOPREFIX = 1 ] ; then
926 # No "lib" or ".so" part
927 echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
928 OPTS="-shared -Wl,--enable-auto-image-base"
929 if [ "${ALTOPTS}" ] ; then
933 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
934 FINAL_LIBS=${LIBNAME}
936 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
937 LIBNAME="lib${LIBNAME}" # prefix with "lib"
939 if [ $STATIC = 1 ] ; then
941 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
943 if [ "${ALTOPTS}" ] ; then
946 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${OBJECTS}`
948 OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
949 if [ "${ALTOPTS}" ] ; then
952 echo "mklib: Making" $ARCH "shared library: " ${CYGNAME}-${MAJOR}.dll
954 if [ $CPLUSPLUS = 1 ] ; then
961 rm -f ${CYGNAME}-${MAJOR}.dll
962 rm -f ${LIBNAME}-${MAJOR}.dll.a
963 rm -f ${LIBNAME}.dll.a
967 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
968 # make usual symlinks
969 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
971 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
972 # special case for installing in bin
973 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
979 # If you're adding support for a new architecture, you can
981 if [ $STATIC = 1 ] ; then
982 LIBNAME="lib${LIBNAME}.a"
983 echo "mklib: Making static library for example arch: " ${LIBNAME}
984 FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
986 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
987 echo "mklib: Making shared library for example arch: " ${LIBNAME}
988 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
989 FINAL_LIBS="${LIBNAME}"
994 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
995 echo "mklib: Please add necessary commands to mklib script."
1001 # Put library files into installation directory if specified.
1003 if [ ${INSTALLDIR} != "." ] ; then
1004 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
1005 test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
1006 mv ${FINAL_LIBS} ${INSTALLDIR}/