3 # Make a shared library.
4 # Basically do a switch/case depending on the OS and make a shared (or static)
5 # library conforming to that OS.
9 # mklib [options] objects ...
11 # -o LIBRARY specifies the name of resulting library
12 # ("-o GL" for example, might result in "libGL.so" being made)
13 # -major N specifies major version number (default is 1)
14 # -minor N specifies minor version number (default is 0)
15 # -patch N specifies patch version number (default is 0)
16 # -lLIBRARY specifies a dependency on LIBRARY
17 # -LDIR search in DIR for library dependencies
18 # -cplusplus link with C++ runtime
19 # -static make a static library (default is dynamic/shared)
20 # -install DIR move resulting library file(s) to DIR
21 # -arch ARCH override using `uname` to determine architecture
22 # -archopt OPT specify an extra achitecture-specific option OPT
23 # -noprefix don't prefix library name with "lib" or any suffix
24 # -exports FILE only export the symbols listed in FILE
26 # The library name should just be "GL" or "GLU", etc. The 'lib' prefix
27 # will be added here if needed, as well as the ".so" or ".a" suffix,
28 # etc (unless the -noprefix option is used).
30 # objects should be: foo.o bar.o etc.o
32 # Environment variables recognized:
33 # CC C compiler command
34 # CXX C++ compiler command
61 '-o') shift 1; LIBNAME
=$1;;
62 '-major') shift 1; MAJOR
=$1;;
63 '-minor') shift 1; MINOR
=$1;;
64 '-patch') shift 1; PATCH
=$1;;
65 -l*) DEPS
="$DEPS $1";;
66 -L*) DEPS
="$DEPS $1";;
67 '-cplusplus') CPLUSPLUS
=1;;
69 '-install') shift 1; INSTALLDIR
=$1;;
70 '-arch') shift 1; ARCH
=$1;;
71 '-archopt') shift 1; ARCHOPT
=$1;;
72 '-noprefix') NOPREFIX
=1;;
73 '-exports') shift 1; EXPORTS
=$1;;
74 -*) echo "mklib: Unknown option: " $1 ; exit 1;;
81 if [ ${ARCH} = "auto" ] ; then
89 if [ "x${LIBNAME}" = "x" ] ; then
90 echo "mklib: Error: no library name specified"
93 if [ "x${OBJECTS}" = "x" ] ; then
94 echo "mklib: Error: no object files specified"
103 echo "-----------------"
105 echo LIBNAME is
$LIBNAME
110 echo "EXPORTS in" $EXPORTS
111 echo "-----------------"
116 # OK, make the library now
123 # Set default compilers if env vars not set
124 if [ "x$CXX" = "x" ] ; then
127 if [ "x$CC" = "x" ] ; then
131 if [ $NOPREFIX = 1 ] ; then
132 # No "lib" or ".so" part
133 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
134 #OPTS="-shared -Wl,-soname,${LIBNAME}" # soname???
136 if [ $CPLUSPLUS = 1 ] ; then
144 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
146 FINAL_LIBS
="${LIBNAME}"
147 elif [ $STATIC = 1 ] ; then
148 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
149 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
153 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
156 FINAL_LIBS
=${LIBNAME}.a
158 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
159 if [ $ARCH = 'Linux' ] ; then
160 OPTS
="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
162 OPTS
="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
164 if [ $EXPORTS ] ; then
165 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
166 # Make the 'exptmp' file for --version-script option
167 echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
168 echo "global:" >> exptmp
169 sed 's/$/;/' ${EXPORTS} >> exptmp
170 echo "local:" >> exptmp
173 OPTS
="${OPTS} -Xlinker --version-script=exptmp"
174 # exptmp is removed below
176 if [ x
${PATCH} = "x" ] ; then
177 VERSION
="${MAJOR}.${MINOR}"
179 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
182 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.
${VERSION}
184 if [ $CPLUSPLUS = 1 ] ; then
191 rm -f ${LIBNAME}.so.
${VERSION}
192 rm -f ${LIBNAME}.so.
${MAJOR}
196 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
197 # make usual symlinks
198 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
199 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
201 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
207 if [ $STATIC = 1 ] ; then
208 LIBNAME
="lib${LIBNAME}.a"
209 echo "mklib: Making SunOS static library: " ${LIBNAME}
211 ar -ruv ${LIBNAME} ${OBJECTS}
212 FINAL_LIBS
=${LIBNAME}
214 LIBNAME
="lib${LIBNAME}.so"
215 echo "mklib: Making SunOS shared library: " ${LIBNAME}
216 # XXX OPTS for gcc should be -shared, but that doesn't work.
217 # Using -G does work though.
218 if [ $CPLUSPLUS = 1 ] ; then
219 # determine linker and options for C++ code
220 if [ "x${CXX}" = "xg++" ] ; then
224 elif [ "x${CXX}" = "xCC" ] ; then
228 elif [ "x${CXX}" = "xc++" ] ; then
232 elif [ `which c++` ] ; then
236 elif [ `type g++` ] ; then
241 echo "mklib: warning: can't find C++ comiler, trying CC."
245 elif [ "x${CC}" = "xgcc" ] ; then
246 # use gcc for linking
250 # use native Sun linker
254 echo "mklib: linker is" ${LINK} ${OPTS}
255 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
256 ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
257 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
258 FINAL_LIBS
="${LIBNAME}.${MAJOR} ${LIBNAME}"
263 if [ $NOPREFIX = 1 ] ; then
264 # No "lib" or ".so" part
265 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
267 ld
-Bshareable -o ${LIBNAME} ${OBJECTS}
268 FINAL_LIBS
=${LIBNAME}
269 elif [ $STATIC = 1 ] ; then
270 STLIB
="lib${LIBNAME}.a"
271 echo "mklib: Making FreeBSD static library: " ${STLIB}
273 ar cq
${STLIB} ${OBJECTS}
277 SHLIB
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
278 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
280 ld
-Bshareable -o ${SHLIB} ${OBJECTS}
281 # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
287 if [ $STATIC = 1 ] ; then
288 LIBNAME
="lib${LIBNAME}_pic.a"
289 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
291 ar cq
${LIBNAME} ${OBJECTS}
293 FINAL_LIBS
=${LIBNAME}
295 LIBNAME
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
296 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
298 ld
-x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
299 FINAL_LIBS
=${LIBNAME}
304 if [ $STATIC = 1 ] ; then
305 LIBNAME
="lib${LIBNAME}.a"
307 ar rc
${LIBNAME} ${OBJECTS}
308 FINAL_LIBS
=${LIBNAME}
310 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
311 if [ $ARCHOPT = "64" ] ; then
313 OPTS
="-64 -shared -all"
314 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
315 elif [ $ARCHOPT = "o32" ] ; then
317 OPTS
="-32 -shared -all"
318 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
321 OPTS
="-n32 -shared -all"
322 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
324 if [ $CPLUSPLUS = 1 ] ; then
329 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
330 FINAL_LIBS
=${LIBNAME}
335 LIBNAME
="lib${LIBNAME}.a"
336 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
338 gnuwin32ar ruv
${LIBNAME} ${OBJECTS}
339 FINAL_LIBS
=${LIBNAME}
343 if [ $STATIC = 1 ] ; then
344 LIBNAME
="lib${LIBNAME}.a"
345 echo "mklib: Making HP-UX static library: " ${LIBNAME}
347 ar -ruv ${LIBNAME} ${OBJECTS}
348 FINAL_LIBS
=${LIBNAME}
350 RUNLIB
="lib${LIBNAME}.${MAJOR}"
351 DEVLIB
="lib${LIBNAME}.sl"
352 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
353 ld
-b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
354 ln -s ${RUNLIB} ${DEVLIB}
355 FINAL_LIBS
="${RUNLIB} ${DEVLIB}"
360 if [ $STATIC = 1 ] ; then
361 LIBNAME
="lib${LIBNAME}.a"
362 echo "mklib: Making AIX static library: " ${LIBNAME}
363 ar -ruv ${LIBNAME} ${OBJECTS}
364 FINAL_LIBS
=${LIBNAME}
366 EXPFILE
="lib${LIBNAME}.exp"
367 OFILE
=shr.o
#Want to be consistent with the IBM libGL.a
368 LIBNAME
="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
369 OPTS
="-bE:${EXPFILE} -bM:SRE -bnoentry"
370 rm -f ${EXPFILE} ${OFILE}
372 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
373 ${NM} ${OBJECTS} |
awk '{
374 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
375 && ( substr($1,1,1) != ".")) {
376 if (substr ($1, 1, 7) != "__sinit" &&
377 substr ($1, 1, 7) != "__sterm") {
378 if (substr ($1, 1, 5) == "__tf1")
379 print (substr ($1, 7))
380 else if (substr ($1, 1, 5) == "__tf9")
381 print (substr ($1, 15))
386 }' |
sort -u >> ${EXPFILE}
387 cc
${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
388 ar -r ${LIBNAME} ${OFILE}
389 FINAL_LIBS
="${LIBNAME}"
394 if [ $STATIC = 1 ] ; then
395 LIBNAME
="lib${LIBNAME}.a"
396 echo "mklib: Making AIX static library: " ${LIBNAME}
397 ar -X64 -ruv ${LIBNAME} ${OBJECTS}
398 FINAL_LIBS
=${LIBNAME}
400 EXPFILE
="lib${LIBNAME}.exp"
401 OFILE
=shr.o
#Want to be consistent with the IBM libGL.a
402 LIBNAME
="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
403 OPTS
="-bE:${EXPFILE} -bM:SRE -bnoentry -q64"
404 rm -f ${EXPFILE} ${OFILE}
405 NM
="/bin/nm -eC -X64"
406 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
407 ${NM} ${OBJECTS} |
awk '{
408 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
409 && ( substr($1,1,1) != ".")) {
410 if (substr ($1, 1, 7) != "__sinit" &&
411 substr ($1, 1, 7) != "__sterm") {
412 if (substr ($1, 1, 5) == "__tf1")
413 print (substr ($1, 7))
414 else if (substr ($1, 1, 5) == "__tf9")
415 print (substr ($1, 15))
420 }' |
sort -u >> ${EXPFILE}
421 cc
${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
422 ar -X64 -r ${LIBNAME} ${OFILE}
423 FINAL_LIBS
="${LIBNAME}"
428 LIBNAME
="lib${LIBNAME}.a"
429 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
430 libtool
-static -o ${LIBNAME} - ${OBJECTS}
431 FINAL_LIBS
=${LIBNAME}
435 if [ $STATIC = 1 ] ; then
436 LIBNAME
="lib${LIBNAME}.a"
437 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
439 ar -ruv ${LIBNAME} ${OBJECTS}
440 FINAL_LIBS
=${LIBNAME}
442 VERSION
="${MAJOR}.${MINOR}"
443 LIBNAME
="lib${LIBNAME}.so"
444 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
445 rm -f ${LIBNAME}.
${VERSION}
446 ld
-o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
447 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
448 FINAL_LIBS
="${LIBNAME} ${LIBNAME}.${VERSION}"
453 if [ $STATIC = 1 ] ; then
454 LIBNAME
="lib${LIBNAME}.a"
455 echo "mklib: Making Darwin static library: " ${LIBNAME}
458 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
459 FINAL_LIBS
=${LIBNAME}
461 LIBNAME
="${LIBNAME}.dylib"
462 echo "mklib: Making Darwin shared library: " ${LIBNAME}
463 FLAGS
="-dynamiclib -multiply_defined suppress"
464 if [ $CPLUSPLUS = 1 ] ; then
469 ${LINK} ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
470 FINAL_LIBS
=${LIBNAME}
475 LIBNAME
="lib${LIBNAME}.a"
476 echo "mklib: Making LynxOS static library: " ${LIBNAME}
478 ar ru
${LIBNAME} ${OBJECTS}
479 FINAL_LIBS
=${LIBNAME}
483 if [ $STATIC = 1 ] ; then
484 LIBNAME
="lib${LIBNAME}.a"
485 echo "mklib: Making BeOS static library: " ${LIBNAME}
486 ar -cru "${LIBNAME}" ${OBJECTS}
488 LIBNAME
="lib${LIBNAME}.so"
489 echo "mklib: Making BeOS shared library: " ${LIBNAME}
490 gcc
-nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
491 mimeset
-f "${LIBNAME}"
492 setversion
"${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D
!" -long "Powered by Mesa3D
!"
494 FINAL_LIBS=${LIBNAME}
498 LIBNAME="lib
${LIBNAME}.a
"
499 echo "mklib
: Making QNX library
: " ${LIBNAME}
500 wlib ${LIBNAME} ${OBJECTS}
501 FINAL_LIBS=${LIBNAME}
505 LIBNAME="lib
${LIBNAME}.a
"
506 echo "mklib
: Making MorphOS library
: " ${LIBNAME}
507 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
508 FINAL_LIBS="${LIBNAME}"
513 LIBNAME="lib
${LIBNAME}" # prefix with "lib
"
515 if [ $STATIC = 1 ] ; then
516 echo "mklib
: Making Intel ICC static library
: " ${LIBNAME}.a
520 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
522 FINAL_LIBS="${LIBNAME}.a
"
525 VERSION="${MAJOR}.${MINOR}.${PATCH}"
526 echo "mklib
: Making Intel ICC shared library
: " ${LIBNAME}.so.${VERSION}
528 if [ $CPLUSPLUS = 1 ] ; then
534 rm -f ${LIBNAME}.so.${VERSION}
535 rm -f ${LIBNAME}.so.${MAJOR}
538 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
539 # make usual symlinks
540 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
541 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
543 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
"
549 if [ $STATIC = 1 ] ; then
550 LIBNAME="lib
${LIBNAME}.a
"
551 echo "mklib
: Making AIX GCC static library
: " ${LIBNAME}
553 ar ru ${LIBNAME} ${OBJECTS}
554 FINAL_LIBS=${LIBNAME}
556 LIBNAME="lib
${LIBNAME}.so
" # prefix with "lib
", suffix with ".so
"
557 echo "mklib
: Making AIX GCC shared library
: " ${LIBNAME}
561 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
562 # NOTE: the application linking with this library must specify
563 # the -Wl,-brtl flags to gcc
564 FINAL_LIBS=${LIBNAME}
570 if [ $STATIC = 0 ] ; then
571 echo "mklib
: Warning shared libs not supported on Ultrix
"
573 LIBNAME="lib
${LIBNAME}.a
"
574 echo "mklib
: Making static library
for Ultrix
: " ${LIBNAME}
576 ar ru ${LIBNAME} ${OBJECTS}
577 FINAL_LIBS="${LIBNAME}"
581 # GCC-based environment
582 CYGNAME="cyg
${LIBNAME}" # prefix with "cyg
"
583 LIBNAME="lib
${LIBNAME}" # prefix with "lib
"
585 if [ $STATIC = 1 ] ; then
586 echo "mklib
: Making
" $ARCH "static library
: " ${LIBNAME}.a
590 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
593 FINAL_LIBS=${LIBNAME}.a
595 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a
"
596 echo "mklib
: Making
" $ARCH "shared library
: " ${LIBNAME}-${MAJOR}.dll
598 if [ $CPLUSPLUS = 1 ] ; then
605 rm -f ${LIBNAME}-${MAJOR}.dll
606 rm -f ${LIBNAME}.dll.a
610 ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
611 # make usual symlinks
612 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
614 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
"
615 # special case for installing in bin
616 FINAL_BINS="${CYGNAME}-${MAJOR}.dll
"
621 # If you're adding support for a new architecture, you can
623 if [ $STATIC = 1 ] ; then
624 LIBNAME="lib
${LIBNAME}.a
"
625 echo "mklib
: Making static library
for example arch
: " ${LIBNAME}
627 ar rv ${LIBNAME} ${OBJECTS}
628 FINAL_LIBS="${LIBNAME}"
630 LIBNAME="lib
${LIBNAME}.so
" # prefix with "lib
"
631 echo "mklib
: Making shared library
for example arch
: " ${LIBNAME}
632 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
633 FINAL_LIBS="${LIBNAME}"
638 echo "mklib
: ERROR
: Don
't know how to make a static/shared library for" ${ARCH}
639 echo "mklib: Please add necessary commands to mklib script."
645 # Put library files into installation directory if specified.
647 if [ ${INSTALLDIR} != "." ] ; then
648 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
649 mv ${FINAL_LIBS} ${INSTALLDIR}/