st/mesa: fix glCopyPixels bugs/crashes when src region need clipping
[mesa.git] / bin / mklib
1 #!/bin/sh
2
3 # Make a shared library.
4 # This script should be useful for projects other than Mesa.
5 # Improvements/fixes are welcome.
6
7
8 # Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
9 #
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:
16 #
17 # The above copyright notice and this permission notice shall be included
18 # in all copies or substantial portions of the Software.
19 #
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.
26
27
28 # Clear CDPATH as the 'cd' command will echo stuff
29 # to stdout if it is set
30 unset CDPATH
31
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
57 ;;
58 *)
59 # other file type, just add to list
60 NEWFILES="$NEWFILES $FILE"
61 ;;
62 esac
63 done
64 cd "$ORIG_DIR"
65 echo $NEWFILES
66 }
67
68
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=$@
85
86 # remove existing lib, if present
87 rm -f ${LIBNAME}
88
89 # make static lib
90 ar ${OPTS} ${LIBNAME} ${OBJECTS}
91
92 # run ranlib
93 if [ ${RANLIB} = 1 ] ; then
94 ranlib ${LIBNAME}
95 fi
96
97 echo ${LIBNAME}
98 }
99
100
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'
128 }
129
130
131 #
132 # Option defaults
133 #
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=""
150
151 #
152 # Parse arguments
153 #
154 while true
155 do
156 case $1 in
157 '-h' | '--help')
158 usage
159 exit 1
160 ;;
161 '-o')
162 shift 1;
163 LIBNAME=$1
164 ;;
165 '-major')
166 shift 1;
167 MAJOR=$1
168 ;;
169 '-minor')
170 shift 1;
171 MINOR=$1
172 ;;
173 '-patch')
174 shift 1;
175 PATCH=$1
176 ;;
177 '-linker')
178 shift 1;
179 LINK=$1
180 ;;
181 '-ldflags')
182 shift 1;
183 LDFLAGS=$1
184 ;;
185 -l*)
186 DEPS="$DEPS $1"
187 ;;
188 -L*)
189 DEPS="$DEPS $1"
190 ;;
191 -R*)
192 DEPS="$DEPS $1"
193 ;;
194 -Wl*)
195 DEPS="$DEPS $1"
196 ;;
197 -pthread)
198 # this is a special case (see bugzilla 10876)
199 DEPS="$DEPS $1"
200 ;;
201 '-pthread')
202 DEPS="$DEPS -pthread"
203 ;;
204 '-cplusplus')
205 CPLUSPLUS=1
206 ;;
207 '-static')
208 STATIC=1
209 ;;
210 '-dlopen')
211 DLOPEN=1
212 ;;
213 '-install')
214 shift 1;
215 INSTALLDIR=$1
216 ;;
217 '-arch')
218 shift 1;
219 ARCH=$1
220 ;;
221 '-archopt')
222 shift 1;
223 ARCHOPT=$1
224 ;;
225 '-altopts')
226 shift 1;
227 ALTOPTS=$1
228 ;;
229 '-noprefix')
230 NOPREFIX=1
231 ;;
232 '-exports')
233 shift 1;
234 EXPORTS=$1
235 ;;
236 '-id')
237 shift 1;
238 ID=$1
239 ;;
240 -*)
241 echo "mklib: Unknown option: " $1 ;
242 exit 1
243 ;;
244 *)
245 # This should be the first object file, stop parsing
246 break
247 esac
248 shift 1
249 done
250 OBJECTS=$@
251
252
253 if [ ${ARCH} = "auto" ] ; then
254 ARCH=`uname`
255 fi
256
257
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"
265 ;;
266 *)
267 NEWOBJECTS="$NEWOBJECTS $OBJ"
268 ;;
269 esac
270 done
271 OBJECTS=$NEWOBJECTS
272 fi
273
274
275 #
276 # Error checking
277 #
278 if [ "x${LIBNAME}" = "x" ] ; then
279 echo "mklib: Error: no library name specified (-h for help)"
280 exit 1
281 fi
282 if [ "x${OBJECTS}" = "x" ] ; then
283 echo "mklib: Error: no object files specified (-h for help)"
284 exit 1
285 fi
286
287
288 #
289 # Debugging info
290 #
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 "-----------------"
302 fi
303
304
305 #
306 # OK, make the library now
307 #
308 case $ARCH in
309
310 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*)
311 # we assume gcc
312
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
319 fi
320 fi
321
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"
327 ;;
328 *)
329 OPTS="-shared"
330 ;;
331 esac
332
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}"
339 fi
340
341 if [ "${ALTOPTS}" ] ; then
342 OPTS=${ALTOPTS}
343 fi
344
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}
357 fi
358
359 # expand .a into .o files
360 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
361
362 # make static lib
363 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
364
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}"
372 ;;
373 *)
374 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
375 ;;
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
388 fi
389
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}"
396 fi
397 if [ "${ALTOPTS}" ] ; then
398 OPTS=${ALTOPTS}
399 fi
400
401 if [ x${PATCH} = "x" ] ; then
402 VERSION="${MAJOR}.${MINOR}"
403 else
404 VERSION="${MAJOR}.${MINOR}.${PATCH}"
405 fi
406
407 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
408
409 # rm any old libs
410 rm -f ${LIBNAME}.so.${VERSION}
411 rm -f ${LIBNAME}.so.${MAJOR}
412 rm -f ${LIBNAME}.so
413
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
422 fi
423 ;;
424
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"
433 fi
434 echo "mklib: Making SunOS shared library: " ${LIBNAME}
435
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"
449 fi
450 else
451 # use native Sun linker for C code
452 LINK="ld"
453 fi
454 fi
455
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"
470 fi
471 fi
472
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"
477 fi
478
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"
483 fi
484 DEPS="${DEPS} -lc"
485
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"
495 fi
496
497 # Check if objects are SPARC v9
498 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
499 set ${OBJECTS}
500 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
501 SPARCV9=`file $1 | grep SPARCV9`
502 if [ "${SPARCV9}" ] ; then
503 OPTS="${OPTS} -xarch=v9"
504 fi
505 fi
506 if [ "${ALTOPTS}" ] ; then
507 OPTS=${ALTOPTS}
508 fi
509
510 # for debug:
511 #echo "mklib: linker is" ${LINK} ${OPTS}
512 if [ $NOPREFIX = 1 ] ; then
513 rm -f ${LIBNAME}
514 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
515 FINAL_LIBS="${LIBNAME}"
516 else
517 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
518 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
519 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
520 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
521 fi
522 fi
523 ;;
524
525 'FreeBSD')
526 # we assume gcc
527
528 if [ "x$LINK" = "x" ] ; then
529 # -linker was not specified so set default link command now
530 if [ $CPLUSPLUS = 1 ] ; then
531 LINK=g++
532 else
533 LINK=gcc
534 fi
535 fi
536
537 if [ $NOPREFIX = 1 ] ; then
538 # No "lib" or ".so" part
539 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
540 OPTS="-shared"
541 if [ "${ALTOPTS}" ] ; then
542 OPTS=${ALTOPTS}
543 fi
544 rm -f ${LIBNAME}
545 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
546 FINAL_LIBS=${LIBNAME}
547 elif [ $STATIC = 1 ] ; then
548 # make a static .a library
549 STLIB="lib${LIBNAME}.a"
550 echo "mklib: Making FreeBSD static library: " ${STLIB}
551
552 # expand .a into .o files
553 NEW_OBJECTS=`expand_archives ${STLIB}.obj $OBJECTS`
554
555 FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
556
557 # remove temporary extracted .o files
558 rm -rf ${STLIB}.obj
559 else
560 # make dynamic library
561 SHLIB="lib${LIBNAME}.so.${MAJOR}"
562 OPTS="-shared -Wl,-soname,${SHLIB}"
563 if [ "${ALTOPTS}" ] ; then
564 OPTS=${ALTOPTS}
565 fi
566 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
567 rm -f ${SHLIB}
568 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
569 ln -sf ${SHLIB} "lib${LIBNAME}.so"
570 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
571 fi
572 ;;
573
574 'NetBSD')
575 if [ $STATIC = 1 ] ; then
576 LIBNAME="lib${LIBNAME}_pic.a"
577 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
578 FINAL_LIBS=`make_ar_static_lib cq 1 ${LIBNAME} ${OBJECTS}`
579 else
580 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
581 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
582 rm -f ${LIBNAME}
583 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
584 FINAL_LIBS=${LIBNAME}
585 fi
586 ;;
587
588 'IRIX' | 'IRIX64')
589 if [ $STATIC = 1 ] ; then
590 LIBNAME="lib${LIBNAME}.a"
591 FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
592 else
593 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
594
595 # examine first object to determine ABI
596 set ${OBJECTS}
597 ABI_O32=`file $1 | grep 'ELF 32-bit'`
598 ABI_N32=`file $1 | grep 'ELF N32'`
599 ABI_N64=`file $1 | grep 'ELF 64-bit'`
600 if [ "${ABI_O32}" ] ; then
601 OPTS="-32 -shared -all"
602 ABI="o32-bit"
603 elif [ "${ABI_N32}" ] ; then
604 OPTS="-n32 -shared -all"
605 ABI="n32-bit"
606 elif [ "${ABI_N64}" ] ; then
607 OPTS="-64 -shared -all"
608 ABI="64-bit"
609 else
610 echo "Error: Unexpected IRIX ABI!"
611 exit 1
612 fi
613
614 if [ "${ALTOPTS}" ] ; then
615 OPTS=${ALTOPTS}
616 fi
617
618 if [ $CPLUSPLUS = 1 ] ; then
619 LINK="CC"
620 else
621 LINK="ld"
622 fi
623
624 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
625 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
626 FINAL_LIBS=${LIBNAME}
627 fi
628 ;;
629
630 'linux-cygwin')
631 LIBNAME="lib${LIBNAME}.a"
632 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
633 rm -f ${LIBNAME}
634 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
635 FINAL_LIBS=${LIBNAME}
636 ;;
637
638 'HP-UX')
639 if [ $STATIC = 1 ] ; then
640 LIBNAME="lib${LIBNAME}.a"
641 echo "mklib: Making HP-UX static library: " ${LIBNAME}
642 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
643 else
644 # HP uses a .2 for their current GL/GLU libraries
645 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
646 MAJOR=2
647 fi
648 RUNLIB="lib${LIBNAME}.${MAJOR}"
649 DEVLIB="lib${LIBNAME}.sl"
650 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
651 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
652 ln -s ${RUNLIB} ${DEVLIB}
653 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
654 fi
655 ;;
656
657 'AIX' )
658 # examine first object to determine ABI
659 set ${OBJECTS}
660 ABI_64=`file $1 | grep '64-bit'`
661 if [ "${ABI_64}" ] ; then
662 X64="-X64"
663 Q64="-q64"
664 OFILE=shr_64.o
665 else
666 OFILE=shr.o #Want to be consistent with the IBM libGL.a
667 fi
668
669 if [ $STATIC = 1 ] ; then
670 LIBNAME="lib${LIBNAME}.a"
671 echo "mklib: Making AIX static library: " ${LIBNAME}
672 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
673 else
674 EXPFILE="lib${LIBNAME}.exp"
675 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
676 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
677 rm -f ${EXPFILE} ${OFILE}
678 NM="/bin/nm -eC ${X64}"
679 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
680 ${NM} ${OBJECTS} | awk '{
681 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
682 && ( substr($1,1,1) != ".")) {
683 if (substr ($1, 1, 7) != "__sinit" &&
684 substr ($1, 1, 7) != "__sterm") {
685 if (substr ($1, 1, 5) == "__tf1")
686 print (substr ($1, 7))
687 else if (substr ($1, 1, 5) == "__tf9")
688 print (substr ($1, 15))
689 else
690 print $1
691 }
692 }
693 }' | sort -u >> ${EXPFILE}
694
695 if [ "${ALTOPTS}" ] ; then
696 OPTS=${ALTOPTS}
697 fi
698
699 # On AIX a shared library is linked differently when
700 # you want to dlopen the file
701 if [ $DLOPEN = "1" ] ; then
702 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
703 else
704 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
705 ar ${X64} -r ${LIBNAME} ${OFILE}
706 fi
707
708 FINAL_LIBS="${LIBNAME}"
709 fi
710 ;;
711
712 'OpenSTEP')
713 LIBNAME="lib${LIBNAME}.a"
714 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
715 libtool -static -o ${LIBNAME} - ${OBJECTS}
716 FINAL_LIBS=${LIBNAME}
717 ;;
718
719 'OSF1')
720 if [ $STATIC = 1 ] ; then
721 LIBNAME="lib${LIBNAME}.a"
722 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
723 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
724 else
725 VERSION="${MAJOR}.${MINOR}"
726 LIBNAME="lib${LIBNAME}.so"
727 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
728 if [ "x$LINK" = "x" ] ; then
729 if [ $CPLUSPLUS = 1 ] ; then
730 LINK=cxx
731 else
732 LINK=cc
733 fi
734 fi
735 rm -f ${LIBNAME}.${VERSION}
736 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
737 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
738 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
739 fi
740 ;;
741
742 'Darwin')
743 if [ $STATIC = 1 ] ; then
744 LIBNAME="lib${LIBNAME}.a"
745 echo "mklib: Making Darwin static library: " ${LIBNAME}
746 OPTS="-ruvs"
747 if [ "${ALTOPTS}" ] ; then
748 OPTS=${ALTOPTS}
749 fi
750
751 # expand .a into .o files
752 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
753
754 # make static lib
755 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
756
757 # remove temporary extracted .o files
758 rm -rf ${LIBNAME}.obj
759
760 FINAL_LIBS=${LIBNAME}
761 else
762 # On Darwin a .bundle is used for a library that you want to dlopen
763 if [ $DLOPEN = "1" ] ; then
764 LIBSUFFIX="bundle"
765 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
766 else
767 LIBSUFFIX="dylib"
768 if [ -z "$ID" ] ; then
769 ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
770 fi
771 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
772 fi
773
774 if [ ${EXPORTS} ] ; then
775 if [ -f ${EXPORTS}".darwin" ] ; then
776 EXPORTS=$EXPORTS".darwin"
777 fi
778 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
779 fi
780
781 LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
782 LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
783 LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
784
785 # examine first object to determine ABI
786 set ${OBJECTS}
787 ABIS=`lipo -info $1 | sed s/.*://`
788 for ABI in $ABIS; do
789 OPTS="${OPTS} -arch ${ABI}"
790 done
791
792 if [ "${ALTOPTS}" ] ; then
793 OPTS=${ALTOPTS}
794 fi
795
796 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
797 # to OPTS here?
798
799 # determine linker
800 if [ $CPLUSPLUS = 1 ] ; then
801 LINK="g++"
802 else
803 LINK="cc"
804 fi
805
806 echo "mklib: Making Darwin shared library: " ${LIBNAME}
807
808 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
809 ln -s ${LIBNAME} ${LINKNAME}
810 ln -s ${LIBNAME} ${LINKNAME2}
811 FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
812 fi
813 ;;
814
815 'LynxOS')
816 LIBNAME="lib${LIBNAME}.a"
817 echo "mklib: Making LynxOS static library: " ${LIBNAME}
818 FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
819 ;;
820
821 'BeOS')
822 if [ $STATIC = 1 ] ; then
823 LIBNAME="lib${LIBNAME}.a"
824 echo "mklib: Making BeOS static library: " ${LIBNAME}
825 FINAL_LIBS=`make_ar_static_lib -cru 0 ${LIBNAME} ${OBJECTS}`
826 else
827 LIBNAME="lib${LIBNAME}.so"
828 echo "mklib: Making BeOS shared library: " ${LIBNAME}
829 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
830 mimeset -f "${LIBNAME}"
831 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
832 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
833 fi
834 FINAL_LIBS=${LIBNAME}
835 ;;
836
837 'QNX')
838 LIBNAME="lib${LIBNAME}.a"
839 echo "mklib: Making QNX library: " ${LIBNAME}
840 wlib ${LIBNAME} ${OBJECTS}
841 FINAL_LIBS=${LIBNAME}
842 ;;
843
844 'MorphOS')
845 LIBNAME="lib${LIBNAME}.a"
846 echo "mklib: Making MorphOS library: " ${LIBNAME}
847 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
848 FINAL_LIBS="${LIBNAME}"
849 ;;
850
851 'icc' | 'icc-istatic')
852 # Intel C compiler
853 # This should get merged into the Linux code, above, since this isn't
854 # really a different architecture.
855 LIBNAME="lib${LIBNAME}" # prefix with "lib"
856
857 if [ $STATIC = 1 ] ; then
858 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
859 LINK="ar"
860 OPTS="-ruv"
861 if [ "${ALTOPTS}" ] ; then
862 OPTS=${ALTOPTS}
863 fi
864 # make lib
865 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
866 # finish up
867 FINAL_LIBS="${LIBNAME}.a"
868 else
869 if [ $ARCH = icc-istatic ] ; then
870 OPTS="-shared -i-static -cxxlib-icc"
871 else
872 OPTS="-shared"
873 fi
874 if [ "${ALTOPTS}" ] ; then
875 OPTS=${ALTOPTS}
876 fi
877 VERSION="${MAJOR}.${MINOR}.${PATCH}"
878 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
879
880 if [ $CPLUSPLUS = 1 ] ; then
881 LINK="icpc"
882 else
883 LINK="icc"
884 fi
885 # rm any old libs
886 rm -f ${LIBNAME}.so.${VERSION}
887 rm -f ${LIBNAME}.so.${MAJOR}
888 rm -f ${LIBNAME}.so
889 # make lib
890 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
891 # make usual symlinks
892 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
893 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
894 # finish up
895 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
896 fi
897 ;;
898
899 'aix-gcc')
900 # AIX with gcc
901 if [ $STATIC = 1 ] ; then
902 LIBNAME="lib${LIBNAME}.a"
903 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
904 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
905 else
906 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
907 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
908 # remove old lib
909 rm -f ${LIBNAME}
910 # make the lib
911 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
912 # NOTE: the application linking with this library must specify
913 # the -Wl,-brtl flags to gcc
914 FINAL_LIBS=${LIBNAME}
915 fi
916 ;;
917
918 'ultrix')
919 # XXX untested
920 if [ $STATIC = 0 ] ; then
921 echo "mklib: Warning shared libs not supported on Ultrix"
922 fi
923 LIBNAME="lib${LIBNAME}.a"
924 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
925 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
926 ;;
927
928 CYGWIN*)
929 # GCC-based environment
930 if [ $NOPREFIX = 1 ] ; then
931 # No "lib" or ".so" part
932 echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
933 OPTS="-shared -Wl,--enable-auto-image-base"
934 if [ "${ALTOPTS}" ] ; then
935 OPTS=${ALTOPTS}
936 fi
937 rm -f ${LIBNAME}
938 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
939 FINAL_LIBS=${LIBNAME}
940 else
941 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
942 LIBNAME="lib${LIBNAME}" # prefix with "lib"
943
944 if [ $STATIC = 1 ] ; then
945 LIBNAME=${LIBNAME}.a
946 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
947 OPTS="-ru"
948 if [ "${ALTOPTS}" ] ; then
949 OPTS=${ALTOPTS}
950 fi
951
952 # expand .a into .o files
953 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
954
955 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
956
957 # remove temporary extracted .o files
958 rm -rf ${LIBNAME}.obj
959 else
960 OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
961 if [ "${ALTOPTS}" ] ; then
962 OPTS=${ALTOPTS}
963 fi
964 echo "mklib: Making" $ARCH "shared library: " ${CYGNAME}-${MAJOR}.dll
965
966 if [ $CPLUSPLUS = 1 ] ; then
967 LINK="g++"
968 else
969 LINK="gcc"
970 fi
971
972 # rm any old libs
973 rm -f ${CYGNAME}-${MAJOR}.dll
974 rm -f ${LIBNAME}-${MAJOR}.dll.a
975 rm -f ${LIBNAME}.dll.a
976 rm -f ${LIBNAME}.a
977
978 # make lib
979 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
980 # make build fail if link failed
981 es=$?
982 if [ "$es" -ne "0" ]; then
983 exit $es
984 fi
985 # make usual symlinks
986 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
987 # finish up
988 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
989 # special case for installing in bin
990 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
991 fi
992 fi
993 ;;
994
995 'example')
996 # If you're adding support for a new architecture, you can
997 # start with this:
998 if [ $STATIC = 1 ] ; then
999 LIBNAME="lib${LIBNAME}.a"
1000 echo "mklib: Making static library for example arch: " ${LIBNAME}
1001 FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
1002 else
1003 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
1004 echo "mklib: Making shared library for example arch: " ${LIBNAME}
1005 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
1006 FINAL_LIBS="${LIBNAME}"
1007 fi
1008 ;;
1009
1010 *)
1011 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
1012 echo "mklib: Please add necessary commands to mklib script."
1013 ;;
1014 esac
1015
1016
1017 #
1018 # Put library files into installation directory if specified.
1019 #
1020 if [ ${INSTALLDIR} != "." ] ; then
1021 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
1022 test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
1023 mv ${FINAL_LIBS} ${INSTALLDIR}/
1024 fi