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