blob: 2bfd1b9e04968a25a91c78677fc724d11b623a58 [file] [log] [blame]
Brian Paul8c20c7b2003-06-01 16:21:45 +00001#!/bin/sh
2
3# Make a shared library.
Brian Paul7c1ab402005-07-25 23:49:50 +00004# This script should be useful for projects other than Mesa.
5# Improvements/fixes are welcome.
Brian Paul8c20c7b2003-06-01 16:21:45 +00006
7
Brian Paul56e0ee82006-04-13 15:17:50 +00008# Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
Brian Paul8c20c7b2003-06-01 16:21:45 +00009#
Brian Paul7c1ab402005-07-25 23:49:50 +000010# Permission is hereby granted, free of charge, to any person obtaining a
11# copy of this software and associated documentation files (the "Software"),
12# to deal in the Software without restriction, including without limitation
13# the rights to use, copy, modify, merge, publish, distribute, sublicense,
14# and/or sell copies of the Software, and to permit persons to whom the
15# Software is furnished to do so, subject to the following conditions:
Brian Paul8c20c7b2003-06-01 16:21:45 +000016#
Brian Paul7c1ab402005-07-25 23:49:50 +000017# The above copyright notice and this permission notice shall be included
18# in all copies or substantial portions of the Software.
Brian Paul8c20c7b2003-06-01 16:21:45 +000019#
Brian Paul7c1ab402005-07-25 23:49:50 +000020# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27
Brian Paul8c20c7b2003-06-01 16:21:45 +000028#
29# Option defaults
30#
31LIBNAME=""
32MAJOR=1
33MINOR=0
Brian Paul6e450f22004-02-21 18:08:41 +000034PATCH=""
Brian Paul8c20c7b2003-06-01 16:21:45 +000035DEPS=""
Brian Paul8dcc6732005-07-25 22:59:58 +000036LINK=""
Dan Nicholson2a3e3382007-09-28 18:42:21 -060037LDFLAGS=""
Brian Paul8c20c7b2003-06-01 16:21:45 +000038CPLUSPLUS=0
39STATIC=0
Brian Paul1e1af992006-04-14 14:14:51 +000040DLOPEN=0
Brian Paul8c20c7b2003-06-01 16:21:45 +000041INSTALLDIR="."
42ARCH="auto"
43ARCHOPT=""
Brian Pauldd74e362004-04-08 22:26:22 +000044NOPREFIX=0
Brian Paul158a2512004-10-16 15:10:45 +000045EXPORTS=""
Brian Paul8c20c7b2003-06-01 16:21:45 +000046
47
48#
49# Parse arguments
50#
51while true
52do
53 case $1 in
Brian Paul7c1ab402005-07-25 23:49:50 +000054 '-h' | '--help')
Eric Anholtf1a26132005-08-08 03:26:18 +000055 echo 'Usage: mklib [options] objects'
56 echo 'Create a shared library from object files.'
57 echo ' -o LIBRARY specifies the name of the resulting library, without'
58 echo ' the leading "lib" or any suffix.'
59 echo ' (eg: "-o GL" might result in "libGL.so" being made)'
60 echo ' -major N specifies major version number (default is 1)'
61 echo ' -minor N specifies minor version number (default is 0)'
62 echo ' -patch N specifies patch version number (default is 0)'
63 echo ' -lLIBRARY specifies a dependency on LIBRARY'
64 echo ' -LDIR search in DIR for library dependencies'
65 echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
66 echo ' Not observed on all systems at this time.'
Dan Nicholson2a3e3382007-09-28 18:42:21 -060067 echo ' -ldflags OPT specify any additional linker flags in OPT'
Eric Anholtf1a26132005-08-08 03:26:18 +000068 echo ' -cplusplus link with C++ runtime'
69 echo ' -static make a static library (default is dynamic/shared)'
Brian Paul1e1af992006-04-14 14:14:51 +000070 echo ' -dlopen make a shared library suitable for dynamic loading'
Eric Anholtf1a26132005-08-08 03:26:18 +000071 echo ' -install DIR put resulting library file(s) in DIR'
72 echo ' -arch ARCH override using `uname` to determine host system'
73 echo ' -archopt OPT specify an extra achitecture-specific option OPT'
74 echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
75 echo ' -exports FILE only export the symbols listed in FILE'
76 echo ' -h, --help display this information and exit'
Brian Paul7c1ab402005-07-25 23:49:50 +000077 exit 1
78 ;;
79 '-o')
80 shift 1;
81 LIBNAME=$1
82 ;;
83 '-major')
84 shift 1;
85 MAJOR=$1
86 ;;
87 '-minor')
88 shift 1;
89 MINOR=$1
90 ;;
91 '-patch')
92 shift 1;
93 PATCH=$1
94 ;;
95 '-linker')
96 shift 1;
97 LINK=$1
98 ;;
Dan Nicholson2a3e3382007-09-28 18:42:21 -060099 '-ldflags')
100 shift 1;
101 LDFLAGS=$1
102 ;;
Brian Paul7c1ab402005-07-25 23:49:50 +0000103 -l*)
104 DEPS="$DEPS $1"
105 ;;
106 -L*)
107 DEPS="$DEPS $1"
108 ;;
Brianed2fddc2007-05-08 14:03:04 -0600109 -pthread)
110 # this is a special case (see bugzilla 10876)
111 DEPS="$DEPS $1"
112 ;;
Eric Anholt1a413b42007-06-22 10:29:54 -0700113 '-pthread')
114 DEPS="$DEPS -pthread"
115 ;;
Brian Paul7c1ab402005-07-25 23:49:50 +0000116 '-cplusplus')
117 CPLUSPLUS=1
118 ;;
119 '-static')
120 STATIC=1
121 ;;
Brian Paul1e1af992006-04-14 14:14:51 +0000122 '-dlopen')
123 DLOPEN=1
124 ;;
Brian Paul7c1ab402005-07-25 23:49:50 +0000125 '-install')
126 shift 1;
127 INSTALLDIR=$1
128 ;;
129 '-arch')
130 shift 1;
131 ARCH=$1
132 ;;
133 '-archopt')
134 shift 1;
135 ARCHOPT=$1
136 ;;
137 '-noprefix')
138 NOPREFIX=1
139 ;;
140 '-exports')
141 shift 1;
142 EXPORTS=$1
143 ;;
144 -*)
145 echo "mklib: Unknown option: " $1 ;
146 exit 1
147 ;;
148 *)
149 # This should be the first object file, stop parsing
150 break
Brian Paul8c20c7b2003-06-01 16:21:45 +0000151 esac
152 shift 1
153done
154OBJECTS=$@
155
Brian Paul7c1ab402005-07-25 23:49:50 +0000156
Brian Paul8c20c7b2003-06-01 16:21:45 +0000157if [ ${ARCH} = "auto" ] ; then
158 ARCH=`uname`
159fi
160
161
162#
163# Error checking
164#
165if [ "x${LIBNAME}" = "x" ] ; then
166 echo "mklib: Error: no library name specified"
167 exit 1
168fi
169if [ "x${OBJECTS}" = "x" ] ; then
170 echo "mklib: Error: no object files specified"
171 exit 1
172fi
173
174
175#
176# Debugging info
177#
178if [ ] ; then
179 echo "-----------------"
180 echo ARCH is $ARCH
181 echo LIBNAME is $LIBNAME
182 echo MAJOR is $MAJOR
183 echo MINOR is $MINOR
184 echo PATCH is $PATCH
185 echo DEPS are $DEPS
Brian Paul158a2512004-10-16 15:10:45 +0000186 echo "EXPORTS in" $EXPORTS
Brian Paul8c20c7b2003-06-01 16:21:45 +0000187 echo "-----------------"
188fi
189
190
191#
192# OK, make the library now
193#
194case $ARCH in
195
Brian Paul5beff7c2006-04-19 14:03:04 +0000196 'Linux' | 'OpenBSD' | 'GNU' | GNU/*)
Brian Paul158a2512004-10-16 15:10:45 +0000197 # we assume gcc
Brian Paul8c20c7b2003-06-01 16:21:45 +0000198
Brian Paul8dcc6732005-07-25 22:59:58 +0000199 if [ "x$LINK" = "x" ] ; then
200 # -linker was not specified so set default link command now
201 if [ $CPLUSPLUS = 1 ] ; then
202 LINK=g++
203 else
204 LINK=gcc
205 fi
Brian Paulc4987422004-10-16 15:02:16 +0000206 fi
207
Brian Pauldd74e362004-04-08 22:26:22 +0000208 if [ $NOPREFIX = 1 ] ; then
209 # No "lib" or ".so" part
210 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
211 #OPTS="-shared -Wl,-soname,${LIBNAME}" # soname???
212 OPTS="-shared"
Ian Romanickaba48642005-08-08 23:22:46 +0000213
214 # Check if objects are 32-bit and we're running in 64-bit
215 # environment. If so, pass -m32 flag to linker.
216 set ${OBJECTS}
217 ABI32=`file $1 | grep 32-bit`
218 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
219 OPTS="-m32 ${OPTS}"
220 fi
221
Brian Pauldd74e362004-04-08 22:26:22 +0000222 rm -f ${LIBNAME}
Brian Pauldd74e362004-04-08 22:26:22 +0000223 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600224 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Pauldd74e362004-04-08 22:26:22 +0000225 # finish up
226 FINAL_LIBS="${LIBNAME}"
227 elif [ $STATIC = 1 ] ; then
Brian98abd1b2007-03-27 07:58:47 -0600228 LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
229 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
Brian Paul56e0ee82006-04-13 15:17:50 +0000230 LINK="ar"
231 OPTS="-ru"
Brian98abd1b2007-03-27 07:58:47 -0600232 rm -f ${LIBNAME}
Brian Paul56e0ee82006-04-13 15:17:50 +0000233 # make lib
Brian98abd1b2007-03-27 07:58:47 -0600234 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
235 ranlib ${LIBNAME}
Brian Paul1c4b7112003-10-10 17:58:38 +0000236 # finish up
Brian98abd1b2007-03-27 07:58:47 -0600237 FINAL_LIBS=${LIBNAME}
Brian Paul1c4b7112003-10-10 17:58:38 +0000238 else
Brian Pauldd74e362004-04-08 22:26:22 +0000239 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5beff7c2006-04-19 14:03:04 +0000240 case $ARCH in 'Linux' | 'GNU' | GNU/*)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000241 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000242 ;;
243 *)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000244 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000245 ;;
246 esac
Brian Paul158a2512004-10-16 15:10:45 +0000247 if [ $EXPORTS ] ; then
248 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
249 # Make the 'exptmp' file for --version-script option
250 echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
251 echo "global:" >> exptmp
252 sed 's/$/;/' ${EXPORTS} >> exptmp
253 echo "local:" >> exptmp
254 echo "*;" >> exptmp
255 echo "};" >> exptmp
256 OPTS="${OPTS} -Xlinker --version-script=exptmp"
257 # exptmp is removed below
258 fi
Brian Paul3e196182005-03-03 01:38:13 +0000259
260 # Check if objects are 32-bit and we're running in 64-bit
261 # environment. If so, pass -m32 flag to linker.
262 set ${OBJECTS}
263 ABI32=`file $1 | grep 32-bit`
264 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
265 OPTS="-m32 ${OPTS}"
266 fi
267
Brian Paul6e450f22004-02-21 18:08:41 +0000268 if [ x${PATCH} = "x" ] ; then
269 VERSION="${MAJOR}.${MINOR}"
270 else
271 VERSION="${MAJOR}.${MINOR}.${PATCH}"
272 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000273
Brian Paul5396ab22004-02-12 14:48:52 +0000274 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000275
Brian Paul1c4b7112003-10-10 17:58:38 +0000276 # rm any old libs
277 rm -f ${LIBNAME}.so.${VERSION}
278 rm -f ${LIBNAME}.so.${MAJOR}
279 rm -f ${LIBNAME}.so
280
281 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600282 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
Brian Paul1c4b7112003-10-10 17:58:38 +0000283 # make usual symlinks
284 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
285 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
286 # finish up
287 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
Brian Paulb17a1a12004-11-01 22:28:42 +0000288# rm -f exptmp
Brian Paul1c4b7112003-10-10 17:58:38 +0000289 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000290 ;;
291
292 'SunOS')
Brian Paul5396ab22004-02-12 14:48:52 +0000293 if [ $STATIC = 1 ] ; then
294 LIBNAME="lib${LIBNAME}.a"
295 echo "mklib: Making SunOS static library: " ${LIBNAME}
296 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000297 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000298 FINAL_LIBS=${LIBNAME}
299 else
Brian Paul0a3a1c62006-11-10 12:47:56 +0000300 if [ $NOPREFIX = 0 ] ; then
301 LIBNAME="lib${LIBNAME}.so"
302 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000303 echo "mklib: Making SunOS shared library: " ${LIBNAME}
Brian Paul59ebe1f2006-04-05 13:43:02 +0000304
Brian Paul8dcc6732005-07-25 22:59:58 +0000305 if [ "x$LINK" = "x" ] ; then
306 # -linker was not specified, choose default linker now
307 if [ $CPLUSPLUS = 1 ] ; then
308 # determine linker and options for C++ code
309 if [ `which c++` ] ; then
310 # use Sun c++
311 LINK="c++"
312 elif [ `type g++` ] ; then
313 # use g++
314 LINK="g++"
315 else
316 echo "mklib: warning: can't find C++ comiler, trying CC."
317 LINK="CC"
318 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000319 else
Brian Paul8dcc6732005-07-25 22:59:58 +0000320 # use native Sun linker for C code
321 LINK="ld"
Brian Paul5396ab22004-02-12 14:48:52 +0000322 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000323 fi
Brian Paul59ebe1f2006-04-05 13:43:02 +0000324
325 # linker options
Brian Paulb3282a32006-04-18 12:56:11 +0000326 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
327 # SunOS tools, -G to make shared libs
Brian Paul59ebe1f2006-04-05 13:43:02 +0000328 OPTS="-G"
329 else
330 # gcc linker
331 # Check if objects are 32-bit and we're running in 64-bit
332 # environment. If so, pass -m32 flag to linker.
333 set ${OBJECTS}
334 ABI32=`file $1 | grep 32-bit`
335 if [ "${ABI32}" ] ; then
336 OPTS="-m32 -shared -Wl,-Bdynamic"
337 else
338 OPTS="-m64 -shared -Wl,-Bdynamic"
339 fi
340 fi
341
Brian Paul1e1af992006-04-14 14:14:51 +0000342 # Check if objects are SPARC v9
343 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
344 set ${OBJECTS}
345 SPARCV9=`file $1 | grep SPARCV9`
346 if [ "${SPARCV9}" ] ; then
347 OPTS="${OPTS} -xarch=v9"
348 fi
349
Brian Paul59ebe1f2006-04-05 13:43:02 +0000350 # for debug:
Brian Paul1e1af992006-04-14 14:14:51 +0000351 #echo "mklib: linker is" ${LINK} ${OPTS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000352 if [ $NOPREFIX = 1 ] ; then
353 rm -f ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600354 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000355 else
356 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600357 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000358 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
359 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000360 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000361 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000362 ;;
363
364 'FreeBSD')
Eric Anholtb83435f2005-10-18 23:36:40 +0000365 # we assume gcc
366
367 if [ "x$LINK" = "x" ] ; then
368 # -linker was not specified so set default link command now
369 if [ $CPLUSPLUS = 1 ] ; then
370 LINK=g++
371 else
372 LINK=gcc
373 fi
374 fi
375
Brian Pauldd74e362004-04-08 22:26:22 +0000376 if [ $NOPREFIX = 1 ] ; then
377 # No "lib" or ".so" part
378 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
Eric Anholtb83435f2005-10-18 23:36:40 +0000379 OPTS="-shared"
Brian Pauldd74e362004-04-08 22:26:22 +0000380 rm -f ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600381 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Pauldd74e362004-04-08 22:26:22 +0000382 FINAL_LIBS=${LIBNAME}
383 elif [ $STATIC = 1 ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000384 STLIB="lib${LIBNAME}.a"
385 echo "mklib: Making FreeBSD static library: " ${STLIB}
386 rm -f ${STLIB}
387 ar cq ${STLIB} ${OBJECTS}
388 ranlib ${STLIB}
389 FINAL_LIBS=${STLIB}
390 else
Eric Anholtb83435f2005-10-18 23:36:40 +0000391 SHLIB="lib${LIBNAME}.so.${MAJOR}"
392 OPTS="-shared -Wl,-soname,${SHLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000393 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
394 rm -f ${SHLIB}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600395 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
Eric Anholt1c04be52005-10-22 01:41:40 +0000396 ln -sf ${SHLIB} "lib${LIBNAME}.so"
397 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
Brian Paul5396ab22004-02-12 14:48:52 +0000398 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000399 ;;
400
Brian Paul8c20c7b2003-06-01 16:21:45 +0000401 'NetBSD')
Brian Paul5396ab22004-02-12 14:48:52 +0000402 if [ $STATIC = 1 ] ; then
403 LIBNAME="lib${LIBNAME}_pic.a"
404 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
405 rm -f ${LIBNAME}
406 ar cq ${LIBNAME} ${OBJECTS}
407 ranlib ${LIBNAME}
408 FINAL_LIBS=${LIBNAME}
409 else
410 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
411 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
412 rm -f ${LIBNAME}
413 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
414 FINAL_LIBS=${LIBNAME}
415 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000416 ;;
417
Brian Paulf8c31fc2004-01-29 15:21:47 +0000418 'IRIX' | 'IRIX64')
Brian Paul5396ab22004-02-12 14:48:52 +0000419 if [ $STATIC = 1 ] ; then
420 LIBNAME="lib${LIBNAME}.a"
421 rm -f ${LIBNAME}
422 ar rc ${LIBNAME} ${OBJECTS}
423 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000424 else
Brian Paul5396ab22004-02-12 14:48:52 +0000425 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul1e1af992006-04-14 14:14:51 +0000426
427 # examine first object to determine ABI
428 set ${OBJECTS}
429 ABI_O32=`file $1 | grep 'ELF 32-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000430 ABI_N32=`file $1 | grep 'ELF N32'`
Brian Paul1e1af992006-04-14 14:14:51 +0000431 ABI_N64=`file $1 | grep 'ELF 64-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000432 if [ "${ABI_O32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000433 OPTS="-32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000434 ABI="o32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000435 elif [ "${ABI_N32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000436 OPTS="-n32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000437 ABI="n32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000438 elif [ "${ABI_N64}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000439 OPTS="-64 -shared -all"
440 ABI="64-bit"
441 else
442 echo "Error: Unexpected IRIX ABI!"
443 exit 1
Brian Paul5396ab22004-02-12 14:48:52 +0000444 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000445
Brian Paul5396ab22004-02-12 14:48:52 +0000446 if [ $CPLUSPLUS = 1 ] ; then
447 LINK="CC"
448 else
449 LINK="ld"
450 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000451
452 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600453 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000454 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000455 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000456 ;;
457
Brian Paul8c20c7b2003-06-01 16:21:45 +0000458 'linux-cygwin')
459 LIBNAME="lib${LIBNAME}.a"
460 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000461 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000462 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
463 FINAL_LIBS=${LIBNAME}
464 ;;
465
Brian Paulc193bd02004-03-18 15:41:59 +0000466 'HP-UX')
Brian Paul5396ab22004-02-12 14:48:52 +0000467 if [ $STATIC = 1 ] ; then
468 LIBNAME="lib${LIBNAME}.a"
Brian Paul52fb07e2004-03-30 14:47:02 +0000469 echo "mklib: Making HP-UX static library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000470 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000471 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000472 FINAL_LIBS=${LIBNAME}
473 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000474 # HP uses a .2 for their current GL/GLU libraries
475 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
476 MAJOR=2
477 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000478 RUNLIB="lib${LIBNAME}.${MAJOR}"
479 DEVLIB="lib${LIBNAME}.sl"
Brian Paul52fb07e2004-03-30 14:47:02 +0000480 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
Brian Paul5396ab22004-02-12 14:48:52 +0000481 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
482 ln -s ${RUNLIB} ${DEVLIB}
Brian Paulac0cfee2004-04-25 15:13:56 +0000483 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000484 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000485 ;;
486
Brian Paulb3282a32006-04-18 12:56:11 +0000487 'AIX' )
488 # examine first object to determine ABI
489 set ${OBJECTS}
490 ABI_64=`file $1 | grep '64-bit'`
491 if [ "${ABI_64}" ] ; then
Brian Paulb17a1a12004-11-01 22:28:42 +0000492 X64="-X64"
Brian Paulb3282a32006-04-18 12:56:11 +0000493 Q64="-q64"
494 OFILE=shr_64.o
495 else
496 OFILE=shr.o #Want to be consistent with the IBM libGL.a
Brian Paulb17a1a12004-11-01 22:28:42 +0000497 fi
Brian Paulc193bd02004-03-18 15:41:59 +0000498
Brian Paulb3282a32006-04-18 12:56:11 +0000499 if [ $STATIC = 1 ] ; then
500 LIBNAME="lib${LIBNAME}.a"
501 echo "mklib: Making AIX static library: " ${LIBNAME}
502 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
503 FINAL_LIBS=${LIBNAME}
504 else
Karl Schultza16bdb52004-10-01 13:33:26 +0000505 EXPFILE="lib${LIBNAME}.exp"
Karl Schultza16bdb52004-10-01 13:33:26 +0000506 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
Brian Paulb3282a32006-04-18 12:56:11 +0000507 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000508 rm -f ${EXPFILE} ${OFILE}
Brian Paulb17a1a12004-11-01 22:28:42 +0000509 NM="/bin/nm -eC ${X64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000510 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
511 ${NM} ${OBJECTS} | awk '{
512 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
513 && ( substr($1,1,1) != ".")) {
514 if (substr ($1, 1, 7) != "__sinit" &&
515 substr ($1, 1, 7) != "__sterm") {
516 if (substr ($1, 1, 5) == "__tf1")
517 print (substr ($1, 7))
518 else if (substr ($1, 1, 5) == "__tf9")
519 print (substr ($1, 15))
520 else
521 print $1
522 }
523 }
524 }' | sort -u >> ${EXPFILE}
Brian Paulfe14cf62006-04-13 02:23:25 +0000525
526 # On AIX a shared library is linked differently when
527 # you want to dlopen the file
Brian Paul1e1af992006-04-14 14:14:51 +0000528 if [ $DLOPEN = "1" ] ; then
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600529 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul1e1af992006-04-14 14:14:51 +0000530 else
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600531 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
Brian Paul1e1af992006-04-14 14:14:51 +0000532 ar ${X64} -r ${LIBNAME} ${OFILE}
533 fi
Brian Paul56e0ee82006-04-13 15:17:50 +0000534
Brian Paul1e1af992006-04-14 14:14:51 +0000535 FINAL_LIBS="${LIBNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000536 fi
537 ;;
538
Brian Paul8c20c7b2003-06-01 16:21:45 +0000539 'OpenSTEP')
540 LIBNAME="lib${LIBNAME}.a"
541 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
542 libtool -static -o ${LIBNAME} - ${OBJECTS}
543 FINAL_LIBS=${LIBNAME}
544 ;;
545
546 'OSF1')
Brian Paul5396ab22004-02-12 14:48:52 +0000547 if [ $STATIC = 1 ] ; then
548 LIBNAME="lib${LIBNAME}.a"
549 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
550 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000551 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000552 FINAL_LIBS=${LIBNAME}
553 else
554 VERSION="${MAJOR}.${MINOR}"
555 LIBNAME="lib${LIBNAME}.so"
556 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
Brian Paul8dcc6732005-07-25 22:59:58 +0000557 if [ "x$LINK" = "x" ] ; then
558 if [ $CPLUSPLUS = 1 ] ; then
559 LINK=cxx
560 else
561 LINK=cc
562 fi
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000563 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000564 rm -f ${LIBNAME}.${VERSION}
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000565 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000566 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
567 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
568 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000569 ;;
570
571 'Darwin')
Brian Paulc193bd02004-03-18 15:41:59 +0000572 if [ $STATIC = 1 ] ; then
573 LIBNAME="lib${LIBNAME}.a"
574 echo "mklib: Making Darwin static library: " ${LIBNAME}
575 LINK="ar"
Brian Paulfe14cf62006-04-13 02:23:25 +0000576 OPTS="-ruvs"
Brian Paulc193bd02004-03-18 15:41:59 +0000577 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
578 FINAL_LIBS=${LIBNAME}
579 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000580 # On Darwin a .bundle is used for a library that you want to dlopen
Brian Paul1e1af992006-04-14 14:14:51 +0000581 if [ $DLOPEN = "1" ] ; then
582 LIBSUFFIX="bundle"
583 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
584 else
585 LIBSUFFIX="dylib"
586 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
587 fi
588 LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
589 LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
590
591 # examine first object to determine ABI
592 set ${OBJECTS}
Brian Paulb3282a32006-04-18 12:56:11 +0000593 ABI_PPC=`file $1 | grep 'object ppc'`
Brian Paul1e1af992006-04-14 14:14:51 +0000594 ABI_I386=`file $1 | grep 'object i386'`
Brian Paulb3282a32006-04-18 12:56:11 +0000595 if [ "${ABI_PPC}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000596 OPTS="${OPTS} -arch ppc"
597 fi
Brian Paulb3282a32006-04-18 12:56:11 +0000598 if [ "${ABI_I386}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000599 OPTS="${OPTS} -arch i386"
600 fi
601
602 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
603 # to OPTS here?
604
605 # determine linker
Brian Paul56e0ee82006-04-13 15:17:50 +0000606 if [ $CPLUSPLUS = 1 ] ; then
607 LINK="g++"
608 else
609 LINK="cc"
610 fi
Brian Paulfe14cf62006-04-13 02:23:25 +0000611
Brian Paulc50d77a2004-04-13 17:35:17 +0000612 echo "mklib: Making Darwin shared library: " ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600613 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paulfe14cf62006-04-13 02:23:25 +0000614 ln -s ${LIBNAME} ${LINKNAME}
Brian Paul1e1af992006-04-14 14:14:51 +0000615 FINAL_LIBS="${LIBNAME} ${LINKNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000616 fi
617 ;;
Brian Paul8c20c7b2003-06-01 16:21:45 +0000618
619 'LynxOS')
620 LIBNAME="lib${LIBNAME}.a"
Brian Paul5396ab22004-02-12 14:48:52 +0000621 echo "mklib: Making LynxOS static library: " ${LIBNAME}
622 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000623 ar ru ${LIBNAME} ${OBJECTS}
624 FINAL_LIBS=${LIBNAME}
625 ;;
626
627 'BeOS')
Philippe Houdoinef4dd5a2004-08-14 10:12:38 +0000628 if [ $STATIC = 1 ] ; then
629 LIBNAME="lib${LIBNAME}.a"
630 echo "mklib: Making BeOS static library: " ${LIBNAME}
631 ar -cru "${LIBNAME}" ${OBJECTS}
632 else
Brian Paulb784b8f2004-08-14 14:30:36 +0000633 LIBNAME="lib${LIBNAME}.so"
634 echo "mklib: Making BeOS shared library: " ${LIBNAME}
635 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
636 mimeset -f "${LIBNAME}"
Brian Paul8dcc6732005-07-25 22:59:58 +0000637 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
Brian Paulb784b8f2004-08-14 14:30:36 +0000638 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
639 fi
640 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000641 ;;
642
643 'QNX')
644 LIBNAME="lib${LIBNAME}.a"
645 echo "mklib: Making QNX library: " ${LIBNAME}
646 wlib ${LIBNAME} ${OBJECTS}
647 FINAL_LIBS=${LIBNAME}
648 ;;
649
Brian Paul65e2ab32003-10-27 18:13:37 +0000650 'MorphOS')
651 LIBNAME="lib${LIBNAME}.a"
652 echo "mklib: Making MorphOS library: " ${LIBNAME}
653 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
654 FINAL_LIBS="${LIBNAME}"
655 ;;
656
Brian Paulfe14cf62006-04-13 02:23:25 +0000657 'icc' | 'icc-istatic')
Brian Paulb3b725b2003-12-15 16:14:55 +0000658 # Intel C compiler
Brian Paul7c1ab402005-07-25 23:49:50 +0000659 # This should get merged into the Linux code, above, since this isn't
660 # really a different architecture.
Brian Paulb3b725b2003-12-15 16:14:55 +0000661 LIBNAME="lib${LIBNAME}" # prefix with "lib"
662
663 if [ $STATIC = 1 ] ; then
664 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
665 LINK="ar"
666 OPTS="-ruv"
667 # make lib
668 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
669 # finish up
670 FINAL_LIBS="${LIBNAME}.a"
671 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000672 if [ $ARCH = icc-istatic ] ; then
673 OPTS="-shared -i-static -cxxlib-icc"
674 else
675 OPTS="-shared"
676 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000677 VERSION="${MAJOR}.${MINOR}.${PATCH}"
Brian Paulb3b725b2003-12-15 16:14:55 +0000678 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
679
680 if [ $CPLUSPLUS = 1 ] ; then
Brian Paulfe14cf62006-04-13 02:23:25 +0000681 LINK="icpc"
Brian Paulb3b725b2003-12-15 16:14:55 +0000682 else
683 LINK="icc"
684 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000685 # rm any old libs
686 rm -f ${LIBNAME}.so.${VERSION}
687 rm -f ${LIBNAME}.so.${MAJOR}
688 rm -f ${LIBNAME}.so
Brian Paulb3b725b2003-12-15 16:14:55 +0000689 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600690 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
Brian Paulb3b725b2003-12-15 16:14:55 +0000691 # make usual symlinks
692 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
693 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
694 # finish up
695 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
696 fi
697 ;;
698
Brian Paul12d6cae2004-01-10 22:12:21 +0000699 'aix-gcc')
700 # AIX with gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000701 if [ $STATIC = 1 ] ; then
702 LIBNAME="lib${LIBNAME}.a"
703 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
704 rm -f ${LIBNAME}
705 ar ru ${LIBNAME} ${OBJECTS}
706 FINAL_LIBS=${LIBNAME}
707 else
708 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
709 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
710 # remove old lib
711 rm -f ${LIBNAME}
712 # make the lib
713 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000714 # NOTE: the application linking with this library must specify
715 # the -Wl,-brtl flags to gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000716 FINAL_LIBS=${LIBNAME}
717 fi
718 ;;
719
720 'ultrix')
721 # XXX untested
722 if [ $STATIC = 0 ] ; then
723 echo "mklib: Warning shared libs not supported on Ultrix"
724 fi
725 LIBNAME="lib${LIBNAME}.a"
726 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
Brian Paul12d6cae2004-01-10 22:12:21 +0000727 rm -f ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000728 ar ru ${LIBNAME} ${OBJECTS}
729 FINAL_LIBS="${LIBNAME}"
Brian Paul12d6cae2004-01-10 22:12:21 +0000730 ;;
Brian Paulb3b725b2003-12-15 16:14:55 +0000731
Brian Paul580548d2004-04-22 16:16:42 +0000732 CYGWIN*)
733 # GCC-based environment
734 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
735 LIBNAME="lib${LIBNAME}" # prefix with "lib"
736
737 if [ $STATIC = 1 ] ; then
738 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
739 LINK="ar"
740 OPTS="-ru"
741 # make lib
742 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
743 ranlib ${LIBNAME}.a
744 # finish up
745 FINAL_LIBS=${LIBNAME}.a
746 else
747 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
748 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
749
750 if [ $CPLUSPLUS = 1 ] ; then
751 LINK="g++"
752 else
753 LINK="gcc"
754 fi
755
756 # rm any old libs
757 rm -f ${LIBNAME}-${MAJOR}.dll
758 rm -f ${LIBNAME}.dll.a
759 rm -f ${LIBNAME}.a
760
761 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600762 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
Brian Paul580548d2004-04-22 16:16:42 +0000763 # make usual symlinks
764 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
765 # finish up
766 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
767 # special case for installing in bin
768 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
769 fi
770 ;;
771
Brian Paul8c20c7b2003-06-01 16:21:45 +0000772 'example')
773 # If you're adding support for a new architecture, you can
774 # start with this:
Brian Paul5396ab22004-02-12 14:48:52 +0000775 if [ $STATIC = 1 ] ; then
776 LIBNAME="lib${LIBNAME}.a"
777 echo "mklib: Making static library for example arch: " ${LIBNAME}
778 rm -f ${LIBNAME}
779 ar rv ${LIBNAME} ${OBJECTS}
780 FINAL_LIBS="${LIBNAME}"
781 else
Brian Paul7c1ab402005-07-25 23:49:50 +0000782 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul5396ab22004-02-12 14:48:52 +0000783 echo "mklib: Making shared library for example arch: " ${LIBNAME}
784 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
785 FINAL_LIBS="${LIBNAME}"
786 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000787 ;;
788
789 *)
Brian Paul5396ab22004-02-12 14:48:52 +0000790 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
791 echo "mklib: Please add necessary commands to mklib script."
Brian Paul8c20c7b2003-06-01 16:21:45 +0000792 ;;
793esac
794
795
796#
797# Put library files into installation directory if specified.
798#
799if [ ${INSTALLDIR} != "." ] ; then
800 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
801 mv ${FINAL_LIBS} ${INSTALLDIR}/
802fi