blob: 7d271de11805763984cebaf9e5ccc68232059364 [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}
Michel Dänzerfc7ddea2007-12-04 10:46:45 +0100211 case $ARCH in 'Linux' | 'GNU' | GNU/*)
212 OPTS="-Xlinker -Bsymbolic -shared"
213 ;;
214 *)
215 OPTS="-shared"
216 ;;
217 esac
Ian Romanickaba48642005-08-08 23:22:46 +0000218
219 # Check if objects are 32-bit and we're running in 64-bit
220 # environment. If so, pass -m32 flag to linker.
221 set ${OBJECTS}
222 ABI32=`file $1 | grep 32-bit`
223 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
224 OPTS="-m32 ${OPTS}"
225 fi
226
Brian Pauldd74e362004-04-08 22:26:22 +0000227 rm -f ${LIBNAME}
Brian Pauldd74e362004-04-08 22:26:22 +0000228 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600229 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Pauldd74e362004-04-08 22:26:22 +0000230 # finish up
231 FINAL_LIBS="${LIBNAME}"
232 elif [ $STATIC = 1 ] ; then
Brian98abd1b2007-03-27 07:58:47 -0600233 LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
234 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
Brian Paul56e0ee82006-04-13 15:17:50 +0000235 LINK="ar"
236 OPTS="-ru"
Brian98abd1b2007-03-27 07:58:47 -0600237 rm -f ${LIBNAME}
Brian Paul56e0ee82006-04-13 15:17:50 +0000238 # make lib
Brian98abd1b2007-03-27 07:58:47 -0600239 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
240 ranlib ${LIBNAME}
Brian Paul1c4b7112003-10-10 17:58:38 +0000241 # finish up
Brian98abd1b2007-03-27 07:58:47 -0600242 FINAL_LIBS=${LIBNAME}
Brian Paul1c4b7112003-10-10 17:58:38 +0000243 else
Brian Pauldd74e362004-04-08 22:26:22 +0000244 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5beff7c2006-04-19 14:03:04 +0000245 case $ARCH in 'Linux' | 'GNU' | GNU/*)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000246 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000247 ;;
248 *)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000249 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000250 ;;
251 esac
Brian Paul158a2512004-10-16 15:10:45 +0000252 if [ $EXPORTS ] ; then
253 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
254 # Make the 'exptmp' file for --version-script option
255 echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
256 echo "global:" >> exptmp
257 sed 's/$/;/' ${EXPORTS} >> exptmp
258 echo "local:" >> exptmp
259 echo "*;" >> exptmp
260 echo "};" >> exptmp
261 OPTS="${OPTS} -Xlinker --version-script=exptmp"
262 # exptmp is removed below
263 fi
Brian Paul3e196182005-03-03 01:38:13 +0000264
265 # Check if objects are 32-bit and we're running in 64-bit
266 # environment. If so, pass -m32 flag to linker.
267 set ${OBJECTS}
268 ABI32=`file $1 | grep 32-bit`
269 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
270 OPTS="-m32 ${OPTS}"
271 fi
272
Brian Paul6e450f22004-02-21 18:08:41 +0000273 if [ x${PATCH} = "x" ] ; then
274 VERSION="${MAJOR}.${MINOR}"
275 else
276 VERSION="${MAJOR}.${MINOR}.${PATCH}"
277 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000278
Brian Paul5396ab22004-02-12 14:48:52 +0000279 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000280
Brian Paul1c4b7112003-10-10 17:58:38 +0000281 # rm any old libs
282 rm -f ${LIBNAME}.so.${VERSION}
283 rm -f ${LIBNAME}.so.${MAJOR}
284 rm -f ${LIBNAME}.so
285
286 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600287 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
Brian Paul1c4b7112003-10-10 17:58:38 +0000288 # make usual symlinks
289 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
290 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
291 # finish up
292 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
Brian Paulb17a1a12004-11-01 22:28:42 +0000293# rm -f exptmp
Brian Paul1c4b7112003-10-10 17:58:38 +0000294 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000295 ;;
296
297 'SunOS')
Brian Paul5396ab22004-02-12 14:48:52 +0000298 if [ $STATIC = 1 ] ; then
299 LIBNAME="lib${LIBNAME}.a"
300 echo "mklib: Making SunOS static library: " ${LIBNAME}
301 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000302 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000303 FINAL_LIBS=${LIBNAME}
304 else
Brian Paul0a3a1c62006-11-10 12:47:56 +0000305 if [ $NOPREFIX = 0 ] ; then
306 LIBNAME="lib${LIBNAME}.so"
307 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000308 echo "mklib: Making SunOS shared library: " ${LIBNAME}
Brian Paul59ebe1f2006-04-05 13:43:02 +0000309
Brian Paul8dcc6732005-07-25 22:59:58 +0000310 if [ "x$LINK" = "x" ] ; then
311 # -linker was not specified, choose default linker now
312 if [ $CPLUSPLUS = 1 ] ; then
313 # determine linker and options for C++ code
314 if [ `which c++` ] ; then
315 # use Sun c++
316 LINK="c++"
317 elif [ `type g++` ] ; then
318 # use g++
319 LINK="g++"
320 else
321 echo "mklib: warning: can't find C++ comiler, trying CC."
322 LINK="CC"
323 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000324 else
Brian Paul8dcc6732005-07-25 22:59:58 +0000325 # use native Sun linker for C code
326 LINK="ld"
Brian Paul5396ab22004-02-12 14:48:52 +0000327 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000328 fi
Brian Paul59ebe1f2006-04-05 13:43:02 +0000329
330 # linker options
Brian Paulb3282a32006-04-18 12:56:11 +0000331 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
332 # SunOS tools, -G to make shared libs
Brian Paul59ebe1f2006-04-05 13:43:02 +0000333 OPTS="-G"
334 else
335 # gcc linker
336 # Check if objects are 32-bit and we're running in 64-bit
337 # environment. If so, pass -m32 flag to linker.
338 set ${OBJECTS}
339 ABI32=`file $1 | grep 32-bit`
340 if [ "${ABI32}" ] ; then
341 OPTS="-m32 -shared -Wl,-Bdynamic"
342 else
343 OPTS="-m64 -shared -Wl,-Bdynamic"
344 fi
345 fi
346
Brian Paul1e1af992006-04-14 14:14:51 +0000347 # Check if objects are SPARC v9
348 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
349 set ${OBJECTS}
350 SPARCV9=`file $1 | grep SPARCV9`
351 if [ "${SPARCV9}" ] ; then
352 OPTS="${OPTS} -xarch=v9"
353 fi
354
Brian Paul59ebe1f2006-04-05 13:43:02 +0000355 # for debug:
Brian Paul1e1af992006-04-14 14:14:51 +0000356 #echo "mklib: linker is" ${LINK} ${OPTS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000357 if [ $NOPREFIX = 1 ] ; then
358 rm -f ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600359 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000360 else
361 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600362 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000363 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
364 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000365 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000366 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000367 ;;
368
369 'FreeBSD')
Eric Anholtb83435f2005-10-18 23:36:40 +0000370 # we assume gcc
371
372 if [ "x$LINK" = "x" ] ; then
373 # -linker was not specified so set default link command now
374 if [ $CPLUSPLUS = 1 ] ; then
375 LINK=g++
376 else
377 LINK=gcc
378 fi
379 fi
380
Brian Pauldd74e362004-04-08 22:26:22 +0000381 if [ $NOPREFIX = 1 ] ; then
382 # No "lib" or ".so" part
383 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
Eric Anholtb83435f2005-10-18 23:36:40 +0000384 OPTS="-shared"
Brian Pauldd74e362004-04-08 22:26:22 +0000385 rm -f ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600386 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Pauldd74e362004-04-08 22:26:22 +0000387 FINAL_LIBS=${LIBNAME}
388 elif [ $STATIC = 1 ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000389 STLIB="lib${LIBNAME}.a"
390 echo "mklib: Making FreeBSD static library: " ${STLIB}
391 rm -f ${STLIB}
392 ar cq ${STLIB} ${OBJECTS}
393 ranlib ${STLIB}
394 FINAL_LIBS=${STLIB}
395 else
Eric Anholtb83435f2005-10-18 23:36:40 +0000396 SHLIB="lib${LIBNAME}.so.${MAJOR}"
397 OPTS="-shared -Wl,-soname,${SHLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000398 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
399 rm -f ${SHLIB}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600400 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
Eric Anholt1c04be52005-10-22 01:41:40 +0000401 ln -sf ${SHLIB} "lib${LIBNAME}.so"
402 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
Brian Paul5396ab22004-02-12 14:48:52 +0000403 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000404 ;;
405
Brian Paul8c20c7b2003-06-01 16:21:45 +0000406 'NetBSD')
Brian Paul5396ab22004-02-12 14:48:52 +0000407 if [ $STATIC = 1 ] ; then
408 LIBNAME="lib${LIBNAME}_pic.a"
409 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
410 rm -f ${LIBNAME}
411 ar cq ${LIBNAME} ${OBJECTS}
412 ranlib ${LIBNAME}
413 FINAL_LIBS=${LIBNAME}
414 else
415 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
416 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
417 rm -f ${LIBNAME}
418 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
419 FINAL_LIBS=${LIBNAME}
420 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000421 ;;
422
Brian Paulf8c31fc2004-01-29 15:21:47 +0000423 'IRIX' | 'IRIX64')
Brian Paul5396ab22004-02-12 14:48:52 +0000424 if [ $STATIC = 1 ] ; then
425 LIBNAME="lib${LIBNAME}.a"
426 rm -f ${LIBNAME}
427 ar rc ${LIBNAME} ${OBJECTS}
428 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000429 else
Brian Paul5396ab22004-02-12 14:48:52 +0000430 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul1e1af992006-04-14 14:14:51 +0000431
432 # examine first object to determine ABI
433 set ${OBJECTS}
434 ABI_O32=`file $1 | grep 'ELF 32-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000435 ABI_N32=`file $1 | grep 'ELF N32'`
Brian Paul1e1af992006-04-14 14:14:51 +0000436 ABI_N64=`file $1 | grep 'ELF 64-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000437 if [ "${ABI_O32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000438 OPTS="-32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000439 ABI="o32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000440 elif [ "${ABI_N32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000441 OPTS="-n32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000442 ABI="n32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000443 elif [ "${ABI_N64}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000444 OPTS="-64 -shared -all"
445 ABI="64-bit"
446 else
447 echo "Error: Unexpected IRIX ABI!"
448 exit 1
Brian Paul5396ab22004-02-12 14:48:52 +0000449 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000450
Brian Paul5396ab22004-02-12 14:48:52 +0000451 if [ $CPLUSPLUS = 1 ] ; then
452 LINK="CC"
453 else
454 LINK="ld"
455 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000456
457 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600458 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000459 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000460 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000461 ;;
462
Brian Paul8c20c7b2003-06-01 16:21:45 +0000463 'linux-cygwin')
464 LIBNAME="lib${LIBNAME}.a"
465 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000466 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000467 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
468 FINAL_LIBS=${LIBNAME}
469 ;;
470
Brian Paulc193bd02004-03-18 15:41:59 +0000471 'HP-UX')
Brian Paul5396ab22004-02-12 14:48:52 +0000472 if [ $STATIC = 1 ] ; then
473 LIBNAME="lib${LIBNAME}.a"
Brian Paul52fb07e2004-03-30 14:47:02 +0000474 echo "mklib: Making HP-UX static library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000475 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000476 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000477 FINAL_LIBS=${LIBNAME}
478 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000479 # HP uses a .2 for their current GL/GLU libraries
480 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
481 MAJOR=2
482 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000483 RUNLIB="lib${LIBNAME}.${MAJOR}"
484 DEVLIB="lib${LIBNAME}.sl"
Brian Paul52fb07e2004-03-30 14:47:02 +0000485 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
Brian Paul5396ab22004-02-12 14:48:52 +0000486 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
487 ln -s ${RUNLIB} ${DEVLIB}
Brian Paulac0cfee2004-04-25 15:13:56 +0000488 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000489 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000490 ;;
491
Brian Paulb3282a32006-04-18 12:56:11 +0000492 'AIX' )
493 # examine first object to determine ABI
494 set ${OBJECTS}
495 ABI_64=`file $1 | grep '64-bit'`
496 if [ "${ABI_64}" ] ; then
Brian Paulb17a1a12004-11-01 22:28:42 +0000497 X64="-X64"
Brian Paulb3282a32006-04-18 12:56:11 +0000498 Q64="-q64"
499 OFILE=shr_64.o
500 else
501 OFILE=shr.o #Want to be consistent with the IBM libGL.a
Brian Paulb17a1a12004-11-01 22:28:42 +0000502 fi
Brian Paulc193bd02004-03-18 15:41:59 +0000503
Brian Paulb3282a32006-04-18 12:56:11 +0000504 if [ $STATIC = 1 ] ; then
505 LIBNAME="lib${LIBNAME}.a"
506 echo "mklib: Making AIX static library: " ${LIBNAME}
507 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
508 FINAL_LIBS=${LIBNAME}
509 else
Karl Schultza16bdb52004-10-01 13:33:26 +0000510 EXPFILE="lib${LIBNAME}.exp"
Karl Schultza16bdb52004-10-01 13:33:26 +0000511 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
Brian Paulb3282a32006-04-18 12:56:11 +0000512 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000513 rm -f ${EXPFILE} ${OFILE}
Brian Paulb17a1a12004-11-01 22:28:42 +0000514 NM="/bin/nm -eC ${X64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000515 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
516 ${NM} ${OBJECTS} | awk '{
517 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
518 && ( substr($1,1,1) != ".")) {
519 if (substr ($1, 1, 7) != "__sinit" &&
520 substr ($1, 1, 7) != "__sterm") {
521 if (substr ($1, 1, 5) == "__tf1")
522 print (substr ($1, 7))
523 else if (substr ($1, 1, 5) == "__tf9")
524 print (substr ($1, 15))
525 else
526 print $1
527 }
528 }
529 }' | sort -u >> ${EXPFILE}
Brian Paulfe14cf62006-04-13 02:23:25 +0000530
531 # On AIX a shared library is linked differently when
532 # you want to dlopen the file
Brian Paul1e1af992006-04-14 14:14:51 +0000533 if [ $DLOPEN = "1" ] ; then
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600534 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul1e1af992006-04-14 14:14:51 +0000535 else
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600536 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
Brian Paul1e1af992006-04-14 14:14:51 +0000537 ar ${X64} -r ${LIBNAME} ${OFILE}
538 fi
Brian Paul56e0ee82006-04-13 15:17:50 +0000539
Brian Paul1e1af992006-04-14 14:14:51 +0000540 FINAL_LIBS="${LIBNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000541 fi
542 ;;
543
Brian Paul8c20c7b2003-06-01 16:21:45 +0000544 'OpenSTEP')
545 LIBNAME="lib${LIBNAME}.a"
546 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
547 libtool -static -o ${LIBNAME} - ${OBJECTS}
548 FINAL_LIBS=${LIBNAME}
549 ;;
550
551 'OSF1')
Brian Paul5396ab22004-02-12 14:48:52 +0000552 if [ $STATIC = 1 ] ; then
553 LIBNAME="lib${LIBNAME}.a"
554 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
555 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000556 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000557 FINAL_LIBS=${LIBNAME}
558 else
559 VERSION="${MAJOR}.${MINOR}"
560 LIBNAME="lib${LIBNAME}.so"
561 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
Brian Paul8dcc6732005-07-25 22:59:58 +0000562 if [ "x$LINK" = "x" ] ; then
563 if [ $CPLUSPLUS = 1 ] ; then
564 LINK=cxx
565 else
566 LINK=cc
567 fi
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000568 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000569 rm -f ${LIBNAME}.${VERSION}
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000570 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000571 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
572 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
573 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000574 ;;
575
576 'Darwin')
Brian Paulc193bd02004-03-18 15:41:59 +0000577 if [ $STATIC = 1 ] ; then
578 LIBNAME="lib${LIBNAME}.a"
579 echo "mklib: Making Darwin static library: " ${LIBNAME}
580 LINK="ar"
Brian Paulfe14cf62006-04-13 02:23:25 +0000581 OPTS="-ruvs"
Brian Paulc193bd02004-03-18 15:41:59 +0000582 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
583 FINAL_LIBS=${LIBNAME}
584 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000585 # On Darwin a .bundle is used for a library that you want to dlopen
Brian Paul1e1af992006-04-14 14:14:51 +0000586 if [ $DLOPEN = "1" ] ; then
587 LIBSUFFIX="bundle"
588 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
589 else
590 LIBSUFFIX="dylib"
591 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
592 fi
593 LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
594 LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
595
596 # examine first object to determine ABI
597 set ${OBJECTS}
Brian Paulb3282a32006-04-18 12:56:11 +0000598 ABI_PPC=`file $1 | grep 'object ppc'`
Brian Paul1e1af992006-04-14 14:14:51 +0000599 ABI_I386=`file $1 | grep 'object i386'`
Brian Paulb3282a32006-04-18 12:56:11 +0000600 if [ "${ABI_PPC}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000601 OPTS="${OPTS} -arch ppc"
602 fi
Brian Paulb3282a32006-04-18 12:56:11 +0000603 if [ "${ABI_I386}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000604 OPTS="${OPTS} -arch i386"
605 fi
606
607 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
608 # to OPTS here?
609
610 # determine linker
Brian Paul56e0ee82006-04-13 15:17:50 +0000611 if [ $CPLUSPLUS = 1 ] ; then
612 LINK="g++"
613 else
614 LINK="cc"
615 fi
Brian Paulfe14cf62006-04-13 02:23:25 +0000616
Brian Paulc50d77a2004-04-13 17:35:17 +0000617 echo "mklib: Making Darwin shared library: " ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600618 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paulfe14cf62006-04-13 02:23:25 +0000619 ln -s ${LIBNAME} ${LINKNAME}
Brian Paul1e1af992006-04-14 14:14:51 +0000620 FINAL_LIBS="${LIBNAME} ${LINKNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000621 fi
622 ;;
Brian Paul8c20c7b2003-06-01 16:21:45 +0000623
624 'LynxOS')
625 LIBNAME="lib${LIBNAME}.a"
Brian Paul5396ab22004-02-12 14:48:52 +0000626 echo "mklib: Making LynxOS static library: " ${LIBNAME}
627 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000628 ar ru ${LIBNAME} ${OBJECTS}
629 FINAL_LIBS=${LIBNAME}
630 ;;
631
632 'BeOS')
Philippe Houdoinef4dd5a2004-08-14 10:12:38 +0000633 if [ $STATIC = 1 ] ; then
634 LIBNAME="lib${LIBNAME}.a"
635 echo "mklib: Making BeOS static library: " ${LIBNAME}
636 ar -cru "${LIBNAME}" ${OBJECTS}
637 else
Brian Paulb784b8f2004-08-14 14:30:36 +0000638 LIBNAME="lib${LIBNAME}.so"
639 echo "mklib: Making BeOS shared library: " ${LIBNAME}
640 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
641 mimeset -f "${LIBNAME}"
Brian Paul8dcc6732005-07-25 22:59:58 +0000642 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
Brian Paulb784b8f2004-08-14 14:30:36 +0000643 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
644 fi
645 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000646 ;;
647
648 'QNX')
649 LIBNAME="lib${LIBNAME}.a"
650 echo "mklib: Making QNX library: " ${LIBNAME}
651 wlib ${LIBNAME} ${OBJECTS}
652 FINAL_LIBS=${LIBNAME}
653 ;;
654
Brian Paul65e2ab32003-10-27 18:13:37 +0000655 'MorphOS')
656 LIBNAME="lib${LIBNAME}.a"
657 echo "mklib: Making MorphOS library: " ${LIBNAME}
658 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
659 FINAL_LIBS="${LIBNAME}"
660 ;;
661
Brian Paulfe14cf62006-04-13 02:23:25 +0000662 'icc' | 'icc-istatic')
Brian Paulb3b725b2003-12-15 16:14:55 +0000663 # Intel C compiler
Brian Paul7c1ab402005-07-25 23:49:50 +0000664 # This should get merged into the Linux code, above, since this isn't
665 # really a different architecture.
Brian Paulb3b725b2003-12-15 16:14:55 +0000666 LIBNAME="lib${LIBNAME}" # prefix with "lib"
667
668 if [ $STATIC = 1 ] ; then
669 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
670 LINK="ar"
671 OPTS="-ruv"
672 # make lib
673 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
674 # finish up
675 FINAL_LIBS="${LIBNAME}.a"
676 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000677 if [ $ARCH = icc-istatic ] ; then
678 OPTS="-shared -i-static -cxxlib-icc"
679 else
680 OPTS="-shared"
681 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000682 VERSION="${MAJOR}.${MINOR}.${PATCH}"
Brian Paulb3b725b2003-12-15 16:14:55 +0000683 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
684
685 if [ $CPLUSPLUS = 1 ] ; then
Brian Paulfe14cf62006-04-13 02:23:25 +0000686 LINK="icpc"
Brian Paulb3b725b2003-12-15 16:14:55 +0000687 else
688 LINK="icc"
689 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000690 # rm any old libs
691 rm -f ${LIBNAME}.so.${VERSION}
692 rm -f ${LIBNAME}.so.${MAJOR}
693 rm -f ${LIBNAME}.so
Brian Paulb3b725b2003-12-15 16:14:55 +0000694 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600695 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
Brian Paulb3b725b2003-12-15 16:14:55 +0000696 # make usual symlinks
697 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
698 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
699 # finish up
700 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
701 fi
702 ;;
703
Brian Paul12d6cae2004-01-10 22:12:21 +0000704 'aix-gcc')
705 # AIX with gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000706 if [ $STATIC = 1 ] ; then
707 LIBNAME="lib${LIBNAME}.a"
708 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
709 rm -f ${LIBNAME}
710 ar ru ${LIBNAME} ${OBJECTS}
711 FINAL_LIBS=${LIBNAME}
712 else
713 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
714 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
715 # remove old lib
716 rm -f ${LIBNAME}
717 # make the lib
718 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000719 # NOTE: the application linking with this library must specify
720 # the -Wl,-brtl flags to gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000721 FINAL_LIBS=${LIBNAME}
722 fi
723 ;;
724
725 'ultrix')
726 # XXX untested
727 if [ $STATIC = 0 ] ; then
728 echo "mklib: Warning shared libs not supported on Ultrix"
729 fi
730 LIBNAME="lib${LIBNAME}.a"
731 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
Brian Paul12d6cae2004-01-10 22:12:21 +0000732 rm -f ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000733 ar ru ${LIBNAME} ${OBJECTS}
734 FINAL_LIBS="${LIBNAME}"
Brian Paul12d6cae2004-01-10 22:12:21 +0000735 ;;
Brian Paulb3b725b2003-12-15 16:14:55 +0000736
Brian Paul580548d2004-04-22 16:16:42 +0000737 CYGWIN*)
738 # GCC-based environment
739 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
740 LIBNAME="lib${LIBNAME}" # prefix with "lib"
741
742 if [ $STATIC = 1 ] ; then
743 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
744 LINK="ar"
745 OPTS="-ru"
746 # make lib
747 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
748 ranlib ${LIBNAME}.a
749 # finish up
750 FINAL_LIBS=${LIBNAME}.a
751 else
752 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
753 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
754
755 if [ $CPLUSPLUS = 1 ] ; then
756 LINK="g++"
757 else
758 LINK="gcc"
759 fi
760
761 # rm any old libs
762 rm -f ${LIBNAME}-${MAJOR}.dll
763 rm -f ${LIBNAME}.dll.a
764 rm -f ${LIBNAME}.a
765
766 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600767 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
Brian Paul580548d2004-04-22 16:16:42 +0000768 # make usual symlinks
769 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
770 # finish up
771 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
772 # special case for installing in bin
773 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
774 fi
775 ;;
776
Brian Paul8c20c7b2003-06-01 16:21:45 +0000777 'example')
778 # If you're adding support for a new architecture, you can
779 # start with this:
Brian Paul5396ab22004-02-12 14:48:52 +0000780 if [ $STATIC = 1 ] ; then
781 LIBNAME="lib${LIBNAME}.a"
782 echo "mklib: Making static library for example arch: " ${LIBNAME}
783 rm -f ${LIBNAME}
784 ar rv ${LIBNAME} ${OBJECTS}
785 FINAL_LIBS="${LIBNAME}"
786 else
Brian Paul7c1ab402005-07-25 23:49:50 +0000787 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul5396ab22004-02-12 14:48:52 +0000788 echo "mklib: Making shared library for example arch: " ${LIBNAME}
789 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
790 FINAL_LIBS="${LIBNAME}"
791 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000792 ;;
793
794 *)
Brian Paul5396ab22004-02-12 14:48:52 +0000795 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
796 echo "mklib: Please add necessary commands to mklib script."
Brian Paul8c20c7b2003-06-01 16:21:45 +0000797 ;;
798esac
799
800
801#
802# Put library files into installation directory if specified.
803#
804if [ ${INSTALLDIR} != "." ] ; then
805 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
806 mv ${FINAL_LIBS} ${INSTALLDIR}/
807fi