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 ("GL" for example)
12 # -major N specifies major version number (default is 1)
13 # -minor N specifies minor version number (default is 0)
14 # -patch N specifies patch version number (default is 0)
15 # -lLIBRARY specifies a dependency on LIBRARY
16 # -LDIR search in DIR for library dependencies
17 # -cplusplus link with C++ runtime
18 # -static make a static library (default is dynamic/shared)
19 # -install DIR move resulting library files to DIR
20 # -arch ARCH override using `uname` to determine architecture
21 # -archopt OPT specify an extra achitecture-specific option OPT
23 # The library name should just be "GL" or "GLU", etc. The 'lib' prefix
24 # will be added here if needed, as well as the ".so" or ".a" suffix, etc.
26 # objects should be: foo.o bar.o etc.o
28 # Environment variables recognized:
29 # CC C compiler command
30 # CXX C++ compiler command
55 '-o') shift 1; LIBNAME
=$1;;
56 '-major') shift 1; MAJOR
=$1;;
57 '-minor') shift 1; MINOR
=$1;;
58 '-patch') shift 1; PATCH
=$1;;
59 -l*) DEPS
="$DEPS $1";;
60 -L*) DEPS
="$DEPS $1";;
61 '-cplusplus') CPLUSPLUS
=1;;
63 '-install') shift 1; INSTALLDIR
=$1;;
64 '-arch') shift 1; ARCH
=$1;;
65 '-archopt') shift 1; ARCHOPT
=$1;;
66 -*) echo "mklib: Unknown option: " $1 ; exit 1;;
73 if [ ${ARCH} = "auto" ] ; then
81 if [ "x${LIBNAME}" = "x" ] ; then
82 echo "mklib: Error: no library name specified"
85 if [ "x${OBJECTS}" = "x" ] ; then
86 echo "mklib: Error: no object files specified"
95 echo "-----------------"
97 echo LIBNAME is
$LIBNAME
102 echo "-----------------"
107 # OK, make the library now
112 LIBNAME
="lib${LIBNAME}" # prefix with "lib"
114 if [ $STATIC = 1 ] ; then
115 echo "mklib: Making Linux static library: " ${LIBNAME}.a
119 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
121 FINAL_LIBS
="${LIBNAME}.a"
123 OPTS
="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
124 VERSION
="${MAJOR}.${MINOR}.${PATCH}"
126 echo "mklib: Making Linux shared library: " ${LIBNAME}.so.
${VERSION}
128 if [ $CPLUSPLUS = 1 ] ; then
135 rm -f ${LIBNAME}.so.
${VERSION}
136 rm -f ${LIBNAME}.so.
${MAJOR}
140 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
141 # make usual symlinks
142 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
143 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
145 FINAL_LIBS
="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
150 LIBNAME
="lib${LIBNAME}.so"
151 echo "mklib: Making SunOS shared library: " ${LIBNAME}
153 if [ $CPLUSPLUS = 1 ] ; then
155 if [ "x${CXX}" = "xg++" ] ; then
157 elif [ "x${CXX}" = "xCC" ] ; then
159 elif [ `which c++` ] ; then
161 elif [ `type g++` ] ; then
164 echo "mklib: warning: can't find C++ comiler, trying CC."
167 elif [ "x${CC}" = "xgcc" ] ; then
168 # use gcc for linking
171 # use native Sun linker
174 echo "mklib: linker is " ${LINK}
176 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
177 FINAL_LIBS
=${LIBNAME}
181 SHLIB
="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
182 STLIB
="lib${LIBNAME}.a"
183 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
184 rm -f ${SHLIB} ${STLIB}
185 ar cq
${STLIB} ${OBJECTS}
187 ld
-Bshareable -o ${SHLIB} ${OBJECTS}
188 # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
189 FINAL_LIBS
="${SHLIB} ${STLIB}"
193 LIBNAME
="lib${LIBNAME}"
194 VERSION
="${MAJOR}.${MINOR}"
195 echo "Building OpenBSD PIC library: " ${LIBNAME}
196 rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}
197 ar cq
${LIBNAME}_pic.a
${OBJECTS}
198 ranlib
${LIBNAME}_pic.a
199 ld
-x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a
200 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so
201 FINAL_LIBS
="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION} ${LIBNAME}.so"
205 LIBNAME
="lib${LIBNAME}"
206 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
207 VERSION
="${MAJOR}.${MINOR}"
208 rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}
209 ar cq
${LIBNAME}_pic.a
${OBJECTS}
210 ranlib
${LIBNAME}_pic.a
211 ld
-x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a
212 FINAL_LIBS
="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}"
216 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
217 if [ $ARCHOPTS = "64" ] ; then
219 OPTS
="-64 -shared -all"
220 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
221 elif [ $ARCHOPTS = "o32" ] ; then
223 OPTS
="-32 -shared -all"
224 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
227 OPTS
="-n32 -shared -all"
228 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
230 ld
${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
231 FINAL_LIBS
="${LIBNAME}"
235 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
236 echo "mklib: Making IRIX64 library: " ${LIBNAME}
238 OPTS
="-64 -shared -all"
239 ld
${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
240 FINAL_LIBS
="${LIBNAME}"
244 LIBNAME
="lib${LIBNAME}.a"
245 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
246 gnuwin32ar ruv
${LIBNAME} ${OBJECTS}
247 FINAL_LIBS
=${LIBNAME}
251 RUNLIB
="lib${LIBNAME}.${MAJOR}"
252 DEVLIB
="lib${LIBNAME}.sl"
253 echo "mklib: Making HPUX library: " ${RUNLIB} ${DEVLIB}
254 ld
-b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
255 ln -s ${RUNLIB} ${DEVLIB}
256 FINAL_LIBS
="{RUNLIB} ${DEVLIB}"
260 LIBNAME
="lib${LIBNAME}.a"
261 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
262 libtool
-static -o ${LIBNAME} - ${OBJECTS}
263 FINAL_LIBS
=${LIBNAME}
267 VERSION
="${MAJOR}.${MINOR}"
268 LIBNAME
="lib${LIBNAME}.so"
269 ARNAME
="lib${LIBNAME}.a"
270 echo "mklib: Making OSF/1 library: " ${LIBNAME}
271 rm -f ${LIBNAME}.
${VERSION}
272 ld
-o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
273 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
275 # also make static lib
277 ar clqz
${ARNAME} ${OBJECTS}
278 FINAL_LIBS
="${ARNAME} ${LIBNAME} ${LIBNAME}.${VERSION}"
282 VERSION
="${MAJOR}.${MINOR}.${TINY}"
283 LIBNAME
="lib${LIBNAME}.dylib"
284 ARNAME
="lib${LIBNAME}.dylib.a"
285 echo "mklib: Making Darwin libraries: " ${LIBNAME} ${ARNAME}
286 FLAGS
="-dynamiclib -multiply_defined suppress"
287 cc
${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
288 # also make regular .a files,
289 # provided by Danek Duvall (duvall@dhduvall.student.princeton.edu)
290 ar ruv
${ARNAME} ${OBJECTS}
292 FINAL_LIBS
="${ARNAME} ${LIBNAME}"
296 LIBNAME
="lib${LIBNAME}.a"
297 echo "mklib: Making LynxOS library: " ${LIBNAME}
298 ar ru
${LIBNAME} ${OBJECTS}
299 FINAL_LIBS
=${LIBNAME}
303 LIBNAME
="lib${LIBNAME}.so"
304 echo "mklib: Making BeOS shared library: " ${LIBNAME}
305 gcc
-nostart -Xlinker -soname=${LIBNAME} -L/Be/develop/lib/x86 ${OBJECTS} -lbe -o ${LIBNAME}
306 FINAL_LIBS
=${LIBNAME}
310 LIBNAME
="lib${LIBNAME}.a"
311 echo "mklib: Making QNX library: " ${LIBNAME}
312 wlib
${LIBNAME} ${OBJECTS}
313 FINAL_LIBS
=${LIBNAME}
317 LIBNAME
="lib${LIBNAME}.a"
318 echo "mklib: Making MorphOS library: " ${LIBNAME}
319 ppc-morphos-ar rc
${LIBNAME} ${OBJECTS}
320 FINAL_LIBS
="${LIBNAME}"
324 # If you're adding support for a new architecture, you can
326 LIBNAME
="lib${LIBNAME}.so" # prefix with "lib"
327 echo "mklib: Making library for example arch: " ${LIBNAME}
328 ld
-o ${LIBNAME} ${OBJECTS} ${DEPS}
329 FINAL_LIBS
="${LIBNAME}"
333 echo "mklib: WARNING: making library for unknown platform!"
334 echo "mklib: WARNING: this may not work!"
335 echo "mklib: WARNING: please update the bin/mklib script!"
336 # XXX this is a total hack for Mesa - remove someday
337 # fall-back to an old mklib.* script
338 ${TOP}/${MAKELIB} "lib${LIBNAME}.a" ${MAJOR} ${MINOR} ${PATCH} ${OBJECTS}
339 FINAL_LIBS
="${LIBNAME}"
345 # Put library files into installation directory if specified.
347 if [ ${INSTALLDIR} != "." ] ; then
348 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
349 mv ${FINAL_LIBS} ${INSTALLDIR}/