fb160a2aae92e9dc56ce613971e0be24979ba743
[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 # Given a list of files, look for .a archives and unpack them.
29 # Return the original list of files minus the .a files plus the unpacked files.
30 expand_archives() {
31 FILES=$@
32 NEWFILES=""
33 for FILE in $FILES ; do
34 case $FILE in
35 *.a)
36 # extract the .o files from this .a archive
37 MEMBERS=`ar t $FILE`
38 ar x $FILE
39 NEWFILES="$NEWFILES $MEMBERS"
40 ;;
41 *)
42 # other file type, just add to list
43 NEWFILES="$NEWFILES $FILE"
44 ;;
45 esac
46 done
47 echo $NEWFILES
48 }
49
50
51 # Given a list of files, look for .a archives and return a list of all objects
52 # in the .a archives.
53 contents_of_archives() {
54 FILES=$@
55 NEWFILES=""
56 for FILE in $FILES ; do
57 case $FILE in
58 *.a)
59 # get list of members in this .a archive
60 MEMBERS=`ar t $FILE`
61 NEWFILES="$NEWFILES $MEMBERS"
62 ;;
63 *)
64 # skip other file types
65 ;;
66 esac
67 done
68 echo $NEWFILES
69 }
70
71
72 # Print usage info.
73 usage() {
74 echo 'Usage: mklib [options] objects'
75 echo 'Create a shared library from object files.'
76 echo ' -o LIBRARY specifies the name of the resulting library, without'
77 echo ' the leading "lib" or any suffix.'
78 echo ' (eg: "-o GL" might result in "libGL.so" being made)'
79 echo ' -major N specifies major version number (default is 1)'
80 echo ' -minor N specifies minor version number (default is 0)'
81 echo ' -patch N specifies patch version number (default is 0)'
82 echo ' -lLIBRARY specifies a dependency on LIBRARY'
83 echo ' -LDIR search in DIR for library dependencies at build time'
84 echo ' -RDIR search in DIR for library dependencies at run time'
85 echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
86 echo ' Not observed on all systems at this time.'
87 echo ' -ldflags OPT specify any additional linker flags in OPT'
88 echo ' -cplusplus link with C++ runtime'
89 echo ' -static make a static library (default is dynamic/shared)'
90 echo ' -dlopen make a shared library suitable for dynamic loading'
91 echo ' -install DIR put resulting library file(s) in DIR'
92 echo ' -arch ARCH override using `uname` to determine host system'
93 echo ' -archopt OPT specify an extra achitecture-specific option OPT'
94 echo ' -altopts OPTS alternate options to override all others'
95 echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
96 echo ' -exports FILE only export the symbols listed in FILE'
97 echo ' -id NAME Sets the id of the dylib (Darwin)'
98 echo ' -h, --help display this information and exit'
99 }
100
101
102 #
103 # Option defaults
104 #
105 LIBNAME=""
106 MAJOR=1
107 MINOR=0
108 PATCH=""
109 DEPS=""
110 LINK=""
111 LDFLAGS=""
112 CPLUSPLUS=0
113 STATIC=0
114 DLOPEN=0
115 INSTALLDIR="."
116 ARCH="auto"
117 ARCHOPT=""
118 NOPREFIX=0
119 EXPORTS=""
120 ID=""
121
122 #
123 # Parse arguments
124 #
125 while true
126 do
127 case $1 in
128 '-h' | '--help')
129 usage
130 exit 1
131 ;;
132 '-o')
133 shift 1;
134 LIBNAME=$1
135 ;;
136 '-major')
137 shift 1;
138 MAJOR=$1
139 ;;
140 '-minor')
141 shift 1;
142 MINOR=$1
143 ;;
144 '-patch')
145 shift 1;
146 PATCH=$1
147 ;;
148 '-linker')
149 shift 1;
150 LINK=$1
151 ;;
152 '-ldflags')
153 shift 1;
154 LDFLAGS=$1
155 ;;
156 -l*)
157 DEPS="$DEPS $1"
158 ;;
159 -L*)
160 DEPS="$DEPS $1"
161 ;;
162 -R*)
163 DEPS="$DEPS $1"
164 ;;
165 -Wl*)
166 DEPS="$DEPS $1"
167 ;;
168 -pthread)
169 # this is a special case (see bugzilla 10876)
170 DEPS="$DEPS $1"
171 ;;
172 '-pthread')
173 DEPS="$DEPS -pthread"
174 ;;
175 '-cplusplus')
176 CPLUSPLUS=1
177 ;;
178 '-static')
179 STATIC=1
180 ;;
181 '-dlopen')
182 DLOPEN=1
183 ;;
184 '-install')
185 shift 1;
186 INSTALLDIR=$1
187 ;;
188 '-arch')
189 shift 1;
190 ARCH=$1
191 ;;
192 '-archopt')
193 shift 1;
194 ARCHOPT=$1
195 ;;
196 '-altopts')
197 shift 1;
198 ALTOPTS=$1
199 ;;
200 '-noprefix')
201 NOPREFIX=1
202 ;;
203 '-exports')
204 shift 1;
205 EXPORTS=$1
206 ;;
207 '-id')
208 shift 1;
209 ID=$1
210 ;;
211 -*)
212 echo "mklib: Unknown option: " $1 ;
213 exit 1
214 ;;
215 *)
216 # This should be the first object file, stop parsing
217 break
218 esac
219 shift 1
220 done
221 OBJECTS=$@
222
223
224 if [ ${ARCH} = "auto" ] ; then
225 ARCH=`uname`
226 fi
227
228
229 if [ $STATIC = 1 ]; then
230 # filter out linker options inside object list
231 NEWOBJECTS=""
232 for OBJ in $OBJECTS ; do
233 case $OBJ in
234 -Wl,*)
235 echo "mklib: warning: ignoring $OBJ for static library"
236 ;;
237 *)
238 NEWOBJECTS="$NEWOBJECTS $OBJ"
239 ;;
240 esac
241 done
242 OBJECTS=$NEWOBJECTS
243 fi
244
245
246 #
247 # Error checking
248 #
249 if [ "x${LIBNAME}" = "x" ] ; then
250 echo "mklib: Error: no library name specified (-h for help)"
251 exit 1
252 fi
253 if [ "x${OBJECTS}" = "x" ] ; then
254 echo "mklib: Error: no object files specified (-h for help)"
255 exit 1
256 fi
257
258
259 #
260 # Debugging info
261 #
262 if [ ] ; then
263 echo "-----------------"
264 echo ARCH is $ARCH
265 echo LIBNAME is $LIBNAME
266 echo MAJOR is $MAJOR
267 echo MINOR is $MINOR
268 echo PATCH is $PATCH
269 echo DEPS are $DEPS
270 echo "EXPORTS in" $EXPORTS
271 echo ID is $ID
272 echo "-----------------"
273 fi
274
275
276 #
277 # OK, make the library now
278 #
279 case $ARCH in
280
281 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*)
282 # we assume gcc
283
284 if [ "x$LINK" = "x" ] ; then
285 # -linker was not specified so set default link command now
286 if [ $CPLUSPLUS = 1 ] ; then
287 LINK=g++
288 else
289 LINK=gcc
290 fi
291 fi
292
293 if [ $NOPREFIX = 1 ] ; then
294 # No "lib" or ".so" part
295 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
296 case $ARCH in 'Linux' | 'GNU' | GNU/*)
297 OPTS="-Xlinker -Bsymbolic -shared"
298 ;;
299 *)
300 OPTS="-shared"
301 ;;
302 esac
303
304 # Check if objects are 32-bit and we're running in 64-bit
305 # environment. If so, pass -m32 flag to linker.
306 set ${OBJECTS}
307 ABI32=`file $1 | grep 32-bit`
308 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
309 OPTS="-m32 ${OPTS}"
310 fi
311
312 if [ "${ALTOPTS}" ] ; then
313 OPTS=${ALTOPTS}
314 fi
315
316 rm -f ${LIBNAME}
317 # make lib
318 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
319 # finish up
320 FINAL_LIBS="${LIBNAME}"
321 elif [ $STATIC = 1 ] ; then
322 # make a static .a library
323 LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
324 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
325 OPTS="-ru"
326 if [ "${ALTOPTS}" ] ; then
327 OPTS=${ALTOPTS}
328 fi
329
330 # expand .a into .o files
331 NEW_OBJECTS=`expand_archives $OBJECTS`
332
333 # make static lib
334 rm -f ${LIBNAME}
335 ar ${OPTS} ${LIBNAME} ${NEW_OBJECTS}
336 ranlib ${LIBNAME}
337
338 # remove temporary extracted .o files
339 rm -f `contents_of_archives $OBJECTS`
340
341 # finish up
342 FINAL_LIBS=${LIBNAME}
343 else
344 # make dynamic library
345 LIBNAME="lib${LIBNAME}" # prefix with "lib"
346 case $ARCH in 'Linux' | 'GNU' | GNU/*)
347 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
348 ;;
349 *)
350 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
351 ;;
352 esac
353 if [ $EXPORTS ] ; then
354 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
355 # Make the 'exptmp' file for --version-script option
356 echo "{" > exptmp
357 echo "global:" >> exptmp
358 sed 's/$/;/' ${EXPORTS} >> exptmp
359 echo "local:" >> exptmp
360 echo "*;" >> exptmp
361 echo "};" >> exptmp
362 OPTS="${OPTS} -Xlinker --version-script=exptmp"
363 # exptmp is removed below
364 fi
365
366 # Check if objects are 32-bit and we're running in 64-bit
367 # environment. If so, pass -m32 flag to linker.
368 set ${OBJECTS}
369 ABI32=`file $1 | grep 32-bit`
370 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
371 OPTS="-m32 ${OPTS}"
372 fi
373 if [ "${ALTOPTS}" ] ; then
374 OPTS=${ALTOPTS}
375 fi
376
377 if [ x${PATCH} = "x" ] ; then
378 VERSION="${MAJOR}.${MINOR}"
379 else
380 VERSION="${MAJOR}.${MINOR}.${PATCH}"
381 fi
382
383 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
384
385 # rm any old libs
386 rm -f ${LIBNAME}.so.${VERSION}
387 rm -f ${LIBNAME}.so.${MAJOR}
388 rm -f ${LIBNAME}.so
389
390 # make lib
391 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
392 # make usual symlinks
393 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
394 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
395 # finish up
396 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
397 # rm -f exptmp
398 fi
399 ;;
400
401 'SunOS')
402 if [ $STATIC = 1 ] ; then
403 LIBNAME="lib${LIBNAME}.a"
404 echo "mklib: Making SunOS static library: " ${LIBNAME}
405 rm -f ${LIBNAME}
406 ar -ruv ${LIBNAME} ${OBJECTS}
407 FINAL_LIBS=${LIBNAME}
408 else
409 if [ $NOPREFIX = 0 ] ; then
410 LIBNAME="lib${LIBNAME}.so"
411 fi
412 echo "mklib: Making SunOS shared library: " ${LIBNAME}
413
414 if [ "x$LINK" = "x" ] ; then
415 # -linker was not specified, choose default linker now
416 if [ $CPLUSPLUS = 1 ] ; then
417 # determine linker and options for C++ code
418 if [ `which c++` ] ; then
419 # use Sun c++
420 LINK="c++"
421 elif [ `type g++` ] ; then
422 # use g++
423 LINK="g++"
424 else
425 echo "mklib: warning: can't find C++ compiler, trying CC."
426 LINK="CC"
427 fi
428 else
429 # use native Sun linker for C code
430 LINK="ld"
431 fi
432 fi
433
434 # linker options
435 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
436 # SunOS tools, -G to make shared libs
437 OPTS="-G"
438 else
439 # gcc linker
440 # Check if objects are 32-bit and we're running in 64-bit
441 # environment. If so, pass -m32 flag to linker.
442 set ${OBJECTS}
443 ABI32=`file $1 | grep 32-bit`
444 if [ "${ABI32}" ] ; then
445 OPTS="-m32 -shared -Wl,-Bdynamic"
446 else
447 OPTS="-m64 -shared -Wl,-Bdynamic"
448 fi
449 fi
450
451 # If using Sun C++ compiler, need to tell it not to add runpaths
452 # that are specific to the build machine
453 if [ ${LINK} = "CC" ] ; then
454 OPTS="${OPTS} -norunpath"
455 fi
456
457 # Solaris linker requires explicitly listing the Standard C & C++
458 # libraries in the link path when building shared objects
459 if [ ${LINK} = "CC" ] ; then
460 DEPS="${DEPS} -lCrun"
461 fi
462 DEPS="${DEPS} -lc"
463
464 if [ $EXPORTS ] ; then
465 # Make the 'mapfile.scope' linker mapfile
466 echo "{" > mapfile.scope
467 echo "global:" >> mapfile.scope
468 sed 's/$/;/' ${EXPORTS} >> mapfile.scope
469 echo "local:" >> mapfile.scope
470 echo " *;" >> mapfile.scope
471 echo "};" >> mapfile.scope
472 OPTS="${OPTS} -Wl,-Mmapfile.scope"
473 fi
474
475 # Check if objects are SPARC v9
476 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
477 set ${OBJECTS}
478 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
479 SPARCV9=`file $1 | grep SPARCV9`
480 if [ "${SPARCV9}" ] ; then
481 OPTS="${OPTS} -xarch=v9"
482 fi
483 fi
484 if [ "${ALTOPTS}" ] ; then
485 OPTS=${ALTOPTS}
486 fi
487
488 # for debug:
489 #echo "mklib: linker is" ${LINK} ${OPTS}
490 if [ $NOPREFIX = 1 ] ; then
491 rm -f ${LIBNAME}
492 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
493 FINAL_LIBS="${LIBNAME}"
494 else
495 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
496 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
497 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
498 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
499 fi
500 fi
501 ;;
502
503 'FreeBSD')
504 # we assume gcc
505
506 if [ "x$LINK" = "x" ] ; then
507 # -linker was not specified so set default link command now
508 if [ $CPLUSPLUS = 1 ] ; then
509 LINK=g++
510 else
511 LINK=gcc
512 fi
513 fi
514
515 if [ $NOPREFIX = 1 ] ; then
516 # No "lib" or ".so" part
517 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
518 OPTS="-shared"
519 if [ "${ALTOPTS}" ] ; then
520 OPTS=${ALTOPTS}
521 fi
522 rm -f ${LIBNAME}
523 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
524 FINAL_LIBS=${LIBNAME}
525 elif [ $STATIC = 1 ] ; then
526 # make a static .a library
527 STLIB="lib${LIBNAME}.a"
528 echo "mklib: Making FreeBSD static library: " ${STLIB}
529
530 # expand .a into .o files
531 NEW_OBJECTS=`expand_archives $OBJECTS`
532
533 # make static lib
534 rm -f ${STLIB}
535 ar cq ${STLIB} ${NEW_OBJECTS}
536 ranlib ${STLIB}
537
538 # remove temporary extracted .o files
539 rm -f `contents_of_archives $OBJECTS`
540
541 FINAL_LIBS=${STLIB}
542 else
543 # make dynamic library
544 SHLIB="lib${LIBNAME}.so.${MAJOR}"
545 OPTS="-shared -Wl,-soname,${SHLIB}"
546 if [ "${ALTOPTS}" ] ; then
547 OPTS=${ALTOPTS}
548 fi
549 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
550 rm -f ${SHLIB}
551 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
552 ln -sf ${SHLIB} "lib${LIBNAME}.so"
553 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
554 fi
555 ;;
556
557 'NetBSD')
558 if [ $STATIC = 1 ] ; then
559 LIBNAME="lib${LIBNAME}_pic.a"
560 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
561 rm -f ${LIBNAME}
562 ar cq ${LIBNAME} ${OBJECTS}
563 ranlib ${LIBNAME}
564 FINAL_LIBS=${LIBNAME}
565 else
566 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
567 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
568 rm -f ${LIBNAME}
569 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
570 FINAL_LIBS=${LIBNAME}
571 fi
572 ;;
573
574 'IRIX' | 'IRIX64')
575 if [ $STATIC = 1 ] ; then
576 LIBNAME="lib${LIBNAME}.a"
577 rm -f ${LIBNAME}
578 ar rc ${LIBNAME} ${OBJECTS}
579 FINAL_LIBS=${LIBNAME}
580 else
581 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
582
583 # examine first object to determine ABI
584 set ${OBJECTS}
585 ABI_O32=`file $1 | grep 'ELF 32-bit'`
586 ABI_N32=`file $1 | grep 'ELF N32'`
587 ABI_N64=`file $1 | grep 'ELF 64-bit'`
588 if [ "${ABI_O32}" ] ; then
589 OPTS="-32 -shared -all"
590 ABI="o32-bit"
591 elif [ "${ABI_N32}" ] ; then
592 OPTS="-n32 -shared -all"
593 ABI="n32-bit"
594 elif [ "${ABI_N64}" ] ; then
595 OPTS="-64 -shared -all"
596 ABI="64-bit"
597 else
598 echo "Error: Unexpected IRIX ABI!"
599 exit 1
600 fi
601
602 if [ "${ALTOPTS}" ] ; then
603 OPTS=${ALTOPTS}
604 fi
605
606 if [ $CPLUSPLUS = 1 ] ; then
607 LINK="CC"
608 else
609 LINK="ld"
610 fi
611
612 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
613 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
614 FINAL_LIBS=${LIBNAME}
615 fi
616 ;;
617
618 'linux-cygwin')
619 LIBNAME="lib${LIBNAME}.a"
620 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
621 rm -f ${LIBNAME}
622 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
623 FINAL_LIBS=${LIBNAME}
624 ;;
625
626 'HP-UX')
627 if [ $STATIC = 1 ] ; then
628 LIBNAME="lib${LIBNAME}.a"
629 echo "mklib: Making HP-UX static library: " ${LIBNAME}
630 rm -f ${LIBNAME}
631 ar -ruv ${LIBNAME} ${OBJECTS}
632 FINAL_LIBS=${LIBNAME}
633 else
634 # HP uses a .2 for their current GL/GLU libraries
635 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
636 MAJOR=2
637 fi
638 RUNLIB="lib${LIBNAME}.${MAJOR}"
639 DEVLIB="lib${LIBNAME}.sl"
640 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
641 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
642 ln -s ${RUNLIB} ${DEVLIB}
643 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
644 fi
645 ;;
646
647 'AIX' )
648 # examine first object to determine ABI
649 set ${OBJECTS}
650 ABI_64=`file $1 | grep '64-bit'`
651 if [ "${ABI_64}" ] ; then
652 X64="-X64"
653 Q64="-q64"
654 OFILE=shr_64.o
655 else
656 OFILE=shr.o #Want to be consistent with the IBM libGL.a
657 fi
658
659 if [ $STATIC = 1 ] ; then
660 LIBNAME="lib${LIBNAME}.a"
661 echo "mklib: Making AIX static library: " ${LIBNAME}
662 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
663 FINAL_LIBS=${LIBNAME}
664 else
665 EXPFILE="lib${LIBNAME}.exp"
666 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
667 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
668 rm -f ${EXPFILE} ${OFILE}
669 NM="/bin/nm -eC ${X64}"
670 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
671 ${NM} ${OBJECTS} | awk '{
672 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
673 && ( substr($1,1,1) != ".")) {
674 if (substr ($1, 1, 7) != "__sinit" &&
675 substr ($1, 1, 7) != "__sterm") {
676 if (substr ($1, 1, 5) == "__tf1")
677 print (substr ($1, 7))
678 else if (substr ($1, 1, 5) == "__tf9")
679 print (substr ($1, 15))
680 else
681 print $1
682 }
683 }
684 }' | sort -u >> ${EXPFILE}
685
686 if [ "${ALTOPTS}" ] ; then
687 OPTS=${ALTOPTS}
688 fi
689
690 # On AIX a shared library is linked differently when
691 # you want to dlopen the file
692 if [ $DLOPEN = "1" ] ; then
693 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
694 else
695 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
696 ar ${X64} -r ${LIBNAME} ${OFILE}
697 fi
698
699 FINAL_LIBS="${LIBNAME}"
700 fi
701 ;;
702
703 'OpenSTEP')
704 LIBNAME="lib${LIBNAME}.a"
705 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
706 libtool -static -o ${LIBNAME} - ${OBJECTS}
707 FINAL_LIBS=${LIBNAME}
708 ;;
709
710 'OSF1')
711 if [ $STATIC = 1 ] ; then
712 LIBNAME="lib${LIBNAME}.a"
713 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
714 rm -f ${LIBNAME}
715 ar -ruv ${LIBNAME} ${OBJECTS}
716 FINAL_LIBS=${LIBNAME}
717 else
718 VERSION="${MAJOR}.${MINOR}"
719 LIBNAME="lib${LIBNAME}.so"
720 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
721 if [ "x$LINK" = "x" ] ; then
722 if [ $CPLUSPLUS = 1 ] ; then
723 LINK=cxx
724 else
725 LINK=cc
726 fi
727 fi
728 rm -f ${LIBNAME}.${VERSION}
729 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
730 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
731 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
732 fi
733 ;;
734
735 'Darwin')
736 if [ $STATIC = 1 ] ; then
737 LIBNAME="lib${LIBNAME}.a"
738 echo "mklib: Making Darwin static library: " ${LIBNAME}
739 LINK="ar"
740 OPTS="-ruvs"
741 if [ "${ALTOPTS}" ] ; then
742 OPTS=${ALTOPTS}
743 fi
744 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
745 FINAL_LIBS=${LIBNAME}
746 else
747 # On Darwin a .bundle is used for a library that you want to dlopen
748 if [ $DLOPEN = "1" ] ; then
749 LIBSUFFIX="bundle"
750 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
751 else
752 LIBSUFFIX="dylib"
753 if [ -z "$ID" ] ; then
754 ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
755 fi
756 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
757 fi
758
759 if [ ${EXPORTS} ] ; then
760 if [ -f ${EXPORTS}".darwin" ] ; then
761 EXPORTS=$EXPORTS".darwin"
762 fi
763 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
764 fi
765
766 LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
767 LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
768 LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
769
770 # examine first object to determine ABI
771 set ${OBJECTS}
772 ABIS=`lipo -info $1 | sed s/.*://`
773 for ABI in $ABIS; do
774 OPTS="${OPTS} -arch ${ABI}"
775 done
776
777 if [ "${ALTOPTS}" ] ; then
778 OPTS=${ALTOPTS}
779 fi
780
781 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
782 # to OPTS here?
783
784 # determine linker
785 if [ $CPLUSPLUS = 1 ] ; then
786 LINK="g++"
787 else
788 LINK="cc"
789 fi
790
791 echo "mklib: Making Darwin shared library: " ${LIBNAME}
792
793 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
794 ln -s ${LIBNAME} ${LINKNAME}
795 ln -s ${LIBNAME} ${LINKNAME2}
796 FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
797 fi
798 ;;
799
800 'LynxOS')
801 LIBNAME="lib${LIBNAME}.a"
802 echo "mklib: Making LynxOS static library: " ${LIBNAME}
803 rm -f ${LIBNAME}
804 ar ru ${LIBNAME} ${OBJECTS}
805 FINAL_LIBS=${LIBNAME}
806 ;;
807
808 'BeOS')
809 if [ $STATIC = 1 ] ; then
810 LIBNAME="lib${LIBNAME}.a"
811 echo "mklib: Making BeOS static library: " ${LIBNAME}
812 ar -cru "${LIBNAME}" ${OBJECTS}
813 else
814 LIBNAME="lib${LIBNAME}.so"
815 echo "mklib: Making BeOS shared library: " ${LIBNAME}
816 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
817 mimeset -f "${LIBNAME}"
818 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
819 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
820 fi
821 FINAL_LIBS=${LIBNAME}
822 ;;
823
824 'QNX')
825 LIBNAME="lib${LIBNAME}.a"
826 echo "mklib: Making QNX library: " ${LIBNAME}
827 wlib ${LIBNAME} ${OBJECTS}
828 FINAL_LIBS=${LIBNAME}
829 ;;
830
831 'MorphOS')
832 LIBNAME="lib${LIBNAME}.a"
833 echo "mklib: Making MorphOS library: " ${LIBNAME}
834 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
835 FINAL_LIBS="${LIBNAME}"
836 ;;
837
838 'icc' | 'icc-istatic')
839 # Intel C compiler
840 # This should get merged into the Linux code, above, since this isn't
841 # really a different architecture.
842 LIBNAME="lib${LIBNAME}" # prefix with "lib"
843
844 if [ $STATIC = 1 ] ; then
845 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
846 LINK="ar"
847 OPTS="-ruv"
848 if [ "${ALTOPTS}" ] ; then
849 OPTS=${ALTOPTS}
850 fi
851 # make lib
852 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
853 # finish up
854 FINAL_LIBS="${LIBNAME}.a"
855 else
856 if [ $ARCH = icc-istatic ] ; then
857 OPTS="-shared -i-static -cxxlib-icc"
858 else
859 OPTS="-shared"
860 fi
861 if [ "${ALTOPTS}" ] ; then
862 OPTS=${ALTOPTS}
863 fi
864 VERSION="${MAJOR}.${MINOR}.${PATCH}"
865 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
866
867 if [ $CPLUSPLUS = 1 ] ; then
868 LINK="icpc"
869 else
870 LINK="icc"
871 fi
872 # rm any old libs
873 rm -f ${LIBNAME}.so.${VERSION}
874 rm -f ${LIBNAME}.so.${MAJOR}
875 rm -f ${LIBNAME}.so
876 # make lib
877 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
878 # make usual symlinks
879 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
880 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
881 # finish up
882 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
883 fi
884 ;;
885
886 'aix-gcc')
887 # AIX with gcc
888 if [ $STATIC = 1 ] ; then
889 LIBNAME="lib${LIBNAME}.a"
890 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
891 rm -f ${LIBNAME}
892 ar ru ${LIBNAME} ${OBJECTS}
893 FINAL_LIBS=${LIBNAME}
894 else
895 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
896 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
897 # remove old lib
898 rm -f ${LIBNAME}
899 # make the lib
900 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
901 # NOTE: the application linking with this library must specify
902 # the -Wl,-brtl flags to gcc
903 FINAL_LIBS=${LIBNAME}
904 fi
905 ;;
906
907 'ultrix')
908 # XXX untested
909 if [ $STATIC = 0 ] ; then
910 echo "mklib: Warning shared libs not supported on Ultrix"
911 fi
912 LIBNAME="lib${LIBNAME}.a"
913 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
914 rm -f ${LIBNAME}
915 ar ru ${LIBNAME} ${OBJECTS}
916 FINAL_LIBS="${LIBNAME}"
917 ;;
918
919 CYGWIN*)
920 # GCC-based environment
921 if [ $NOPREFIX = 1 ] ; then
922 # No "lib" or ".so" part
923 echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
924 OPTS="-shared -Wl,--enable-auto-image-base"
925 if [ "${ALTOPTS}" ] ; then
926 OPTS=${ALTOPTS}
927 fi
928 rm -f ${LIBNAME}
929 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
930 FINAL_LIBS=${LIBNAME}
931 else
932 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
933 LIBNAME="lib${LIBNAME}" # prefix with "lib"
934
935 if [ $STATIC = 1 ] ; then
936 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
937 LINK="ar"
938 OPTS="-ru"
939 if [ "${ALTOPTS}" ] ; then
940 OPTS=${ALTOPTS}
941 fi
942 # make lib
943 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
944 ranlib ${LIBNAME}.a
945 # finish up
946 FINAL_LIBS=${LIBNAME}.a
947 else
948 OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
949 if [ "${ALTOPTS}" ] ; then
950 OPTS=${ALTOPTS}
951 fi
952 echo "mklib: Making" $ARCH "shared library: " ${CYGNAME}-${MAJOR}.dll
953
954 if [ $CPLUSPLUS = 1 ] ; then
955 LINK="g++"
956 else
957 LINK="gcc"
958 fi
959
960 # rm any old libs
961 rm -f ${CYGNAME}-${MAJOR}.dll
962 rm -f ${LIBNAME}-${MAJOR}.dll.a
963 rm -f ${LIBNAME}.dll.a
964 rm -f ${LIBNAME}.a
965
966 # make lib
967 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
968 # make usual symlinks
969 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
970 # finish up
971 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
972 # special case for installing in bin
973 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
974 fi
975 fi
976 ;;
977
978 'example')
979 # If you're adding support for a new architecture, you can
980 # start with this:
981 if [ $STATIC = 1 ] ; then
982 LIBNAME="lib${LIBNAME}.a"
983 echo "mklib: Making static library for example arch: " ${LIBNAME}
984 rm -f ${LIBNAME}
985 ar rv ${LIBNAME} ${OBJECTS}
986 FINAL_LIBS="${LIBNAME}"
987 else
988 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
989 echo "mklib: Making shared library for example arch: " ${LIBNAME}
990 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
991 FINAL_LIBS="${LIBNAME}"
992 fi
993 ;;
994
995 *)
996 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
997 echo "mklib: Please add necessary commands to mklib script."
998 ;;
999 esac
1000
1001
1002 #
1003 # Put library files into installation directory if specified.
1004 #
1005 if [ ${INSTALLDIR} != "." ] ; then
1006 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
1007 test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
1008 mv ${FINAL_LIBS} ${INSTALLDIR}/
1009 fi