blob: 317abc06957bcf064a8f70eeab96665336117bd8 [file] [log] [blame]
Brian Paul8c20c7b2003-06-01 16:21:45 +00001#!/bin/sh
2
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.
6
7
8# Usage:
9# mklib [options] objects ...
10# Options:
Brian Paul1a644b32003-12-06 17:57:12 +000011# -o LIBRARY specifies the name of resulting library
12# ("-o GL" for example, might result in "libGL.so" being made)
Brian Paul8c20c7b2003-06-01 16:21:45 +000013# -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
23#
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.
26#
27# objects should be: foo.o bar.o etc.o
28#
29# Environment variables recognized:
30# CC C compiler command
31# CXX C++ compiler command
32#
33
34
35#
36# Option defaults
37#
38LIBNAME=""
39MAJOR=1
40MINOR=0
41PATCH=0
42DEPS=""
43CPLUSPLUS=0
44STATIC=0
45INSTALLDIR="."
46ARCH="auto"
47ARCHOPT=""
48
49
50#
51# Parse arguments
52#
53while true
54do
55 case $1 in
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;;
63 '-static') STATIC=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;;
68 *) break
69 esac
70 shift 1
71done
72OBJECTS=$@
73
74if [ ${ARCH} = "auto" ] ; then
75 ARCH=`uname`
76fi
77
78
79#
80# Error checking
81#
82if [ "x${LIBNAME}" = "x" ] ; then
83 echo "mklib: Error: no library name specified"
84 exit 1
85fi
86if [ "x${OBJECTS}" = "x" ] ; then
87 echo "mklib: Error: no object files specified"
88 exit 1
89fi
90
91
92#
93# Debugging info
94#
95if [ ] ; then
96 echo "-----------------"
97 echo ARCH is $ARCH
98 echo LIBNAME is $LIBNAME
99 echo MAJOR is $MAJOR
100 echo MINOR is $MINOR
101 echo PATCH is $PATCH
102 echo DEPS are $DEPS
103 echo "-----------------"
104fi
105
106
107#
108# OK, make the library now
109#
110case $ARCH in
111
Brian Paul12d6cae2004-01-10 22:12:21 +0000112 'Linux' | 'OpenBSD')
113 # GCC-based environment
Brian Paul8c20c7b2003-06-01 16:21:45 +0000114 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000115
Brian Paul1c4b7112003-10-10 17:58:38 +0000116 if [ $STATIC = 1 ] ; then
Brian Paul5b9a9d42004-01-17 18:31:12 +0000117 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
Brian Paul1c4b7112003-10-10 17:58:38 +0000118 LINK="ar"
119 OPTS="-ruv"
120 # make lib
121 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
122 # finish up
123 FINAL_LIBS="${LIBNAME}.a"
124 else
Brian Paul5b9a9d42004-01-17 18:31:12 +0000125 if [ $ARCH = 'Linux' ] ; then
126 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
127 else
128 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
129 fi
Brian Paul1c4b7112003-10-10 17:58:38 +0000130 VERSION="${MAJOR}.${MINOR}.${PATCH}"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000131
Brian Paul12d6cae2004-01-10 22:12:21 +0000132 echo "mklib: Making " $ARCH " shared library: " ${LIBNAME}.so.${VERSION}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000133
Brian Paul1c4b7112003-10-10 17:58:38 +0000134 if [ $CPLUSPLUS = 1 ] ; then
135 LINK="g++"
136 else
137 LINK="gcc"
138 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000139
Brian Paul1c4b7112003-10-10 17:58:38 +0000140 # rm any old libs
141 rm -f ${LIBNAME}.so.${VERSION}
142 rm -f ${LIBNAME}.so.${MAJOR}
143 rm -f ${LIBNAME}.so
144
145 # make lib
146 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
147 # make usual symlinks
148 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
149 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
150 # finish up
151 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
152 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000153 ;;
154
155 'SunOS')
156 LIBNAME="lib${LIBNAME}.so"
157 echo "mklib: Making SunOS shared library: " ${LIBNAME}
Brian Paul4b603442004-01-14 23:18:47 +0000158 # XXX OPTS for gcc should be -shared, but that doesn't work.
159 # Using -G does work though.
Brian Paul8c20c7b2003-06-01 16:21:45 +0000160 if [ $CPLUSPLUS = 1 ] ; then
Brian Paul1a644b32003-12-06 17:57:12 +0000161 # determine linker and options for C++ code
Brian Paul8c20c7b2003-06-01 16:21:45 +0000162 if [ "x${CXX}" = "xg++" ] ; then
Brian Paul1a644b32003-12-06 17:57:12 +0000163 # use g++
Brian Paul8c20c7b2003-06-01 16:21:45 +0000164 LINK="g++"
Brian Paul4b603442004-01-14 23:18:47 +0000165 OPTS="-G"
Brian Paul17610872003-09-08 14:59:11 +0000166 elif [ "x${CXX}" = "xCC" ] ; then
Brian Paul1a644b32003-12-06 17:57:12 +0000167 # use Sun CC
Brian Paul17610872003-09-08 14:59:11 +0000168 LINK="CC"
Brian Paul1a644b32003-12-06 17:57:12 +0000169 OPTS="-G"
170 elif [ "x${CXX}" = "xc++" ] ; then
171 # use Sun c++
Brian Paul8c20c7b2003-06-01 16:21:45 +0000172 LINK="c++"
Brian Paul1a644b32003-12-06 17:57:12 +0000173 OPTS="-G"
174 elif [ `which c++` ] ; then
175 # use Sun c++
176 LINK="c++"
177 OPTS="-G"
Brian Paul17610872003-09-08 14:59:11 +0000178 elif [ `type g++` ] ; then
Brian Paul1a644b32003-12-06 17:57:12 +0000179 # use g++
Brian Paul8c20c7b2003-06-01 16:21:45 +0000180 LINK="g++"
Brian Paul4b603442004-01-14 23:18:47 +0000181 OPTS="-G"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000182 else
183 echo "mklib: warning: can't find C++ comiler, trying CC."
184 LINK="CC"
Brian Paul1a644b32003-12-06 17:57:12 +0000185 OPTS="-G"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000186 fi
187 elif [ "x${CC}" = "xgcc" ] ; then
188 # use gcc for linking
189 LINK="gcc"
Brian Paul4b603442004-01-14 23:18:47 +0000190 OPTS="-G"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000191 else
192 # use native Sun linker
193 LINK="ld"
Brian Paul1a644b32003-12-06 17:57:12 +0000194 OPTS="-G"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000195 fi
Brian Paul1a644b32003-12-06 17:57:12 +0000196 echo "mklib: linker is" ${LINK} ${OPTS}
Brian Paul5b9a9d42004-01-17 18:31:12 +0000197 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
198 ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
199 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
200 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000201 ;;
202
203 'FreeBSD')
204 SHLIB="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
205 STLIB="lib${LIBNAME}.a"
206 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
207 rm -f ${SHLIB} ${STLIB}
208 ar cq ${STLIB} ${OBJECTS}
209 ranlib ${STLIB}
210 ld -Bshareable -o ${SHLIB} ${OBJECTS}
211 # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
212 FINAL_LIBS="${SHLIB} ${STLIB}"
213 ;;
214
Brian Paul8c20c7b2003-06-01 16:21:45 +0000215 'NetBSD')
216 LIBNAME="lib${LIBNAME}"
217 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
218 VERSION="${MAJOR}.${MINOR}"
219 rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}
220 ar cq ${LIBNAME}_pic.a ${OBJECTS}
221 ranlib ${LIBNAME}_pic.a
222 ld -x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a
223 FINAL_LIBS="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}"
224 ;;
225
226 'IRIX')
227 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
228 if [ $ARCHOPTS = "64" ] ; then
229 # 64-bit ABI
230 OPTS="-64 -shared -all"
231 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
232 elif [ $ARCHOPTS = "o32" ] ; then
233 # old 32-bit ABI
234 OPTS="-32 -shared -all"
235 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
236 else
237 # new 32-bit ABI
238 OPTS="-n32 -shared -all"
239 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
240 fi
Brian Paul9ca723f2004-01-28 22:54:33 +0000241 if [ $CPLUSPLUS = 1 ] ; then
242 LINK="CC"
243 else
244 LINK="ld"
245 fi
246 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000247 FINAL_LIBS="${LIBNAME}"
248 ;;
249
250 'IRIX64')
251 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
252 echo "mklib: Making IRIX64 library: " ${LIBNAME}
253 # 64-bit ABI
254 OPTS="-64 -shared -all"
Brian Paul9ca723f2004-01-28 22:54:33 +0000255 if [ $CPLUSPLUS = 1 ] ; then
256 LINK="CC"
257 else
258 LINK="ld"
259 fi
260 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000261 FINAL_LIBS="${LIBNAME}"
262 ;;
263
264 'linux-cygwin')
265 LIBNAME="lib${LIBNAME}.a"
266 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
267 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
268 FINAL_LIBS=${LIBNAME}
269 ;;
270
271 'HPUX')
272 RUNLIB="lib${LIBNAME}.${MAJOR}"
273 DEVLIB="lib${LIBNAME}.sl"
274 echo "mklib: Making HPUX library: " ${RUNLIB} ${DEVLIB}
275 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
276 ln -s ${RUNLIB} ${DEVLIB}
277 FINAL_LIBS="{RUNLIB} ${DEVLIB}"
278 ;;
279
280 'OpenSTEP')
281 LIBNAME="lib${LIBNAME}.a"
282 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
283 libtool -static -o ${LIBNAME} - ${OBJECTS}
284 FINAL_LIBS=${LIBNAME}
285 ;;
286
287 'OSF1')
288 VERSION="${MAJOR}.${MINOR}"
289 LIBNAME="lib${LIBNAME}.so"
290 ARNAME="lib${LIBNAME}.a"
291 echo "mklib: Making OSF/1 library: " ${LIBNAME}
292 rm -f ${LIBNAME}.${VERSION}
293 ld -o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
294 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
295
296 # also make static lib
297 rm -f ${ARNAME}
298 ar clqz ${ARNAME} ${OBJECTS}
299 FINAL_LIBS="${ARNAME} ${LIBNAME} ${LIBNAME}.${VERSION}"
300 ;;
301
302 'Darwin')
303 VERSION="${MAJOR}.${MINOR}.${TINY}"
304 LIBNAME="lib${LIBNAME}.dylib"
305 ARNAME="lib${LIBNAME}.dylib.a"
306 echo "mklib: Making Darwin libraries: " ${LIBNAME} ${ARNAME}
307 FLAGS="-dynamiclib -multiply_defined suppress"
308 cc ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
309 # also make regular .a files,
310 # provided by Danek Duvall (duvall@dhduvall.student.princeton.edu)
311 ar ruv ${ARNAME} ${OBJECTS}
312 ranlib ${ARNAME}
313 FINAL_LIBS="${ARNAME} ${LIBNAME}"
314 ;;
315
316 'LynxOS')
317 LIBNAME="lib${LIBNAME}.a"
318 echo "mklib: Making LynxOS library: " ${LIBNAME}
319 ar ru ${LIBNAME} ${OBJECTS}
320 FINAL_LIBS=${LIBNAME}
321 ;;
322
323 'BeOS')
324 LIBNAME="lib${LIBNAME}.so"
325 echo "mklib: Making BeOS shared library: " ${LIBNAME}
326 gcc -nostart -Xlinker -soname=${LIBNAME} -L/Be/develop/lib/x86 ${OBJECTS} -lbe -o ${LIBNAME}
327 FINAL_LIBS=${LIBNAME}
328 ;;
329
330 'QNX')
331 LIBNAME="lib${LIBNAME}.a"
332 echo "mklib: Making QNX library: " ${LIBNAME}
333 wlib ${LIBNAME} ${OBJECTS}
334 FINAL_LIBS=${LIBNAME}
335 ;;
336
Brian Paul65e2ab32003-10-27 18:13:37 +0000337 'MorphOS')
338 LIBNAME="lib${LIBNAME}.a"
339 echo "mklib: Making MorphOS library: " ${LIBNAME}
340 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
341 FINAL_LIBS="${LIBNAME}"
342 ;;
343
Brian Paulb3b725b2003-12-15 16:14:55 +0000344 'icc')
345 # Intel C compiler
346 LIBNAME="lib${LIBNAME}" # prefix with "lib"
347
348 if [ $STATIC = 1 ] ; then
349 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
350 LINK="ar"
351 OPTS="-ruv"
352 # make lib
353 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
354 # finish up
355 FINAL_LIBS="${LIBNAME}.a"
356 else
357 OPTS="-shared"
358 VERSION="${MAJOR}.${MINOR}.${PATCH}"
359
360 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
361
362 if [ $CPLUSPLUS = 1 ] ; then
363 LINK="icc"
364 else
365 LINK="icc"
366 fi
367
368 # rm any old libs
369 rm -f ${LIBNAME}.so.${VERSION}
370 rm -f ${LIBNAME}.so.${MAJOR}
371 rm -f ${LIBNAME}.so
372
373 # make lib
374 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
375 # make usual symlinks
376 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
377 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
378 # finish up
379 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
380 fi
381 ;;
382
Brian Paul12d6cae2004-01-10 22:12:21 +0000383 'aix-gcc')
384 # AIX with gcc
385 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
386 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
387 # remove old lib
388 rm -f ${LIBNAME}
389 # make the lib
390 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
391
392 # NOTE: the application linking with this library must specify
393 # the -Wl,-brtl flags to gcc
394
395 FINAL_LIBS=${LIBNAME}
396 ;;
Brian Paulb3b725b2003-12-15 16:14:55 +0000397
Brian Paul8c20c7b2003-06-01 16:21:45 +0000398 'example')
399 # If you're adding support for a new architecture, you can
400 # start with this:
401 LIBNAME="lib${LIBNAME}.so" # prefix with "lib"
402 echo "mklib: Making library for example arch: " ${LIBNAME}
403 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
404 FINAL_LIBS="${LIBNAME}"
405 ;;
406
407 *)
408 echo "mklib: WARNING: making library for unknown platform!"
409 echo "mklib: WARNING: this may not work!"
410 echo "mklib: WARNING: please update the bin/mklib script!"
411 # XXX this is a total hack for Mesa - remove someday
412 # fall-back to an old mklib.* script
Brian Paulf0233912003-11-03 21:59:36 +0000413 LIBNAME="lib${LIBNAME}.a"
Brian Paule96a1212003-10-27 20:04:43 +0000414 ${TOP}/${MAKELIB} "lib${LIBNAME}.a" ${MAJOR} ${MINOR} ${PATCH} ${OBJECTS}
Brian Paul65e2ab32003-10-27 18:13:37 +0000415 FINAL_LIBS="${LIBNAME}"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000416 ;;
417esac
418
419
420#
421# Put library files into installation directory if specified.
422#
423if [ ${INSTALLDIR} != "." ] ; then
424 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
425 mv ${FINAL_LIBS} ${INSTALLDIR}/
426fi