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