Debian Codegraph @

cextern/xpa/mklib

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