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 [ $ARCH = "AIX64" ] ; then
364 if [ $STATIC = 1 ] ; then
365 LIBNAME
="lib${LIBNAME}.a"
366 echo "mklib: Making AIX static library: " ${LIBNAME}
367 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
368 FINAL_LIBS
=${LIBNAME}
370 EXPFILE
="lib${LIBNAME}.exp"
371 OFILE
=shr.o
#Want to be consistent with the IBM libGL.a
372 LIBNAME
="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
373 if [ $ARCH = "AIX64" ] ; then
374 OPTS
="-bE:${EXPFILE} -bM:SRE -bnoentry -q64"
376 OPTS
="-bE:${EXPFILE} -bM:SRE -bnoentry"
378 rm -f ${EXPFILE} ${OFILE}
379 NM
="/bin/nm -eC ${X64}"
380 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
381 ${NM} ${OBJECTS} |
awk '{
382 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
383 && ( substr($1,1,1) != ".")) {
384 if (substr ($1, 1, 7) != "__sinit" &&
385 substr ($1, 1, 7) != "__sterm") {
386 if (substr ($1, 1, 5) == "__tf1")
387 print (substr ($1, 7))
388 else if (substr ($1, 1, 5) == "__tf9")
389 print (substr ($1, 15))
394 }' |
sort -u >> ${EXPFILE}
395 cc
${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
396 ar ${X64} -r ${LIBNAME} ${OFILE}
397 FINAL_LIBS
="${LIBNAME}"
402 LIBNAME
="lib${LIBNAME}.a"
403 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
404 libtool
-static -o ${LIBNAME} - ${OBJECTS}
405 FINAL_LIBS
=${LIBNAME}
409 if [ $STATIC = 1 ] ; then
410 LIBNAME
="lib${LIBNAME}.a"
411 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
413 ar -ruv ${LIBNAME} ${OBJECTS}
414 FINAL_LIBS
=${LIBNAME}
416 VERSION
="${MAJOR}.${MINOR}"
417 LIBNAME
="lib${LIBNAME}.so"
418 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
419 if [ $CPLUSPLUS = 1 ] ; then
424 rm -f ${LIBNAME}.
${VERSION}
425 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
426 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
427 FINAL_LIBS
="${LIBNAME} ${LIBNAME}.${VERSION}"
432 if [ $STATIC = 1 ] ; then
433 LIBNAME
="lib${LIBNAME}.a"
434 echo "mklib: Making Darwin static library: " ${LIBNAME}
437 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
438 FINAL_LIBS
=${LIBNAME}
440 LIBNAME
="${LIBNAME}.dylib"
441 echo "mklib: Making Darwin shared library: " ${LIBNAME}
442 FLAGS
="-dynamiclib -multiply_defined suppress"
443 if [ $CPLUSPLUS = 1 ] ; then
448 ${LINK} ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
449 FINAL_LIBS
=${LIBNAME}
454 LIBNAME
="lib${LIBNAME}.a"
455 echo "mklib: Making LynxOS static library: " ${LIBNAME}
457 ar ru
${LIBNAME} ${OBJECTS}
458 FINAL_LIBS
=${LIBNAME}
462 if [ $STATIC = 1 ] ; then
463 LIBNAME
="lib${LIBNAME}.a"
464 echo "mklib: Making BeOS static library: " ${LIBNAME}
465 ar -cru "${LIBNAME}" ${OBJECTS}
467 LIBNAME
="lib${LIBNAME}.so"
468 echo "mklib: Making BeOS shared library: " ${LIBNAME}
469 gcc
-nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
470 mimeset
-f "${LIBNAME}"
471 setversion
"${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D
!" -long "Powered by Mesa3D
!"
473 FINAL_LIBS=${LIBNAME}
477 LIBNAME="lib
${LIBNAME}.a
"
478 echo "mklib
: Making QNX library
: " ${LIBNAME}
479 wlib ${LIBNAME} ${OBJECTS}
480 FINAL_LIBS=${LIBNAME}
484 LIBNAME="lib
${LIBNAME}.a
"
485 echo "mklib
: Making MorphOS library
: " ${LIBNAME}
486 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
487 FINAL_LIBS="${LIBNAME}"
492 LIBNAME="lib
${LIBNAME}" # prefix with "lib
"
494 if [ $STATIC = 1 ] ; then
495 echo "mklib
: Making Intel ICC static library
: " ${LIBNAME}.a
499 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
501 FINAL_LIBS="${LIBNAME}.a
"
504 VERSION="${MAJOR}.${MINOR}.${PATCH}"
505 echo "mklib
: Making Intel ICC shared library
: " ${LIBNAME}.so.${VERSION}
507 if [ $CPLUSPLUS = 1 ] ; then
513 rm -f ${LIBNAME}.so.${VERSION}
514 rm -f ${LIBNAME}.so.${MAJOR}
517 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
518 # make usual symlinks
519 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
520 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
522 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
"
528 if [ $STATIC = 1 ] ; then
529 LIBNAME="lib
${LIBNAME}.a
"
530 echo "mklib
: Making AIX GCC static library
: " ${LIBNAME}
532 ar ru ${LIBNAME} ${OBJECTS}
533 FINAL_LIBS=${LIBNAME}
535 LIBNAME="lib
${LIBNAME}.so
" # prefix with "lib
", suffix with ".so
"
536 echo "mklib
: Making AIX GCC shared library
: " ${LIBNAME}
540 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
541 # NOTE: the application linking with this library must specify
542 # the -Wl,-brtl flags to gcc
543 FINAL_LIBS=${LIBNAME}
549 if [ $STATIC = 0 ] ; then
550 echo "mklib
: Warning shared libs not supported on Ultrix
"
552 LIBNAME="lib
${LIBNAME}.a
"
553 echo "mklib
: Making static library
for Ultrix
: " ${LIBNAME}
555 ar ru ${LIBNAME} ${OBJECTS}
556 FINAL_LIBS="${LIBNAME}"
560 # GCC-based environment
561 CYGNAME="cyg
${LIBNAME}" # prefix with "cyg
"
562 LIBNAME="lib
${LIBNAME}" # prefix with "lib
"
564 if [ $STATIC = 1 ] ; then
565 echo "mklib
: Making
" $ARCH "static library
: " ${LIBNAME}.a
569 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
572 FINAL_LIBS=${LIBNAME}.a
574 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a
"
575 echo "mklib
: Making
" $ARCH "shared library
: " ${LIBNAME}-${MAJOR}.dll
577 if [ $CPLUSPLUS = 1 ] ; then
584 rm -f ${LIBNAME}-${MAJOR}.dll
585 rm -f ${LIBNAME}.dll.a
589 ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
590 # make usual symlinks
591 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
593 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
"
594 # special case for installing in bin
595 FINAL_BINS="${CYGNAME}-${MAJOR}.dll
"
600 # If you're adding support for a new architecture, you can
602 if [ $STATIC = 1 ] ; then
603 LIBNAME="lib
${LIBNAME}.a
"
604 echo "mklib
: Making static library
for example arch
: " ${LIBNAME}
606 ar rv ${LIBNAME} ${OBJECTS}
607 FINAL_LIBS="${LIBNAME}"
609 LIBNAME="lib
${LIBNAME}.so
" # prefix with "lib
"
610 echo "mklib
: Making shared library
for example arch
: " ${LIBNAME}
611 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
612 FINAL_LIBS="${LIBNAME}"
617 echo "mklib
: ERROR
: Don
't know how to make a static/shared library for" ${ARCH}
618 echo "mklib: Please add necessary commands to mklib script."
624 # Put library files into installation directory if specified.
626 if [ ${INSTALLDIR} != "." ] ; then
627 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
628 mv ${FINAL_LIBS} ${INSTALLDIR}/