remove .a file before creating new one
[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-2005 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 CPLUSPLUS=0
38 STATIC=0
39 INSTALLDIR="."
40 ARCH="auto"
41 ARCHOPT=""
42 NOPREFIX=0
43 EXPORTS=""
44
45
46 #
47 # Parse arguments
48 #
49 while true
50 do
51 case $1 in
52 '-h' | '--help')
53 echo 'Usage: mklib [options] objects'
54 echo 'Create a shared library from object files.'
55 echo ' -o LIBRARY specifies the name of the resulting library, without'
56 echo ' the leading "lib" or any suffix.'
57 echo ' (eg: "-o GL" might result in "libGL.so" being made)'
58 echo ' -major N specifies major version number (default is 1)'
59 echo ' -minor N specifies minor version number (default is 0)'
60 echo ' -patch N specifies patch version number (default is 0)'
61 echo ' -lLIBRARY specifies a dependency on LIBRARY'
62 echo ' -LDIR search in DIR for library dependencies'
63 echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
64 echo ' Not observed on all systems at this time.'
65 echo ' -cplusplus link with C++ runtime'
66 echo ' -static make a static library (default is dynamic/shared)'
67 echo ' -install DIR put resulting library file(s) in DIR'
68 echo ' -arch ARCH override using `uname` to determine host system'
69 echo ' -archopt OPT specify an extra achitecture-specific option OPT'
70 echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
71 echo ' -exports FILE only export the symbols listed in FILE'
72 echo ' -h, --help display this information and exit'
73 exit 1
74 ;;
75 '-o')
76 shift 1;
77 LIBNAME=$1
78 ;;
79 '-major')
80 shift 1;
81 MAJOR=$1
82 ;;
83 '-minor')
84 shift 1;
85 MINOR=$1
86 ;;
87 '-patch')
88 shift 1;
89 PATCH=$1
90 ;;
91 '-linker')
92 shift 1;
93 LINK=$1
94 ;;
95 -l*)
96 DEPS="$DEPS $1"
97 ;;
98 -L*)
99 DEPS="$DEPS $1"
100 ;;
101 '-cplusplus')
102 CPLUSPLUS=1
103 ;;
104 '-static')
105 STATIC=1
106 ;;
107 '-install')
108 shift 1;
109 INSTALLDIR=$1
110 ;;
111 '-arch')
112 shift 1;
113 ARCH=$1
114 ;;
115 '-archopt')
116 shift 1;
117 ARCHOPT=$1
118 ;;
119 '-noprefix')
120 NOPREFIX=1
121 ;;
122 '-exports')
123 shift 1;
124 EXPORTS=$1
125 ;;
126 -*)
127 echo "mklib: Unknown option: " $1 ;
128 exit 1
129 ;;
130 *)
131 # This should be the first object file, stop parsing
132 break
133 esac
134 shift 1
135 done
136 OBJECTS=$@
137
138
139 if [ ${ARCH} = "auto" ] ; then
140 ARCH=`uname`
141 fi
142
143
144 #
145 # Error checking
146 #
147 if [ "x${LIBNAME}" = "x" ] ; then
148 echo "mklib: Error: no library name specified"
149 exit 1
150 fi
151 if [ "x${OBJECTS}" = "x" ] ; then
152 echo "mklib: Error: no object files specified"
153 exit 1
154 fi
155
156
157 #
158 # Debugging info
159 #
160 if [ ] ; then
161 echo "-----------------"
162 echo ARCH is $ARCH
163 echo LIBNAME is $LIBNAME
164 echo MAJOR is $MAJOR
165 echo MINOR is $MINOR
166 echo PATCH is $PATCH
167 echo DEPS are $DEPS
168 echo "EXPORTS in" $EXPORTS
169 echo "-----------------"
170 fi
171
172
173 #
174 # OK, make the library now
175 #
176 case $ARCH in
177
178 'Linux' | 'OpenBSD')
179 # we assume gcc
180
181 if [ "x$LINK" = "x" ] ; then
182 # -linker was not specified so set default link command now
183 if [ $CPLUSPLUS = 1 ] ; then
184 LINK=g++
185 else
186 LINK=gcc
187 fi
188 fi
189
190 if [ $NOPREFIX = 1 ] ; then
191 # No "lib" or ".so" part
192 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
193 #OPTS="-shared -Wl,-soname,${LIBNAME}" # soname???
194 OPTS="-shared"
195
196 # Check if objects are 32-bit and we're running in 64-bit
197 # environment. If so, pass -m32 flag to linker.
198 set ${OBJECTS}
199 ABI32=`file $1 | grep 32-bit`
200 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
201 OPTS="-m32 ${OPTS}"
202 fi
203
204 rm -f ${LIBNAME}
205 # make lib
206 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
207 # finish up
208 FINAL_LIBS="${LIBNAME}"
209 elif [ $STATIC = 1 ] ; then
210 LIBNAME="lib${LIBNAME}" # prefix with "lib"
211 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
212 rm -f ${LIBNAME}.a
213 ar -ru ${LIBNAME}.a ${OBJECTS}
214 ranlib ${LIBNAME}.a
215 # finish up
216 FINAL_LIBS=${LIBNAME}.a
217 else
218 LIBNAME="lib${LIBNAME}" # prefix with "lib"
219 if [ $ARCH = 'Linux' ] ; then
220 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
221 else
222 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
223 fi
224 if [ $EXPORTS ] ; then
225 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
226 # Make the 'exptmp' file for --version-script option
227 echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
228 echo "global:" >> exptmp
229 sed 's/$/;/' ${EXPORTS} >> exptmp
230 echo "local:" >> exptmp
231 echo "*;" >> exptmp
232 echo "};" >> exptmp
233 OPTS="${OPTS} -Xlinker --version-script=exptmp"
234 # exptmp is removed below
235 fi
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 [ x${PATCH} = "x" ] ; then
246 VERSION="${MAJOR}.${MINOR}"
247 else
248 VERSION="${MAJOR}.${MINOR}.${PATCH}"
249 fi
250
251 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
252
253 # rm any old libs
254 rm -f ${LIBNAME}.so.${VERSION}
255 rm -f ${LIBNAME}.so.${MAJOR}
256 rm -f ${LIBNAME}.so
257
258 # make lib
259 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
260 # make usual symlinks
261 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
262 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
263 # finish up
264 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
265 # rm -f exptmp
266 fi
267 ;;
268
269 'SunOS')
270 if [ $STATIC = 1 ] ; then
271 LIBNAME="lib${LIBNAME}.a"
272 echo "mklib: Making SunOS static library: " ${LIBNAME}
273 rm -f ${LIBNAME}
274 ar -ruv ${LIBNAME} ${OBJECTS}
275 FINAL_LIBS=${LIBNAME}
276 else
277 LIBNAME="lib${LIBNAME}.so"
278 echo "mklib: Making SunOS shared library: " ${LIBNAME}
279 # XXX OPTS for gcc should be -shared, but that doesn't work.
280 # Using -G does work though.
281 OPTS="-G"
282 if [ "x$LINK" = "x" ] ; then
283 # -linker was not specified, choose default linker now
284 if [ $CPLUSPLUS = 1 ] ; then
285 # determine linker and options for C++ code
286 if [ `which c++` ] ; then
287 # use Sun c++
288 LINK="c++"
289 elif [ `type g++` ] ; then
290 # use g++
291 LINK="g++"
292 else
293 echo "mklib: warning: can't find C++ comiler, trying CC."
294 LINK="CC"
295 fi
296 else
297 # use native Sun linker for C code
298 LINK="ld"
299 fi
300 fi
301 echo "mklib: linker is" ${LINK} ${OPTS}
302 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
303 ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
304 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
305 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
306 fi
307 ;;
308
309 'FreeBSD')
310 if [ $NOPREFIX = 1 ] ; then
311 # No "lib" or ".so" part
312 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
313 rm -f ${LIBNAME}
314 ld -Bshareable -o ${LIBNAME} ${OBJECTS}
315 FINAL_LIBS=${LIBNAME}
316 elif [ $STATIC = 1 ] ; then
317 STLIB="lib${LIBNAME}.a"
318 echo "mklib: Making FreeBSD static library: " ${STLIB}
319 rm -f ${STLIB}
320 ar cq ${STLIB} ${OBJECTS}
321 ranlib ${STLIB}
322 FINAL_LIBS=${STLIB}
323 else
324 SHLIB="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
325 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
326 rm -f ${SHLIB}
327 ld -Bshareable -o ${SHLIB} ${OBJECTS}
328 # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
329 FINAL_LIBS=${SHLIB}
330 fi
331 ;;
332
333 'NetBSD')
334 if [ $STATIC = 1 ] ; then
335 LIBNAME="lib${LIBNAME}_pic.a"
336 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
337 rm -f ${LIBNAME}
338 ar cq ${LIBNAME} ${OBJECTS}
339 ranlib ${LIBNAME}
340 FINAL_LIBS=${LIBNAME}
341 else
342 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
343 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
344 rm -f ${LIBNAME}
345 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
346 FINAL_LIBS=${LIBNAME}
347 fi
348 ;;
349
350 'IRIX' | 'IRIX64')
351 if [ $STATIC = 1 ] ; then
352 LIBNAME="lib${LIBNAME}.a"
353 rm -f ${LIBNAME}
354 ar rc ${LIBNAME} ${OBJECTS}
355 FINAL_LIBS=${LIBNAME}
356 else
357 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
358 # XXX we should run 'file' on the first object file to determine
359 # if it's o32, n32 or 64 format, as we do for Linux above.
360 if [ $ARCHOPT = "64" ] ; then
361 # 64-bit ABI
362 OPTS="-64 -shared -all"
363 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
364 elif [ $ARCHOPT = "o32" ] ; then
365 # old 32-bit ABI
366 OPTS="-32 -shared -all"
367 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
368 else
369 # new 32-bit ABI
370 OPTS="-n32 -shared -all"
371 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
372 fi
373 if [ $CPLUSPLUS = 1 ] ; then
374 LINK="CC"
375 else
376 LINK="ld"
377 fi
378 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
379 FINAL_LIBS=${LIBNAME}
380 fi
381 ;;
382
383 'linux-cygwin')
384 LIBNAME="lib${LIBNAME}.a"
385 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
386 rm -f ${LIBNAME}
387 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
388 FINAL_LIBS=${LIBNAME}
389 ;;
390
391 'HP-UX')
392 if [ $STATIC = 1 ] ; then
393 LIBNAME="lib${LIBNAME}.a"
394 echo "mklib: Making HP-UX static library: " ${LIBNAME}
395 rm -f ${LIBNAME}
396 ar -ruv ${LIBNAME} ${OBJECTS}
397 FINAL_LIBS=${LIBNAME}
398 else
399 RUNLIB="lib${LIBNAME}.${MAJOR}"
400 DEVLIB="lib${LIBNAME}.sl"
401 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
402 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
403 ln -s ${RUNLIB} ${DEVLIB}
404 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
405 fi
406 ;;
407
408 'AIX' | 'AIX64')
409 if [ $ARCH = "AIX64" ] ; then
410 X64="-X64"
411 fi
412
413 if [ $STATIC = 1 ] ; then
414 LIBNAME="lib${LIBNAME}.a"
415 echo "mklib: Making AIX static library: " ${LIBNAME}
416 rm -f ${LIBNAME}
417 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
418 FINAL_LIBS=${LIBNAME}
419 else
420 EXPFILE="lib${LIBNAME}.exp"
421 OFILE=shr.o #Want to be consistent with the IBM libGL.a
422 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
423 if [ $ARCH = "AIX64" ] ; then
424 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry -q64"
425 else
426 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry"
427 fi
428 rm -f ${EXPFILE} ${OFILE}
429 NM="/bin/nm -eC ${X64}"
430 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
431 ${NM} ${OBJECTS} | awk '{
432 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
433 && ( substr($1,1,1) != ".")) {
434 if (substr ($1, 1, 7) != "__sinit" &&
435 substr ($1, 1, 7) != "__sterm") {
436 if (substr ($1, 1, 5) == "__tf1")
437 print (substr ($1, 7))
438 else if (substr ($1, 1, 5) == "__tf9")
439 print (substr ($1, 15))
440 else
441 print $1
442 }
443 }
444 }' | sort -u >> ${EXPFILE}
445 cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
446 ar ${X64} -r ${LIBNAME} ${OFILE}
447 FINAL_LIBS="${LIBNAME}"
448 fi
449 ;;
450
451 'OpenSTEP')
452 LIBNAME="lib${LIBNAME}.a"
453 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
454 libtool -static -o ${LIBNAME} - ${OBJECTS}
455 FINAL_LIBS=${LIBNAME}
456 ;;
457
458 'OSF1')
459 if [ $STATIC = 1 ] ; then
460 LIBNAME="lib${LIBNAME}.a"
461 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
462 rm -f ${LIBNAME}
463 ar -ruv ${LIBNAME} ${OBJECTS}
464 FINAL_LIBS=${LIBNAME}
465 else
466 VERSION="${MAJOR}.${MINOR}"
467 LIBNAME="lib${LIBNAME}.so"
468 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
469 if [ "x$LINK" = "x" ] ; then
470 if [ $CPLUSPLUS = 1 ] ; then
471 LINK=cxx
472 else
473 LINK=cc
474 fi
475 fi
476 rm -f ${LIBNAME}.${VERSION}
477 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
478 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
479 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
480 fi
481 ;;
482
483 'Darwin')
484 if [ $STATIC = 1 ] ; then
485 LIBNAME="lib${LIBNAME}.a"
486 echo "mklib: Making Darwin static library: " ${LIBNAME}
487 LINK="ar"
488 OPTS="-ruv"
489 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
490 FINAL_LIBS=${LIBNAME}
491 else
492 LIBNAME="lib${LIBNAME}.dylib"
493 echo "mklib: Making Darwin shared library: " ${LIBNAME}
494 FLAGS="-dynamiclib -multiply_defined suppress"
495 if [ $CPLUSPLUS = 1 ] ; then
496 LINK="g++"
497 else
498 LINK="cc"
499 fi
500 ${LINK} ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
501 FINAL_LIBS=${LIBNAME}
502 fi
503 ;;
504
505 'LynxOS')
506 LIBNAME="lib${LIBNAME}.a"
507 echo "mklib: Making LynxOS static library: " ${LIBNAME}
508 rm -f ${LIBNAME}
509 ar ru ${LIBNAME} ${OBJECTS}
510 FINAL_LIBS=${LIBNAME}
511 ;;
512
513 'BeOS')
514 if [ $STATIC = 1 ] ; then
515 LIBNAME="lib${LIBNAME}.a"
516 echo "mklib: Making BeOS static library: " ${LIBNAME}
517 ar -cru "${LIBNAME}" ${OBJECTS}
518 else
519 LIBNAME="lib${LIBNAME}.so"
520 echo "mklib: Making BeOS shared library: " ${LIBNAME}
521 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
522 mimeset -f "${LIBNAME}"
523 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
524 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
525 fi
526 FINAL_LIBS=${LIBNAME}
527 ;;
528
529 'QNX')
530 LIBNAME="lib${LIBNAME}.a"
531 echo "mklib: Making QNX library: " ${LIBNAME}
532 wlib ${LIBNAME} ${OBJECTS}
533 FINAL_LIBS=${LIBNAME}
534 ;;
535
536 'MorphOS')
537 LIBNAME="lib${LIBNAME}.a"
538 echo "mklib: Making MorphOS library: " ${LIBNAME}
539 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
540 FINAL_LIBS="${LIBNAME}"
541 ;;
542
543 'icc')
544 # Intel C compiler
545 # This should get merged into the Linux code, above, since this isn't
546 # really a different architecture.
547 LIBNAME="lib${LIBNAME}" # prefix with "lib"
548
549 if [ $STATIC = 1 ] ; then
550 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
551 LINK="ar"
552 OPTS="-ruv"
553 # make lib
554 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
555 # finish up
556 FINAL_LIBS="${LIBNAME}.a"
557 else
558 OPTS="-shared"
559 VERSION="${MAJOR}.${MINOR}.${PATCH}"
560 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
561
562 if [ $CPLUSPLUS = 1 ] ; then
563 LINK="icc"
564 else
565 LINK="icc"
566 fi
567 # rm any old libs
568 rm -f ${LIBNAME}.so.${VERSION}
569 rm -f ${LIBNAME}.so.${MAJOR}
570 rm -f ${LIBNAME}.so
571 # make lib
572 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
573 # make usual symlinks
574 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
575 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
576 # finish up
577 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
578 fi
579 ;;
580
581 'aix-gcc')
582 # AIX with gcc
583 if [ $STATIC = 1 ] ; then
584 LIBNAME="lib${LIBNAME}.a"
585 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
586 rm -f ${LIBNAME}
587 ar ru ${LIBNAME} ${OBJECTS}
588 FINAL_LIBS=${LIBNAME}
589 else
590 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
591 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
592 # remove old lib
593 rm -f ${LIBNAME}
594 # make the lib
595 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
596 # NOTE: the application linking with this library must specify
597 # the -Wl,-brtl flags to gcc
598 FINAL_LIBS=${LIBNAME}
599 fi
600 ;;
601
602 'ultrix')
603 # XXX untested
604 if [ $STATIC = 0 ] ; then
605 echo "mklib: Warning shared libs not supported on Ultrix"
606 fi
607 LIBNAME="lib${LIBNAME}.a"
608 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
609 rm -f ${LIBNAME}
610 ar ru ${LIBNAME} ${OBJECTS}
611 FINAL_LIBS="${LIBNAME}"
612 ;;
613
614 CYGWIN*)
615 # GCC-based environment
616 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
617 LIBNAME="lib${LIBNAME}" # prefix with "lib"
618
619 if [ $STATIC = 1 ] ; then
620 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
621 LINK="ar"
622 OPTS="-ru"
623 # make lib
624 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
625 ranlib ${LIBNAME}.a
626 # finish up
627 FINAL_LIBS=${LIBNAME}.a
628 else
629 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
630 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
631
632 if [ $CPLUSPLUS = 1 ] ; then
633 LINK="g++"
634 else
635 LINK="gcc"
636 fi
637
638 # rm any old libs
639 rm -f ${LIBNAME}-${MAJOR}.dll
640 rm -f ${LIBNAME}.dll.a
641 rm -f ${LIBNAME}.a
642
643 # make lib
644 ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
645 # make usual symlinks
646 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
647 # finish up
648 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
649 # special case for installing in bin
650 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
651 fi
652 ;;
653
654 'example')
655 # If you're adding support for a new architecture, you can
656 # start with this:
657 if [ $STATIC = 1 ] ; then
658 LIBNAME="lib${LIBNAME}.a"
659 echo "mklib: Making static library for example arch: " ${LIBNAME}
660 rm -f ${LIBNAME}
661 ar rv ${LIBNAME} ${OBJECTS}
662 FINAL_LIBS="${LIBNAME}"
663 else
664 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
665 echo "mklib: Making shared library for example arch: " ${LIBNAME}
666 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
667 FINAL_LIBS="${LIBNAME}"
668 fi
669 ;;
670
671 *)
672 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
673 echo "mklib: Please add necessary commands to mklib script."
674 ;;
675 esac
676
677
678 #
679 # Put library files into installation directory if specified.
680 #
681 if [ ${INSTALLDIR} != "." ] ; then
682 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
683 mv ${FINAL_LIBS} ${INSTALLDIR}/
684 fi