xvmc: Replace frame_started by picture_structure
[mesa/nouveau-pmpeg.git] / bin / mklib
blobfd87aad420f2e5d8e35db55ccd7e2247acb34523
1 #!/bin/sh
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
30 unset CDPATH
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
36 expand_archives() {
37 DIR=$1
38 shift
39 FILES=$@
40 NEWFILES=""
41 ORIG_DIR=`pwd`
42 mkdir -p "$DIR"
43 cd "$DIR"
44 for FILE in $FILES ; do
45 case $FILE in
46 *.a)
47 # extract the .o files from this .a archive
48 case $FILE in
49 /*) ;;
50 *) FILE="$ORIG_DIR/$FILE" ;;
51 esac
52 MEMBERS=`ar t $FILE`
53 ar x $FILE
54 for MEMBER in $MEMBERS ; do
55 NEWFILES="$NEWFILES $DIR/$MEMBER"
56 done
59 # other file type, just add to list
60 NEWFILES="$NEWFILES $FILE"
62 esac
63 done
64 cd "$ORIG_DIR"
65 echo $NEWFILES
69 # Make static library with 'ar'
70 # params:
71 # options to ar
72 # 1 or 0 to indicate if ranlib should be run
73 # libname to make
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() {
78 OPTS=$1
79 shift;
80 RANLIB=$1
81 shift;
82 LIBNAME=$1
83 shift;
84 OBJECTS=$@
86 # remove existing lib, if present
87 rm -f ${LIBNAME}
89 # make static lib
90 ar ${OPTS} ${LIBNAME} ${OBJECTS}
92 # run ranlib
93 if [ ${RANLIB} = 1 ] ; then
94 ranlib ${LIBNAME}
97 echo ${LIBNAME}
101 # Print usage info.
102 usage() {
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'
132 # Option defaults
134 LIBNAME=""
135 MAJOR=1
136 MINOR=0
137 PATCH=""
138 DEPS=""
139 LINK=""
140 LDFLAGS=""
141 CPLUSPLUS=0
142 STATIC=0
143 DLOPEN=0
144 INSTALLDIR="."
145 ARCH="auto"
146 ARCHOPT=""
147 NOPREFIX=0
148 EXPORTS=""
149 ID=""
152 # Parse arguments
154 while true
156 case $1 in
157 '-h' | '--help')
158 usage
159 exit 1
161 '-o')
162 shift 1;
163 LIBNAME=$1
165 '-major')
166 shift 1;
167 MAJOR=$1
169 '-minor')
170 shift 1;
171 MINOR=$1
173 '-patch')
174 shift 1;
175 PATCH=$1
177 '-linker')
178 shift 1;
179 LINK=$1
181 '-ldflags')
182 shift 1;
183 LDFLAGS=$1
185 -l*)
186 DEPS="$DEPS $1"
188 -L*)
189 DEPS="$DEPS $1"
191 -R*)
192 DEPS="$DEPS $1"
194 -Wl*)
195 DEPS="$DEPS $1"
197 -pthread)
198 # this is a special case (see bugzilla 10876)
199 DEPS="$DEPS $1"
201 '-pthread')
202 DEPS="$DEPS -pthread"
204 '-cplusplus')
205 CPLUSPLUS=1
207 '-static')
208 STATIC=1
210 '-dlopen')
211 DLOPEN=1
213 '-install')
214 shift 1;
215 INSTALLDIR=$1
217 '-arch')
218 shift 1;
219 ARCH=$1
221 '-archopt')
222 shift 1;
223 ARCHOPT=$1
225 '-altopts')
226 shift 1;
227 ALTOPTS=$1
229 '-noprefix')
230 NOPREFIX=1
232 '-exports')
233 shift 1;
234 EXPORTS=$1
236 '-id')
237 shift 1;
238 ID=$1
241 echo "mklib: Unknown option: " $1 ;
242 exit 1
245 # This should be the first object file, stop parsing
246 break
247 esac
248 shift 1
249 done
250 OBJECTS=$@
253 if [ ${ARCH} = "auto" ] ; then
254 ARCH=`uname`
258 if [ $STATIC = 1 ]; then
259 # filter out linker options inside object list
260 NEWOBJECTS=""
261 for OBJ in $OBJECTS ; do
262 case $OBJ in
263 -Wl,*)
264 echo "mklib: warning: ignoring $OBJ for static library"
267 NEWOBJECTS="$NEWOBJECTS $OBJ"
269 esac
270 done
271 OBJECTS=$NEWOBJECTS
276 # Error checking
278 if [ "x${LIBNAME}" = "x" ] ; then
279 echo "mklib: Error: no library name specified (-h for help)"
280 exit 1
282 if [ "x${OBJECTS}" = "x" ] ; then
283 echo "mklib: Error: no object files specified (-h for help)"
284 exit 1
289 # Debugging info
291 if [ ] ; then
292 echo "-----------------"
293 echo ARCH is $ARCH
294 echo LIBNAME is $LIBNAME
295 echo MAJOR is $MAJOR
296 echo MINOR is $MINOR
297 echo PATCH is $PATCH
298 echo DEPS are $DEPS
299 echo "EXPORTS in" $EXPORTS
300 echo ID is $ID
301 echo "-----------------"
306 # OK, make the library now
308 case $ARCH in
310 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/* | 'NetBSD')
311 # we assume gcc
313 if [ "x$LINK" = "x" ] ; then
314 # -linker was not specified so set default link command now
315 if [ $CPLUSPLUS = 1 ] ; then
316 LINK=g++
317 else
318 LINK=gcc
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"
329 OPTS="-shared"
331 esac
333 # Check if objects are 32-bit and we're running in 64-bit
334 # environment. If so, pass -m32 flag to linker.
335 set ${OBJECTS}
336 ABI32=`file $1 | grep 32-bit`
337 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
338 OPTS="-m32 ${OPTS}"
341 if [ "${ALTOPTS}" ] ; then
342 OPTS=${ALTOPTS}
345 rm -f ${LIBNAME}
346 # make lib
347 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
348 # finish up
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}
354 OPTS="-ru"
355 if [ "${ALTOPTS}" ] ; then
356 OPTS=${ALTOPTS}
359 # expand .a into .o files
360 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
362 # make static lib
363 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
365 # remove temporary extracted .o files
366 rm -rf ${LIBNAME}.obj
367 else
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}"
376 esac
377 if [ $EXPORTS ] ; then
378 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
379 # Make the 'exptmp' file for --version-script option
380 echo "{" > exptmp
381 echo "global:" >> exptmp
382 sed 's/$/;/' ${EXPORTS} >> exptmp
383 echo "local:" >> exptmp
384 echo "*;" >> exptmp
385 echo "};" >> 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.
392 set ${OBJECTS}
393 ABI32=`file $1 | grep 32-bit`
394 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
395 OPTS="-m32 ${OPTS}"
397 if [ "${ALTOPTS}" ] ; then
398 OPTS=${ALTOPTS}
401 if [ x${PATCH} = "x" ] ; then
402 VERSION="${MAJOR}.${MINOR}"
403 else
404 VERSION="${MAJOR}.${MINOR}.${PATCH}"
407 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
409 # rm any old libs
410 rm -f ${LIBNAME}.so.${VERSION}
411 rm -f ${LIBNAME}.so.${MAJOR}
412 rm -f ${LIBNAME}.so
414 # make lib
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
419 # finish up
420 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
421 # rm -f exptmp
425 'SunOS')
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}`
430 else
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
441 # use Sun c++
442 LINK="c++"
443 elif [ `type g++` ] ; then
444 # use g++
445 LINK="g++"
446 else
447 echo "mklib: warning: can't find C++ compiler, trying CC."
448 LINK="CC"
450 else
451 # use native Sun linker for C code
452 LINK="ld"
456 # linker options
457 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
458 # SunOS tools, -G to make shared libs
459 OPTS="-G"
460 else
461 # gcc linker
462 # Check if objects are 32-bit and we're running in 64-bit
463 # environment. If so, pass -m32 flag to linker.
464 set ${OBJECTS}
465 ABI32=`file $1 | grep 32-bit`
466 if [ "${ABI32}" ] ; then
467 OPTS="-m32 -shared -Wl,-Bdynamic"
468 else
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"
484 DEPS="${DEPS} -lc"
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
499 set ${OBJECTS}
500 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
501 ABI64=`file $1 | grep "ELF 64-bit"`
502 if [ "${ABI64}" ] ; then
503 case `uname -p` in
504 sparc) OPTS="${OPTS} -xarch=v9" ;;
505 i386) OPTS="${OPTS} -xarch=amd64" ;;
506 esac
509 if [ "${ALTOPTS}" ] ; then
510 OPTS=${ALTOPTS}
513 # for debug:
514 #echo "mklib: linker is" ${LINK} ${OPTS}
515 if [ $NOPREFIX = 1 ] ; then
516 rm -f ${LIBNAME}
517 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
518 FINAL_LIBS="${LIBNAME}"
519 else
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}"
528 'FreeBSD')
529 # we assume gcc
531 if [ "x$LINK" = "x" ] ; then
532 # -linker was not specified so set default link command now
533 if [ $CPLUSPLUS = 1 ] ; then
534 LINK=g++
535 else
536 LINK=gcc
540 if [ $NOPREFIX = 1 ] ; then
541 # No "lib" or ".so" part
542 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
543 OPTS="-shared"
544 if [ "${ALTOPTS}" ] ; then
545 OPTS=${ALTOPTS}
547 rm -f ${LIBNAME}
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
561 rm -rf ${STLIB}.obj
562 else
563 # make dynamic library
564 SHLIB="lib${LIBNAME}.so.${MAJOR}"
565 OPTS="-shared -Wl,-soname,${SHLIB}"
566 if [ "${ALTOPTS}" ] ; then
567 OPTS=${ALTOPTS}
569 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
570 rm -f ${SHLIB}
571 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
572 ln -sf ${SHLIB} "lib${LIBNAME}.so"
573 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
577 'IRIX' | 'IRIX64')
578 if [ $STATIC = 1 ] ; then
579 LIBNAME="lib${LIBNAME}.a"
580 FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
581 else
582 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
584 # examine first object to determine ABI
585 set ${OBJECTS}
586 ABI_O32=`file $1 | grep 'ELF 32-bit'`
587 ABI_N32=`file $1 | grep 'ELF N32'`
588 ABI_N64=`file $1 | grep 'ELF 64-bit'`
589 if [ "${ABI_O32}" ] ; then
590 OPTS="-32 -shared -all"
591 ABI="o32-bit"
592 elif [ "${ABI_N32}" ] ; then
593 OPTS="-n32 -shared -all"
594 ABI="n32-bit"
595 elif [ "${ABI_N64}" ] ; then
596 OPTS="-64 -shared -all"
597 ABI="64-bit"
598 else
599 echo "Error: Unexpected IRIX ABI!"
600 exit 1
603 if [ "${ALTOPTS}" ] ; then
604 OPTS=${ALTOPTS}
607 if [ $CPLUSPLUS = 1 ] ; then
608 LINK="CC"
609 else
610 LINK="ld"
613 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
614 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
615 FINAL_LIBS=${LIBNAME}
619 'linux-cygwin')
620 LIBNAME="lib${LIBNAME}.a"
621 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
622 rm -f ${LIBNAME}
623 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
624 FINAL_LIBS=${LIBNAME}
627 'HP-UX')
628 if [ $STATIC = 1 ] ; then
629 LIBNAME="lib${LIBNAME}.a"
630 echo "mklib: Making HP-UX static library: " ${LIBNAME}
631 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
632 else
633 # HP uses a .2 for their current GL/GLU libraries
634 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
635 MAJOR=2
637 RUNLIB="lib${LIBNAME}.${MAJOR}"
638 DEVLIB="lib${LIBNAME}.sl"
639 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
640 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
641 ln -s ${RUNLIB} ${DEVLIB}
642 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
646 'AIX' )
647 # examine first object to determine ABI
648 set ${OBJECTS}
649 ABI_64=`file $1 | grep '64-bit'`
650 if [ "${ABI_64}" ] ; then
651 X64="-X64"
652 Q64="-q64"
653 OFILE=shr_64.o
654 else
655 OFILE=shr.o #Want to be consistent with the IBM libGL.a
658 if [ $STATIC = 1 ] ; then
659 LIBNAME="lib${LIBNAME}.a"
660 echo "mklib: Making AIX static library: " ${LIBNAME}
661 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
662 else
663 EXPFILE="lib${LIBNAME}.exp"
664 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
665 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
666 rm -f ${EXPFILE} ${OFILE}
667 NM="/bin/nm -eC ${X64}"
668 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
669 ${NM} ${OBJECTS} | awk '{
670 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
671 && ( substr($1,1,1) != ".")) {
672 if (substr ($1, 1, 7) != "__sinit" &&
673 substr ($1, 1, 7) != "__sterm") {
674 if (substr ($1, 1, 5) == "__tf1")
675 print (substr ($1, 7))
676 else if (substr ($1, 1, 5) == "__tf9")
677 print (substr ($1, 15))
678 else
679 print $1
682 }' | sort -u >> ${EXPFILE}
684 if [ "${ALTOPTS}" ] ; then
685 OPTS=${ALTOPTS}
688 # On AIX a shared library is linked differently when
689 # you want to dlopen the file
690 if [ $DLOPEN = "1" ] ; then
691 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
692 else
693 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
694 ar ${X64} -r ${LIBNAME} ${OFILE}
697 FINAL_LIBS="${LIBNAME}"
701 'OpenSTEP')
702 LIBNAME="lib${LIBNAME}.a"
703 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
704 libtool -static -o ${LIBNAME} - ${OBJECTS}
705 FINAL_LIBS=${LIBNAME}
708 'OSF1')
709 if [ $STATIC = 1 ] ; then
710 LIBNAME="lib${LIBNAME}.a"
711 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
712 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
713 else
714 VERSION="${MAJOR}.${MINOR}"
715 LIBNAME="lib${LIBNAME}.so"
716 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
717 if [ "x$LINK" = "x" ] ; then
718 if [ $CPLUSPLUS = 1 ] ; then
719 LINK=cxx
720 else
721 LINK=cc
724 rm -f ${LIBNAME}.${VERSION}
725 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
726 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
727 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
731 'Darwin')
732 if [ $STATIC = 1 ] ; then
733 LIBNAME="lib${LIBNAME}.a"
734 echo "mklib: Making Darwin static library: " ${LIBNAME}
735 OPTS="-ruvs"
736 if [ "${ALTOPTS}" ] ; then
737 OPTS=${ALTOPTS}
740 # expand .a into .o files
741 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
743 # make static lib
744 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
746 # remove temporary extracted .o files
747 rm -rf ${LIBNAME}.obj
749 FINAL_LIBS=${LIBNAME}
750 else
751 # On Darwin a .bundle is used for a library that you want to dlopen
752 if [ $DLOPEN = "1" ] ; then
753 LIBSUFFIX="bundle"
754 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
755 else
756 LIBSUFFIX="dylib"
757 if [ -z "$ID" ] ; then
758 ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
760 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
763 if [ ${EXPORTS} ] ; then
764 if [ -f ${EXPORTS}".darwin" ] ; then
765 EXPORTS=$EXPORTS".darwin"
767 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
770 LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
771 LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
773 # examine first object to determine ABI
774 set ${OBJECTS}
775 ABIS=`lipo -info $1 | sed s/.*://`
776 for ABI in $ABIS; do
777 OPTS="${OPTS} -arch ${ABI}"
778 done
780 if [ "${ALTOPTS}" ] ; then
781 OPTS=${ALTOPTS}
784 # determine linker
785 if [ $CPLUSPLUS = 1 ] ; then
786 LINK="g++"
787 else
788 LINK="cc"
791 echo "mklib: Making Darwin shared library: " ${LIBNAME}
793 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
794 ln -s ${LIBNAME} ${LINKNAME}
795 FINAL_LIBS="${LIBNAME} ${LINKNAME}"
799 'LynxOS')
800 LIBNAME="lib${LIBNAME}.a"
801 echo "mklib: Making LynxOS static library: " ${LIBNAME}
802 FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
805 'QNX')
806 LIBNAME="lib${LIBNAME}.a"
807 echo "mklib: Making QNX library: " ${LIBNAME}
808 wlib ${LIBNAME} ${OBJECTS}
809 FINAL_LIBS=${LIBNAME}
812 'MorphOS')
813 LIBNAME="lib${LIBNAME}.a"
814 echo "mklib: Making MorphOS library: " ${LIBNAME}
815 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
816 FINAL_LIBS="${LIBNAME}"
819 'icc' | 'icc-istatic')
820 # Intel C compiler
821 # This should get merged into the Linux code, above, since this isn't
822 # really a different architecture.
823 LIBNAME="lib${LIBNAME}" # prefix with "lib"
825 if [ $STATIC = 1 ] ; then
826 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
827 LINK="ar"
828 OPTS="-ruv"
829 if [ "${ALTOPTS}" ] ; then
830 OPTS=${ALTOPTS}
832 # make lib
833 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
834 # finish up
835 FINAL_LIBS="${LIBNAME}.a"
836 else
837 if [ $ARCH = icc-istatic ] ; then
838 OPTS="-shared -i-static -cxxlib-icc"
839 else
840 OPTS="-shared"
842 if [ "${ALTOPTS}" ] ; then
843 OPTS=${ALTOPTS}
845 VERSION="${MAJOR}.${MINOR}.${PATCH}"
846 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
848 if [ $CPLUSPLUS = 1 ] ; then
849 LINK="icpc"
850 else
851 LINK="icc"
853 # rm any old libs
854 rm -f ${LIBNAME}.so.${VERSION}
855 rm -f ${LIBNAME}.so.${MAJOR}
856 rm -f ${LIBNAME}.so
857 # make lib
858 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
859 # make usual symlinks
860 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
861 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
862 # finish up
863 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
867 'aix-gcc')
868 # AIX with gcc
869 if [ $STATIC = 1 ] ; then
870 LIBNAME="lib${LIBNAME}.a"
871 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
872 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
873 else
874 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
875 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
876 # remove old lib
877 rm -f ${LIBNAME}
878 # make the lib
879 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
880 # NOTE: the application linking with this library must specify
881 # the -Wl,-brtl flags to gcc
882 FINAL_LIBS=${LIBNAME}
886 'ultrix')
887 # XXX untested
888 if [ $STATIC = 0 ] ; then
889 echo "mklib: Warning shared libs not supported on Ultrix"
891 LIBNAME="lib${LIBNAME}.a"
892 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
893 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
896 CYGWIN*)
897 # GCC-based environment
899 if [ "x$LINK" = "x" ] ; then
900 # -linker was not specified so set default link command now
901 if [ $CPLUSPLUS = 1 ] ; then
902 LINK=g++
903 else
904 LINK=gcc
908 if [ $NOPREFIX = 1 ] ; then
909 # No "lib" or ".so" part
910 echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
911 OPTS="-shared -Wl,--enable-auto-image-base"
912 if [ "${ALTOPTS}" ] ; then
913 OPTS=${ALTOPTS}
915 rm -f ${LIBNAME}
916 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} || exit $?
917 FINAL_LIBS=${LIBNAME}
918 else
919 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
920 LIBNAME="lib${LIBNAME}" # prefix with "lib"
922 if [ $STATIC = 1 ] ; then
923 LIBNAME=${LIBNAME}.a
924 echo "mklib: Making CYGWIN static library: " ${LIBNAME}
925 OPTS="-ru"
926 if [ "${ALTOPTS}" ] ; then
927 OPTS=${ALTOPTS}
930 # expand .a into .o files
931 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
933 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
935 # remove temporary extracted .o files
936 rm -rf ${LIBNAME}.obj
937 else
938 OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
939 if [ "${ALTOPTS}" ] ; then
940 OPTS=${ALTOPTS}
942 echo "mklib: Making CYGWIN shared library: " ${CYGNAME}-${MAJOR}.dll
944 # rm any old libs
945 rm -f ${CYGNAME}-${MAJOR}.dll
946 rm -f ${LIBNAME}-${MAJOR}.dll.a
947 rm -f ${LIBNAME}.dll.a
948 rm -f ${LIBNAME}.a
950 # make lib
951 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} || exit $?
952 # make usual symlinks
953 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
954 # finish up
955 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
956 # special case for installing in bin
957 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
962 'example')
963 # If you're adding support for a new architecture, you can
964 # start with this:
965 if [ $STATIC = 1 ] ; then
966 LIBNAME="lib${LIBNAME}.a"
967 echo "mklib: Making static library for example arch: " ${LIBNAME}
968 FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
969 else
970 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
971 echo "mklib: Making shared library for example arch: " ${LIBNAME}
972 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
973 FINAL_LIBS="${LIBNAME}"
978 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
979 echo "mklib: Please add necessary commands to mklib script."
981 esac
985 # Put library files into installation directory if specified.
987 if [ ${INSTALLDIR} != "." ] ; then
988 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
989 test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
990 mv ${FINAL_LIBS} ${INSTALLDIR}/
992 if [ "x${FINAL_BINS}" != "x" ] ; then
993 echo "mklib: Installing" ${FINAL_BINS} "in" ${INSTALLDIR}
994 mv ${FINAL_BINS} ${INSTALLDIR}/