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
/* |
'NetBSD')
313 if [ "x$LINK" = "x" ] ; then
314 # -linker was not specified so set default link command now
315 if [ $CPLUSPLUS = 1 ] ; then
322 # Check if objects are 32-bit and we're running in 64-bit
323 # environment. If so, pass -m32 flag to linker.
324 add_abi_flag_to_opts
() {
341 if [ $NOPREFIX = 1 ] ; then
342 # No "lib" or ".so" part
343 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
344 case $ARCH in 'Linux' |
'GNU' | GNU
/*)
345 OPTS
="-Xlinker -Bsymbolic -shared"
352 # Check to see if we are building for a different ABI.
353 add_abi_flag_to_opts
${OBJECTS}
355 if [ "${ALTOPTS}" ] ; then
361 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
363 FINAL_LIBS
="${LIBNAME}"
364 elif [ $STATIC = 1 ] ; then
365 # make a static .a library
366 LIBNAME
="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
367 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
369 if [ "${ALTOPTS}" ] ; then
373 # expand .a into .o files
374 NEW_OBJECTS
=`expand_archives ${LIBNAME}.obj $OBJECTS`
377 FINAL_LIBS
=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
379 # remove temporary extracted .o files
380 rm -rf ${LIBNAME}.obj
382 # make dynamic library
383 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
384 case $ARCH in 'Linux' |
'GNU' | GNU
/*)
385 OPTS
="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
388 OPTS
="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
391 if [ $EXPORTS ] ; then
392 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
393 # Make the 'exptmp' file for --version-script option
395 echo "global:" >> exptmp
396 sed 's/$/;/' ${EXPORTS} >> exptmp
397 echo "local:" >> exptmp
400 OPTS
="${OPTS} -Xlinker --version-script=exptmp"
401 # exptmp is removed below
404 # Check to see if we are building for a different ABI.
405 add_abi_flag_to_opts
${OBJECTS}
407 if [ "${ALTOPTS}" ] ; then
411 if [ x
${PATCH} = "x" ] ; then
412 VERSION
="${MAJOR}.${MINOR}"
414 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
417 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.
${VERSION}
420 rm -f ${LIBNAME}.so.
${VERSION}
421 rm -f ${LIBNAME}.so.
${MAJOR}
425 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
426 # make usual symlinks
427 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
428 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
430 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
436 if [ $STATIC = 1 ] ; then
437 LIBNAME
="lib${LIBNAME}.a"
438 echo "mklib: Making SunOS static library: " ${LIBNAME}
439 FINAL_LIBS
=`make_ar_static_lib -ruc 0 ${LIBNAME} ${OBJECTS}`
441 if [ $NOPREFIX = 0 ] ; then
442 LIBNAME
="lib${LIBNAME}.so"
444 echo "mklib: Making SunOS shared library: " ${LIBNAME}
446 if [ "x$LINK" = "x" ] ; then
447 # -linker was not specified, choose default linker now
448 if [ $CPLUSPLUS = 1 ] ; then
449 # determine linker and options for C++ code
450 if [ `which c++` ] ; then
453 elif [ `type g++` ] ; then
457 echo "mklib: warning: can't find C++ compiler, trying CC."
461 # use native Sun linker for C code
467 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
468 # SunOS tools, -G to make shared libs
472 # Check if objects are 32-bit and we're running in 64-bit
473 # environment. If so, pass -m32 flag to linker.
475 ABI32
=`file $1 | grep 32-bit`
476 if [ "${ABI32}" ] ; then
477 OPTS
="-m32 -shared -Wl,-Bdynamic"
479 OPTS
="-m64 -shared -Wl,-Bdynamic"
483 # If using Sun C++ compiler, need to tell it not to add runpaths
484 # that are specific to the build machine
485 if [ ${LINK} = "CC" ] ; then
486 OPTS
="${OPTS} -norunpath"
489 # Solaris linker requires explicitly listing the Standard C & C++
490 # libraries in the link path when building shared objects
491 if [ ${LINK} = "CC" ] ; then
492 DEPS
="${DEPS} -lCrun"
496 if [ $EXPORTS ] ; then
497 # Make the 'mapfile.scope' linker mapfile
498 echo "{" > mapfile.scope
499 echo "global:" >> mapfile.scope
500 sed 's/$/;/' ${EXPORTS} >> mapfile.scope
501 echo "local:" >> mapfile.scope
502 echo " *;" >> mapfile.scope
503 echo "};" >> mapfile.scope
504 OPTS
="${OPTS} -Wl,-Mmapfile.scope"
507 # Check if objects are 64-bit
508 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
510 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
511 ABI64
=`file $1 | grep "ELF 64-bit"`
512 if [ "${ABI64}" ] ; then
514 sparc
) OPTS
="${OPTS} -xarch=v9" ;;
515 i386
) OPTS
="${OPTS} -xarch=amd64" ;;
519 if [ "${ALTOPTS}" ] ; then
524 #echo "mklib: linker is" ${LINK} ${OPTS}
525 if [ $NOPREFIX = 1 ] ; then
527 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
528 FINAL_LIBS
="${LIBNAME}"
530 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
531 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
532 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
533 FINAL_LIBS
="${LIBNAME}.${MAJOR} ${LIBNAME}"
541 if [ "x$LINK" = "x" ] ; then
542 # -linker was not specified so set default link command now
543 if [ $CPLUSPLUS = 1 ] ; then
550 if [ $NOPREFIX = 1 ] ; then
551 # No "lib" or ".so" part
552 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
554 if [ "${ALTOPTS}" ] ; then
558 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
559 FINAL_LIBS
=${LIBNAME}
560 elif [ $STATIC = 1 ] ; then
561 # make a static .a library
562 STLIB
="lib${LIBNAME}.a"
563 echo "mklib: Making FreeBSD static library: " ${STLIB}
565 # expand .a into .o files
566 NEW_OBJECTS
=`expand_archives ${STLIB}.obj $OBJECTS`
568 FINAL_LIBS
=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
570 # remove temporary extracted .o files
573 # make dynamic library
574 SHLIB
="lib${LIBNAME}.so.${MAJOR}"
575 OPTS
="-shared -Wl,-soname,${SHLIB}"
576 if [ "${ALTOPTS}" ] ; then
579 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
581 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
582 ln -sf ${SHLIB} "lib${LIBNAME}.so"
583 FINAL_LIBS
="${SHLIB} lib${LIBNAME}.so"
588 if [ $STATIC = 1 ] ; then
589 LIBNAME
="lib${LIBNAME}.a"
590 FINAL_LIBS
=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
592 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
594 # examine first object to determine ABI
596 ABI_O32
=`file $1 | grep 'ELF 32-bit'`
597 ABI_N32
=`file $1 | grep 'ELF N32'`
598 ABI_N64
=`file $1 | grep 'ELF 64-bit'`
599 if [ "${ABI_O32}" ] ; then
600 OPTS
="-32 -shared -all"
602 elif [ "${ABI_N32}" ] ; then
603 OPTS
="-n32 -shared -all"
605 elif [ "${ABI_N64}" ] ; then
606 OPTS
="-64 -shared -all"
609 echo "Error: Unexpected IRIX ABI!"
613 if [ "${ALTOPTS}" ] ; then
617 if [ $CPLUSPLUS = 1 ] ; then
623 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
624 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
625 FINAL_LIBS
=${LIBNAME}
630 LIBNAME
="lib${LIBNAME}.a"
631 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
633 gnuwin32ar ruv
${LIBNAME} ${OBJECTS}
634 FINAL_LIBS
=${LIBNAME}
638 if [ $STATIC = 1 ] ; then
639 LIBNAME
="lib${LIBNAME}.a"
640 echo "mklib: Making HP-UX static library: " ${LIBNAME}
641 FINAL_LIBS
=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
643 # HP uses a .2 for their current GL/GLU libraries
644 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
647 RUNLIB
="lib${LIBNAME}.${MAJOR}"
648 DEVLIB
="lib${LIBNAME}.sl"
649 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
650 ld
-b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
651 ln -s ${RUNLIB} ${DEVLIB}
652 FINAL_LIBS
="${RUNLIB} ${DEVLIB}"
657 # examine first object to determine ABI
659 ABI_64
=`file $1 | grep '64-bit'`
660 if [ "${ABI_64}" ] ; then
665 OFILE
=shr.o
#Want to be consistent with the IBM libGL.a
668 if [ $STATIC = 1 ] ; then
669 LIBNAME
="lib${LIBNAME}.a"
670 echo "mklib: Making AIX static library: " ${LIBNAME}
671 FINAL_LIBS
=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
673 EXPFILE
="lib${LIBNAME}.exp"
674 LIBNAME
="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
675 OPTS
="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
676 rm -f ${EXPFILE} ${OFILE}
677 NM
="/bin/nm -eC ${X64}"
678 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
679 ${NM} ${OBJECTS} |
awk '{
680 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
681 && ( substr($1,1,1) != ".")) {
682 if (substr ($1, 1, 7) != "__sinit" &&
683 substr ($1, 1, 7) != "__sterm") {
684 if (substr ($1, 1, 5) == "__tf1")
685 print (substr ($1, 7))
686 else if (substr ($1, 1, 5) == "__tf9")
687 print (substr ($1, 15))
692 }' |
sort -u >> ${EXPFILE}
694 if [ "${ALTOPTS}" ] ; then
698 # On AIX a shared library is linked differently when
699 # you want to dlopen the file
700 if [ $DLOPEN = "1" ] ; then
701 cc
-G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
703 cc
${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
704 ar ${X64} -r ${LIBNAME} ${OFILE}
707 FINAL_LIBS
="${LIBNAME}"
712 LIBNAME
="lib${LIBNAME}.a"
713 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
714 libtool
-static -o ${LIBNAME} - ${OBJECTS}
715 FINAL_LIBS
=${LIBNAME}
719 if [ $STATIC = 1 ] ; then
720 LIBNAME
="lib${LIBNAME}.a"
721 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
722 FINAL_LIBS
=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
724 VERSION
="${MAJOR}.${MINOR}"
725 LIBNAME
="lib${LIBNAME}.so"
726 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
727 if [ "x$LINK" = "x" ] ; then
728 if [ $CPLUSPLUS = 1 ] ; then
734 rm -f ${LIBNAME}.
${VERSION}
735 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
736 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
737 FINAL_LIBS
="${LIBNAME} ${LIBNAME}.${VERSION}"
742 if [ $STATIC = 1 ] ; then
743 LIBNAME
="lib${LIBNAME}.a"
744 echo "mklib: Making Darwin static library: " ${LIBNAME}
746 if [ "${ALTOPTS}" ] ; then
750 # expand .a into .o files
751 NEW_OBJECTS
=`expand_archives ${LIBNAME}.obj $OBJECTS`
754 FINAL_LIBS
=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
756 # remove temporary extracted .o files
757 rm -rf ${LIBNAME}.obj
759 FINAL_LIBS
=${LIBNAME}
761 # On Darwin a .bundle is used for a library that you want to dlopen
762 if [ $DLOPEN = "1" ] ; then
764 OPTS
="${ARCHOPT} -bundle -multiply_defined suppress"
767 if [ -z "$ID" ] ; then
768 ID
="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
770 OPTS
="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
773 if [ ${EXPORTS} ] ; then
774 if [ -f ${EXPORTS}".darwin" ] ; then
775 EXPORTS
=$EXPORTS".darwin"
777 OPTS
="${OPTS} -exported_symbols_list ${EXPORTS}"
780 LINKNAME
="lib${LIBNAME}.${LIBSUFFIX}"
781 LIBNAME
="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
783 # examine first object to determine ABI
785 ABIS
=`lipo -info $1 | sed s/.*://`
787 OPTS
="${OPTS} -arch ${ABI}"
790 if [ "${ALTOPTS}" ] ; then
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 FINAL_LIBS
="${LIBNAME} ${LINKNAME}"
810 LIBNAME
="lib${LIBNAME}.a"
811 echo "mklib: Making LynxOS static library: " ${LIBNAME}
812 FINAL_LIBS
=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
816 LIBNAME
="lib${LIBNAME}.a"
817 echo "mklib: Making QNX library: " ${LIBNAME}
818 wlib
${LIBNAME} ${OBJECTS}
819 FINAL_LIBS
=${LIBNAME}
823 LIBNAME
="lib${LIBNAME}.a"
824 echo "mklib: Making MorphOS library: " ${LIBNAME}
825 ppc-morphos-ar rc
${LIBNAME} ${OBJECTS}
826 FINAL_LIBS
="${LIBNAME}"
829 'icc' |
'icc-istatic')
831 # This should get merged into the Linux code, above, since this isn't
832 # really a different architecture.
833 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
835 if [ $STATIC = 1 ] ; then
836 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
839 if [ "${ALTOPTS}" ] ; then
843 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
845 FINAL_LIBS
="${LIBNAME}.a"
847 if [ $ARCH = icc-istatic
] ; then
848 OPTS
="-shared -i-static -cxxlib-icc"
852 if [ "${ALTOPTS}" ] ; then
855 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
856 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.
${VERSION}
858 if [ $CPLUSPLUS = 1 ] ; then
864 rm -f ${LIBNAME}.so.
${VERSION}
865 rm -f ${LIBNAME}.so.
${MAJOR}
868 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
869 # make usual symlinks
870 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
871 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
873 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
879 if [ $STATIC = 1 ] ; then
880 LIBNAME
="lib${LIBNAME}.a"
881 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
882 FINAL_LIBS
=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
884 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
885 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
889 gcc
-shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
890 # NOTE: the application linking with this library must specify
891 # the -Wl,-brtl flags to gcc
892 FINAL_LIBS
=${LIBNAME}
898 if [ $STATIC = 0 ] ; then
899 echo "mklib: Warning shared libs not supported on Ultrix"
901 LIBNAME
="lib${LIBNAME}.a"
902 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
903 FINAL_LIBS
=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
907 # GCC-based environment
909 if [ "x$LINK" = "x" ] ; then
910 # -linker was not specified so set default link command now
911 if [ $CPLUSPLUS = 1 ] ; then
918 if [ $NOPREFIX = 1 ] ; then
919 # No "lib" or ".so" part
920 echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
921 OPTS
="-shared -Wl,--enable-auto-image-base"
922 if [ "${ALTOPTS}" ] ; then
926 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} ||
exit $?
927 FINAL_LIBS
=${LIBNAME}
929 CYGNAME
="cyg${LIBNAME}" # prefix with "cyg"
930 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
932 if [ $STATIC = 1 ] ; then
934 echo "mklib: Making CYGWIN static library: " ${LIBNAME}
936 if [ "${ALTOPTS}" ] ; then
940 # expand .a into .o files
941 NEW_OBJECTS
=`expand_archives ${LIBNAME}.obj $OBJECTS`
943 FINAL_LIBS
=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
945 # remove temporary extracted .o files
946 rm -rf ${LIBNAME}.obj
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 CYGWIN shared library: " ${CYGNAME}-${MAJOR}.dll
955 rm -f ${CYGNAME}-${MAJOR}.dll
956 rm -f ${LIBNAME}-${MAJOR}.dll.a
957 rm -f ${LIBNAME}.dll.a
961 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} ||
exit $?
962 # make usual symlinks
963 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
965 FINAL_LIBS
="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
966 # special case for installing in bin
967 FINAL_BINS
="${CYGNAME}-${MAJOR}.dll"
973 if [ $STATIC = 1 ] ; then
974 LIBNAME
="lib${LIBNAME}.a"
975 if [ "x$LINK" = "x" ] ; then
976 # -linker was not specified so set default link command now
977 if [ $CPLUSPLUS = 1 ] ; then
985 if [ "${ALTOPTS}" ] ; then
989 echo "mklib: Making static library for Haiku: " ${LIBNAME}
991 # expand .a into .o files
992 NEW_OBJECTS
=`expand_archives ${LIBNAME}.obj $OBJECTS`
995 FINAL_LIBS
=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
997 # remove temporary extracted .o files
998 rm -rf ${LIBNAME}.obj
1000 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
1003 echo "mklib: Making shared library for Haiku: " ${LIBNAME}
1004 ${LINK} ${OPTS} ${LDFLAGS} ${OBJECTS} ${DEPS} -o ${LIBNAME}
1005 FINAL_LIBS
="${LIBNAME}"
1010 # If you're adding support for a new architecture, you can
1012 if [ $STATIC = 1 ] ; then
1013 LIBNAME
="lib${LIBNAME}.a"
1014 echo "mklib: Making static library for example arch: " ${LIBNAME}
1015 FINAL_LIBS
=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
1017 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
1018 echo "mklib: Making shared library for example arch: " ${LIBNAME}
1019 ld
-o ${LIBNAME} ${OBJECTS} ${DEPS}
1020 FINAL_LIBS
="${LIBNAME}"
1025 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
1026 echo "mklib: Please add necessary commands to mklib script."
1032 # Put library files into installation directory if specified.
1034 if [ ${INSTALLDIR} != "." ] ; then
1035 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
1036 test -d ${INSTALLDIR} || mkdir
-p ${INSTALLDIR}
1037 mv ${FINAL_LIBS} ${INSTALLDIR}/
1039 if [ "x${FINAL_BINS}" != "x" ] ; then
1040 echo "mklib: Installing" ${FINAL_BINS} "in" ${INSTALLDIR}
1041 mv ${FINAL_BINS} ${INSTALLDIR}/