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