mklib: don't version symbols when using --exports
[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 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 ' -h, --help display this information and exit'
79 exit 1
80 ;;
81 '-o')
82 shift 1;
83 LIBNAME=$1
84 ;;
85 '-major')
86 shift 1;
87 MAJOR=$1
88 ;;
89 '-minor')
90 shift 1;
91 MINOR=$1
92 ;;
93 '-patch')
94 shift 1;
95 PATCH=$1
96 ;;
97 '-linker')
98 shift 1;
99 LINK=$1
100 ;;
101 '-ldflags')
102 shift 1;
103 LDFLAGS=$1
104 ;;
105 -l*)
106 DEPS="$DEPS $1"
107 ;;
108 -L*)
109 DEPS="$DEPS $1"
110 ;;
111 -R*)
112 DEPS="$DEPS $1"
113 ;;
114 -Wl*)
115 DEPS="$DEPS $1"
116 ;;
117 -pthread)
118 # this is a special case (see bugzilla 10876)
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++ compiler, 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 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
373 SPARCV9=`file $1 | grep SPARCV9`
374 if [ "${SPARCV9}" ] ; then
375 OPTS="${OPTS} -xarch=v9"
376 fi
377 fi
378 if [ "${ALTOPTS}" ] ; then
379 OPTS=${ALTOPTS}
380 fi
381 # for debug:
382 #echo "mklib: linker is" ${LINK} ${OPTS}
383 if [ $NOPREFIX = 1 ] ; then
384 rm -f ${LIBNAME}
385 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
386 else
387 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
388 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
389 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
390 fi
391 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
392 fi
393 ;;
394
395 'FreeBSD')
396 # we assume gcc
397
398 if [ "x$LINK" = "x" ] ; then
399 # -linker was not specified so set default link command now
400 if [ $CPLUSPLUS = 1 ] ; then
401 LINK=g++
402 else
403 LINK=gcc
404 fi
405 fi
406
407 if [ $NOPREFIX = 1 ] ; then
408 # No "lib" or ".so" part
409 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
410 OPTS="-shared"
411 if [ "${ALTOPTS}" ] ; then
412 OPTS=${ALTOPTS}
413 fi
414 rm -f ${LIBNAME}
415 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
416 FINAL_LIBS=${LIBNAME}
417 elif [ $STATIC = 1 ] ; then
418 STLIB="lib${LIBNAME}.a"
419 echo "mklib: Making FreeBSD static library: " ${STLIB}
420 rm -f ${STLIB}
421 ar cq ${STLIB} ${OBJECTS}
422 ranlib ${STLIB}
423 FINAL_LIBS=${STLIB}
424 else
425 SHLIB="lib${LIBNAME}.so.${MAJOR}"
426 OPTS="-shared -Wl,-soname,${SHLIB}"
427 if [ "${ALTOPTS}" ] ; then
428 OPTS=${ALTOPTS}
429 fi
430 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
431 rm -f ${SHLIB}
432 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
433 ln -sf ${SHLIB} "lib${LIBNAME}.so"
434 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
435 fi
436 ;;
437
438 'NetBSD')
439 if [ $STATIC = 1 ] ; then
440 LIBNAME="lib${LIBNAME}_pic.a"
441 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
442 rm -f ${LIBNAME}
443 ar cq ${LIBNAME} ${OBJECTS}
444 ranlib ${LIBNAME}
445 FINAL_LIBS=${LIBNAME}
446 else
447 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
448 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
449 rm -f ${LIBNAME}
450 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
451 FINAL_LIBS=${LIBNAME}
452 fi
453 ;;
454
455 'IRIX' | 'IRIX64')
456 if [ $STATIC = 1 ] ; then
457 LIBNAME="lib${LIBNAME}.a"
458 rm -f ${LIBNAME}
459 ar rc ${LIBNAME} ${OBJECTS}
460 FINAL_LIBS=${LIBNAME}
461 else
462 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
463
464 # examine first object to determine ABI
465 set ${OBJECTS}
466 ABI_O32=`file $1 | grep 'ELF 32-bit'`
467 ABI_N32=`file $1 | grep 'ELF N32'`
468 ABI_N64=`file $1 | grep 'ELF 64-bit'`
469 if [ "${ABI_O32}" ] ; then
470 OPTS="-32 -shared -all"
471 ABI="o32-bit"
472 elif [ "${ABI_N32}" ] ; then
473 OPTS="-n32 -shared -all"
474 ABI="n32-bit"
475 elif [ "${ABI_N64}" ] ; then
476 OPTS="-64 -shared -all"
477 ABI="64-bit"
478 else
479 echo "Error: Unexpected IRIX ABI!"
480 exit 1
481 fi
482
483 if [ "${ALTOPTS}" ] ; then
484 OPTS=${ALTOPTS}
485 fi
486
487 if [ $CPLUSPLUS = 1 ] ; then
488 LINK="CC"
489 else
490 LINK="ld"
491 fi
492
493 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
494 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
495 FINAL_LIBS=${LIBNAME}
496 fi
497 ;;
498
499 'linux-cygwin')
500 LIBNAME="lib${LIBNAME}.a"
501 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
502 rm -f ${LIBNAME}
503 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
504 FINAL_LIBS=${LIBNAME}
505 ;;
506
507 'HP-UX')
508 if [ $STATIC = 1 ] ; then
509 LIBNAME="lib${LIBNAME}.a"
510 echo "mklib: Making HP-UX static library: " ${LIBNAME}
511 rm -f ${LIBNAME}
512 ar -ruv ${LIBNAME} ${OBJECTS}
513 FINAL_LIBS=${LIBNAME}
514 else
515 # HP uses a .2 for their current GL/GLU libraries
516 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
517 MAJOR=2
518 fi
519 RUNLIB="lib${LIBNAME}.${MAJOR}"
520 DEVLIB="lib${LIBNAME}.sl"
521 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
522 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
523 ln -s ${RUNLIB} ${DEVLIB}
524 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
525 fi
526 ;;
527
528 'AIX' )
529 # examine first object to determine ABI
530 set ${OBJECTS}
531 ABI_64=`file $1 | grep '64-bit'`
532 if [ "${ABI_64}" ] ; then
533 X64="-X64"
534 Q64="-q64"
535 OFILE=shr_64.o
536 else
537 OFILE=shr.o #Want to be consistent with the IBM libGL.a
538 fi
539
540 if [ $STATIC = 1 ] ; then
541 LIBNAME="lib${LIBNAME}.a"
542 echo "mklib: Making AIX static library: " ${LIBNAME}
543 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
544 FINAL_LIBS=${LIBNAME}
545 else
546 EXPFILE="lib${LIBNAME}.exp"
547 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
548 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
549 rm -f ${EXPFILE} ${OFILE}
550 NM="/bin/nm -eC ${X64}"
551 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
552 ${NM} ${OBJECTS} | awk '{
553 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
554 && ( substr($1,1,1) != ".")) {
555 if (substr ($1, 1, 7) != "__sinit" &&
556 substr ($1, 1, 7) != "__sterm") {
557 if (substr ($1, 1, 5) == "__tf1")
558 print (substr ($1, 7))
559 else if (substr ($1, 1, 5) == "__tf9")
560 print (substr ($1, 15))
561 else
562 print $1
563 }
564 }
565 }' | sort -u >> ${EXPFILE}
566
567 if [ "${ALTOPTS}" ] ; then
568 OPTS=${ALTOPTS}
569 fi
570
571 # On AIX a shared library is linked differently when
572 # you want to dlopen the file
573 if [ $DLOPEN = "1" ] ; then
574 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
575 else
576 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
577 ar ${X64} -r ${LIBNAME} ${OFILE}
578 fi
579
580 FINAL_LIBS="${LIBNAME}"
581 fi
582 ;;
583
584 'OpenSTEP')
585 LIBNAME="lib${LIBNAME}.a"
586 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
587 libtool -static -o ${LIBNAME} - ${OBJECTS}
588 FINAL_LIBS=${LIBNAME}
589 ;;
590
591 'OSF1')
592 if [ $STATIC = 1 ] ; then
593 LIBNAME="lib${LIBNAME}.a"
594 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
595 rm -f ${LIBNAME}
596 ar -ruv ${LIBNAME} ${OBJECTS}
597 FINAL_LIBS=${LIBNAME}
598 else
599 VERSION="${MAJOR}.${MINOR}"
600 LIBNAME="lib${LIBNAME}.so"
601 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
602 if [ "x$LINK" = "x" ] ; then
603 if [ $CPLUSPLUS = 1 ] ; then
604 LINK=cxx
605 else
606 LINK=cc
607 fi
608 fi
609 rm -f ${LIBNAME}.${VERSION}
610 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
611 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
612 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
613 fi
614 ;;
615
616 'Darwin')
617 if [ $STATIC = 1 ] ; then
618 LIBNAME="lib${LIBNAME}.a"
619 echo "mklib: Making Darwin static library: " ${LIBNAME}
620 LINK="ar"
621 OPTS="-ruvs"
622 if [ "${ALTOPTS}" ] ; then
623 OPTS=${ALTOPTS}
624 fi
625 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
626 FINAL_LIBS=${LIBNAME}
627 else
628 # On Darwin a .bundle is used for a library that you want to dlopen
629 if [ $DLOPEN = "1" ] ; then
630 LIBSUFFIX="bundle"
631 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
632 else
633 LIBSUFFIX="dylib"
634 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
635 fi
636
637 if [ ${EXPORTS} ] ; then
638 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
639 fi
640
641 LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
642 LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
643 LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
644
645 # examine first object to determine ABI
646 set ${OBJECTS}
647 ABI_PPC=`file $1 | grep ' ppc'`
648 ABI_I386=`file $1 | grep ' i386'`
649 ABI_PPC64=`file $1 | grep ' ppc64'`
650 ABI_X86_64=`file $1 | grep ' x86_64'`
651 if [ "${ABI_PPC}" ] ; then
652 OPTS="${OPTS} -arch ppc"
653 fi
654 if [ "${ABI_I386}" ] ; then
655 OPTS="${OPTS} -arch i386"
656 fi
657 if [ "${ABI_PPC64}" ] ; then
658 OPTS="${OPTS} -arch ppc64"
659 fi
660 if [ "${ABI_X86_64}" ] ; then
661 OPTS="${OPTS} -arch x86_64"
662 fi
663
664 if [ "${ALTOPTS}" ] ; then
665 OPTS=${ALTOPTS}
666 fi
667
668 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
669 # to OPTS here?
670
671 # determine linker
672 if [ $CPLUSPLUS = 1 ] ; then
673 LINK="g++"
674 else
675 LINK="cc"
676 fi
677
678 echo "mklib: Making Darwin shared library: " ${LIBNAME}
679
680 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
681 ln -s ${LIBNAME} ${LINKNAME}
682 ln -s ${LIBNAME} ${LINKNAME2}
683 FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
684 fi
685 ;;
686
687 'LynxOS')
688 LIBNAME="lib${LIBNAME}.a"
689 echo "mklib: Making LynxOS static library: " ${LIBNAME}
690 rm -f ${LIBNAME}
691 ar ru ${LIBNAME} ${OBJECTS}
692 FINAL_LIBS=${LIBNAME}
693 ;;
694
695 'BeOS')
696 if [ $STATIC = 1 ] ; then
697 LIBNAME="lib${LIBNAME}.a"
698 echo "mklib: Making BeOS static library: " ${LIBNAME}
699 ar -cru "${LIBNAME}" ${OBJECTS}
700 else
701 LIBNAME="lib${LIBNAME}.so"
702 echo "mklib: Making BeOS shared library: " ${LIBNAME}
703 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
704 mimeset -f "${LIBNAME}"
705 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
706 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
707 fi
708 FINAL_LIBS=${LIBNAME}
709 ;;
710
711 'QNX')
712 LIBNAME="lib${LIBNAME}.a"
713 echo "mklib: Making QNX library: " ${LIBNAME}
714 wlib ${LIBNAME} ${OBJECTS}
715 FINAL_LIBS=${LIBNAME}
716 ;;
717
718 'MorphOS')
719 LIBNAME="lib${LIBNAME}.a"
720 echo "mklib: Making MorphOS library: " ${LIBNAME}
721 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
722 FINAL_LIBS="${LIBNAME}"
723 ;;
724
725 'icc' | 'icc-istatic')
726 # Intel C compiler
727 # This should get merged into the Linux code, above, since this isn't
728 # really a different architecture.
729 LIBNAME="lib${LIBNAME}" # prefix with "lib"
730
731 if [ $STATIC = 1 ] ; then
732 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
733 LINK="ar"
734 OPTS="-ruv"
735 if [ "${ALTOPTS}" ] ; then
736 OPTS=${ALTOPTS}
737 fi
738 # make lib
739 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
740 # finish up
741 FINAL_LIBS="${LIBNAME}.a"
742 else
743 if [ $ARCH = icc-istatic ] ; then
744 OPTS="-shared -i-static -cxxlib-icc"
745 else
746 OPTS="-shared"
747 fi
748 if [ "${ALTOPTS}" ] ; then
749 OPTS=${ALTOPTS}
750 fi
751 VERSION="${MAJOR}.${MINOR}.${PATCH}"
752 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
753
754 if [ $CPLUSPLUS = 1 ] ; then
755 LINK="icpc"
756 else
757 LINK="icc"
758 fi
759 # rm any old libs
760 rm -f ${LIBNAME}.so.${VERSION}
761 rm -f ${LIBNAME}.so.${MAJOR}
762 rm -f ${LIBNAME}.so
763 # make lib
764 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
765 # make usual symlinks
766 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
767 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
768 # finish up
769 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
770 fi
771 ;;
772
773 'aix-gcc')
774 # AIX with gcc
775 if [ $STATIC = 1 ] ; then
776 LIBNAME="lib${LIBNAME}.a"
777 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
778 rm -f ${LIBNAME}
779 ar ru ${LIBNAME} ${OBJECTS}
780 FINAL_LIBS=${LIBNAME}
781 else
782 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
783 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
784 # remove old lib
785 rm -f ${LIBNAME}
786 # make the lib
787 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
788 # NOTE: the application linking with this library must specify
789 # the -Wl,-brtl flags to gcc
790 FINAL_LIBS=${LIBNAME}
791 fi
792 ;;
793
794 'ultrix')
795 # XXX untested
796 if [ $STATIC = 0 ] ; then
797 echo "mklib: Warning shared libs not supported on Ultrix"
798 fi
799 LIBNAME="lib${LIBNAME}.a"
800 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
801 rm -f ${LIBNAME}
802 ar ru ${LIBNAME} ${OBJECTS}
803 FINAL_LIBS="${LIBNAME}"
804 ;;
805
806 CYGWIN*)
807 # GCC-based environment
808 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
809 LIBNAME="lib${LIBNAME}" # prefix with "lib"
810
811 if [ $STATIC = 1 ] ; then
812 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
813 LINK="ar"
814 OPTS="-ru"
815 if [ "${ALTOPTS}" ] ; then
816 OPTS=${ALTOPTS}
817 fi
818 # make lib
819 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
820 ranlib ${LIBNAME}.a
821 # finish up
822 FINAL_LIBS=${LIBNAME}.a
823 else
824 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
825 if [ "${ALTOPTS}" ] ; then
826 OPTS=${ALTOPTS}
827 fi
828 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
829
830 if [ $CPLUSPLUS = 1 ] ; then
831 LINK="g++"
832 else
833 LINK="gcc"
834 fi
835
836 # rm any old libs
837 rm -f ${LIBNAME}-${MAJOR}.dll
838 rm -f ${LIBNAME}.dll.a
839 rm -f ${LIBNAME}.a
840
841 # make lib
842 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
843 # make usual symlinks
844 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
845 # finish up
846 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
847 # special case for installing in bin
848 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
849 fi
850 ;;
851
852 'example')
853 # If you're adding support for a new architecture, you can
854 # start with this:
855 if [ $STATIC = 1 ] ; then
856 LIBNAME="lib${LIBNAME}.a"
857 echo "mklib: Making static library for example arch: " ${LIBNAME}
858 rm -f ${LIBNAME}
859 ar rv ${LIBNAME} ${OBJECTS}
860 FINAL_LIBS="${LIBNAME}"
861 else
862 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
863 echo "mklib: Making shared library for example arch: " ${LIBNAME}
864 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
865 FINAL_LIBS="${LIBNAME}"
866 fi
867 ;;
868
869 *)
870 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
871 echo "mklib: Please add necessary commands to mklib script."
872 ;;
873 esac
874
875
876 #
877 # Put library files into installation directory if specified.
878 #
879 if [ ${INSTALLDIR} != "." ] ; then
880 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
881 mv ${FINAL_LIBS} ${INSTALLDIR}/
882 fi