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