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
177 # Check if objects are 32-bit and we're running in 64-bit
178 # environment. If so, pass -m32 flag to linker.
180 ABI32
=`file $1 | grep 32-bit`
181 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
185 if [ x
${PATCH} = "x" ] ; then
186 VERSION
="${MAJOR}.${MINOR}"
188 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
191 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.
${VERSION}
193 if [ $CPLUSPLUS = 1 ] ; then
200 rm -f ${LIBNAME}.so.
${VERSION}
201 rm -f ${LIBNAME}.so.
${MAJOR}
205 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
206 # make usual symlinks
207 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
208 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
210 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
216 if [ $STATIC = 1 ] ; then
217 LIBNAME
="lib${LIBNAME}.a"
218 echo "mklib: Making SunOS static library: " ${LIBNAME}
220 ar -ruv ${LIBNAME} ${OBJECTS}
221 FINAL_LIBS
=${LIBNAME}
223 LIBNAME
="lib${LIBNAME}.so"
224 echo "mklib: Making SunOS shared library: " ${LIBNAME}
225 # XXX OPTS for gcc should be -shared, but that doesn't work.
226 # Using -G does work though.
227 if [ $CPLUSPLUS = 1 ] ; then
228 # determine linker and options for C++ code
229 if [ "x${CXX}" = "xg++" ] ; then
233 elif [ "x${CXX}" = "xCC" ] ; then
237 elif [ "x${CXX}" = "xc++" ] ; then
241 elif [ `which c++` ] ; then
245 elif [ `type g++` ] ; then
250 echo "mklib: warning: can't find C++ comiler, trying CC."
254 elif [ "x${CC}" = "xgcc" ] ; then
255 # use gcc for linking
259 # use native Sun linker
263 echo "mklib: linker is" ${LINK} ${OPTS}
264 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
265 ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
266 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
267 FINAL_LIBS
="${LIBNAME}.${MAJOR} ${LIBNAME}"
272 if [ $NOPREFIX = 1 ] ; then
273 # No "lib" or ".so" part
274 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
276 ld
-Bshareable -o ${LIBNAME} ${OBJECTS}
277 FINAL_LIBS
=${LIBNAME}
278 elif [ $STATIC = 1 ] ; then
279 STLIB
="lib${LIBNAME}.a"
280 echo "mklib: Making FreeBSD static library: " ${STLIB}
282 ar cq
${STLIB} ${OBJECTS}
286 SHLIB
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
287 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
289 ld
-Bshareable -o ${SHLIB} ${OBJECTS}
290 # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
296 if [ $STATIC = 1 ] ; then
297 LIBNAME
="lib${LIBNAME}_pic.a"
298 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
300 ar cq
${LIBNAME} ${OBJECTS}
302 FINAL_LIBS
=${LIBNAME}
304 LIBNAME
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
305 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
307 ld
-x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
308 FINAL_LIBS
=${LIBNAME}
313 if [ $STATIC = 1 ] ; then
314 LIBNAME
="lib${LIBNAME}.a"
316 ar rc
${LIBNAME} ${OBJECTS}
317 FINAL_LIBS
=${LIBNAME}
319 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
320 if [ $ARCHOPT = "64" ] ; then
322 OPTS
="-64 -shared -all"
323 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
324 elif [ $ARCHOPT = "o32" ] ; then
326 OPTS
="-32 -shared -all"
327 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
330 OPTS
="-n32 -shared -all"
331 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
333 if [ $CPLUSPLUS = 1 ] ; then
338 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
339 FINAL_LIBS
=${LIBNAME}
344 LIBNAME
="lib${LIBNAME}.a"
345 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
347 gnuwin32ar ruv
${LIBNAME} ${OBJECTS}
348 FINAL_LIBS
=${LIBNAME}
352 if [ $STATIC = 1 ] ; then
353 LIBNAME
="lib${LIBNAME}.a"
354 echo "mklib: Making HP-UX static library: " ${LIBNAME}
356 ar -ruv ${LIBNAME} ${OBJECTS}
357 FINAL_LIBS
=${LIBNAME}
359 RUNLIB
="lib${LIBNAME}.${MAJOR}"
360 DEVLIB
="lib${LIBNAME}.sl"
361 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
362 ld
-b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
363 ln -s ${RUNLIB} ${DEVLIB}
364 FINAL_LIBS
="${RUNLIB} ${DEVLIB}"
369 if [ $ARCH = "AIX64" ] ; then
373 if [ $STATIC = 1 ] ; then
374 LIBNAME
="lib${LIBNAME}.a"
375 echo "mklib: Making AIX static library: " ${LIBNAME}
376 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
377 FINAL_LIBS
=${LIBNAME}
379 EXPFILE
="lib${LIBNAME}.exp"
380 OFILE
=shr.o
#Want to be consistent with the IBM libGL.a
381 LIBNAME
="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
382 if [ $ARCH = "AIX64" ] ; then
383 OPTS
="-bE:${EXPFILE} -bM:SRE -bnoentry -q64"
385 OPTS
="-bE:${EXPFILE} -bM:SRE -bnoentry"
387 rm -f ${EXPFILE} ${OFILE}
388 NM
="/bin/nm -eC ${X64}"
389 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
390 ${NM} ${OBJECTS} |
awk '{
391 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
392 && ( substr($1,1,1) != ".")) {
393 if (substr ($1, 1, 7) != "__sinit" &&
394 substr ($1, 1, 7) != "__sterm") {
395 if (substr ($1, 1, 5) == "__tf1")
396 print (substr ($1, 7))
397 else if (substr ($1, 1, 5) == "__tf9")
398 print (substr ($1, 15))
403 }' |
sort -u >> ${EXPFILE}
404 cc
${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
405 ar ${X64} -r ${LIBNAME} ${OFILE}
406 FINAL_LIBS
="${LIBNAME}"
411 LIBNAME
="lib${LIBNAME}.a"
412 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
413 libtool
-static -o ${LIBNAME} - ${OBJECTS}
414 FINAL_LIBS
=${LIBNAME}
418 if [ $STATIC = 1 ] ; then
419 LIBNAME
="lib${LIBNAME}.a"
420 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
422 ar -ruv ${LIBNAME} ${OBJECTS}
423 FINAL_LIBS
=${LIBNAME}
425 VERSION
="${MAJOR}.${MINOR}"
426 LIBNAME
="lib${LIBNAME}.so"
427 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
428 if [ $CPLUSPLUS = 1 ] ; then
433 rm -f ${LIBNAME}.
${VERSION}
434 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
435 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
436 FINAL_LIBS
="${LIBNAME} ${LIBNAME}.${VERSION}"
441 if [ $STATIC = 1 ] ; then
442 LIBNAME
="lib${LIBNAME}.a"
443 echo "mklib: Making Darwin static library: " ${LIBNAME}
446 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
447 FINAL_LIBS
=${LIBNAME}
449 LIBNAME
="${LIBNAME}.dylib"
450 echo "mklib: Making Darwin shared library: " ${LIBNAME}
451 FLAGS
="-dynamiclib -multiply_defined suppress"
452 if [ $CPLUSPLUS = 1 ] ; then
457 ${LINK} ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
458 FINAL_LIBS
=${LIBNAME}
463 LIBNAME
="lib${LIBNAME}.a"
464 echo "mklib: Making LynxOS static library: " ${LIBNAME}
466 ar ru
${LIBNAME} ${OBJECTS}
467 FINAL_LIBS
=${LIBNAME}
471 if [ $STATIC = 1 ] ; then
472 LIBNAME
="lib${LIBNAME}.a"
473 echo "mklib: Making BeOS static library: " ${LIBNAME}
474 ar -cru "${LIBNAME}" ${OBJECTS}
476 LIBNAME
="lib${LIBNAME}.so"
477 echo "mklib: Making BeOS shared library: " ${LIBNAME}
478 gcc
-nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
479 mimeset
-f "${LIBNAME}"
480 setversion
"${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D
!" -long "Powered by Mesa3D
!"
482 FINAL_LIBS=${LIBNAME}
486 LIBNAME="lib
${LIBNAME}.a
"
487 echo "mklib
: Making QNX library
: " ${LIBNAME}
488 wlib ${LIBNAME} ${OBJECTS}
489 FINAL_LIBS=${LIBNAME}
493 LIBNAME="lib
${LIBNAME}.a
"
494 echo "mklib
: Making MorphOS library
: " ${LIBNAME}
495 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
496 FINAL_LIBS="${LIBNAME}"
501 LIBNAME="lib
${LIBNAME}" # prefix with "lib
"
503 if [ $STATIC = 1 ] ; then
504 echo "mklib
: Making Intel ICC static library
: " ${LIBNAME}.a
508 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
510 FINAL_LIBS="${LIBNAME}.a
"
513 VERSION="${MAJOR}.${MINOR}.${PATCH}"
514 echo "mklib
: Making Intel ICC shared library
: " ${LIBNAME}.so.${VERSION}
516 if [ $CPLUSPLUS = 1 ] ; then
522 rm -f ${LIBNAME}.so.${VERSION}
523 rm -f ${LIBNAME}.so.${MAJOR}
526 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
527 # make usual symlinks
528 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
529 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
531 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
"
537 if [ $STATIC = 1 ] ; then
538 LIBNAME="lib
${LIBNAME}.a
"
539 echo "mklib
: Making AIX GCC static library
: " ${LIBNAME}
541 ar ru ${LIBNAME} ${OBJECTS}
542 FINAL_LIBS=${LIBNAME}
544 LIBNAME="lib
${LIBNAME}.so
" # prefix with "lib
", suffix with ".so
"
545 echo "mklib
: Making AIX GCC shared library
: " ${LIBNAME}
549 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
550 # NOTE: the application linking with this library must specify
551 # the -Wl,-brtl flags to gcc
552 FINAL_LIBS=${LIBNAME}
558 if [ $STATIC = 0 ] ; then
559 echo "mklib
: Warning shared libs not supported on Ultrix
"
561 LIBNAME="lib
${LIBNAME}.a
"
562 echo "mklib
: Making static library
for Ultrix
: " ${LIBNAME}
564 ar ru ${LIBNAME} ${OBJECTS}
565 FINAL_LIBS="${LIBNAME}"
569 # GCC-based environment
570 CYGNAME="cyg
${LIBNAME}" # prefix with "cyg
"
571 LIBNAME="lib
${LIBNAME}" # prefix with "lib
"
573 if [ $STATIC = 1 ] ; then
574 echo "mklib
: Making
" $ARCH "static library
: " ${LIBNAME}.a
578 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
581 FINAL_LIBS=${LIBNAME}.a
583 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a
"
584 echo "mklib
: Making
" $ARCH "shared library
: " ${LIBNAME}-${MAJOR}.dll
586 if [ $CPLUSPLUS = 1 ] ; then
593 rm -f ${LIBNAME}-${MAJOR}.dll
594 rm -f ${LIBNAME}.dll.a
598 ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
599 # make usual symlinks
600 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
602 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
"
603 # special case for installing in bin
604 FINAL_BINS="${CYGNAME}-${MAJOR}.dll
"
609 # If you're adding support for a new architecture, you can
611 if [ $STATIC = 1 ] ; then
612 LIBNAME="lib
${LIBNAME}.a
"
613 echo "mklib
: Making static library
for example arch
: " ${LIBNAME}
615 ar rv ${LIBNAME} ${OBJECTS}
616 FINAL_LIBS="${LIBNAME}"
618 LIBNAME="lib
${LIBNAME}.so
" # prefix with "lib
"
619 echo "mklib
: Making shared library
for example arch
: " ${LIBNAME}
620 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
621 FINAL_LIBS="${LIBNAME}"
626 echo "mklib
: ERROR
: Don
't know how to make a static/shared library for" ${ARCH}
627 echo "mklib: Please add necessary commands to mklib script."
633 # Put library files into installation directory if specified.
635 if [ ${INSTALLDIR} != "." ] ; then
636 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
637 mv ${FINAL_LIBS} ${INSTALLDIR}/