Merge branch 'new-frag-attribs'
[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 ABI_PPC=`file $1 | grep ' ppc'`
728 ABI_I386=`file $1 | grep ' i386'`
729 ABI_PPC64=`file $1 | grep ' ppc64'`
730 ABI_X86_64=`file $1 | grep ' x86_64'`
731 if [ "${ABI_PPC}" ] ; then
732 OPTS="${OPTS} -arch ppc"
733 fi
734 if [ "${ABI_I386}" ] ; then
735 OPTS="${OPTS} -arch i386"
736 fi
737 if [ "${ABI_PPC64}" ] ; then
738 OPTS="${OPTS} -arch ppc64"
739 fi
740 if [ "${ABI_X86_64}" ] ; then
741 OPTS="${OPTS} -arch x86_64"
742 fi
743
744 if [ "${ALTOPTS}" ] ; then
745 OPTS=${ALTOPTS}
746 fi
747
748 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
749 # to OPTS here?
750
751 # determine linker
752 if [ $CPLUSPLUS = 1 ] ; then
753 LINK="g++"
754 else
755 LINK="cc"
756 fi
757
758 echo "mklib: Making Darwin shared library: " ${LIBNAME}
759
760 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
761 ln -s ${LIBNAME} ${LINKNAME}
762 ln -s ${LIBNAME} ${LINKNAME2}
763 FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
764 fi
765 ;;
766
767 'LynxOS')
768 LIBNAME="lib${LIBNAME}.a"
769 echo "mklib: Making LynxOS static library: " ${LIBNAME}
770 rm -f ${LIBNAME}
771 ar ru ${LIBNAME} ${OBJECTS}
772 FINAL_LIBS=${LIBNAME}
773 ;;
774
775 'BeOS')
776 if [ $STATIC = 1 ] ; then
777 LIBNAME="lib${LIBNAME}.a"
778 echo "mklib: Making BeOS static library: " ${LIBNAME}
779 ar -cru "${LIBNAME}" ${OBJECTS}
780 else
781 LIBNAME="lib${LIBNAME}.so"
782 echo "mklib: Making BeOS shared library: " ${LIBNAME}
783 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
784 mimeset -f "${LIBNAME}"
785 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
786 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
787 fi
788 FINAL_LIBS=${LIBNAME}
789 ;;
790
791 'QNX')
792 LIBNAME="lib${LIBNAME}.a"
793 echo "mklib: Making QNX library: " ${LIBNAME}
794 wlib ${LIBNAME} ${OBJECTS}
795 FINAL_LIBS=${LIBNAME}
796 ;;
797
798 'MorphOS')
799 LIBNAME="lib${LIBNAME}.a"
800 echo "mklib: Making MorphOS library: " ${LIBNAME}
801 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
802 FINAL_LIBS="${LIBNAME}"
803 ;;
804
805 'icc' | 'icc-istatic')
806 # Intel C compiler
807 # This should get merged into the Linux code, above, since this isn't
808 # really a different architecture.
809 LIBNAME="lib${LIBNAME}" # prefix with "lib"
810
811 if [ $STATIC = 1 ] ; then
812 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
813 LINK="ar"
814 OPTS="-ruv"
815 if [ "${ALTOPTS}" ] ; then
816 OPTS=${ALTOPTS}
817 fi
818 # make lib
819 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
820 # finish up
821 FINAL_LIBS="${LIBNAME}.a"
822 else
823 if [ $ARCH = icc-istatic ] ; then
824 OPTS="-shared -i-static -cxxlib-icc"
825 else
826 OPTS="-shared"
827 fi
828 if [ "${ALTOPTS}" ] ; then
829 OPTS=${ALTOPTS}
830 fi
831 VERSION="${MAJOR}.${MINOR}.${PATCH}"
832 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
833
834 if [ $CPLUSPLUS = 1 ] ; then
835 LINK="icpc"
836 else
837 LINK="icc"
838 fi
839 # rm any old libs
840 rm -f ${LIBNAME}.so.${VERSION}
841 rm -f ${LIBNAME}.so.${MAJOR}
842 rm -f ${LIBNAME}.so
843 # make lib
844 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
845 # make usual symlinks
846 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
847 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
848 # finish up
849 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
850 fi
851 ;;
852
853 'aix-gcc')
854 # AIX with gcc
855 if [ $STATIC = 1 ] ; then
856 LIBNAME="lib${LIBNAME}.a"
857 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
858 rm -f ${LIBNAME}
859 ar ru ${LIBNAME} ${OBJECTS}
860 FINAL_LIBS=${LIBNAME}
861 else
862 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
863 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
864 # remove old lib
865 rm -f ${LIBNAME}
866 # make the lib
867 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
868 # NOTE: the application linking with this library must specify
869 # the -Wl,-brtl flags to gcc
870 FINAL_LIBS=${LIBNAME}
871 fi
872 ;;
873
874 'ultrix')
875 # XXX untested
876 if [ $STATIC = 0 ] ; then
877 echo "mklib: Warning shared libs not supported on Ultrix"
878 fi
879 LIBNAME="lib${LIBNAME}.a"
880 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
881 rm -f ${LIBNAME}
882 ar ru ${LIBNAME} ${OBJECTS}
883 FINAL_LIBS="${LIBNAME}"
884 ;;
885
886 CYGWIN*)
887 # GCC-based environment
888 if [ $NOPREFIX = 1 ] ; then
889 # No "lib" or ".so" part
890 echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
891 OPTS="-shared -Wl,--enable-auto-image-base"
892 if [ "${ALTOPTS}" ] ; then
893 OPTS=${ALTOPTS}
894 fi
895 rm -f ${LIBNAME}
896 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
897 FINAL_LIBS=${LIBNAME}
898 else
899 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
900 LIBNAME="lib${LIBNAME}" # prefix with "lib"
901
902 if [ $STATIC = 1 ] ; then
903 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
904 LINK="ar"
905 OPTS="-ru"
906 if [ "${ALTOPTS}" ] ; then
907 OPTS=${ALTOPTS}
908 fi
909 # make lib
910 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
911 ranlib ${LIBNAME}.a
912 # finish up
913 FINAL_LIBS=${LIBNAME}.a
914 else
915 OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
916 if [ "${ALTOPTS}" ] ; then
917 OPTS=${ALTOPTS}
918 fi
919 echo "mklib: Making" $ARCH "shared library: " ${CYGNAME}-${MAJOR}.dll
920
921 if [ $CPLUSPLUS = 1 ] ; then
922 LINK="g++"
923 else
924 LINK="gcc"
925 fi
926
927 # rm any old libs
928 rm -f ${CYGNAME}-${MAJOR}.dll
929 rm -f ${LIBNAME}-${MAJOR}.dll.a
930 rm -f ${LIBNAME}.dll.a
931 rm -f ${LIBNAME}.a
932
933 # make lib
934 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
935 # make usual symlinks
936 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
937 # finish up
938 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
939 # special case for installing in bin
940 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
941 fi
942 fi
943 ;;
944
945 'example')
946 # If you're adding support for a new architecture, you can
947 # start with this:
948 if [ $STATIC = 1 ] ; then
949 LIBNAME="lib${LIBNAME}.a"
950 echo "mklib: Making static library for example arch: " ${LIBNAME}
951 rm -f ${LIBNAME}
952 ar rv ${LIBNAME} ${OBJECTS}
953 FINAL_LIBS="${LIBNAME}"
954 else
955 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
956 echo "mklib: Making shared library for example arch: " ${LIBNAME}
957 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
958 FINAL_LIBS="${LIBNAME}"
959 fi
960 ;;
961
962 *)
963 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
964 echo "mklib: Please add necessary commands to mklib script."
965 ;;
966 esac
967
968
969 #
970 # Put library files into installation directory if specified.
971 #
972 if [ ${INSTALLDIR} != "." ] ; then
973 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
974 test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
975 mv ${FINAL_LIBS} ${INSTALLDIR}/
976 fi