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