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