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