Merge branch 'radeon-rewrite' of git+ssh://agd5f@git.freedesktop.org/git/mesa/mesa...
[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
264 # expand any .a objects into constituent .o files.
265 NEWOBJECTS=""
266 DELETIA=""
267 for OBJ in ${OBJECTS} ; do
268 if [ `expr match $OBJ '.*\.a'` -gt 0 ] ; then
269 # extract the .o files from this .a archive
270 FILES=`ar t $OBJ`
271 ar x $OBJ
272 NEWOBJECTS="$NEWOBJECTS $FILES"
273 # keep track of temporary .o files and delete them below
274 DELETIA="$DELETIA $FILES"
275 else
276 # ordinary .o file
277 NEWOBJECTS="$NEWOBJECTS $OBJ"
278 fi
279 done
280
281 # make lib
282 ${LINK} ${OPTS} ${LIBNAME} ${NEWOBJECTS}
283 ranlib ${LIBNAME}
284
285 # remove temporary extracted .o files
286 rm -f ${DELETIA}
287
288 # finish up
289 FINAL_LIBS=${LIBNAME}
290 else
291 LIBNAME="lib${LIBNAME}" # prefix with "lib"
292 case $ARCH in 'Linux' | 'GNU' | GNU/*)
293 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
294 ;;
295 *)
296 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
297 ;;
298 esac
299 if [ $EXPORTS ] ; then
300 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
301 # Make the 'exptmp' file for --version-script option
302 echo "{" > exptmp
303 echo "global:" >> exptmp
304 sed 's/$/;/' ${EXPORTS} >> exptmp
305 echo "local:" >> exptmp
306 echo "*;" >> exptmp
307 echo "};" >> exptmp
308 OPTS="${OPTS} -Xlinker --version-script=exptmp"
309 # exptmp is removed below
310 fi
311
312 # Check if objects are 32-bit and we're running in 64-bit
313 # environment. If so, pass -m32 flag to linker.
314 set ${OBJECTS}
315 ABI32=`file $1 | grep 32-bit`
316 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
317 OPTS="-m32 ${OPTS}"
318 fi
319 if [ "${ALTOPTS}" ] ; then
320 OPTS=${ALTOPTS}
321 fi
322
323 if [ x${PATCH} = "x" ] ; then
324 VERSION="${MAJOR}.${MINOR}"
325 else
326 VERSION="${MAJOR}.${MINOR}.${PATCH}"
327 fi
328
329 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
330
331 # rm any old libs
332 rm -f ${LIBNAME}.so.${VERSION}
333 rm -f ${LIBNAME}.so.${MAJOR}
334 rm -f ${LIBNAME}.so
335
336 # make lib
337 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
338 # make usual symlinks
339 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
340 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
341 # finish up
342 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
343 # rm -f exptmp
344 fi
345 ;;
346
347 'SunOS')
348 if [ $STATIC = 1 ] ; then
349 LIBNAME="lib${LIBNAME}.a"
350 echo "mklib: Making SunOS static library: " ${LIBNAME}
351 rm -f ${LIBNAME}
352 ar -ruv ${LIBNAME} ${OBJECTS}
353 FINAL_LIBS=${LIBNAME}
354 else
355 if [ $NOPREFIX = 0 ] ; then
356 LIBNAME="lib${LIBNAME}.so"
357 fi
358 echo "mklib: Making SunOS shared library: " ${LIBNAME}
359
360 if [ "x$LINK" = "x" ] ; then
361 # -linker was not specified, choose default linker now
362 if [ $CPLUSPLUS = 1 ] ; then
363 # determine linker and options for C++ code
364 if [ `which c++` ] ; then
365 # use Sun c++
366 LINK="c++"
367 elif [ `type g++` ] ; then
368 # use g++
369 LINK="g++"
370 else
371 echo "mklib: warning: can't find C++ compiler, trying CC."
372 LINK="CC"
373 fi
374 else
375 # use native Sun linker for C code
376 LINK="ld"
377 fi
378 fi
379
380 # linker options
381 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
382 # SunOS tools, -G to make shared libs
383 OPTS="-G"
384 else
385 # gcc linker
386 # Check if objects are 32-bit and we're running in 64-bit
387 # environment. If so, pass -m32 flag to linker.
388 set ${OBJECTS}
389 ABI32=`file $1 | grep 32-bit`
390 if [ "${ABI32}" ] ; then
391 OPTS="-m32 -shared -Wl,-Bdynamic"
392 else
393 OPTS="-m64 -shared -Wl,-Bdynamic"
394 fi
395 fi
396
397 # If using Sun C++ compiler, need to tell it not to add runpaths
398 # that are specific to the build machine
399 if [ ${LINK} = "CC" ] ; then
400 OPTS="${OPTS} -norunpath"
401 fi
402
403 # Solaris linker requires explicitly listing the Standard C & C++
404 # libraries in the link path when building shared objects
405 if [ ${LINK} = "CC" ] ; then
406 DEPS="${DEPS} -lCrun"
407 fi
408 DEPS="${DEPS} -lc"
409
410 if [ $EXPORTS ] ; then
411 # Make the 'mapfile.scope' linker mapfile
412 echo "{" > mapfile.scope
413 echo "global:" >> mapfile.scope
414 sed 's/$/;/' ${EXPORTS} >> mapfile.scope
415 echo "local:" >> mapfile.scope
416 echo " *;" >> mapfile.scope
417 echo "};" >> mapfile.scope
418 OPTS="${OPTS} -Wl,-Mmapfile.scope"
419 fi
420
421 # Check if objects are SPARC v9
422 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
423 set ${OBJECTS}
424 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
425 SPARCV9=`file $1 | grep SPARCV9`
426 if [ "${SPARCV9}" ] ; then
427 OPTS="${OPTS} -xarch=v9"
428 fi
429 fi
430 if [ "${ALTOPTS}" ] ; then
431 OPTS=${ALTOPTS}
432 fi
433
434 # for debug:
435 #echo "mklib: linker is" ${LINK} ${OPTS}
436 if [ $NOPREFIX = 1 ] ; then
437 rm -f ${LIBNAME}
438 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
439 FINAL_LIBS="${LIBNAME}"
440 else
441 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
442 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
443 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
444 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
445 fi
446 fi
447 ;;
448
449 'FreeBSD')
450 # we assume gcc
451
452 if [ "x$LINK" = "x" ] ; then
453 # -linker was not specified so set default link command now
454 if [ $CPLUSPLUS = 1 ] ; then
455 LINK=g++
456 else
457 LINK=gcc
458 fi
459 fi
460
461 if [ $NOPREFIX = 1 ] ; then
462 # No "lib" or ".so" part
463 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
464 OPTS="-shared"
465 if [ "${ALTOPTS}" ] ; then
466 OPTS=${ALTOPTS}
467 fi
468 rm -f ${LIBNAME}
469 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
470 FINAL_LIBS=${LIBNAME}
471 elif [ $STATIC = 1 ] ; then
472 STLIB="lib${LIBNAME}.a"
473 echo "mklib: Making FreeBSD static library: " ${STLIB}
474 rm -f ${STLIB}
475 ar cq ${STLIB} ${OBJECTS}
476 ranlib ${STLIB}
477 FINAL_LIBS=${STLIB}
478 else
479 SHLIB="lib${LIBNAME}.so.${MAJOR}"
480 OPTS="-shared -Wl,-soname,${SHLIB}"
481 if [ "${ALTOPTS}" ] ; then
482 OPTS=${ALTOPTS}
483 fi
484 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
485 rm -f ${SHLIB}
486 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
487 ln -sf ${SHLIB} "lib${LIBNAME}.so"
488 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
489 fi
490 ;;
491
492 'NetBSD')
493 if [ $STATIC = 1 ] ; then
494 LIBNAME="lib${LIBNAME}_pic.a"
495 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
496 rm -f ${LIBNAME}
497 ar cq ${LIBNAME} ${OBJECTS}
498 ranlib ${LIBNAME}
499 FINAL_LIBS=${LIBNAME}
500 else
501 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
502 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
503 rm -f ${LIBNAME}
504 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
505 FINAL_LIBS=${LIBNAME}
506 fi
507 ;;
508
509 'IRIX' | 'IRIX64')
510 if [ $STATIC = 1 ] ; then
511 LIBNAME="lib${LIBNAME}.a"
512 rm -f ${LIBNAME}
513 ar rc ${LIBNAME} ${OBJECTS}
514 FINAL_LIBS=${LIBNAME}
515 else
516 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
517
518 # examine first object to determine ABI
519 set ${OBJECTS}
520 ABI_O32=`file $1 | grep 'ELF 32-bit'`
521 ABI_N32=`file $1 | grep 'ELF N32'`
522 ABI_N64=`file $1 | grep 'ELF 64-bit'`
523 if [ "${ABI_O32}" ] ; then
524 OPTS="-32 -shared -all"
525 ABI="o32-bit"
526 elif [ "${ABI_N32}" ] ; then
527 OPTS="-n32 -shared -all"
528 ABI="n32-bit"
529 elif [ "${ABI_N64}" ] ; then
530 OPTS="-64 -shared -all"
531 ABI="64-bit"
532 else
533 echo "Error: Unexpected IRIX ABI!"
534 exit 1
535 fi
536
537 if [ "${ALTOPTS}" ] ; then
538 OPTS=${ALTOPTS}
539 fi
540
541 if [ $CPLUSPLUS = 1 ] ; then
542 LINK="CC"
543 else
544 LINK="ld"
545 fi
546
547 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
548 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
549 FINAL_LIBS=${LIBNAME}
550 fi
551 ;;
552
553 'linux-cygwin')
554 LIBNAME="lib${LIBNAME}.a"
555 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
556 rm -f ${LIBNAME}
557 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
558 FINAL_LIBS=${LIBNAME}
559 ;;
560
561 'HP-UX')
562 if [ $STATIC = 1 ] ; then
563 LIBNAME="lib${LIBNAME}.a"
564 echo "mklib: Making HP-UX static library: " ${LIBNAME}
565 rm -f ${LIBNAME}
566 ar -ruv ${LIBNAME} ${OBJECTS}
567 FINAL_LIBS=${LIBNAME}
568 else
569 # HP uses a .2 for their current GL/GLU libraries
570 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
571 MAJOR=2
572 fi
573 RUNLIB="lib${LIBNAME}.${MAJOR}"
574 DEVLIB="lib${LIBNAME}.sl"
575 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
576 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
577 ln -s ${RUNLIB} ${DEVLIB}
578 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
579 fi
580 ;;
581
582 'AIX' )
583 # examine first object to determine ABI
584 set ${OBJECTS}
585 ABI_64=`file $1 | grep '64-bit'`
586 if [ "${ABI_64}" ] ; then
587 X64="-X64"
588 Q64="-q64"
589 OFILE=shr_64.o
590 else
591 OFILE=shr.o #Want to be consistent with the IBM libGL.a
592 fi
593
594 if [ $STATIC = 1 ] ; then
595 LIBNAME="lib${LIBNAME}.a"
596 echo "mklib: Making AIX static library: " ${LIBNAME}
597 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
598 FINAL_LIBS=${LIBNAME}
599 else
600 EXPFILE="lib${LIBNAME}.exp"
601 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
602 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
603 rm -f ${EXPFILE} ${OFILE}
604 NM="/bin/nm -eC ${X64}"
605 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
606 ${NM} ${OBJECTS} | awk '{
607 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
608 && ( substr($1,1,1) != ".")) {
609 if (substr ($1, 1, 7) != "__sinit" &&
610 substr ($1, 1, 7) != "__sterm") {
611 if (substr ($1, 1, 5) == "__tf1")
612 print (substr ($1, 7))
613 else if (substr ($1, 1, 5) == "__tf9")
614 print (substr ($1, 15))
615 else
616 print $1
617 }
618 }
619 }' | sort -u >> ${EXPFILE}
620
621 if [ "${ALTOPTS}" ] ; then
622 OPTS=${ALTOPTS}
623 fi
624
625 # On AIX a shared library is linked differently when
626 # you want to dlopen the file
627 if [ $DLOPEN = "1" ] ; then
628 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
629 else
630 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
631 ar ${X64} -r ${LIBNAME} ${OFILE}
632 fi
633
634 FINAL_LIBS="${LIBNAME}"
635 fi
636 ;;
637
638 'OpenSTEP')
639 LIBNAME="lib${LIBNAME}.a"
640 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
641 libtool -static -o ${LIBNAME} - ${OBJECTS}
642 FINAL_LIBS=${LIBNAME}
643 ;;
644
645 'OSF1')
646 if [ $STATIC = 1 ] ; then
647 LIBNAME="lib${LIBNAME}.a"
648 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
649 rm -f ${LIBNAME}
650 ar -ruv ${LIBNAME} ${OBJECTS}
651 FINAL_LIBS=${LIBNAME}
652 else
653 VERSION="${MAJOR}.${MINOR}"
654 LIBNAME="lib${LIBNAME}.so"
655 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
656 if [ "x$LINK" = "x" ] ; then
657 if [ $CPLUSPLUS = 1 ] ; then
658 LINK=cxx
659 else
660 LINK=cc
661 fi
662 fi
663 rm -f ${LIBNAME}.${VERSION}
664 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
665 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
666 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
667 fi
668 ;;
669
670 'Darwin')
671 if [ $STATIC = 1 ] ; then
672 LIBNAME="lib${LIBNAME}.a"
673 echo "mklib: Making Darwin static library: " ${LIBNAME}
674 LINK="ar"
675 OPTS="-ruvs"
676 if [ "${ALTOPTS}" ] ; then
677 OPTS=${ALTOPTS}
678 fi
679 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
680 FINAL_LIBS=${LIBNAME}
681 else
682 # On Darwin a .bundle is used for a library that you want to dlopen
683 if [ $DLOPEN = "1" ] ; then
684 LIBSUFFIX="bundle"
685 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
686 else
687 LIBSUFFIX="dylib"
688 if [ -z "$ID" ] ; then
689 ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
690 fi
691 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
692 fi
693
694 if [ ${EXPORTS} ] ; then
695 if [ -f ${EXPORTS}".darwin" ] ; then
696 EXPORTS=$EXPORTS".darwin"
697 fi
698 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
699 fi
700
701 LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
702 LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
703 LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
704
705 # examine first object to determine ABI
706 set ${OBJECTS}
707 ABI_PPC=`file $1 | grep ' ppc'`
708 ABI_I386=`file $1 | grep ' i386'`
709 ABI_PPC64=`file $1 | grep ' ppc64'`
710 ABI_X86_64=`file $1 | grep ' x86_64'`
711 if [ "${ABI_PPC}" ] ; then
712 OPTS="${OPTS} -arch ppc"
713 fi
714 if [ "${ABI_I386}" ] ; then
715 OPTS="${OPTS} -arch i386"
716 fi
717 if [ "${ABI_PPC64}" ] ; then
718 OPTS="${OPTS} -arch ppc64"
719 fi
720 if [ "${ABI_X86_64}" ] ; then
721 OPTS="${OPTS} -arch x86_64"
722 fi
723
724 if [ "${ALTOPTS}" ] ; then
725 OPTS=${ALTOPTS}
726 fi
727
728 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
729 # to OPTS here?
730
731 # determine linker
732 if [ $CPLUSPLUS = 1 ] ; then
733 LINK="g++"
734 else
735 LINK="cc"
736 fi
737
738 echo "mklib: Making Darwin shared library: " ${LIBNAME}
739
740 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
741 ln -s ${LIBNAME} ${LINKNAME}
742 ln -s ${LIBNAME} ${LINKNAME2}
743 FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
744 fi
745 ;;
746
747 'LynxOS')
748 LIBNAME="lib${LIBNAME}.a"
749 echo "mklib: Making LynxOS static library: " ${LIBNAME}
750 rm -f ${LIBNAME}
751 ar ru ${LIBNAME} ${OBJECTS}
752 FINAL_LIBS=${LIBNAME}
753 ;;
754
755 'BeOS')
756 if [ $STATIC = 1 ] ; then
757 LIBNAME="lib${LIBNAME}.a"
758 echo "mklib: Making BeOS static library: " ${LIBNAME}
759 ar -cru "${LIBNAME}" ${OBJECTS}
760 else
761 LIBNAME="lib${LIBNAME}.so"
762 echo "mklib: Making BeOS shared library: " ${LIBNAME}
763 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
764 mimeset -f "${LIBNAME}"
765 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
766 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
767 fi
768 FINAL_LIBS=${LIBNAME}
769 ;;
770
771 'QNX')
772 LIBNAME="lib${LIBNAME}.a"
773 echo "mklib: Making QNX library: " ${LIBNAME}
774 wlib ${LIBNAME} ${OBJECTS}
775 FINAL_LIBS=${LIBNAME}
776 ;;
777
778 'MorphOS')
779 LIBNAME="lib${LIBNAME}.a"
780 echo "mklib: Making MorphOS library: " ${LIBNAME}
781 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
782 FINAL_LIBS="${LIBNAME}"
783 ;;
784
785 'icc' | 'icc-istatic')
786 # Intel C compiler
787 # This should get merged into the Linux code, above, since this isn't
788 # really a different architecture.
789 LIBNAME="lib${LIBNAME}" # prefix with "lib"
790
791 if [ $STATIC = 1 ] ; then
792 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
793 LINK="ar"
794 OPTS="-ruv"
795 if [ "${ALTOPTS}" ] ; then
796 OPTS=${ALTOPTS}
797 fi
798 # make lib
799 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
800 # finish up
801 FINAL_LIBS="${LIBNAME}.a"
802 else
803 if [ $ARCH = icc-istatic ] ; then
804 OPTS="-shared -i-static -cxxlib-icc"
805 else
806 OPTS="-shared"
807 fi
808 if [ "${ALTOPTS}" ] ; then
809 OPTS=${ALTOPTS}
810 fi
811 VERSION="${MAJOR}.${MINOR}.${PATCH}"
812 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
813
814 if [ $CPLUSPLUS = 1 ] ; then
815 LINK="icpc"
816 else
817 LINK="icc"
818 fi
819 # rm any old libs
820 rm -f ${LIBNAME}.so.${VERSION}
821 rm -f ${LIBNAME}.so.${MAJOR}
822 rm -f ${LIBNAME}.so
823 # make lib
824 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
825 # make usual symlinks
826 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
827 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
828 # finish up
829 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
830 fi
831 ;;
832
833 'aix-gcc')
834 # AIX with gcc
835 if [ $STATIC = 1 ] ; then
836 LIBNAME="lib${LIBNAME}.a"
837 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
838 rm -f ${LIBNAME}
839 ar ru ${LIBNAME} ${OBJECTS}
840 FINAL_LIBS=${LIBNAME}
841 else
842 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
843 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
844 # remove old lib
845 rm -f ${LIBNAME}
846 # make the lib
847 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
848 # NOTE: the application linking with this library must specify
849 # the -Wl,-brtl flags to gcc
850 FINAL_LIBS=${LIBNAME}
851 fi
852 ;;
853
854 'ultrix')
855 # XXX untested
856 if [ $STATIC = 0 ] ; then
857 echo "mklib: Warning shared libs not supported on Ultrix"
858 fi
859 LIBNAME="lib${LIBNAME}.a"
860 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
861 rm -f ${LIBNAME}
862 ar ru ${LIBNAME} ${OBJECTS}
863 FINAL_LIBS="${LIBNAME}"
864 ;;
865
866 CYGWIN*)
867 # GCC-based environment
868 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
869 LIBNAME="lib${LIBNAME}" # prefix with "lib"
870
871 if [ $STATIC = 1 ] ; then
872 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
873 LINK="ar"
874 OPTS="-ru"
875 if [ "${ALTOPTS}" ] ; then
876 OPTS=${ALTOPTS}
877 fi
878 # make lib
879 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
880 ranlib ${LIBNAME}.a
881 # finish up
882 FINAL_LIBS=${LIBNAME}.a
883 else
884 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
885 if [ "${ALTOPTS}" ] ; then
886 OPTS=${ALTOPTS}
887 fi
888 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
889
890 if [ $CPLUSPLUS = 1 ] ; then
891 LINK="g++"
892 else
893 LINK="gcc"
894 fi
895
896 # rm any old libs
897 rm -f ${LIBNAME}-${MAJOR}.dll
898 rm -f ${LIBNAME}.dll.a
899 rm -f ${LIBNAME}.a
900
901 # make lib
902 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
903 # make usual symlinks
904 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
905 # finish up
906 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
907 # special case for installing in bin
908 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
909 fi
910 ;;
911
912 'example')
913 # If you're adding support for a new architecture, you can
914 # start with this:
915 if [ $STATIC = 1 ] ; then
916 LIBNAME="lib${LIBNAME}.a"
917 echo "mklib: Making static library for example arch: " ${LIBNAME}
918 rm -f ${LIBNAME}
919 ar rv ${LIBNAME} ${OBJECTS}
920 FINAL_LIBS="${LIBNAME}"
921 else
922 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
923 echo "mklib: Making shared library for example arch: " ${LIBNAME}
924 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
925 FINAL_LIBS="${LIBNAME}"
926 fi
927 ;;
928
929 *)
930 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
931 echo "mklib: Please add necessary commands to mklib script."
932 ;;
933 esac
934
935
936 #
937 # Put library files into installation directory if specified.
938 #
939 if [ ${INSTALLDIR} != "." ] ; then
940 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
941 mv ${FINAL_LIBS} ${INSTALLDIR}/
942 fi