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
25 # The library name should just be "GL" or "GLU", etc. The 'lib' prefix
26 # will be added here if needed, as well as the ".so" or ".a" suffix,
27 # etc (unless the -noprefix option is used).
29 # objects should be: foo.o bar.o etc.o
31 # Environment variables recognized:
32 # CC C compiler command
33 # CXX C++ compiler command
59 '-o') shift 1; LIBNAME
=$1;;
60 '-major') shift 1; MAJOR
=$1;;
61 '-minor') shift 1; MINOR
=$1;;
62 '-patch') shift 1; PATCH
=$1;;
63 -l*) DEPS
="$DEPS $1";;
64 -L*) DEPS
="$DEPS $1";;
65 '-cplusplus') CPLUSPLUS
=1;;
67 '-install') shift 1; INSTALLDIR
=$1;;
68 '-arch') shift 1; ARCH
=$1;;
69 '-archopt') shift 1; ARCHOPT
=$1;;
70 '-noprefix') NOPREFIX
=1;;
71 -*) echo "mklib: Unknown option: " $1 ; exit 1;;
78 if [ ${ARCH} = "auto" ] ; then
86 if [ "x${LIBNAME}" = "x" ] ; then
87 echo "mklib: Error: no library name specified"
90 if [ "x${OBJECTS}" = "x" ] ; then
91 echo "mklib: Error: no object files specified"
100 echo "-----------------"
102 echo LIBNAME is
$LIBNAME
107 echo "-----------------"
112 # OK, make the library now
117 # GCC-based environment
119 if [ $NOPREFIX = 1 ] ; then
120 # No "lib" or ".so" part
121 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
122 #OPTS="-shared -Wl,-soname,${LIBNAME}" # soname???
124 if [ $CPLUSPLUS = 1 ] ; then
132 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
134 FINAL_LIBS
="${LIBNAME}"
135 elif [ $STATIC = 1 ] ; then
136 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
137 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
141 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
144 FINAL_LIBS
=${LIBNAME}.a
146 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
147 if [ $ARCH = 'Linux' ] ; then
148 OPTS
="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
150 OPTS
="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
152 if [ x
${PATCH} = "x" ] ; then
153 VERSION
="${MAJOR}.${MINOR}"
155 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
158 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.
${VERSION}
160 if [ $CPLUSPLUS = 1 ] ; then
167 rm -f ${LIBNAME}.so.
${VERSION}
168 rm -f ${LIBNAME}.so.
${MAJOR}
172 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
173 # make usual symlinks
174 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
175 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
177 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
182 if [ $STATIC = 1 ] ; then
183 LIBNAME
="lib${LIBNAME}.a"
184 echo "mklib: Making SunOS static library: " ${LIBNAME}
186 ar -ruv ${LIBNAME} ${OBJECTS}
187 FINAL_LIBS
=${LIBNAME}
189 LIBNAME
="lib${LIBNAME}.so"
190 echo "mklib: Making SunOS shared library: " ${LIBNAME}
191 # XXX OPTS for gcc should be -shared, but that doesn't work.
192 # Using -G does work though.
193 if [ $CPLUSPLUS = 1 ] ; then
194 # determine linker and options for C++ code
195 if [ "x${CXX}" = "xg++" ] ; then
199 elif [ "x${CXX}" = "xCC" ] ; then
203 elif [ "x${CXX}" = "xc++" ] ; then
207 elif [ `which c++` ] ; then
211 elif [ `type g++` ] ; then
216 echo "mklib: warning: can't find C++ comiler, trying CC."
220 elif [ "x${CC}" = "xgcc" ] ; then
221 # use gcc for linking
225 # use native Sun linker
229 echo "mklib: linker is" ${LINK} ${OPTS}
230 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
231 ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
232 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
233 FINAL_LIBS
="${LIBNAME}.${MAJOR} ${LIBNAME}"
238 if [ $NOPREFIX = 1 ] ; then
239 # No "lib" or ".so" part
240 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
242 ld
-Bshareable -o ${LIBNAME} ${OBJECTS}
243 FINAL_LIBS
=${LIBNAME}
244 elif [ $STATIC = 1 ] ; then
245 STLIB
="lib${LIBNAME}.a"
246 echo "mklib: Making FreeBSD static library: " ${STLIB}
248 ar cq
${STLIB} ${OBJECTS}
252 SHLIB
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
253 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
255 ld
-Bshareable -o ${SHLIB} ${OBJECTS}
256 # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
262 if [ $STATIC = 1 ] ; then
263 LIBNAME
="lib${LIBNAME}_pic.a"
264 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
266 ar cq
${LIBNAME} ${OBJECTS}
268 FINAL_LIBS
=${LIBNAME}
270 LIBNAME
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
271 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
273 ld
-x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
274 FINAL_LIBS
=${LIBNAME}
279 if [ $STATIC = 1 ] ; then
280 LIBNAME
="lib${LIBNAME}.a"
282 ar rc
${LIBNAME} ${OBJECTS}
283 FINAL_LIBS
=${LIBNAME}
285 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
286 if [ $ARCHOPT = "64" ] ; then
288 OPTS
="-64 -shared -all"
289 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
290 elif [ $ARCHOPT = "o32" ] ; then
292 OPTS
="-32 -shared -all"
293 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
296 OPTS
="-n32 -shared -all"
297 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
299 if [ $CPLUSPLUS = 1 ] ; then
304 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
305 FINAL_LIBS
=${LIBNAME}
310 LIBNAME
="lib${LIBNAME}.a"
311 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
313 gnuwin32ar ruv
${LIBNAME} ${OBJECTS}
314 FINAL_LIBS
=${LIBNAME}
318 if [ $STATIC = 1 ] ; then
319 LIBNAME
="lib${LIBNAME}.a"
320 echo "mklib: Making HP-UX static library: " ${LIBNAME}
322 ar -ruv ${LIBNAME} ${OBJECTS}
323 FINAL_LIBS
=${LIBNAME}
325 RUNLIB
="lib${LIBNAME}.${MAJOR}"
326 DEVLIB
="lib${LIBNAME}.sl"
327 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
328 ld
-b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
329 ln -s ${RUNLIB} ${DEVLIB}
330 FINAL_LIBS
="${RUNLIB} ${DEVLIB}"
335 if [ $STATIC = 1 ] ; then
336 LIBNAME
="lib${LIBNAME}.a"
337 echo "mklib: Making AIX static library: " ${LIBNAME}
338 ar -ruv ${LIBNAME} ${OBJECTS}
339 FINAL_LIBS
=${LIBNAME}
341 EXPFILE
="lib${LIBNAME}.exp"
342 OFILE
=shr.o
#Want to be consistent with the IBM libGL.a
343 LIBNAME
="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
344 OPTS
="-bE:${EXPFILE} -bM:SRE -bnoentry"
345 rm -f ${EXPFILE} ${OFILE}
347 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
348 ${NM} ${OBJECTS} |
awk '{
349 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
350 && ( substr($1,1,1) != ".")) {
351 if (substr ($1, 1, 7) != "__sinit" &&
352 substr ($1, 1, 7) != "__sterm") {
353 if (substr ($1, 1, 5) == "__tf1")
354 print (substr ($1, 7))
355 else if (substr ($1, 1, 5) == "__tf9")
356 print (substr ($1, 15))
361 }' |
sort -u >> ${EXPFILE}
362 cc
${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
363 ar -r ${LIBNAME} ${OFILE}
364 FINAL_LIBS
="${LIBNAME}"
369 if [ $STATIC = 1 ] ; then
370 LIBNAME
="lib${LIBNAME}.a"
371 echo "mklib: Making AIX static library: " ${LIBNAME}
372 ar -X64 -ruv ${LIBNAME} ${OBJECTS}
373 FINAL_LIBS
=${LIBNAME}
375 echo "mklib: PROBLEM: AIX64 shared libs not supported!!!"
380 LIBNAME
="lib${LIBNAME}.a"
381 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
382 libtool
-static -o ${LIBNAME} - ${OBJECTS}
383 FINAL_LIBS
=${LIBNAME}
387 if [ $STATIC = 1 ] ; then
388 LIBNAME
="lib${LIBNAME}.a"
389 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
391 ar -ruv ${LIBNAME} ${OBJECTS}
392 FINAL_LIBS
=${LIBNAME}
394 VERSION
="${MAJOR}.${MINOR}"
395 LIBNAME
="lib${LIBNAME}.so"
396 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
397 rm -f ${LIBNAME}.
${VERSION}
398 ld
-o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
399 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
400 FINAL_LIBS
="${LIBNAME} ${LIBNAME}.${VERSION}"
405 if [ $STATIC = 1 ] ; then
406 LIBNAME
="lib${LIBNAME}.a"
407 echo "mklib: Making Darwin static library: " ${LIBNAME}
410 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
411 FINAL_LIBS
=${LIBNAME}
413 LIBNAME
="${LIBNAME}.dylib"
414 echo "mklib: Making Darwin shared library: " ${LIBNAME}
415 FLAGS
="-dynamiclib -multiply_defined suppress"
416 if [ $CPLUSPLUS = 1 ] ; then
421 ${LINK} ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
422 FINAL_LIBS
=${LIBNAME}
427 LIBNAME
="lib${LIBNAME}.a"
428 echo "mklib: Making LynxOS static library: " ${LIBNAME}
430 ar ru
${LIBNAME} ${OBJECTS}
431 FINAL_LIBS
=${LIBNAME}
435 LIBNAME
="lib${LIBNAME}.so"
436 echo "mklib: Making BeOS shared library: " ${LIBNAME}
437 gcc
-nostart -Xlinker -soname=${LIBNAME} -L/Be/develop/lib/x86 ${OBJECTS} -lbe -o ${LIBNAME}
438 FINAL_LIBS
=${LIBNAME}
442 LIBNAME
="lib${LIBNAME}.a"
443 echo "mklib: Making QNX library: " ${LIBNAME}
444 wlib
${LIBNAME} ${OBJECTS}
445 FINAL_LIBS
=${LIBNAME}
449 LIBNAME
="lib${LIBNAME}.a"
450 echo "mklib: Making MorphOS library: " ${LIBNAME}
451 ppc-morphos-ar rc
${LIBNAME} ${OBJECTS}
452 FINAL_LIBS
="${LIBNAME}"
457 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
459 if [ $STATIC = 1 ] ; then
460 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
464 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
466 FINAL_LIBS
="${LIBNAME}.a"
469 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
470 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.
${VERSION}
472 if [ $CPLUSPLUS = 1 ] ; then
478 rm -f ${LIBNAME}.so.
${VERSION}
479 rm -f ${LIBNAME}.so.
${MAJOR}
482 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
483 # make usual symlinks
484 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
485 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
487 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
493 if [ $STATIC = 1 ] ; then
494 LIBNAME
="lib${LIBNAME}.a"
495 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
497 ar ru
${LIBNAME} ${OBJECTS}
498 FINAL_LIBS
=${LIBNAME}
500 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
501 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
505 gcc
-shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
506 # NOTE: the application linking with this library must specify
507 # the -Wl,-brtl flags to gcc
508 FINAL_LIBS
=${LIBNAME}
514 if [ $STATIC = 0 ] ; then
515 echo "mklib: Warning shared libs not supported on Ultrix"
517 LIBNAME
="lib${LIBNAME}.a"
518 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
520 ar ru
${LIBNAME} ${OBJECTS}
521 FINAL_LIBS
="${LIBNAME}"
525 # GCC-based environment
526 CYGNAME
="cyg${LIBNAME}" # prefix with "cyg"
527 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
529 if [ $STATIC = 1 ] ; then
530 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
534 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
537 FINAL_LIBS
=${LIBNAME}.a
539 OPTS
="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
540 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
542 if [ $CPLUSPLUS = 1 ] ; then
549 rm -f ${LIBNAME}-${MAJOR}.dll
550 rm -f ${LIBNAME}.dll.a
554 ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
555 # make usual symlinks
556 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
558 FINAL_LIBS
="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
559 # special case for installing in bin
560 FINAL_BINS
="${CYGNAME}-${MAJOR}.dll"
565 # If you're adding support for a new architecture, you can
567 if [ $STATIC = 1 ] ; then
568 LIBNAME
="lib${LIBNAME}.a"
569 echo "mklib: Making static library for example arch: " ${LIBNAME}
571 ar rv
${LIBNAME} ${OBJECTS}
572 FINAL_LIBS
="${LIBNAME}"
574 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib"
575 echo "mklib: Making shared library for example arch: " ${LIBNAME}
576 ld
-o ${LIBNAME} ${OBJECTS} ${DEPS}
577 FINAL_LIBS
="${LIBNAME}"
582 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
583 echo "mklib: Please add necessary commands to mklib script."
589 # Put library files into installation directory if specified.
591 if [ ${INSTALLDIR} != "." ] ; then
592 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
593 mv ${FINAL_LIBS} ${INSTALLDIR}/