327fd8ccf2276b9b74a9bde6973c159e7afe3dad
3 # Make a shared library.
4 # Basically do a switch/case depending on the OS and make a shared
5 # lib 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 files 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 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
115 if [ $STATIC = 1 ] ; then
116 echo "mklib: Making Linux static library: " ${LIBNAME}.a
120 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
122 FINAL_LIBS
="${LIBNAME}.a"
124 OPTS
="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
125 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
127 echo "mklib: Making Linux shared library: " ${LIBNAME}.so.
${VERSION}
129 if [ $CPLUSPLUS = 1 ] ; then
136 rm -f ${LIBNAME}.so.
${VERSION}
137 rm -f ${LIBNAME}.so.
${MAJOR}
141 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
142 # make usual symlinks
143 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
144 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
146 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
151 LIBNAME
="lib${LIBNAME}.so"
152 echo "mklib: Making SunOS shared library: " ${LIBNAME}
153 if [ $CPLUSPLUS = 1 ] ; then
154 # determine linker and options for C++ code
155 if [ "x${CXX}" = "xg++" ] ; then
159 elif [ "x${CXX}" = "xCC" ] ; then
163 elif [ "x${CXX}" = "xc++" ] ; then
167 elif [ `which c++` ] ; then
171 elif [ `type g++` ] ; then
176 echo "mklib: warning: can't find C++ comiler, trying CC."
180 elif [ "x${CC}" = "xgcc" ] ; then
181 # use gcc for linking
185 # use native Sun linker
189 echo "mklib: linker is" ${LINK} ${OPTS}
191 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
192 FINAL_LIBS
=${LIBNAME}
196 SHLIB
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
197 STLIB
="lib${LIBNAME}.a"
198 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
199 rm -f ${SHLIB} ${STLIB}
200 ar cq
${STLIB} ${OBJECTS}
202 ld
-Bshareable -o ${SHLIB} ${OBJECTS}
203 # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
204 FINAL_LIBS
="${SHLIB} ${STLIB}"
208 LIBNAME
="lib${LIBNAME}"
209 VERSION
="${MAJOR}.${MINOR}"
210 echo "Building OpenBSD PIC library: " ${LIBNAME}
211 rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}
212 ar cq
${LIBNAME}_pic.a
${OBJECTS}
213 ranlib
${LIBNAME}_pic.a
214 ld
-x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a
215 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so
216 FINAL_LIBS
="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION} ${LIBNAME}.so"
220 LIBNAME
="lib${LIBNAME}"
221 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
222 VERSION
="${MAJOR}.${MINOR}"
223 rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}
224 ar cq
${LIBNAME}_pic.a
${OBJECTS}
225 ranlib
${LIBNAME}_pic.a
226 ld
-x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a
227 FINAL_LIBS
="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}"
231 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
232 if [ $ARCHOPTS = "64" ] ; then
234 OPTS
="-64 -shared -all"
235 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
236 elif [ $ARCHOPTS = "o32" ] ; then
238 OPTS
="-32 -shared -all"
239 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
242 OPTS
="-n32 -shared -all"
243 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
245 ld
${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
246 FINAL_LIBS
="${LIBNAME}"
250 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
251 echo "mklib: Making IRIX64 library: " ${LIBNAME}
253 OPTS
="-64 -shared -all"
254 ld
${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
255 FINAL_LIBS
="${LIBNAME}"
259 LIBNAME
="lib${LIBNAME}.a"
260 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
261 gnuwin32ar ruv
${LIBNAME} ${OBJECTS}
262 FINAL_LIBS
=${LIBNAME}
266 RUNLIB
="lib${LIBNAME}.${MAJOR}"
267 DEVLIB
="lib${LIBNAME}.sl"
268 echo "mklib: Making HPUX library: " ${RUNLIB} ${DEVLIB}
269 ld
-b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
270 ln -s ${RUNLIB} ${DEVLIB}
271 FINAL_LIBS
="{RUNLIB} ${DEVLIB}"
275 LIBNAME
="lib${LIBNAME}.a"
276 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
277 libtool
-static -o ${LIBNAME} - ${OBJECTS}
278 FINAL_LIBS
=${LIBNAME}
282 VERSION
="${MAJOR}.${MINOR}"
283 LIBNAME
="lib${LIBNAME}.so"
284 ARNAME
="lib${LIBNAME}.a"
285 echo "mklib: Making OSF/1 library: " ${LIBNAME}
286 rm -f ${LIBNAME}.
${VERSION}
287 ld
-o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
288 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
290 # also make static lib
292 ar clqz
${ARNAME} ${OBJECTS}
293 FINAL_LIBS
="${ARNAME} ${LIBNAME} ${LIBNAME}.${VERSION}"
297 VERSION
="${MAJOR}.${MINOR}.${TINY}"
298 LIBNAME
="lib${LIBNAME}.dylib"
299 ARNAME
="lib${LIBNAME}.dylib.a"
300 echo "mklib: Making Darwin libraries: " ${LIBNAME} ${ARNAME}
301 FLAGS
="-dynamiclib -multiply_defined suppress"
302 cc
${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
303 # also make regular .a files,
304 # provided by Danek Duvall (duvall@dhduvall.student.princeton.edu)
305 ar ruv
${ARNAME} ${OBJECTS}
307 FINAL_LIBS
="${ARNAME} ${LIBNAME}"
311 LIBNAME
="lib${LIBNAME}.a"
312 echo "mklib: Making LynxOS library: " ${LIBNAME}
313 ar ru
${LIBNAME} ${OBJECTS}
314 FINAL_LIBS
=${LIBNAME}
318 LIBNAME
="lib${LIBNAME}.so"
319 echo "mklib: Making BeOS shared library: " ${LIBNAME}
320 gcc
-nostart -Xlinker -soname=${LIBNAME} -L/Be/develop/lib/x86 ${OBJECTS} -lbe -o ${LIBNAME}
321 FINAL_LIBS
=${LIBNAME}
325 LIBNAME
="lib${LIBNAME}.a"
326 echo "mklib: Making QNX library: " ${LIBNAME}
327 wlib
${LIBNAME} ${OBJECTS}
328 FINAL_LIBS
=${LIBNAME}
332 LIBNAME
="lib${LIBNAME}.a"
333 echo "mklib: Making MorphOS library: " ${LIBNAME}
334 ppc-morphos-ar rc
${LIBNAME} ${OBJECTS}
335 FINAL_LIBS
="${LIBNAME}"
339 # If you're adding support for a new architecture, you can
341 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib"
342 echo "mklib: Making library for example arch: " ${LIBNAME}
343 ld
-o ${LIBNAME} ${OBJECTS} ${DEPS}
344 FINAL_LIBS
="${LIBNAME}"
348 echo "mklib: WARNING: making library for unknown platform!"
349 echo "mklib: WARNING: this may not work!"
350 echo "mklib: WARNING: please update the bin/mklib script!"
351 # XXX this is a total hack for Mesa - remove someday
352 # fall-back to an old mklib.* script
353 LIBNAME
="lib${LIBNAME}.a"
354 ${TOP}/${MAKELIB} "lib${LIBNAME}.a" ${MAJOR} ${MINOR} ${PATCH} ${OBJECTS}
355 FINAL_LIBS
="${LIBNAME}"
361 # Put library files into installation directory if specified.
363 if [ ${INSTALLDIR} != "." ] ; then
364 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
365 mv ${FINAL_LIBS} ${INSTALLDIR}/