OSDN Git Service

Merge branch '965-glsl'
[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
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'
65             echo '  -linker L     explicity specify the linker program to use (eg: gcc, g++)'
66             echo '                Not observed on all systems at this time.'
67             echo '  -ldflags OPT  specify any additional linker flags in OPT'
68             echo '  -cplusplus    link with C++ runtime'
69             echo '  -static       make a static library (default is dynamic/shared)'
70             echo '  -dlopen       make a shared library suitable for dynamic loading'
71             echo '  -install DIR  put resulting library file(s) in DIR'
72             echo '  -arch ARCH    override using `uname` to determine host system'
73             echo '  -archopt OPT  specify an extra achitecture-specific option OPT'
74             echo "  -noprefix     don't prefix library name with 'lib' nor add any suffix"
75             echo '  -exports FILE only export the symbols listed in FILE'
76             echo '  -h, --help    display this information and exit'
77             exit 1
78             ;;
79         '-o')
80             shift 1;
81             LIBNAME=$1
82             ;;
83         '-major')
84             shift 1;
85             MAJOR=$1
86             ;;
87         '-minor')
88             shift 1;
89             MINOR=$1
90             ;;
91         '-patch')
92             shift 1;
93             PATCH=$1
94             ;;
95         '-linker')
96             shift 1;
97             LINK=$1
98             ;;
99         '-ldflags')
100             shift 1;
101             LDFLAGS=$1
102             ;;
103         -l*)
104             DEPS="$DEPS $1"
105             ;;
106         -L*)
107             DEPS="$DEPS $1"
108             ;;
109         -pthread)
110             # this is a special case (see bugzilla 10876)
111             DEPS="$DEPS $1"
112             ;;
113         '-pthread')
114             DEPS="$DEPS -pthread"
115             ;;
116         '-cplusplus')
117             CPLUSPLUS=1
118             ;;
119         '-static')
120             STATIC=1
121             ;;
122         '-dlopen')
123             DLOPEN=1
124             ;;
125         '-install')
126             shift 1;
127             INSTALLDIR=$1
128             ;;
129         '-arch')
130             shift 1;
131             ARCH=$1
132             ;;
133         '-archopt')
134             shift 1;
135             ARCHOPT=$1
136             ;;
137         '-noprefix')
138             NOPREFIX=1
139             ;;
140         '-exports')
141             shift 1;
142             EXPORTS=$1
143             ;;
144         -*)
145             echo "mklib: Unknown option: " $1 ;
146             exit 1
147             ;;
148         *)
149             # This should be the first object file, stop parsing
150             break
151     esac
152     shift 1
153 done
154 OBJECTS=$@
155
156
157 if [ ${ARCH} = "auto" ] ; then
158     ARCH=`uname`
159 fi
160
161
162 #
163 # Error checking
164 #
165 if [ "x${LIBNAME}" = "x" ] ; then
166     echo "mklib: Error: no library name specified"
167     exit 1
168 fi
169 if [ "x${OBJECTS}" = "x" ] ; then
170     echo "mklib: Error: no object files specified"
171     exit 1
172 fi
173
174
175 #
176 # Debugging info
177 #
178 if [  ]  ; then
179     echo "-----------------"
180     echo ARCH is $ARCH
181     echo LIBNAME is $LIBNAME
182     echo MAJOR is $MAJOR
183     echo MINOR is $MINOR
184     echo PATCH is $PATCH
185     echo DEPS are $DEPS
186     echo "EXPORTS in" $EXPORTS
187     echo "-----------------"
188 fi
189
190
191 #
192 # OK, make the library now
193 #
194 case $ARCH in
195
196     'Linux' | 'OpenBSD' | 'GNU' | GNU/*)
197         # we assume gcc
198
199         if [ "x$LINK" = "x" ] ; then
200             # -linker was not specified so set default link command now
201             if [ $CPLUSPLUS = 1 ] ; then
202                 LINK=g++
203             else
204                 LINK=gcc
205             fi
206         fi
207
208         if [ $NOPREFIX = 1 ] ; then
209             # No "lib" or ".so" part
210             echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
211             #OPTS="-shared -Wl,-soname,${LIBNAME}"  # soname???
212             OPTS="-shared"
213
214             # Check if objects are 32-bit and we're running in 64-bit
215             # environment.  If so, pass -m32 flag to linker.
216             set ${OBJECTS}
217             ABI32=`file $1 | grep 32-bit`
218             if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
219                 OPTS="-m32 ${OPTS}"
220             fi
221
222             rm -f ${LIBNAME}
223             # make lib
224             ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
225             # finish up
226             FINAL_LIBS="${LIBNAME}"
227         elif [ $STATIC = 1 ] ; then
228             LIBNAME="lib${LIBNAME}.a"     # prefix with "lib", suffix with ".a"
229             echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
230             LINK="ar"
231             OPTS="-ru"
232             rm -f ${LIBNAME}
233             # make lib
234             ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
235             ranlib ${LIBNAME}
236             # finish up
237             FINAL_LIBS=${LIBNAME}
238         else
239             LIBNAME="lib${LIBNAME}"     # prefix with "lib"
240             case $ARCH in 'Linux' | 'GNU' | GNU/*)
241                 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
242             ;;
243             *)
244                 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
245             ;;
246             esac
247             if [ $EXPORTS ] ; then
248                 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
249                 # Make the 'exptmp' file for --version-script option
250                 echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
251                 echo "global:" >> exptmp
252                 sed 's/$/;/' ${EXPORTS} >> exptmp
253                 echo "local:" >> exptmp
254                 echo "*;" >> exptmp
255                 echo "};" >> exptmp
256                 OPTS="${OPTS} -Xlinker --version-script=exptmp"
257                 # exptmp is removed below
258             fi
259
260             # Check if objects are 32-bit and we're running in 64-bit
261             # environment.  If so, pass -m32 flag to linker.
262             set ${OBJECTS}
263             ABI32=`file $1 | grep 32-bit`
264             if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
265                 OPTS="-m32 ${OPTS}"
266             fi
267
268             if [ x${PATCH} = "x" ] ; then
269                 VERSION="${MAJOR}.${MINOR}"
270             else
271                 VERSION="${MAJOR}.${MINOR}.${PATCH}"
272             fi
273
274             echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
275
276             # rm any old libs
277             rm -f ${LIBNAME}.so.${VERSION}
278             rm -f ${LIBNAME}.so.${MAJOR}
279             rm -f ${LIBNAME}.so
280
281             # make lib
282             ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
283             # make usual symlinks
284             ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
285             ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
286             # finish up
287             FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
288 #           rm -f exptmp
289         fi
290         ;;
291
292     'SunOS')
293         if [ $STATIC = 1 ] ; then
294             LIBNAME="lib${LIBNAME}.a"
295             echo "mklib: Making SunOS static library: " ${LIBNAME}
296             rm -f ${LIBNAME}
297             ar -ruv ${LIBNAME} ${OBJECTS}
298             FINAL_LIBS=${LIBNAME}
299         else
300             if [ $NOPREFIX = 0 ] ; then
301                 LIBNAME="lib${LIBNAME}.so"
302             fi
303             echo "mklib: Making SunOS shared library: " ${LIBNAME}
304
305             if [ "x$LINK" = "x" ] ; then
306                 # -linker was not specified, choose default linker now
307                 if [ $CPLUSPLUS = 1 ] ; then
308                     # determine linker and options for C++ code
309                     if [ `which c++` ] ; then
310                         # use Sun c++
311                         LINK="c++"
312                     elif [ `type g++` ] ; then
313                         # use g++
314                         LINK="g++"
315                     else
316                         echo "mklib: warning: can't find C++ comiler, trying CC."
317                         LINK="CC"
318                     fi
319                 else
320                     # use native Sun linker for C code
321                     LINK="ld"
322                 fi
323             fi
324
325             # linker options
326             if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
327                 # SunOS tools, -G to make shared libs
328                 OPTS="-G"
329             else
330                 # gcc linker
331                 # Check if objects are 32-bit and we're running in 64-bit
332                 # environment.  If so, pass -m32 flag to linker.
333                 set ${OBJECTS}
334                 ABI32=`file $1 | grep 32-bit`
335                 if [ "${ABI32}" ] ; then
336                     OPTS="-m32 -shared -Wl,-Bdynamic"
337                 else
338                     OPTS="-m64 -shared -Wl,-Bdynamic"
339                 fi
340             fi
341
342             # Check if objects are SPARC v9
343             # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
344             set ${OBJECTS}
345             SPARCV9=`file $1 | grep SPARCV9`
346             if [ "${SPARCV9}" ] ; then
347                 OPTS="${OPTS} -xarch=v9"
348             fi
349
350             # for debug:
351             #echo "mklib: linker is" ${LINK} ${OPTS}
352             if [ $NOPREFIX = 1 ] ; then
353                 rm -f ${LIBNAME}
354                 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
355             else
356                 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
357                 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
358                 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
359             fi
360             FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
361         fi
362         ;;
363
364     'FreeBSD')
365         # we assume gcc
366
367         if [ "x$LINK" = "x" ] ; then
368             # -linker was not specified so set default link command now
369             if [ $CPLUSPLUS = 1 ] ; then
370                 LINK=g++
371             else
372                 LINK=gcc
373             fi
374         fi
375
376         if [ $NOPREFIX = 1 ] ; then
377             # No "lib" or ".so" part
378             echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
379             OPTS="-shared"
380             rm -f ${LIBNAME}
381             ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
382             FINAL_LIBS=${LIBNAME}
383         elif [ $STATIC = 1 ] ; then
384             STLIB="lib${LIBNAME}.a"
385             echo "mklib: Making FreeBSD static library: " ${STLIB}
386             rm -f ${STLIB}
387             ar cq ${STLIB} ${OBJECTS}
388             ranlib ${STLIB}
389             FINAL_LIBS=${STLIB}
390         else
391             SHLIB="lib${LIBNAME}.so.${MAJOR}"
392             OPTS="-shared -Wl,-soname,${SHLIB}"
393             echo "mklib: Making FreeBSD shared library: " ${SHLIB}
394             rm -f ${SHLIB}
395             ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
396             ln -sf ${SHLIB} "lib${LIBNAME}.so"
397             FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
398         fi
399         ;;
400
401     'NetBSD')
402         if [ $STATIC = 1 ] ; then
403             LIBNAME="lib${LIBNAME}_pic.a"
404             echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
405             rm -f ${LIBNAME}
406             ar cq ${LIBNAME} ${OBJECTS}
407             ranlib ${LIBNAME}
408             FINAL_LIBS=${LIBNAME}
409         else
410             LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
411             echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
412             rm -f ${LIBNAME}
413             ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
414             FINAL_LIBS=${LIBNAME}
415         fi
416         ;;
417
418     'IRIX' | 'IRIX64')
419         if [ $STATIC = 1 ] ; then
420             LIBNAME="lib${LIBNAME}.a"
421             rm -f ${LIBNAME}
422             ar rc ${LIBNAME} ${OBJECTS}
423             FINAL_LIBS=${LIBNAME}
424         else
425             LIBNAME="lib${LIBNAME}.so"  # prefix with "lib", suffix with ".so"
426
427             # examine first object to determine ABI
428             set ${OBJECTS}
429             ABI_O32=`file $1 | grep 'ELF 32-bit'`
430             ABI_N32=`file $1 | grep 'ELF N32'`
431             ABI_N64=`file $1 | grep 'ELF 64-bit'`
432             if [ "${ABI_O32}" ] ; then
433                 OPTS="-32 -shared -all"
434                 ABI="o32-bit"
435             elif [ "${ABI_N32}" ] ; then
436                 OPTS="-n32 -shared -all"
437                 ABI="n32-bit"
438             elif [ "${ABI_N64}" ] ; then
439                 OPTS="-64 -shared -all"
440                 ABI="64-bit"
441             else
442                 echo "Error: Unexpected IRIX ABI!"
443                 exit 1
444             fi
445
446             if [ $CPLUSPLUS = 1 ] ; then
447                 LINK="CC"
448             else
449                 LINK="ld"
450             fi
451
452             echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
453             ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
454             FINAL_LIBS=${LIBNAME}
455         fi
456         ;;
457
458     'linux-cygwin')
459         LIBNAME="lib${LIBNAME}.a"
460         echo "mklib: Making linux-cygwin library: " ${LIBNAME}
461         rm -f ${LIBNAME}
462         gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
463         FINAL_LIBS=${LIBNAME}
464         ;;
465
466     'HP-UX')
467         if [ $STATIC = 1 ] ; then
468             LIBNAME="lib${LIBNAME}.a"
469             echo "mklib: Making HP-UX static library: " ${LIBNAME}
470             rm -f ${LIBNAME}
471             ar -ruv ${LIBNAME} ${OBJECTS}
472             FINAL_LIBS=${LIBNAME}
473         else
474             # HP uses a .2 for their current GL/GLU libraries
475             if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
476                MAJOR=2
477             fi
478             RUNLIB="lib${LIBNAME}.${MAJOR}"
479             DEVLIB="lib${LIBNAME}.sl"
480             echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
481             ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
482             ln -s ${RUNLIB} ${DEVLIB}
483             FINAL_LIBS="${RUNLIB} ${DEVLIB}"
484         fi
485         ;;
486
487     'AIX' )
488         # examine first object to determine ABI
489         set ${OBJECTS}
490         ABI_64=`file $1 | grep '64-bit'`
491         if [ "${ABI_64}" ] ; then
492             X64="-X64"
493             Q64="-q64"
494             OFILE=shr_64.o
495         else
496             OFILE=shr.o  #Want to be consistent with the IBM libGL.a
497         fi
498
499         if [ $STATIC = 1 ] ; then
500             LIBNAME="lib${LIBNAME}.a"
501             echo "mklib: Making AIX static library: " ${LIBNAME}
502             ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
503             FINAL_LIBS=${LIBNAME}
504         else
505             EXPFILE="lib${LIBNAME}.exp"
506             LIBNAME="lib${LIBNAME}.a"  # shared objects are still stored in the .a libraries
507             OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
508             rm -f ${EXPFILE} ${OFILE}
509             NM="/bin/nm -eC ${X64}"
510             echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
511             ${NM} ${OBJECTS} | awk '{
512             if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
513             && ( substr($1,1,1) != ".")) {
514                     if (substr ($1, 1, 7) != "__sinit" &&
515                             substr ($1, 1, 7) != "__sterm") {
516                             if (substr ($1, 1, 5) == "__tf1")
517                                 print (substr ($1, 7))
518                             else if (substr ($1, 1, 5) == "__tf9")
519                                 print (substr ($1, 15))
520                             else
521                                 print $1
522                         }
523                 }
524             }' | sort -u >> ${EXPFILE}
525
526             # On AIX a shared library is linked differently when
527             # you want to dlopen the file
528             if [ $DLOPEN = "1" ] ; then
529                 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
530             else
531                 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
532                 ar ${X64} -r ${LIBNAME} ${OFILE}
533             fi
534
535             FINAL_LIBS="${LIBNAME}"
536         fi
537         ;;
538
539     'OpenSTEP')
540         LIBNAME="lib${LIBNAME}.a"
541         echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
542         libtool -static -o ${LIBNAME} - ${OBJECTS}
543         FINAL_LIBS=${LIBNAME}
544         ;;
545
546     'OSF1')
547         if [ $STATIC = 1 ] ; then
548             LIBNAME="lib${LIBNAME}.a"
549             echo "mklib: Making OSF/1 static library: " ${LIBNAME}
550             rm -f ${LIBNAME}
551             ar -ruv ${LIBNAME} ${OBJECTS}
552             FINAL_LIBS=${LIBNAME}
553         else
554             VERSION="${MAJOR}.${MINOR}"
555             LIBNAME="lib${LIBNAME}.so"
556             echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
557             if [ "x$LINK" = "x" ] ; then
558                 if [ $CPLUSPLUS = 1 ] ; then
559                     LINK=cxx
560                 else
561                     LINK=cc
562                 fi
563             fi
564             rm -f ${LIBNAME}.${VERSION}
565             ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
566             ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
567             FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
568         fi
569         ;;
570
571     'Darwin')
572         if [ $STATIC = 1 ] ; then
573             LIBNAME="lib${LIBNAME}.a"
574             echo "mklib: Making Darwin static library: " ${LIBNAME}
575             LINK="ar"
576             OPTS="-ruvs"
577             ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
578             FINAL_LIBS=${LIBNAME}
579         else
580             # On Darwin a .bundle is used for a library that you want to dlopen
581             if [ $DLOPEN = "1" ] ; then
582                 LIBSUFFIX="bundle"
583                 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
584             else
585                 LIBSUFFIX="dylib"
586                 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
587             fi
588             LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
589             LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
590
591             # examine first object to determine ABI
592             set ${OBJECTS}
593             ABI_PPC=`file $1 | grep 'object ppc'`
594             ABI_I386=`file $1 | grep 'object i386'`
595             if [ "${ABI_PPC}" ] ; then
596                 OPTS="${OPTS} -arch ppc"
597             fi
598             if [ "${ABI_I386}" ] ; then
599                 OPTS="${OPTS} -arch i386"
600             fi
601
602             # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
603             # to OPTS here?
604
605             # determine linker
606             if [ $CPLUSPLUS = 1 ] ; then
607                 LINK="g++"
608             else
609                 LINK="cc"
610             fi
611
612             echo "mklib: Making Darwin shared library: " ${LIBNAME}
613             ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
614             ln -s ${LIBNAME} ${LINKNAME}
615             FINAL_LIBS="${LIBNAME} ${LINKNAME}"
616         fi
617         ;;
618
619     'LynxOS')
620         LIBNAME="lib${LIBNAME}.a"
621         echo "mklib: Making LynxOS static library: " ${LIBNAME}
622         rm -f ${LIBNAME}
623         ar ru ${LIBNAME} ${OBJECTS}
624         FINAL_LIBS=${LIBNAME}
625         ;;
626
627     'BeOS')
628         if [ $STATIC = 1 ] ; then
629             LIBNAME="lib${LIBNAME}.a"
630             echo "mklib: Making BeOS static library: " ${LIBNAME}
631             ar -cru "${LIBNAME}" ${OBJECTS}
632         else
633             LIBNAME="lib${LIBNAME}.so"
634             echo "mklib: Making BeOS shared library: " ${LIBNAME}
635             gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
636             mimeset -f "${LIBNAME}"
637             # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
638             setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
639         fi
640         FINAL_LIBS=${LIBNAME}
641         ;;
642
643     'QNX')
644         LIBNAME="lib${LIBNAME}.a"
645         echo "mklib: Making QNX library: " ${LIBNAME}
646         wlib ${LIBNAME} ${OBJECTS}
647         FINAL_LIBS=${LIBNAME}
648         ;;
649
650     'MorphOS')
651         LIBNAME="lib${LIBNAME}.a"
652         echo "mklib: Making MorphOS library: " ${LIBNAME}
653         ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
654         FINAL_LIBS="${LIBNAME}"
655         ;;
656
657     'icc' | 'icc-istatic')
658         # Intel C compiler
659         # This should get merged into the Linux code, above, since this isn't
660         # really a different architecture.
661         LIBNAME="lib${LIBNAME}"     # prefix with "lib"
662
663         if [ $STATIC = 1 ] ; then
664             echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
665             LINK="ar"
666             OPTS="-ruv"
667             # make lib
668             ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
669             # finish up
670             FINAL_LIBS="${LIBNAME}.a"
671         else
672             if [ $ARCH = icc-istatic ] ; then
673                  OPTS="-shared -i-static -cxxlib-icc"
674             else
675                  OPTS="-shared"
676             fi
677             VERSION="${MAJOR}.${MINOR}.${PATCH}"
678             echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
679
680             if [ $CPLUSPLUS = 1 ] ; then
681                 LINK="icpc"
682             else
683                 LINK="icc"
684             fi
685             # rm any old libs
686             rm -f ${LIBNAME}.so.${VERSION}
687             rm -f ${LIBNAME}.so.${MAJOR}
688             rm -f ${LIBNAME}.so
689             # make lib
690             ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
691             # make usual symlinks
692             ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
693             ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
694             # finish up
695             FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
696         fi
697         ;;
698
699     'aix-gcc')
700         # AIX with gcc
701         if [ $STATIC = 1 ] ; then
702             LIBNAME="lib${LIBNAME}.a"
703             echo "mklib: Making AIX GCC static library: " ${LIBNAME}
704             rm -f ${LIBNAME}
705             ar ru ${LIBNAME} ${OBJECTS}
706             FINAL_LIBS=${LIBNAME}
707         else
708             LIBNAME="lib${LIBNAME}.so"  # prefix with "lib", suffix with ".so"
709             echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
710             # remove old lib
711             rm -f ${LIBNAME}
712             # make the lib
713             gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
714             # NOTE: the application linking with this library must specify
715             # the -Wl,-brtl flags to gcc
716             FINAL_LIBS=${LIBNAME}
717         fi
718         ;;
719
720     'ultrix')
721         # XXX untested
722         if [ $STATIC = 0 ] ; then
723             echo "mklib: Warning shared libs not supported on Ultrix"
724         fi
725         LIBNAME="lib${LIBNAME}.a"
726         echo "mklib: Making static library for Ultrix: " ${LIBNAME}
727         rm -f ${LIBNAME}
728         ar ru ${LIBNAME} ${OBJECTS}
729         FINAL_LIBS="${LIBNAME}"
730         ;;
731
732      CYGWIN*)
733         # GCC-based environment
734         CYGNAME="cyg${LIBNAME}"     # prefix with "cyg"
735         LIBNAME="lib${LIBNAME}"     # prefix with "lib"
736
737         if [ $STATIC = 1 ] ; then
738             echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
739             LINK="ar"
740             OPTS="-ru"
741             # make lib
742             ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
743             ranlib ${LIBNAME}.a
744             # finish up
745             FINAL_LIBS=${LIBNAME}.a
746         else
747             OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
748             echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
749
750             if [ $CPLUSPLUS = 1 ] ; then
751                 LINK="g++"
752             else
753                 LINK="gcc"
754             fi
755
756             # rm any old libs
757             rm -f ${LIBNAME}-${MAJOR}.dll
758             rm -f ${LIBNAME}.dll.a
759             rm -f ${LIBNAME}.a
760
761             # make lib
762             ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
763             # make usual symlinks
764             ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
765             # finish up
766             FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
767             # special case for installing in bin
768             FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
769         fi
770         ;;
771
772     'example')
773         # If you're adding support for a new architecture, you can
774         # start with this:
775         if [ $STATIC = 1 ] ; then
776             LIBNAME="lib${LIBNAME}.a"
777             echo "mklib: Making static library for example arch: " ${LIBNAME}
778             rm -f ${LIBNAME}
779             ar rv ${LIBNAME} ${OBJECTS}
780             FINAL_LIBS="${LIBNAME}"
781         else
782             LIBNAME="lib${LIBNAME}.so"  # prefix with "lib", suffix with ".so"
783             echo "mklib: Making shared library for example arch: " ${LIBNAME}
784             ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
785             FINAL_LIBS="${LIBNAME}"
786         fi
787         ;;
788
789     *)
790         echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
791         echo "mklib: Please add necessary commands to mklib script."
792         ;;
793 esac
794
795
796 #
797 # Put library files into installation directory if specified.
798 #
799 if [ ${INSTALLDIR} != "." ] ; then
800     echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
801     mv ${FINAL_LIBS} ${INSTALLDIR}/
802 fi