blob: 7d468b12e77ed977b13e1ca99c105cfa682b7d5d [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=""
Brian Paul8c20c7b2003-06-01 16:21:45 +000037CPLUSPLUS=0
38STATIC=0
Brian Paul1e1af992006-04-14 14:14:51 +000039DLOPEN=0
Brian Paul8c20c7b2003-06-01 16:21:45 +000040INSTALLDIR="."
41ARCH="auto"
42ARCHOPT=""
Brian Pauldd74e362004-04-08 22:26:22 +000043NOPREFIX=0
Brian Paul158a2512004-10-16 15:10:45 +000044EXPORTS=""
Brian Paul8c20c7b2003-06-01 16:21:45 +000045
46
47#
48# Parse arguments
49#
50while true
51do
52 case $1 in
Brian Paul7c1ab402005-07-25 23:49:50 +000053 '-h' | '--help')
Eric Anholtf1a26132005-08-08 03:26:18 +000054 echo 'Usage: mklib [options] objects'
55 echo 'Create a shared library from object files.'
56 echo ' -o LIBRARY specifies the name of the resulting library, without'
57 echo ' the leading "lib" or any suffix.'
58 echo ' (eg: "-o GL" might result in "libGL.so" being made)'
59 echo ' -major N specifies major version number (default is 1)'
60 echo ' -minor N specifies minor version number (default is 0)'
61 echo ' -patch N specifies patch version number (default is 0)'
62 echo ' -lLIBRARY specifies a dependency on LIBRARY'
63 echo ' -LDIR search in DIR for library dependencies'
64 echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
65 echo ' Not observed on all systems at this time.'
66 echo ' -cplusplus link with C++ runtime'
67 echo ' -static make a static library (default is dynamic/shared)'
Brian Paul1e1af992006-04-14 14:14:51 +000068 echo ' -dlopen make a shared library suitable for dynamic loading'
Eric Anholtf1a26132005-08-08 03:26:18 +000069 echo ' -install DIR put resulting library file(s) in DIR'
70 echo ' -arch ARCH override using `uname` to determine host system'
71 echo ' -archopt OPT specify an extra achitecture-specific option OPT'
72 echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
73 echo ' -exports FILE only export the symbols listed in FILE'
74 echo ' -h, --help display this information and exit'
Brian Paul7c1ab402005-07-25 23:49:50 +000075 exit 1
76 ;;
77 '-o')
78 shift 1;
79 LIBNAME=$1
80 ;;
81 '-major')
82 shift 1;
83 MAJOR=$1
84 ;;
85 '-minor')
86 shift 1;
87 MINOR=$1
88 ;;
89 '-patch')
90 shift 1;
91 PATCH=$1
92 ;;
93 '-linker')
94 shift 1;
95 LINK=$1
96 ;;
97 -l*)
98 DEPS="$DEPS $1"
99 ;;
100 -L*)
101 DEPS="$DEPS $1"
102 ;;
103 '-cplusplus')
104 CPLUSPLUS=1
105 ;;
106 '-static')
107 STATIC=1
108 ;;
Brian Paul1e1af992006-04-14 14:14:51 +0000109 '-dlopen')
110 DLOPEN=1
111 ;;
Brian Paul7c1ab402005-07-25 23:49:50 +0000112 '-install')
113 shift 1;
114 INSTALLDIR=$1
115 ;;
116 '-arch')
117 shift 1;
118 ARCH=$1
119 ;;
120 '-archopt')
121 shift 1;
122 ARCHOPT=$1
123 ;;
124 '-noprefix')
125 NOPREFIX=1
126 ;;
127 '-exports')
128 shift 1;
129 EXPORTS=$1
130 ;;
131 -*)
132 echo "mklib: Unknown option: " $1 ;
133 exit 1
134 ;;
135 *)
136 # This should be the first object file, stop parsing
137 break
Brian Paul8c20c7b2003-06-01 16:21:45 +0000138 esac
139 shift 1
140done
141OBJECTS=$@
142
Brian Paul7c1ab402005-07-25 23:49:50 +0000143
Brian Paul8c20c7b2003-06-01 16:21:45 +0000144if [ ${ARCH} = "auto" ] ; then
145 ARCH=`uname`
146fi
147
148
149#
150# Error checking
151#
152if [ "x${LIBNAME}" = "x" ] ; then
153 echo "mklib: Error: no library name specified"
154 exit 1
155fi
156if [ "x${OBJECTS}" = "x" ] ; then
157 echo "mklib: Error: no object files specified"
158 exit 1
159fi
160
161
162#
163# Debugging info
164#
165if [ ] ; then
166 echo "-----------------"
167 echo ARCH is $ARCH
168 echo LIBNAME is $LIBNAME
169 echo MAJOR is $MAJOR
170 echo MINOR is $MINOR
171 echo PATCH is $PATCH
172 echo DEPS are $DEPS
Brian Paul158a2512004-10-16 15:10:45 +0000173 echo "EXPORTS in" $EXPORTS
Brian Paul8c20c7b2003-06-01 16:21:45 +0000174 echo "-----------------"
175fi
176
177
178#
179# OK, make the library now
180#
181case $ARCH in
182
Brian Paul5beff7c2006-04-19 14:03:04 +0000183 'Linux' | 'OpenBSD' | 'GNU' | GNU/*)
Brian Paul158a2512004-10-16 15:10:45 +0000184 # we assume gcc
Brian Paul8c20c7b2003-06-01 16:21:45 +0000185
Brian Paul8dcc6732005-07-25 22:59:58 +0000186 if [ "x$LINK" = "x" ] ; then
187 # -linker was not specified so set default link command now
188 if [ $CPLUSPLUS = 1 ] ; then
189 LINK=g++
190 else
191 LINK=gcc
192 fi
Brian Paulc4987422004-10-16 15:02:16 +0000193 fi
194
Brian Pauldd74e362004-04-08 22:26:22 +0000195 if [ $NOPREFIX = 1 ] ; then
196 # No "lib" or ".so" part
197 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
198 #OPTS="-shared -Wl,-soname,${LIBNAME}" # soname???
199 OPTS="-shared"
Ian Romanickaba48642005-08-08 23:22:46 +0000200
201 # Check if objects are 32-bit and we're running in 64-bit
202 # environment. If so, pass -m32 flag to linker.
203 set ${OBJECTS}
204 ABI32=`file $1 | grep 32-bit`
205 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
206 OPTS="-m32 ${OPTS}"
207 fi
208
Brian Pauldd74e362004-04-08 22:26:22 +0000209 rm -f ${LIBNAME}
Brian Pauldd74e362004-04-08 22:26:22 +0000210 # make lib
211 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
212 # finish up
213 FINAL_LIBS="${LIBNAME}"
214 elif [ $STATIC = 1 ] ; then
215 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5b9a9d42004-01-17 18:31:12 +0000216 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
Brian Paul56e0ee82006-04-13 15:17:50 +0000217 LINK="ar"
218 OPTS="-ru"
219 # make lib
220 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
Brian Paul6e450f22004-02-21 18:08:41 +0000221 ranlib ${LIBNAME}.a
Brian Paul1c4b7112003-10-10 17:58:38 +0000222 # finish up
Brian Paul6e450f22004-02-21 18:08:41 +0000223 FINAL_LIBS=${LIBNAME}.a
Brian Paul1c4b7112003-10-10 17:58:38 +0000224 else
Brian Pauldd74e362004-04-08 22:26:22 +0000225 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5beff7c2006-04-19 14:03:04 +0000226 case $ARCH in 'Linux' | 'GNU' | GNU/*)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000227 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000228 ;;
229 *)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000230 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000231 ;;
232 esac
Brian Paul158a2512004-10-16 15:10:45 +0000233 if [ $EXPORTS ] ; then
234 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
235 # Make the 'exptmp' file for --version-script option
236 echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
237 echo "global:" >> exptmp
238 sed 's/$/;/' ${EXPORTS} >> exptmp
239 echo "local:" >> exptmp
240 echo "*;" >> exptmp
241 echo "};" >> exptmp
242 OPTS="${OPTS} -Xlinker --version-script=exptmp"
243 # exptmp is removed below
244 fi
Brian Paul3e196182005-03-03 01:38:13 +0000245
246 # Check if objects are 32-bit and we're running in 64-bit
247 # environment. If so, pass -m32 flag to linker.
248 set ${OBJECTS}
249 ABI32=`file $1 | grep 32-bit`
250 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
251 OPTS="-m32 ${OPTS}"
252 fi
253
Brian Paul6e450f22004-02-21 18:08:41 +0000254 if [ x${PATCH} = "x" ] ; then
255 VERSION="${MAJOR}.${MINOR}"
256 else
257 VERSION="${MAJOR}.${MINOR}.${PATCH}"
258 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000259
Brian Paul5396ab22004-02-12 14:48:52 +0000260 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000261
Brian Paul1c4b7112003-10-10 17:58:38 +0000262 # rm any old libs
263 rm -f ${LIBNAME}.so.${VERSION}
264 rm -f ${LIBNAME}.so.${MAJOR}
265 rm -f ${LIBNAME}.so
266
267 # make lib
268 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
269 # make usual symlinks
270 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
271 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
272 # finish up
273 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
Brian Paulb17a1a12004-11-01 22:28:42 +0000274# rm -f exptmp
Brian Paul1c4b7112003-10-10 17:58:38 +0000275 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000276 ;;
277
278 'SunOS')
Brian Paul5396ab22004-02-12 14:48:52 +0000279 if [ $STATIC = 1 ] ; then
280 LIBNAME="lib${LIBNAME}.a"
281 echo "mklib: Making SunOS static library: " ${LIBNAME}
282 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000283 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000284 FINAL_LIBS=${LIBNAME}
285 else
Brian Paul0a3a1c62006-11-10 12:47:56 +0000286 if [ $NOPREFIX = 0 ] ; then
287 LIBNAME="lib${LIBNAME}.so"
288 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000289 echo "mklib: Making SunOS shared library: " ${LIBNAME}
Brian Paul59ebe1f2006-04-05 13:43:02 +0000290
Brian Paul8dcc6732005-07-25 22:59:58 +0000291 if [ "x$LINK" = "x" ] ; then
292 # -linker was not specified, choose default linker now
293 if [ $CPLUSPLUS = 1 ] ; then
294 # determine linker and options for C++ code
295 if [ `which c++` ] ; then
296 # use Sun c++
297 LINK="c++"
298 elif [ `type g++` ] ; then
299 # use g++
300 LINK="g++"
301 else
302 echo "mklib: warning: can't find C++ comiler, trying CC."
303 LINK="CC"
304 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000305 else
Brian Paul8dcc6732005-07-25 22:59:58 +0000306 # use native Sun linker for C code
307 LINK="ld"
Brian Paul5396ab22004-02-12 14:48:52 +0000308 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000309 fi
Brian Paul59ebe1f2006-04-05 13:43:02 +0000310
311 # linker options
Brian Paulb3282a32006-04-18 12:56:11 +0000312 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
313 # SunOS tools, -G to make shared libs
Brian Paul59ebe1f2006-04-05 13:43:02 +0000314 OPTS="-G"
315 else
316 # gcc linker
317 # Check if objects are 32-bit and we're running in 64-bit
318 # environment. If so, pass -m32 flag to linker.
319 set ${OBJECTS}
320 ABI32=`file $1 | grep 32-bit`
321 if [ "${ABI32}" ] ; then
322 OPTS="-m32 -shared -Wl,-Bdynamic"
323 else
324 OPTS="-m64 -shared -Wl,-Bdynamic"
325 fi
326 fi
327
Brian Paul1e1af992006-04-14 14:14:51 +0000328 # Check if objects are SPARC v9
329 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
330 set ${OBJECTS}
331 SPARCV9=`file $1 | grep SPARCV9`
332 if [ "${SPARCV9}" ] ; then
333 OPTS="${OPTS} -xarch=v9"
334 fi
335
Brian Paul59ebe1f2006-04-05 13:43:02 +0000336 # for debug:
Brian Paul1e1af992006-04-14 14:14:51 +0000337 #echo "mklib: linker is" ${LINK} ${OPTS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000338 if [ $NOPREFIX = 1 ] ; then
339 rm -f ${LIBNAME}
340 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
341 else
342 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
343 ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
344 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
345 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000346 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000347 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000348 ;;
349
350 'FreeBSD')
Eric Anholtb83435f2005-10-18 23:36:40 +0000351 # we assume gcc
352
353 if [ "x$LINK" = "x" ] ; then
354 # -linker was not specified so set default link command now
355 if [ $CPLUSPLUS = 1 ] ; then
356 LINK=g++
357 else
358 LINK=gcc
359 fi
360 fi
361
Brian Pauldd74e362004-04-08 22:26:22 +0000362 if [ $NOPREFIX = 1 ] ; then
363 # No "lib" or ".so" part
364 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
Eric Anholtb83435f2005-10-18 23:36:40 +0000365 OPTS="-shared"
Brian Pauldd74e362004-04-08 22:26:22 +0000366 rm -f ${LIBNAME}
Eric Anholtb83435f2005-10-18 23:36:40 +0000367 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Pauldd74e362004-04-08 22:26:22 +0000368 FINAL_LIBS=${LIBNAME}
369 elif [ $STATIC = 1 ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000370 STLIB="lib${LIBNAME}.a"
371 echo "mklib: Making FreeBSD static library: " ${STLIB}
372 rm -f ${STLIB}
373 ar cq ${STLIB} ${OBJECTS}
374 ranlib ${STLIB}
375 FINAL_LIBS=${STLIB}
376 else
Eric Anholtb83435f2005-10-18 23:36:40 +0000377 SHLIB="lib${LIBNAME}.so.${MAJOR}"
378 OPTS="-shared -Wl,-soname,${SHLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000379 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
380 rm -f ${SHLIB}
Eric Anholtb83435f2005-10-18 23:36:40 +0000381 ${LINK} ${OPTS} -o ${SHLIB} ${OBJECTS} ${DEPS}
Eric Anholt1c04be52005-10-22 01:41:40 +0000382 ln -sf ${SHLIB} "lib${LIBNAME}.so"
383 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
Brian Paul5396ab22004-02-12 14:48:52 +0000384 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000385 ;;
386
Brian Paul8c20c7b2003-06-01 16:21:45 +0000387 'NetBSD')
Brian Paul5396ab22004-02-12 14:48:52 +0000388 if [ $STATIC = 1 ] ; then
389 LIBNAME="lib${LIBNAME}_pic.a"
390 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
391 rm -f ${LIBNAME}
392 ar cq ${LIBNAME} ${OBJECTS}
393 ranlib ${LIBNAME}
394 FINAL_LIBS=${LIBNAME}
395 else
396 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
397 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
398 rm -f ${LIBNAME}
399 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
400 FINAL_LIBS=${LIBNAME}
401 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000402 ;;
403
Brian Paulf8c31fc2004-01-29 15:21:47 +0000404 'IRIX' | 'IRIX64')
Brian Paul5396ab22004-02-12 14:48:52 +0000405 if [ $STATIC = 1 ] ; then
406 LIBNAME="lib${LIBNAME}.a"
407 rm -f ${LIBNAME}
408 ar rc ${LIBNAME} ${OBJECTS}
409 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000410 else
Brian Paul5396ab22004-02-12 14:48:52 +0000411 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul1e1af992006-04-14 14:14:51 +0000412
413 # examine first object to determine ABI
414 set ${OBJECTS}
415 ABI_O32=`file $1 | grep 'ELF 32-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000416 ABI_N32=`file $1 | grep 'ELF N32'`
Brian Paul1e1af992006-04-14 14:14:51 +0000417 ABI_N64=`file $1 | grep 'ELF 64-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000418 if [ "${ABI_O32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000419 OPTS="-32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000420 ABI="o32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000421 elif [ "${ABI_N32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000422 OPTS="-n32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000423 ABI="n32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000424 elif [ "${ABI_N64}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000425 OPTS="-64 -shared -all"
426 ABI="64-bit"
427 else
428 echo "Error: Unexpected IRIX ABI!"
429 exit 1
Brian Paul5396ab22004-02-12 14:48:52 +0000430 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000431
Brian Paul5396ab22004-02-12 14:48:52 +0000432 if [ $CPLUSPLUS = 1 ] ; then
433 LINK="CC"
434 else
435 LINK="ld"
436 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000437
438 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000439 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
440 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000441 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000442 ;;
443
Brian Paul8c20c7b2003-06-01 16:21:45 +0000444 'linux-cygwin')
445 LIBNAME="lib${LIBNAME}.a"
446 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000447 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000448 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
449 FINAL_LIBS=${LIBNAME}
450 ;;
451
Brian Paulc193bd02004-03-18 15:41:59 +0000452 'HP-UX')
Brian Paul5396ab22004-02-12 14:48:52 +0000453 if [ $STATIC = 1 ] ; then
454 LIBNAME="lib${LIBNAME}.a"
Brian Paul52fb07e2004-03-30 14:47:02 +0000455 echo "mklib: Making HP-UX static library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000456 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000457 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000458 FINAL_LIBS=${LIBNAME}
459 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000460 # HP uses a .2 for their current GL/GLU libraries
461 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
462 MAJOR=2
463 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000464 RUNLIB="lib${LIBNAME}.${MAJOR}"
465 DEVLIB="lib${LIBNAME}.sl"
Brian Paul52fb07e2004-03-30 14:47:02 +0000466 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
Brian Paul5396ab22004-02-12 14:48:52 +0000467 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
468 ln -s ${RUNLIB} ${DEVLIB}
Brian Paulac0cfee2004-04-25 15:13:56 +0000469 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000470 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000471 ;;
472
Brian Paulb3282a32006-04-18 12:56:11 +0000473 'AIX' )
474 # examine first object to determine ABI
475 set ${OBJECTS}
476 ABI_64=`file $1 | grep '64-bit'`
477 if [ "${ABI_64}" ] ; then
Brian Paulb17a1a12004-11-01 22:28:42 +0000478 X64="-X64"
Brian Paulb3282a32006-04-18 12:56:11 +0000479 Q64="-q64"
480 OFILE=shr_64.o
481 else
482 OFILE=shr.o #Want to be consistent with the IBM libGL.a
Brian Paulb17a1a12004-11-01 22:28:42 +0000483 fi
Brian Paulc193bd02004-03-18 15:41:59 +0000484
Brian Paulb3282a32006-04-18 12:56:11 +0000485 if [ $STATIC = 1 ] ; then
486 LIBNAME="lib${LIBNAME}.a"
487 echo "mklib: Making AIX static library: " ${LIBNAME}
488 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
489 FINAL_LIBS=${LIBNAME}
490 else
Karl Schultza16bdb52004-10-01 13:33:26 +0000491 EXPFILE="lib${LIBNAME}.exp"
Karl Schultza16bdb52004-10-01 13:33:26 +0000492 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
Brian Paulb3282a32006-04-18 12:56:11 +0000493 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000494 rm -f ${EXPFILE} ${OFILE}
Brian Paulb17a1a12004-11-01 22:28:42 +0000495 NM="/bin/nm -eC ${X64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000496 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
497 ${NM} ${OBJECTS} | awk '{
498 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
499 && ( substr($1,1,1) != ".")) {
500 if (substr ($1, 1, 7) != "__sinit" &&
501 substr ($1, 1, 7) != "__sterm") {
502 if (substr ($1, 1, 5) == "__tf1")
503 print (substr ($1, 7))
504 else if (substr ($1, 1, 5) == "__tf9")
505 print (substr ($1, 15))
506 else
507 print $1
508 }
509 }
510 }' | sort -u >> ${EXPFILE}
Brian Paulfe14cf62006-04-13 02:23:25 +0000511
512 # On AIX a shared library is linked differently when
513 # you want to dlopen the file
Brian Paul1e1af992006-04-14 14:14:51 +0000514 if [ $DLOPEN = "1" ] ; then
515 cc -G ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
516 else
517 cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
518 ar ${X64} -r ${LIBNAME} ${OFILE}
519 fi
Brian Paul56e0ee82006-04-13 15:17:50 +0000520
Brian Paul1e1af992006-04-14 14:14:51 +0000521 FINAL_LIBS="${LIBNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000522 fi
523 ;;
524
Brian Paul8c20c7b2003-06-01 16:21:45 +0000525 'OpenSTEP')
526 LIBNAME="lib${LIBNAME}.a"
527 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
528 libtool -static -o ${LIBNAME} - ${OBJECTS}
529 FINAL_LIBS=${LIBNAME}
530 ;;
531
532 'OSF1')
Brian Paul5396ab22004-02-12 14:48:52 +0000533 if [ $STATIC = 1 ] ; then
534 LIBNAME="lib${LIBNAME}.a"
535 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
536 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000537 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000538 FINAL_LIBS=${LIBNAME}
539 else
540 VERSION="${MAJOR}.${MINOR}"
541 LIBNAME="lib${LIBNAME}.so"
542 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
Brian Paul8dcc6732005-07-25 22:59:58 +0000543 if [ "x$LINK" = "x" ] ; then
544 if [ $CPLUSPLUS = 1 ] ; then
545 LINK=cxx
546 else
547 LINK=cc
548 fi
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000549 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000550 rm -f ${LIBNAME}.${VERSION}
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000551 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000552 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
553 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
554 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000555 ;;
556
557 'Darwin')
Brian Paulc193bd02004-03-18 15:41:59 +0000558 if [ $STATIC = 1 ] ; then
559 LIBNAME="lib${LIBNAME}.a"
560 echo "mklib: Making Darwin static library: " ${LIBNAME}
561 LINK="ar"
Brian Paulfe14cf62006-04-13 02:23:25 +0000562 OPTS="-ruvs"
Brian Paulc193bd02004-03-18 15:41:59 +0000563 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
564 FINAL_LIBS=${LIBNAME}
565 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000566 # On Darwin a .bundle is used for a library that you want to dlopen
Brian Paul1e1af992006-04-14 14:14:51 +0000567 if [ $DLOPEN = "1" ] ; then
568 LIBSUFFIX="bundle"
569 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
570 else
571 LIBSUFFIX="dylib"
572 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
573 fi
574 LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
575 LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
576
577 # examine first object to determine ABI
578 set ${OBJECTS}
Brian Paulb3282a32006-04-18 12:56:11 +0000579 ABI_PPC=`file $1 | grep 'object ppc'`
Brian Paul1e1af992006-04-14 14:14:51 +0000580 ABI_I386=`file $1 | grep 'object i386'`
Brian Paulb3282a32006-04-18 12:56:11 +0000581 if [ "${ABI_PPC}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000582 OPTS="${OPTS} -arch ppc"
583 fi
Brian Paulb3282a32006-04-18 12:56:11 +0000584 if [ "${ABI_I386}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000585 OPTS="${OPTS} -arch i386"
586 fi
587
588 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
589 # to OPTS here?
590
591 # determine linker
Brian Paul56e0ee82006-04-13 15:17:50 +0000592 if [ $CPLUSPLUS = 1 ] ; then
593 LINK="g++"
594 else
595 LINK="cc"
596 fi
Brian Paulfe14cf62006-04-13 02:23:25 +0000597
Brian Paulc50d77a2004-04-13 17:35:17 +0000598 echo "mklib: Making Darwin shared library: " ${LIBNAME}
Brian Paul1e1af992006-04-14 14:14:51 +0000599 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paulfe14cf62006-04-13 02:23:25 +0000600 ln -s ${LIBNAME} ${LINKNAME}
Brian Paul1e1af992006-04-14 14:14:51 +0000601 FINAL_LIBS="${LIBNAME} ${LINKNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000602 fi
603 ;;
Brian Paul8c20c7b2003-06-01 16:21:45 +0000604
605 'LynxOS')
606 LIBNAME="lib${LIBNAME}.a"
Brian Paul5396ab22004-02-12 14:48:52 +0000607 echo "mklib: Making LynxOS static library: " ${LIBNAME}
608 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000609 ar ru ${LIBNAME} ${OBJECTS}
610 FINAL_LIBS=${LIBNAME}
611 ;;
612
613 'BeOS')
Philippe Houdoinef4dd5a2004-08-14 10:12:38 +0000614 if [ $STATIC = 1 ] ; then
615 LIBNAME="lib${LIBNAME}.a"
616 echo "mklib: Making BeOS static library: " ${LIBNAME}
617 ar -cru "${LIBNAME}" ${OBJECTS}
618 else
Brian Paulb784b8f2004-08-14 14:30:36 +0000619 LIBNAME="lib${LIBNAME}.so"
620 echo "mklib: Making BeOS shared library: " ${LIBNAME}
621 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
622 mimeset -f "${LIBNAME}"
Brian Paul8dcc6732005-07-25 22:59:58 +0000623 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
Brian Paulb784b8f2004-08-14 14:30:36 +0000624 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
625 fi
626 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000627 ;;
628
629 'QNX')
630 LIBNAME="lib${LIBNAME}.a"
631 echo "mklib: Making QNX library: " ${LIBNAME}
632 wlib ${LIBNAME} ${OBJECTS}
633 FINAL_LIBS=${LIBNAME}
634 ;;
635
Brian Paul65e2ab32003-10-27 18:13:37 +0000636 'MorphOS')
637 LIBNAME="lib${LIBNAME}.a"
638 echo "mklib: Making MorphOS library: " ${LIBNAME}
639 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
640 FINAL_LIBS="${LIBNAME}"
641 ;;
642
Brian Paulfe14cf62006-04-13 02:23:25 +0000643 'icc' | 'icc-istatic')
Brian Paulb3b725b2003-12-15 16:14:55 +0000644 # Intel C compiler
Brian Paul7c1ab402005-07-25 23:49:50 +0000645 # This should get merged into the Linux code, above, since this isn't
646 # really a different architecture.
Brian Paulb3b725b2003-12-15 16:14:55 +0000647 LIBNAME="lib${LIBNAME}" # prefix with "lib"
648
649 if [ $STATIC = 1 ] ; then
650 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
651 LINK="ar"
652 OPTS="-ruv"
653 # make lib
654 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
655 # finish up
656 FINAL_LIBS="${LIBNAME}.a"
657 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000658 if [ $ARCH = icc-istatic ] ; then
659 OPTS="-shared -i-static -cxxlib-icc"
660 else
661 OPTS="-shared"
662 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000663 VERSION="${MAJOR}.${MINOR}.${PATCH}"
Brian Paulb3b725b2003-12-15 16:14:55 +0000664 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
665
666 if [ $CPLUSPLUS = 1 ] ; then
Brian Paulfe14cf62006-04-13 02:23:25 +0000667 LINK="icpc"
Brian Paulb3b725b2003-12-15 16:14:55 +0000668 else
669 LINK="icc"
670 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000671 # rm any old libs
672 rm -f ${LIBNAME}.so.${VERSION}
673 rm -f ${LIBNAME}.so.${MAJOR}
674 rm -f ${LIBNAME}.so
Brian Paulb3b725b2003-12-15 16:14:55 +0000675 # make lib
676 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
677 # make usual symlinks
678 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
679 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
680 # finish up
681 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
682 fi
683 ;;
684
Brian Paul12d6cae2004-01-10 22:12:21 +0000685 'aix-gcc')
686 # AIX with gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000687 if [ $STATIC = 1 ] ; then
688 LIBNAME="lib${LIBNAME}.a"
689 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
690 rm -f ${LIBNAME}
691 ar ru ${LIBNAME} ${OBJECTS}
692 FINAL_LIBS=${LIBNAME}
693 else
694 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
695 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
696 # remove old lib
697 rm -f ${LIBNAME}
698 # make the lib
699 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000700 # NOTE: the application linking with this library must specify
701 # the -Wl,-brtl flags to gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000702 FINAL_LIBS=${LIBNAME}
703 fi
704 ;;
705
706 'ultrix')
707 # XXX untested
708 if [ $STATIC = 0 ] ; then
709 echo "mklib: Warning shared libs not supported on Ultrix"
710 fi
711 LIBNAME="lib${LIBNAME}.a"
712 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
Brian Paul12d6cae2004-01-10 22:12:21 +0000713 rm -f ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000714 ar ru ${LIBNAME} ${OBJECTS}
715 FINAL_LIBS="${LIBNAME}"
Brian Paul12d6cae2004-01-10 22:12:21 +0000716 ;;
Brian Paulb3b725b2003-12-15 16:14:55 +0000717
Brian Paul580548d2004-04-22 16:16:42 +0000718 CYGWIN*)
719 # GCC-based environment
720 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
721 LIBNAME="lib${LIBNAME}" # prefix with "lib"
722
723 if [ $STATIC = 1 ] ; then
724 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
725 LINK="ar"
726 OPTS="-ru"
727 # make lib
728 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
729 ranlib ${LIBNAME}.a
730 # finish up
731 FINAL_LIBS=${LIBNAME}.a
732 else
733 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
734 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
735
736 if [ $CPLUSPLUS = 1 ] ; then
737 LINK="g++"
738 else
739 LINK="gcc"
740 fi
741
742 # rm any old libs
743 rm -f ${LIBNAME}-${MAJOR}.dll
744 rm -f ${LIBNAME}.dll.a
745 rm -f ${LIBNAME}.a
746
747 # make lib
748 ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
749 # make usual symlinks
750 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
751 # finish up
752 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
753 # special case for installing in bin
754 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
755 fi
756 ;;
757
Brian Paul8c20c7b2003-06-01 16:21:45 +0000758 'example')
759 # If you're adding support for a new architecture, you can
760 # start with this:
Brian Paul5396ab22004-02-12 14:48:52 +0000761 if [ $STATIC = 1 ] ; then
762 LIBNAME="lib${LIBNAME}.a"
763 echo "mklib: Making static library for example arch: " ${LIBNAME}
764 rm -f ${LIBNAME}
765 ar rv ${LIBNAME} ${OBJECTS}
766 FINAL_LIBS="${LIBNAME}"
767 else
Brian Paul7c1ab402005-07-25 23:49:50 +0000768 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul5396ab22004-02-12 14:48:52 +0000769 echo "mklib: Making shared library for example arch: " ${LIBNAME}
770 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
771 FINAL_LIBS="${LIBNAME}"
772 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000773 ;;
774
775 *)
Brian Paul5396ab22004-02-12 14:48:52 +0000776 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
777 echo "mklib: Please add necessary commands to mklib script."
Brian Paul8c20c7b2003-06-01 16:21:45 +0000778 ;;
779esac
780
781
782#
783# Put library files into installation directory if specified.
784#
785if [ ${INSTALLDIR} != "." ] ; then
786 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
787 mv ${FINAL_LIBS} ${INSTALLDIR}/
788fi