3262e49841012ef372b834e02c8410234a6f68bb
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
24 # The library name should just be "GL" or "GLU", etc. The 'lib' prefix
25 # will be added here if needed, as well as the ".so" or ".a" suffix, etc.
27 # objects should be: foo.o bar.o etc.o
29 # Environment variables recognized:
30 # CC C compiler command
31 # CXX C++ compiler command
56 '-o') shift 1; LIBNAME
=$1;;
57 '-major') shift 1; MAJOR
=$1;;
58 '-minor') shift 1; MINOR
=$1;;
59 '-patch') shift 1; PATCH
=$1;;
60 -l*) DEPS
="$DEPS $1";;
61 -L*) DEPS
="$DEPS $1";;
62 '-cplusplus') CPLUSPLUS
=1;;
64 '-install') shift 1; INSTALLDIR
=$1;;
65 '-arch') shift 1; ARCH
=$1;;
66 '-archopt') shift 1; ARCHOPT
=$1;;
67 -*) echo "mklib: Unknown option: " $1 ; exit 1;;
74 if [ ${ARCH} = "auto" ] ; then
82 if [ "x${LIBNAME}" = "x" ] ; then
83 echo "mklib: Error: no library name specified"
86 if [ "x${OBJECTS}" = "x" ] ; then
87 echo "mklib: Error: no object files specified"
96 echo "-----------------"
98 echo LIBNAME is
$LIBNAME
103 echo "-----------------"
108 # OK, make the library now
113 # GCC-based environment
114 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
116 if [ $STATIC = 1 ] ; then
117 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
121 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
124 FINAL_LIBS
=${LIBNAME}.a
126 if [ $ARCH = 'Linux' ] ; then
127 OPTS
="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
129 OPTS
="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
131 if [ x
${PATCH} = "x" ] ; then
132 VERSION
="${MAJOR}.${MINOR}"
134 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
137 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.
${VERSION}
139 if [ $CPLUSPLUS = 1 ] ; then
146 rm -f ${LIBNAME}.so.
${VERSION}
147 rm -f ${LIBNAME}.so.
${MAJOR}
151 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
152 # make usual symlinks
153 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
154 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
156 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
161 if [ $STATIC = 1 ] ; then
162 LIBNAME
="lib${LIBNAME}.a"
163 echo "mklib: Making SunOS static library: " ${LIBNAME}
165 ar -ruv ${LIBNAME} ${OBJECTS}
166 FINAL_LIBS
=${LIBNAME}
168 LIBNAME
="lib${LIBNAME}.so"
169 echo "mklib: Making SunOS shared library: " ${LIBNAME}
170 # XXX OPTS for gcc should be -shared, but that doesn't work.
171 # Using -G does work though.
172 if [ $CPLUSPLUS = 1 ] ; then
173 # determine linker and options for C++ code
174 if [ "x${CXX}" = "xg++" ] ; then
178 elif [ "x${CXX}" = "xCC" ] ; then
182 elif [ "x${CXX}" = "xc++" ] ; then
186 elif [ `which c++` ] ; then
190 elif [ `type g++` ] ; then
195 echo "mklib: warning: can't find C++ comiler, trying CC."
199 elif [ "x${CC}" = "xgcc" ] ; then
200 # use gcc for linking
204 # use native Sun linker
208 echo "mklib: linker is" ${LINK} ${OPTS}
209 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
210 ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
211 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
212 FINAL_LIBS
="${LIBNAME}.${MAJOR} ${LIBNAME}"
217 if [ $STATIC = 1 ] ; then
218 STLIB
="lib${LIBNAME}.a"
219 echo "mklib: Making FreeBSD static library: " ${STLIB}
221 ar cq
${STLIB} ${OBJECTS}
225 SHLIB
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
226 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
228 ld
-Bshareable -o ${SHLIB} ${OBJECTS}
229 # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
235 if [ $STATIC = 1 ] ; then
236 LIBNAME
="lib${LIBNAME}_pic.a"
237 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
239 ar cq
${LIBNAME} ${OBJECTS}
241 FINAL_LIBS
=${LIBNAME}
243 LIBNAME
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
244 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
246 ld
-x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
247 FINAL_LIBS
=${LIBNAME}
252 if [ $STATIC = 1 ] ; then
253 LIBNAME
="lib${LIBNAME}.a"
255 ar rc
${LIBNAME} ${OBJECTS}
256 FINAL_LIBS
=${LIBNAME}
258 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
259 if [ $ARCHOPT = "64" ] ; then
261 OPTS
="-64 -shared -all"
262 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
263 elif [ $ARCHOPT = "o32" ] ; then
265 OPTS
="-32 -shared -all"
266 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
269 OPTS
="-n32 -shared -all"
270 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
272 if [ $CPLUSPLUS = 1 ] ; then
277 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
278 FINAL_LIBS
=${LIBNAME}
283 LIBNAME
="lib${LIBNAME}.a"
284 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
286 gnuwin32ar ruv
${LIBNAME} ${OBJECTS}
287 FINAL_LIBS
=${LIBNAME}
291 if [ $STATIC = 1 ] ; then
292 LIBNAME
="lib${LIBNAME}.a"
293 echo "mklib: Making HPUX static library: " ${LIBNAME}
295 ar -ruv ${LIBNAME} ${OBJECTS}
296 FINAL_LIBS
=${LIBNAME}
298 RUNLIB
="lib${LIBNAME}.${MAJOR}"
299 DEVLIB
="lib${LIBNAME}.sl"
300 echo "mklib: Making HPUX stared library: " ${RUNLIB} ${DEVLIB}
301 ld
-b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
302 ln -s ${RUNLIB} ${DEVLIB}
303 FINAL_LIBS
="{RUNLIB} ${DEVLIB}"
308 if [ $STATIC = 1 ] ; then
309 LIBNAME
="lib${LIBNAME}.a"
310 echo "mklib: Making AIX static library: " ${LIBNAME}
311 ar -ruv ${LIBNAME} ${OBJECTS}
312 FINAL_LIBS
=${LIBNAME}
314 echo "mklib: PROBLEM: AIX shared libs not supported!!!"
319 if [ $STATIC = 1 ] ; then
320 LIBNAME
="lib${LIBNAME}.a"
321 echo "mklib: Making AIX static library: " ${LIBNAME}
322 ar -X64 -ruv ${LIBNAME} ${OBJECTS}
323 FINAL_LIBS
=${LIBNAME}
325 echo "mklib: PROBLEM: AIX64 shared libs not supported!!!"
330 LIBNAME
="lib${LIBNAME}.a"
331 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
332 libtool
-static -o ${LIBNAME} - ${OBJECTS}
333 FINAL_LIBS
=${LIBNAME}
337 if [ $STATIC = 1 ] ; then
338 LIBNAME
="lib${LIBNAME}.a"
339 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
341 ar -ruv ${LIBNAME} ${OBJECTS}
342 FINAL_LIBS
=${LIBNAME}
344 VERSION
="${MAJOR}.${MINOR}"
345 LIBNAME
="lib${LIBNAME}.so"
346 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
347 rm -f ${LIBNAME}.
${VERSION}
348 ld
-o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
349 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
350 FINAL_LIBS
="${LIBNAME} ${LIBNAME}.${VERSION}"
355 if [ $STATIC = 1 ] ; then
356 LIBNAME
="lib${LIBNAME}.a"
357 echo "mklib: Making Darwin static library: " ${LIBNAME}
360 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
361 FINAL_LIBS
=${LIBNAME}
363 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
364 LIBNAME
="${LIBNAME}.dylib"
365 ARNAME
="${LIBNAME}.dylib.a"
366 echo "mklib: Making Darwin libraries: " ${LIBNAME} ${ARNAME}
367 FLAGS
="-dynamiclib -multiply_defined suppress"
368 cc
${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
369 # also make regular .a files,
370 # provided by Danek Duvall (duvall@dhduvall.student.princeton.edu)
371 ar ruv
${ARNAME} ${OBJECTS}
373 FINAL_LIBS
="${ARNAME} ${LIBNAME}"
378 LIBNAME
="lib${LIBNAME}.a"
379 echo "mklib: Making LynxOS static library: " ${LIBNAME}
381 ar ru
${LIBNAME} ${OBJECTS}
382 FINAL_LIBS
=${LIBNAME}
386 LIBNAME
="lib${LIBNAME}.so"
387 echo "mklib: Making BeOS shared library: " ${LIBNAME}
388 gcc
-nostart -Xlinker -soname=${LIBNAME} -L/Be/develop/lib/x86 ${OBJECTS} -lbe -o ${LIBNAME}
389 FINAL_LIBS
=${LIBNAME}
393 LIBNAME
="lib${LIBNAME}.a"
394 echo "mklib: Making QNX library: " ${LIBNAME}
395 wlib
${LIBNAME} ${OBJECTS}
396 FINAL_LIBS
=${LIBNAME}
400 LIBNAME
="lib${LIBNAME}.a"
401 echo "mklib: Making MorphOS library: " ${LIBNAME}
402 ppc-morphos-ar rc
${LIBNAME} ${OBJECTS}
403 FINAL_LIBS
="${LIBNAME}"
408 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
410 if [ $STATIC = 1 ] ; then
411 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
415 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
417 FINAL_LIBS
="${LIBNAME}.a"
420 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
421 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.
${VERSION}
423 if [ $CPLUSPLUS = 1 ] ; then
429 rm -f ${LIBNAME}.so.
${VERSION}
430 rm -f ${LIBNAME}.so.
${MAJOR}
433 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
434 # make usual symlinks
435 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
436 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
438 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
444 if [ $STATIC = 1 ] ; then
445 LIBNAME
="lib${LIBNAME}.a"
446 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
448 ar ru
${LIBNAME} ${OBJECTS}
449 FINAL_LIBS
=${LIBNAME}
451 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
452 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
456 gcc
-shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
457 # NOTE: the application linking with this library must specify
458 # the -Wl,-brtl flags to gcc
459 FINAL_LIBS
=${LIBNAME}
465 if [ $STATIC = 0 ] ; then
466 echo "mklib: Warning shared libs not supported on Ultrix"
468 LIBNAME
="lib${LIBNAME}.a"
469 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
471 ar ru
${LIBNAME} ${OBJECTS}
472 FINAL_LIBS
="${LIBNAME}"
476 # If you're adding support for a new architecture, you can
478 if [ $STATIC = 1 ] ; then
479 LIBNAME
="lib${LIBNAME}.a"
480 echo "mklib: Making static library for example arch: " ${LIBNAME}
482 ar rv
${LIBNAME} ${OBJECTS}
483 FINAL_LIBS
="${LIBNAME}"
485 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib"
486 echo "mklib: Making shared library for example arch: " ${LIBNAME}
487 ld
-o ${LIBNAME} ${OBJECTS} ${DEPS}
488 FINAL_LIBS
="${LIBNAME}"
493 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
494 echo "mklib: Please add necessary commands to mklib script."
500 # Put library files into installation directory if specified.
502 if [ ${INSTALLDIR} != "." ] ; then
503 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
504 mv ${FINAL_LIBS} ${INSTALLDIR}/