OSDN Git Service

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