Merge branch 'mesa_7_7_branch'
[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 # 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.
30 expand_archives() {
31 DIR=$1
32 shift
33 FILES=$@
34 NEWFILES=""
35 ORIG_DIR=`pwd`
36 mkdir -p "$DIR"
37 cd "$DIR"
38 for FILE in $FILES ; do
39 case $FILE in
40 *.a)
41 # extract the .o files from this .a archive
42 case $FILE in
43 /*) ;;
44 *) FILE="$ORIG_DIR/$FILE" ;;
45 esac
46 MEMBERS=`ar t $FILE`
47 ar x $FILE
48 for MEMBER in $MEMBERS ; do
49 NEWFILES="$NEWFILES $DIR/$MEMBER"
50 done
51 ;;
52 *)
53 # other file type, just add to list
54 NEWFILES="$NEWFILES $FILE"
55 ;;
56 esac
57 done
58 cd "$ORIG_DIR"
59 echo $NEWFILES
60 }
61
62
63 # Given a list of files, look for .a archives and return a list of all objects
64 # in the .a archives.
65 contents_of_archives() {
66 FILES=$@
67 NEWFILES=""
68 for FILE in $FILES ; do
69 case $FILE in
70 *.a)
71 # get list of members in this .a archive
72 MEMBERS=`ar t $FILE`
73 NEWFILES="$NEWFILES $MEMBERS"
74 ;;
75 *)
76 # skip other file types
77 ;;
78 esac
79 done
80 echo $NEWFILES
81 }
82
83
84 # Make static library with 'ar'
85 # params:
86 # options to ar
87 # 1 or 0 to indicate if ranlib should be run
88 # libname to make
89 # list of object files
90 # Return name of library we made
91 # Example: "make_ar_static_lib -ru 1 libfoo.a foo.o bar.o"
92 make_ar_static_lib() {
93 OPTS=$1
94 shift;
95 RANLIB=$1
96 shift;
97 LIBNAME=$1
98 shift;
99 OBJECTS=$@
100
101 # remove existing lib, if present
102 rm -f ${LIBNAME}
103
104 # make static lib
105 ar ${OPTS} ${LIBNAME} ${OBJECTS}
106
107 # run ranlib
108 if [ ${RANLIB} = 1 ] ; then
109 ranlib ${LIBNAME}
110 fi
111
112 echo ${LIBNAME}
113 }
114
115
116 # Print usage info.
117 usage() {
118 echo 'Usage: mklib [options] objects'
119 echo 'Create a shared library from object files.'
120 echo ' -o LIBRARY specifies the name of the resulting library, without'
121 echo ' the leading "lib" or any suffix.'
122 echo ' (eg: "-o GL" might result in "libGL.so" being made)'
123 echo ' -major N specifies major version number (default is 1)'
124 echo ' -minor N specifies minor version number (default is 0)'
125 echo ' -patch N specifies patch version number (default is 0)'
126 echo ' -lLIBRARY specifies a dependency on LIBRARY'
127 echo ' -LDIR search in DIR for library dependencies at build time'
128 echo ' -RDIR search in DIR for library dependencies at run time'
129 echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
130 echo ' Not observed on all systems at this time.'
131 echo ' -ldflags OPT specify any additional linker flags in OPT'
132 echo ' -cplusplus link with C++ runtime'
133 echo ' -static make a static library (default is dynamic/shared)'
134 echo ' -dlopen make a shared library suitable for dynamic loading'
135 echo ' -install DIR put resulting library file(s) in DIR'
136 echo ' -arch ARCH override using `uname` to determine host system'
137 echo ' -archopt OPT specify an extra achitecture-specific option OPT'
138 echo ' -altopts OPTS alternate options to override all others'
139 echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
140 echo ' -exports FILE only export the symbols listed in FILE'
141 echo ' -id NAME Sets the id of the dylib (Darwin)'
142 echo ' -h, --help display this information and exit'
143 }
144
145
146 #
147 # Option defaults
148 #
149 LIBNAME=""
150 MAJOR=1
151 MINOR=0
152 PATCH=""
153 DEPS=""
154 LINK=""
155 LDFLAGS=""
156 CPLUSPLUS=0
157 STATIC=0
158 DLOPEN=0
159 INSTALLDIR="."
160 ARCH="auto"
161 ARCHOPT=""
162 NOPREFIX=0
163 EXPORTS=""
164 ID=""
165
166 #
167 # Parse arguments
168 #
169 while true
170 do
171 case $1 in
172 '-h' | '--help')
173 usage
174 exit 1
175 ;;
176 '-o')
177 shift 1;
178 LIBNAME=$1
179 ;;
180 '-major')
181 shift 1;
182 MAJOR=$1
183 ;;
184 '-minor')
185 shift 1;
186 MINOR=$1
187 ;;
188 '-patch')
189 shift 1;
190 PATCH=$1
191 ;;
192 '-linker')
193 shift 1;
194 LINK=$1
195 ;;
196 '-ldflags')
197 shift 1;
198 LDFLAGS=$1
199 ;;
200 -l*)
201 DEPS="$DEPS $1"
202 ;;
203 -L*)
204 DEPS="$DEPS $1"
205 ;;
206 -R*)
207 DEPS="$DEPS $1"
208 ;;
209 -Wl*)
210 DEPS="$DEPS $1"
211 ;;
212 -pthread)
213 # this is a special case (see bugzilla 10876)
214 DEPS="$DEPS $1"
215 ;;
216 '-pthread')
217 DEPS="$DEPS -pthread"
218 ;;
219 '-cplusplus')
220 CPLUSPLUS=1
221 ;;
222 '-static')
223 STATIC=1
224 ;;
225 '-dlopen')
226 DLOPEN=1
227 ;;
228 '-install')
229 shift 1;
230 INSTALLDIR=$1
231 ;;
232 '-arch')
233 shift 1;
234 ARCH=$1
235 ;;
236 '-archopt')
237 shift 1;
238 ARCHOPT=$1
239 ;;
240 '-altopts')
241 shift 1;
242 ALTOPTS=$1
243 ;;
244 '-noprefix')
245 NOPREFIX=1
246 ;;
247 '-exports')
248 shift 1;
249 EXPORTS=$1
250 ;;
251 '-id')
252 shift 1;
253 ID=$1
254 ;;
255 -*)
256 echo "mklib: Unknown option: " $1 ;
257 exit 1
258 ;;
259 *)
260 # This should be the first object file, stop parsing
261 break
262 esac
263 shift 1
264 done
265 OBJECTS=$@
266
267
268 if [ ${ARCH} = "auto" ] ; then
269 ARCH=`uname`
270 fi
271
272
273 if [ $STATIC = 1 ]; then
274 # filter out linker options inside object list
275 NEWOBJECTS=""
276 for OBJ in $OBJECTS ; do
277 case $OBJ in
278 -Wl,*)
279 echo "mklib: warning: ignoring $OBJ for static library"
280 ;;
281 *)
282 NEWOBJECTS="$NEWOBJECTS $OBJ"
283 ;;
284 esac
285 done
286 OBJECTS=$NEWOBJECTS
287 fi
288
289
290 #
291 # Error checking
292 #
293 if [ "x${LIBNAME}" = "x" ] ; then
294 echo "mklib: Error: no library name specified (-h for help)"
295 exit 1
296 fi
297 if [ "x${OBJECTS}" = "x" ] ; then
298 echo "mklib: Error: no object files specified (-h for help)"
299 exit 1
300 fi
301
302
303 #
304 # Debugging info
305 #
306 if [ ] ; then
307 echo "-----------------"
308 echo ARCH is $ARCH
309 echo LIBNAME is $LIBNAME
310 echo MAJOR is $MAJOR
311 echo MINOR is $MINOR
312 echo PATCH is $PATCH
313 echo DEPS are $DEPS
314 echo "EXPORTS in" $EXPORTS
315 echo ID is $ID
316 echo "-----------------"
317 fi
318
319
320 #
321 # OK, make the library now
322 #
323 case $ARCH in
324
325 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*)
326 # we assume gcc
327
328 if [ "x$LINK" = "x" ] ; then
329 # -linker was not specified so set default link command now
330 if [ $CPLUSPLUS = 1 ] ; then
331 LINK=g++
332 else
333 LINK=gcc
334 fi
335 fi
336
337 if [ $NOPREFIX = 1 ] ; then
338 # No "lib" or ".so" part
339 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
340 case $ARCH in 'Linux' | 'GNU' | GNU/*)
341 OPTS="-Xlinker -Bsymbolic -shared"
342 ;;
343 *)
344 OPTS="-shared"
345 ;;
346 esac
347
348 # Check if objects are 32-bit and we're running in 64-bit
349 # environment. If so, pass -m32 flag to linker.
350 set ${OBJECTS}
351 ABI32=`file $1 | grep 32-bit`
352 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
353 OPTS="-m32 ${OPTS}"
354 fi
355
356 if [ "${ALTOPTS}" ] ; then
357 OPTS=${ALTOPTS}
358 fi
359
360 rm -f ${LIBNAME}
361 # make lib
362 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
363 # finish up
364 FINAL_LIBS="${LIBNAME}"
365 elif [ $STATIC = 1 ] ; then
366 # make a static .a library
367 LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
368 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
369 OPTS="-ru"
370 if [ "${ALTOPTS}" ] ; then
371 OPTS=${ALTOPTS}
372 fi
373
374 # expand .a into .o files
375 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
376
377 # make static lib
378 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
379
380 # remove temporary extracted .o files
381 rm -rf ${LIBNAME}.obj
382 else
383 # make dynamic library
384 LIBNAME="lib${LIBNAME}" # prefix with "lib"
385 case $ARCH in 'Linux' | 'GNU' | GNU/*)
386 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
387 ;;
388 *)
389 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
390 ;;
391 esac
392 if [ $EXPORTS ] ; then
393 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
394 # Make the 'exptmp' file for --version-script option
395 echo "{" > exptmp
396 echo "global:" >> exptmp
397 sed 's/$/;/' ${EXPORTS} >> exptmp
398 echo "local:" >> exptmp
399 echo "*;" >> exptmp
400 echo "};" >> exptmp
401 OPTS="${OPTS} -Xlinker --version-script=exptmp"
402 # exptmp is removed below
403 fi
404
405 # Check if objects are 32-bit and we're running in 64-bit
406 # environment. If so, pass -m32 flag to linker.
407 set ${OBJECTS}
408 ABI32=`file $1 | grep 32-bit`
409 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
410 OPTS="-m32 ${OPTS}"
411 fi
412 if [ "${ALTOPTS}" ] ; then
413 OPTS=${ALTOPTS}
414 fi
415
416 if [ x${PATCH} = "x" ] ; then
417 VERSION="${MAJOR}.${MINOR}"
418 else
419 VERSION="${MAJOR}.${MINOR}.${PATCH}"
420 fi
421
422 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
423
424 # rm any old libs
425 rm -f ${LIBNAME}.so.${VERSION}
426 rm -f ${LIBNAME}.so.${MAJOR}
427 rm -f ${LIBNAME}.so
428
429 # make lib
430 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
431 # make usual symlinks
432 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
433 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
434 # finish up
435 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
436 # rm -f exptmp
437 fi
438 ;;
439
440 'SunOS')
441 if [ $STATIC = 1 ] ; then
442 LIBNAME="lib${LIBNAME}.a"
443 echo "mklib: Making SunOS static library: " ${LIBNAME}
444 FINAL_LIBS=`make_ar_static_lib -ruc 0 ${LIBNAME} ${OBJECTS}`
445 else
446 if [ $NOPREFIX = 0 ] ; then
447 LIBNAME="lib${LIBNAME}.so"
448 fi
449 echo "mklib: Making SunOS shared library: " ${LIBNAME}
450
451 if [ "x$LINK" = "x" ] ; then
452 # -linker was not specified, choose default linker now
453 if [ $CPLUSPLUS = 1 ] ; then
454 # determine linker and options for C++ code
455 if [ `which c++` ] ; then
456 # use Sun c++
457 LINK="c++"
458 elif [ `type g++` ] ; then
459 # use g++
460 LINK="g++"
461 else
462 echo "mklib: warning: can't find C++ compiler, trying CC."
463 LINK="CC"
464 fi
465 else
466 # use native Sun linker for C code
467 LINK="ld"
468 fi
469 fi
470
471 # linker options
472 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
473 # SunOS tools, -G to make shared libs
474 OPTS="-G"
475 else
476 # gcc linker
477 # Check if objects are 32-bit and we're running in 64-bit
478 # environment. If so, pass -m32 flag to linker.
479 set ${OBJECTS}
480 ABI32=`file $1 | grep 32-bit`
481 if [ "${ABI32}" ] ; then
482 OPTS="-m32 -shared -Wl,-Bdynamic"
483 else
484 OPTS="-m64 -shared -Wl,-Bdynamic"
485 fi
486 fi
487
488 # If using Sun C++ compiler, need to tell it not to add runpaths
489 # that are specific to the build machine
490 if [ ${LINK} = "CC" ] ; then
491 OPTS="${OPTS} -norunpath"
492 fi
493
494 # Solaris linker requires explicitly listing the Standard C & C++
495 # libraries in the link path when building shared objects
496 if [ ${LINK} = "CC" ] ; then
497 DEPS="${DEPS} -lCrun"
498 fi
499 DEPS="${DEPS} -lc"
500
501 if [ $EXPORTS ] ; then
502 # Make the 'mapfile.scope' linker mapfile
503 echo "{" > mapfile.scope
504 echo "global:" >> mapfile.scope
505 sed 's/$/;/' ${EXPORTS} >> mapfile.scope
506 echo "local:" >> mapfile.scope
507 echo " *;" >> mapfile.scope
508 echo "};" >> mapfile.scope
509 OPTS="${OPTS} -Wl,-Mmapfile.scope"
510 fi
511
512 # Check if objects are SPARC v9
513 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
514 set ${OBJECTS}
515 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
516 SPARCV9=`file $1 | grep SPARCV9`
517 if [ "${SPARCV9}" ] ; then
518 OPTS="${OPTS} -xarch=v9"
519 fi
520 fi
521 if [ "${ALTOPTS}" ] ; then
522 OPTS=${ALTOPTS}
523 fi
524
525 # for debug:
526 #echo "mklib: linker is" ${LINK} ${OPTS}
527 if [ $NOPREFIX = 1 ] ; then
528 rm -f ${LIBNAME}
529 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
530 FINAL_LIBS="${LIBNAME}"
531 else
532 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
533 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
534 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
535 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
536 fi
537 fi
538 ;;
539
540 'FreeBSD')
541 # we assume gcc
542
543 if [ "x$LINK" = "x" ] ; then
544 # -linker was not specified so set default link command now
545 if [ $CPLUSPLUS = 1 ] ; then
546 LINK=g++
547 else
548 LINK=gcc
549 fi
550 fi
551
552 if [ $NOPREFIX = 1 ] ; then
553 # No "lib" or ".so" part
554 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
555 OPTS="-shared"
556 if [ "${ALTOPTS}" ] ; then
557 OPTS=${ALTOPTS}
558 fi
559 rm -f ${LIBNAME}
560 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
561 FINAL_LIBS=${LIBNAME}
562 elif [ $STATIC = 1 ] ; then
563 # make a static .a library
564 STLIB="lib${LIBNAME}.a"
565 echo "mklib: Making FreeBSD static library: " ${STLIB}
566
567 # expand .a into .o files
568 NEW_OBJECTS=`expand_archives ${STLIB}.obj $OBJECTS`
569
570 FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
571
572 # remove temporary extracted .o files
573 rm -rf ${STLIB}.obj
574 else
575 # make dynamic library
576 SHLIB="lib${LIBNAME}.so.${MAJOR}"
577 OPTS="-shared -Wl,-soname,${SHLIB}"
578 if [ "${ALTOPTS}" ] ; then
579 OPTS=${ALTOPTS}
580 fi
581 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
582 rm -f ${SHLIB}
583 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
584 ln -sf ${SHLIB} "lib${LIBNAME}.so"
585 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
586 fi
587 ;;
588
589 'NetBSD')
590 if [ $STATIC = 1 ] ; then
591 LIBNAME="lib${LIBNAME}_pic.a"
592 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
593 FINAL_LIBS=`make_ar_static_lib cq 1 ${LIBNAME} ${OBJECTS}`
594 else
595 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
596 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
597 rm -f ${LIBNAME}
598 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
599 FINAL_LIBS=${LIBNAME}
600 fi
601 ;;
602
603 'IRIX' | 'IRIX64')
604 if [ $STATIC = 1 ] ; then
605 LIBNAME="lib${LIBNAME}.a"
606 FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
607 else
608 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
609
610 # examine first object to determine ABI
611 set ${OBJECTS}
612 ABI_O32=`file $1 | grep 'ELF 32-bit'`
613 ABI_N32=`file $1 | grep 'ELF N32'`
614 ABI_N64=`file $1 | grep 'ELF 64-bit'`
615 if [ "${ABI_O32}" ] ; then
616 OPTS="-32 -shared -all"
617 ABI="o32-bit"
618 elif [ "${ABI_N32}" ] ; then
619 OPTS="-n32 -shared -all"
620 ABI="n32-bit"
621 elif [ "${ABI_N64}" ] ; then
622 OPTS="-64 -shared -all"
623 ABI="64-bit"
624 else
625 echo "Error: Unexpected IRIX ABI!"
626 exit 1
627 fi
628
629 if [ "${ALTOPTS}" ] ; then
630 OPTS=${ALTOPTS}
631 fi
632
633 if [ $CPLUSPLUS = 1 ] ; then
634 LINK="CC"
635 else
636 LINK="ld"
637 fi
638
639 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
640 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
641 FINAL_LIBS=${LIBNAME}
642 fi
643 ;;
644
645 'linux-cygwin')
646 LIBNAME="lib${LIBNAME}.a"
647 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
648 rm -f ${LIBNAME}
649 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
650 FINAL_LIBS=${LIBNAME}
651 ;;
652
653 'HP-UX')
654 if [ $STATIC = 1 ] ; then
655 LIBNAME="lib${LIBNAME}.a"
656 echo "mklib: Making HP-UX static library: " ${LIBNAME}
657 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
658 else
659 # HP uses a .2 for their current GL/GLU libraries
660 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
661 MAJOR=2
662 fi
663 RUNLIB="lib${LIBNAME}.${MAJOR}"
664 DEVLIB="lib${LIBNAME}.sl"
665 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
666 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
667 ln -s ${RUNLIB} ${DEVLIB}
668 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
669 fi
670 ;;
671
672 'AIX' )
673 # examine first object to determine ABI
674 set ${OBJECTS}
675 ABI_64=`file $1 | grep '64-bit'`
676 if [ "${ABI_64}" ] ; then
677 X64="-X64"
678 Q64="-q64"
679 OFILE=shr_64.o
680 else
681 OFILE=shr.o #Want to be consistent with the IBM libGL.a
682 fi
683
684 if [ $STATIC = 1 ] ; then
685 LIBNAME="lib${LIBNAME}.a"
686 echo "mklib: Making AIX static library: " ${LIBNAME}
687 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
688 else
689 EXPFILE="lib${LIBNAME}.exp"
690 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
691 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
692 rm -f ${EXPFILE} ${OFILE}
693 NM="/bin/nm -eC ${X64}"
694 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
695 ${NM} ${OBJECTS} | awk '{
696 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
697 && ( substr($1,1,1) != ".")) {
698 if (substr ($1, 1, 7) != "__sinit" &&
699 substr ($1, 1, 7) != "__sterm") {
700 if (substr ($1, 1, 5) == "__tf1")
701 print (substr ($1, 7))
702 else if (substr ($1, 1, 5) == "__tf9")
703 print (substr ($1, 15))
704 else
705 print $1
706 }
707 }
708 }' | sort -u >> ${EXPFILE}
709
710 if [ "${ALTOPTS}" ] ; then
711 OPTS=${ALTOPTS}
712 fi
713
714 # On AIX a shared library is linked differently when
715 # you want to dlopen the file
716 if [ $DLOPEN = "1" ] ; then
717 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
718 else
719 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
720 ar ${X64} -r ${LIBNAME} ${OFILE}
721 fi
722
723 FINAL_LIBS="${LIBNAME}"
724 fi
725 ;;
726
727 'OpenSTEP')
728 LIBNAME="lib${LIBNAME}.a"
729 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
730 libtool -static -o ${LIBNAME} - ${OBJECTS}
731 FINAL_LIBS=${LIBNAME}
732 ;;
733
734 'OSF1')
735 if [ $STATIC = 1 ] ; then
736 LIBNAME="lib${LIBNAME}.a"
737 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
738 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
739 else
740 VERSION="${MAJOR}.${MINOR}"
741 LIBNAME="lib${LIBNAME}.so"
742 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
743 if [ "x$LINK" = "x" ] ; then
744 if [ $CPLUSPLUS = 1 ] ; then
745 LINK=cxx
746 else
747 LINK=cc
748 fi
749 fi
750 rm -f ${LIBNAME}.${VERSION}
751 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
752 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
753 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
754 fi
755 ;;
756
757 'Darwin')
758 if [ $STATIC = 1 ] ; then
759 LIBNAME="lib${LIBNAME}.a"
760 echo "mklib: Making Darwin static library: " ${LIBNAME}
761 LINK="ar"
762 OPTS="-ruvs"
763 if [ "${ALTOPTS}" ] ; then
764 OPTS=${ALTOPTS}
765 fi
766 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
767 FINAL_LIBS=${LIBNAME}
768 else
769 # On Darwin a .bundle is used for a library that you want to dlopen
770 if [ $DLOPEN = "1" ] ; then
771 LIBSUFFIX="bundle"
772 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
773 else
774 LIBSUFFIX="dylib"
775 if [ -z "$ID" ] ; then
776 ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
777 fi
778 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
779 fi
780
781 if [ ${EXPORTS} ] ; then
782 if [ -f ${EXPORTS}".darwin" ] ; then
783 EXPORTS=$EXPORTS".darwin"
784 fi
785 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
786 fi
787
788 LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
789 LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
790 LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
791
792 # examine first object to determine ABI
793 set ${OBJECTS}
794 ABIS=`lipo -info $1 | sed s/.*://`
795 for ABI in $ABIS; do
796 OPTS="${OPTS} -arch ${ABI}"
797 done
798
799 if [ "${ALTOPTS}" ] ; then
800 OPTS=${ALTOPTS}
801 fi
802
803 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
804 # to OPTS here?
805
806 # determine linker
807 if [ $CPLUSPLUS = 1 ] ; then
808 LINK="g++"
809 else
810 LINK="cc"
811 fi
812
813 echo "mklib: Making Darwin shared library: " ${LIBNAME}
814
815 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
816 ln -s ${LIBNAME} ${LINKNAME}
817 ln -s ${LIBNAME} ${LINKNAME2}
818 FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
819 fi
820 ;;
821
822 'LynxOS')
823 LIBNAME="lib${LIBNAME}.a"
824 echo "mklib: Making LynxOS static library: " ${LIBNAME}
825 FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
826 ;;
827
828 'BeOS')
829 if [ $STATIC = 1 ] ; then
830 LIBNAME="lib${LIBNAME}.a"
831 echo "mklib: Making BeOS static library: " ${LIBNAME}
832 FINAL_LIBS=`make_ar_static_lib -cru 0 ${LIBNAME} ${OBJECTS}`
833 else
834 LIBNAME="lib${LIBNAME}.so"
835 echo "mklib: Making BeOS shared library: " ${LIBNAME}
836 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
837 mimeset -f "${LIBNAME}"
838 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
839 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
840 fi
841 FINAL_LIBS=${LIBNAME}
842 ;;
843
844 'QNX')
845 LIBNAME="lib${LIBNAME}.a"
846 echo "mklib: Making QNX library: " ${LIBNAME}
847 wlib ${LIBNAME} ${OBJECTS}
848 FINAL_LIBS=${LIBNAME}
849 ;;
850
851 'MorphOS')
852 LIBNAME="lib${LIBNAME}.a"
853 echo "mklib: Making MorphOS library: " ${LIBNAME}
854 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
855 FINAL_LIBS="${LIBNAME}"
856 ;;
857
858 'icc' | 'icc-istatic')
859 # Intel C compiler
860 # This should get merged into the Linux code, above, since this isn't
861 # really a different architecture.
862 LIBNAME="lib${LIBNAME}" # prefix with "lib"
863
864 if [ $STATIC = 1 ] ; then
865 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
866 LINK="ar"
867 OPTS="-ruv"
868 if [ "${ALTOPTS}" ] ; then
869 OPTS=${ALTOPTS}
870 fi
871 # make lib
872 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
873 # finish up
874 FINAL_LIBS="${LIBNAME}.a"
875 else
876 if [ $ARCH = icc-istatic ] ; then
877 OPTS="-shared -i-static -cxxlib-icc"
878 else
879 OPTS="-shared"
880 fi
881 if [ "${ALTOPTS}" ] ; then
882 OPTS=${ALTOPTS}
883 fi
884 VERSION="${MAJOR}.${MINOR}.${PATCH}"
885 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
886
887 if [ $CPLUSPLUS = 1 ] ; then
888 LINK="icpc"
889 else
890 LINK="icc"
891 fi
892 # rm any old libs
893 rm -f ${LIBNAME}.so.${VERSION}
894 rm -f ${LIBNAME}.so.${MAJOR}
895 rm -f ${LIBNAME}.so
896 # make lib
897 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
898 # make usual symlinks
899 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
900 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
901 # finish up
902 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
903 fi
904 ;;
905
906 'aix-gcc')
907 # AIX with gcc
908 if [ $STATIC = 1 ] ; then
909 LIBNAME="lib${LIBNAME}.a"
910 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
911 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
912 else
913 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
914 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
915 # remove old lib
916 rm -f ${LIBNAME}
917 # make the lib
918 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
919 # NOTE: the application linking with this library must specify
920 # the -Wl,-brtl flags to gcc
921 FINAL_LIBS=${LIBNAME}
922 fi
923 ;;
924
925 'ultrix')
926 # XXX untested
927 if [ $STATIC = 0 ] ; then
928 echo "mklib: Warning shared libs not supported on Ultrix"
929 fi
930 LIBNAME="lib${LIBNAME}.a"
931 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
932 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
933 ;;
934
935 CYGWIN*)
936 # GCC-based environment
937 if [ $NOPREFIX = 1 ] ; then
938 # No "lib" or ".so" part
939 echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
940 OPTS="-shared -Wl,--enable-auto-image-base"
941 if [ "${ALTOPTS}" ] ; then
942 OPTS=${ALTOPTS}
943 fi
944 rm -f ${LIBNAME}
945 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
946 FINAL_LIBS=${LIBNAME}
947 else
948 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
949 LIBNAME="lib${LIBNAME}" # prefix with "lib"
950
951 if [ $STATIC = 1 ] ; then
952 LIBNAME=${LIBNAME}.a
953 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
954 OPTS="-ru"
955 if [ "${ALTOPTS}" ] ; then
956 OPTS=${ALTOPTS}
957 fi
958 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${OBJECTS}`
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 usual symlinks
981 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
982 # finish up
983 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
984 # special case for installing in bin
985 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
986 fi
987 fi
988 ;;
989
990 'example')
991 # If you're adding support for a new architecture, you can
992 # start with this:
993 if [ $STATIC = 1 ] ; then
994 LIBNAME="lib${LIBNAME}.a"
995 echo "mklib: Making static library for example arch: " ${LIBNAME}
996 FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
997 else
998 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
999 echo "mklib: Making shared library for example arch: " ${LIBNAME}
1000 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
1001 FINAL_LIBS="${LIBNAME}"
1002 fi
1003 ;;
1004
1005 *)
1006 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
1007 echo "mklib: Please add necessary commands to mklib script."
1008 ;;
1009 esac
1010
1011
1012 #
1013 # Put library files into installation directory if specified.
1014 #
1015 if [ ${INSTALLDIR} != "." ] ; then
1016 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
1017 test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
1018 mv ${FINAL_LIBS} ${INSTALLDIR}/
1019 fi