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