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