blob: 09f4fac9e5119b8151a09b75e5ec04156e8ede2b [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
Brian98abd1b2007-03-27 07:58:47 -0600215 LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
216 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
Brian Paul56e0ee82006-04-13 15:17:50 +0000217 LINK="ar"
218 OPTS="-ru"
Brian98abd1b2007-03-27 07:58:47 -0600219 rm -f ${LIBNAME}
Brian Paul56e0ee82006-04-13 15:17:50 +0000220 # make lib
Brian98abd1b2007-03-27 07:58:47 -0600221 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
222 ranlib ${LIBNAME}
Brian Paul1c4b7112003-10-10 17:58:38 +0000223 # finish up
Brian98abd1b2007-03-27 07:58:47 -0600224 FINAL_LIBS=${LIBNAME}
Brian Paul1c4b7112003-10-10 17:58:38 +0000225 else
Brian Pauldd74e362004-04-08 22:26:22 +0000226 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5beff7c2006-04-19 14:03:04 +0000227 case $ARCH in 'Linux' | 'GNU' | GNU/*)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000228 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000229 ;;
230 *)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000231 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000232 ;;
233 esac
Brian Paul158a2512004-10-16 15:10:45 +0000234 if [ $EXPORTS ] ; then
235 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
236 # Make the 'exptmp' file for --version-script option
237 echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
238 echo "global:" >> exptmp
239 sed 's/$/;/' ${EXPORTS} >> exptmp
240 echo "local:" >> exptmp
241 echo "*;" >> exptmp
242 echo "};" >> exptmp
243 OPTS="${OPTS} -Xlinker --version-script=exptmp"
244 # exptmp is removed below
245 fi
Brian Paul3e196182005-03-03 01:38:13 +0000246
247 # Check if objects are 32-bit and we're running in 64-bit
248 # environment. If so, pass -m32 flag to linker.
249 set ${OBJECTS}
250 ABI32=`file $1 | grep 32-bit`
251 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
252 OPTS="-m32 ${OPTS}"
253 fi
254
Brian Paul6e450f22004-02-21 18:08:41 +0000255 if [ x${PATCH} = "x" ] ; then
256 VERSION="${MAJOR}.${MINOR}"
257 else
258 VERSION="${MAJOR}.${MINOR}.${PATCH}"
259 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000260
Brian Paul5396ab22004-02-12 14:48:52 +0000261 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000262
Brian Paul1c4b7112003-10-10 17:58:38 +0000263 # rm any old libs
264 rm -f ${LIBNAME}.so.${VERSION}
265 rm -f ${LIBNAME}.so.${MAJOR}
266 rm -f ${LIBNAME}.so
267
268 # make lib
269 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
270 # make usual symlinks
271 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
272 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
273 # finish up
274 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
Brian Paulb17a1a12004-11-01 22:28:42 +0000275# rm -f exptmp
Brian Paul1c4b7112003-10-10 17:58:38 +0000276 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000277 ;;
278
279 'SunOS')
Brian Paul5396ab22004-02-12 14:48:52 +0000280 if [ $STATIC = 1 ] ; then
281 LIBNAME="lib${LIBNAME}.a"
282 echo "mklib: Making SunOS static library: " ${LIBNAME}
283 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000284 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000285 FINAL_LIBS=${LIBNAME}
286 else
Brian Paul0a3a1c62006-11-10 12:47:56 +0000287 if [ $NOPREFIX = 0 ] ; then
288 LIBNAME="lib${LIBNAME}.so"
289 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000290 echo "mklib: Making SunOS shared library: " ${LIBNAME}
Brian Paul59ebe1f2006-04-05 13:43:02 +0000291
Brian Paul8dcc6732005-07-25 22:59:58 +0000292 if [ "x$LINK" = "x" ] ; then
293 # -linker was not specified, choose default linker now
294 if [ $CPLUSPLUS = 1 ] ; then
295 # determine linker and options for C++ code
296 if [ `which c++` ] ; then
297 # use Sun c++
298 LINK="c++"
299 elif [ `type g++` ] ; then
300 # use g++
301 LINK="g++"
302 else
303 echo "mklib: warning: can't find C++ comiler, trying CC."
304 LINK="CC"
305 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000306 else
Brian Paul8dcc6732005-07-25 22:59:58 +0000307 # use native Sun linker for C code
308 LINK="ld"
Brian Paul5396ab22004-02-12 14:48:52 +0000309 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000310 fi
Brian Paul59ebe1f2006-04-05 13:43:02 +0000311
312 # linker options
Brian Paulb3282a32006-04-18 12:56:11 +0000313 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
314 # SunOS tools, -G to make shared libs
Brian Paul59ebe1f2006-04-05 13:43:02 +0000315 OPTS="-G"
316 else
317 # gcc linker
318 # Check if objects are 32-bit and we're running in 64-bit
319 # environment. If so, pass -m32 flag to linker.
320 set ${OBJECTS}
321 ABI32=`file $1 | grep 32-bit`
322 if [ "${ABI32}" ] ; then
323 OPTS="-m32 -shared -Wl,-Bdynamic"
324 else
325 OPTS="-m64 -shared -Wl,-Bdynamic"
326 fi
327 fi
328
Brian Paul1e1af992006-04-14 14:14:51 +0000329 # Check if objects are SPARC v9
330 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
331 set ${OBJECTS}
332 SPARCV9=`file $1 | grep SPARCV9`
333 if [ "${SPARCV9}" ] ; then
334 OPTS="${OPTS} -xarch=v9"
335 fi
336
Brian Paul59ebe1f2006-04-05 13:43:02 +0000337 # for debug:
Brian Paul1e1af992006-04-14 14:14:51 +0000338 #echo "mklib: linker is" ${LINK} ${OPTS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000339 if [ $NOPREFIX = 1 ] ; then
340 rm -f ${LIBNAME}
341 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
342 else
343 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
344 ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
345 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
346 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000347 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000348 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000349 ;;
350
351 'FreeBSD')
Eric Anholtb83435f2005-10-18 23:36:40 +0000352 # we assume gcc
353
354 if [ "x$LINK" = "x" ] ; then
355 # -linker was not specified so set default link command now
356 if [ $CPLUSPLUS = 1 ] ; then
357 LINK=g++
358 else
359 LINK=gcc
360 fi
361 fi
362
Brian Pauldd74e362004-04-08 22:26:22 +0000363 if [ $NOPREFIX = 1 ] ; then
364 # No "lib" or ".so" part
365 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
Eric Anholtb83435f2005-10-18 23:36:40 +0000366 OPTS="-shared"
Brian Pauldd74e362004-04-08 22:26:22 +0000367 rm -f ${LIBNAME}
Eric Anholtb83435f2005-10-18 23:36:40 +0000368 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Pauldd74e362004-04-08 22:26:22 +0000369 FINAL_LIBS=${LIBNAME}
370 elif [ $STATIC = 1 ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000371 STLIB="lib${LIBNAME}.a"
372 echo "mklib: Making FreeBSD static library: " ${STLIB}
373 rm -f ${STLIB}
374 ar cq ${STLIB} ${OBJECTS}
375 ranlib ${STLIB}
376 FINAL_LIBS=${STLIB}
377 else
Eric Anholtb83435f2005-10-18 23:36:40 +0000378 SHLIB="lib${LIBNAME}.so.${MAJOR}"
379 OPTS="-shared -Wl,-soname,${SHLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000380 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
381 rm -f ${SHLIB}
Eric Anholtb83435f2005-10-18 23:36:40 +0000382 ${LINK} ${OPTS} -o ${SHLIB} ${OBJECTS} ${DEPS}
Eric Anholt1c04be52005-10-22 01:41:40 +0000383 ln -sf ${SHLIB} "lib${LIBNAME}.so"
384 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
Brian Paul5396ab22004-02-12 14:48:52 +0000385 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000386 ;;
387
Brian Paul8c20c7b2003-06-01 16:21:45 +0000388 'NetBSD')
Brian Paul5396ab22004-02-12 14:48:52 +0000389 if [ $STATIC = 1 ] ; then
390 LIBNAME="lib${LIBNAME}_pic.a"
391 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
392 rm -f ${LIBNAME}
393 ar cq ${LIBNAME} ${OBJECTS}
394 ranlib ${LIBNAME}
395 FINAL_LIBS=${LIBNAME}
396 else
397 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
398 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
399 rm -f ${LIBNAME}
400 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
401 FINAL_LIBS=${LIBNAME}
402 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000403 ;;
404
Brian Paulf8c31fc2004-01-29 15:21:47 +0000405 'IRIX' | 'IRIX64')
Brian Paul5396ab22004-02-12 14:48:52 +0000406 if [ $STATIC = 1 ] ; then
407 LIBNAME="lib${LIBNAME}.a"
408 rm -f ${LIBNAME}
409 ar rc ${LIBNAME} ${OBJECTS}
410 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000411 else
Brian Paul5396ab22004-02-12 14:48:52 +0000412 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul1e1af992006-04-14 14:14:51 +0000413
414 # examine first object to determine ABI
415 set ${OBJECTS}
416 ABI_O32=`file $1 | grep 'ELF 32-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000417 ABI_N32=`file $1 | grep 'ELF N32'`
Brian Paul1e1af992006-04-14 14:14:51 +0000418 ABI_N64=`file $1 | grep 'ELF 64-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000419 if [ "${ABI_O32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000420 OPTS="-32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000421 ABI="o32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000422 elif [ "${ABI_N32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000423 OPTS="-n32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000424 ABI="n32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000425 elif [ "${ABI_N64}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000426 OPTS="-64 -shared -all"
427 ABI="64-bit"
428 else
429 echo "Error: Unexpected IRIX ABI!"
430 exit 1
Brian Paul5396ab22004-02-12 14:48:52 +0000431 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000432
Brian Paul5396ab22004-02-12 14:48:52 +0000433 if [ $CPLUSPLUS = 1 ] ; then
434 LINK="CC"
435 else
436 LINK="ld"
437 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000438
439 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000440 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
441 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000442 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000443 ;;
444
Brian Paul8c20c7b2003-06-01 16:21:45 +0000445 'linux-cygwin')
446 LIBNAME="lib${LIBNAME}.a"
447 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000448 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000449 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
450 FINAL_LIBS=${LIBNAME}
451 ;;
452
Brian Paulc193bd02004-03-18 15:41:59 +0000453 'HP-UX')
Brian Paul5396ab22004-02-12 14:48:52 +0000454 if [ $STATIC = 1 ] ; then
455 LIBNAME="lib${LIBNAME}.a"
Brian Paul52fb07e2004-03-30 14:47:02 +0000456 echo "mklib: Making HP-UX static library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000457 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000458 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000459 FINAL_LIBS=${LIBNAME}
460 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000461 # HP uses a .2 for their current GL/GLU libraries
462 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
463 MAJOR=2
464 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000465 RUNLIB="lib${LIBNAME}.${MAJOR}"
466 DEVLIB="lib${LIBNAME}.sl"
Brian Paul52fb07e2004-03-30 14:47:02 +0000467 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
Brian Paul5396ab22004-02-12 14:48:52 +0000468 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
469 ln -s ${RUNLIB} ${DEVLIB}
Brian Paulac0cfee2004-04-25 15:13:56 +0000470 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000471 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000472 ;;
473
Brian Paulb3282a32006-04-18 12:56:11 +0000474 'AIX' )
475 # examine first object to determine ABI
476 set ${OBJECTS}
477 ABI_64=`file $1 | grep '64-bit'`
478 if [ "${ABI_64}" ] ; then
Brian Paulb17a1a12004-11-01 22:28:42 +0000479 X64="-X64"
Brian Paulb3282a32006-04-18 12:56:11 +0000480 Q64="-q64"
481 OFILE=shr_64.o
482 else
483 OFILE=shr.o #Want to be consistent with the IBM libGL.a
Brian Paulb17a1a12004-11-01 22:28:42 +0000484 fi
Brian Paulc193bd02004-03-18 15:41:59 +0000485
Brian Paulb3282a32006-04-18 12:56:11 +0000486 if [ $STATIC = 1 ] ; then
487 LIBNAME="lib${LIBNAME}.a"
488 echo "mklib: Making AIX static library: " ${LIBNAME}
489 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
490 FINAL_LIBS=${LIBNAME}
491 else
Karl Schultza16bdb52004-10-01 13:33:26 +0000492 EXPFILE="lib${LIBNAME}.exp"
Karl Schultza16bdb52004-10-01 13:33:26 +0000493 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
Brian Paulb3282a32006-04-18 12:56:11 +0000494 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000495 rm -f ${EXPFILE} ${OFILE}
Brian Paulb17a1a12004-11-01 22:28:42 +0000496 NM="/bin/nm -eC ${X64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000497 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
498 ${NM} ${OBJECTS} | awk '{
499 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
500 && ( substr($1,1,1) != ".")) {
501 if (substr ($1, 1, 7) != "__sinit" &&
502 substr ($1, 1, 7) != "__sterm") {
503 if (substr ($1, 1, 5) == "__tf1")
504 print (substr ($1, 7))
505 else if (substr ($1, 1, 5) == "__tf9")
506 print (substr ($1, 15))
507 else
508 print $1
509 }
510 }
511 }' | sort -u >> ${EXPFILE}
Brian Paulfe14cf62006-04-13 02:23:25 +0000512
513 # On AIX a shared library is linked differently when
514 # you want to dlopen the file
Brian Paul1e1af992006-04-14 14:14:51 +0000515 if [ $DLOPEN = "1" ] ; then
516 cc -G ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
517 else
518 cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
519 ar ${X64} -r ${LIBNAME} ${OFILE}
520 fi
Brian Paul56e0ee82006-04-13 15:17:50 +0000521
Brian Paul1e1af992006-04-14 14:14:51 +0000522 FINAL_LIBS="${LIBNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000523 fi
524 ;;
525
Brian Paul8c20c7b2003-06-01 16:21:45 +0000526 'OpenSTEP')
527 LIBNAME="lib${LIBNAME}.a"
528 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
529 libtool -static -o ${LIBNAME} - ${OBJECTS}
530 FINAL_LIBS=${LIBNAME}
531 ;;
532
533 'OSF1')
Brian Paul5396ab22004-02-12 14:48:52 +0000534 if [ $STATIC = 1 ] ; then
535 LIBNAME="lib${LIBNAME}.a"
536 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
537 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000538 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000539 FINAL_LIBS=${LIBNAME}
540 else
541 VERSION="${MAJOR}.${MINOR}"
542 LIBNAME="lib${LIBNAME}.so"
543 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
Brian Paul8dcc6732005-07-25 22:59:58 +0000544 if [ "x$LINK" = "x" ] ; then
545 if [ $CPLUSPLUS = 1 ] ; then
546 LINK=cxx
547 else
548 LINK=cc
549 fi
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000550 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000551 rm -f ${LIBNAME}.${VERSION}
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000552 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000553 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
554 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
555 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000556 ;;
557
558 'Darwin')
Brian Paulc193bd02004-03-18 15:41:59 +0000559 if [ $STATIC = 1 ] ; then
560 LIBNAME="lib${LIBNAME}.a"
561 echo "mklib: Making Darwin static library: " ${LIBNAME}
562 LINK="ar"
Brian Paulfe14cf62006-04-13 02:23:25 +0000563 OPTS="-ruvs"
Brian Paulc193bd02004-03-18 15:41:59 +0000564 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
565 FINAL_LIBS=${LIBNAME}
566 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000567 # On Darwin a .bundle is used for a library that you want to dlopen
Brian Paul1e1af992006-04-14 14:14:51 +0000568 if [ $DLOPEN = "1" ] ; then
569 LIBSUFFIX="bundle"
570 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
571 else
572 LIBSUFFIX="dylib"
573 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
574 fi
575 LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
576 LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
577
578 # examine first object to determine ABI
579 set ${OBJECTS}
Brian Paulb3282a32006-04-18 12:56:11 +0000580 ABI_PPC=`file $1 | grep 'object ppc'`
Brian Paul1e1af992006-04-14 14:14:51 +0000581 ABI_I386=`file $1 | grep 'object i386'`
Brian Paulb3282a32006-04-18 12:56:11 +0000582 if [ "${ABI_PPC}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000583 OPTS="${OPTS} -arch ppc"
584 fi
Brian Paulb3282a32006-04-18 12:56:11 +0000585 if [ "${ABI_I386}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000586 OPTS="${OPTS} -arch i386"
587 fi
588
589 # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
590 # to OPTS here?
591
592 # determine linker
Brian Paul56e0ee82006-04-13 15:17:50 +0000593 if [ $CPLUSPLUS = 1 ] ; then
594 LINK="g++"
595 else
596 LINK="cc"
597 fi
Brian Paulfe14cf62006-04-13 02:23:25 +0000598
Brian Paulc50d77a2004-04-13 17:35:17 +0000599 echo "mklib: Making Darwin shared library: " ${LIBNAME}
Brian Paul1e1af992006-04-14 14:14:51 +0000600 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paulfe14cf62006-04-13 02:23:25 +0000601 ln -s ${LIBNAME} ${LINKNAME}
Brian Paul1e1af992006-04-14 14:14:51 +0000602 FINAL_LIBS="${LIBNAME} ${LINKNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000603 fi
604 ;;
Brian Paul8c20c7b2003-06-01 16:21:45 +0000605
606 'LynxOS')
607 LIBNAME="lib${LIBNAME}.a"
Brian Paul5396ab22004-02-12 14:48:52 +0000608 echo "mklib: Making LynxOS static library: " ${LIBNAME}
609 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000610 ar ru ${LIBNAME} ${OBJECTS}
611 FINAL_LIBS=${LIBNAME}
612 ;;
613
614 'BeOS')
Philippe Houdoinef4dd5a2004-08-14 10:12:38 +0000615 if [ $STATIC = 1 ] ; then
616 LIBNAME="lib${LIBNAME}.a"
617 echo "mklib: Making BeOS static library: " ${LIBNAME}
618 ar -cru "${LIBNAME}" ${OBJECTS}
619 else
Brian Paulb784b8f2004-08-14 14:30:36 +0000620 LIBNAME="lib${LIBNAME}.so"
621 echo "mklib: Making BeOS shared library: " ${LIBNAME}
622 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
623 mimeset -f "${LIBNAME}"
Brian Paul8dcc6732005-07-25 22:59:58 +0000624 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
Brian Paulb784b8f2004-08-14 14:30:36 +0000625 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
626 fi
627 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000628 ;;
629
630 'QNX')
631 LIBNAME="lib${LIBNAME}.a"
632 echo "mklib: Making QNX library: " ${LIBNAME}
633 wlib ${LIBNAME} ${OBJECTS}
634 FINAL_LIBS=${LIBNAME}
635 ;;
636
Brian Paul65e2ab32003-10-27 18:13:37 +0000637 'MorphOS')
638 LIBNAME="lib${LIBNAME}.a"
639 echo "mklib: Making MorphOS library: " ${LIBNAME}
640 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
641 FINAL_LIBS="${LIBNAME}"
642 ;;
643
Brian Paulfe14cf62006-04-13 02:23:25 +0000644 'icc' | 'icc-istatic')
Brian Paulb3b725b2003-12-15 16:14:55 +0000645 # Intel C compiler
Brian Paul7c1ab402005-07-25 23:49:50 +0000646 # This should get merged into the Linux code, above, since this isn't
647 # really a different architecture.
Brian Paulb3b725b2003-12-15 16:14:55 +0000648 LIBNAME="lib${LIBNAME}" # prefix with "lib"
649
650 if [ $STATIC = 1 ] ; then
651 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
652 LINK="ar"
653 OPTS="-ruv"
654 # make lib
655 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
656 # finish up
657 FINAL_LIBS="${LIBNAME}.a"
658 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000659 if [ $ARCH = icc-istatic ] ; then
660 OPTS="-shared -i-static -cxxlib-icc"
661 else
662 OPTS="-shared"
663 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000664 VERSION="${MAJOR}.${MINOR}.${PATCH}"
Brian Paulb3b725b2003-12-15 16:14:55 +0000665 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
666
667 if [ $CPLUSPLUS = 1 ] ; then
Brian Paulfe14cf62006-04-13 02:23:25 +0000668 LINK="icpc"
Brian Paulb3b725b2003-12-15 16:14:55 +0000669 else
670 LINK="icc"
671 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000672 # rm any old libs
673 rm -f ${LIBNAME}.so.${VERSION}
674 rm -f ${LIBNAME}.so.${MAJOR}
675 rm -f ${LIBNAME}.so
Brian Paulb3b725b2003-12-15 16:14:55 +0000676 # make lib
677 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
678 # make usual symlinks
679 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
680 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
681 # finish up
682 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
683 fi
684 ;;
685
Brian Paul12d6cae2004-01-10 22:12:21 +0000686 'aix-gcc')
687 # AIX with gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000688 if [ $STATIC = 1 ] ; then
689 LIBNAME="lib${LIBNAME}.a"
690 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
691 rm -f ${LIBNAME}
692 ar ru ${LIBNAME} ${OBJECTS}
693 FINAL_LIBS=${LIBNAME}
694 else
695 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
696 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
697 # remove old lib
698 rm -f ${LIBNAME}
699 # make the lib
700 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000701 # NOTE: the application linking with this library must specify
702 # the -Wl,-brtl flags to gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000703 FINAL_LIBS=${LIBNAME}
704 fi
705 ;;
706
707 'ultrix')
708 # XXX untested
709 if [ $STATIC = 0 ] ; then
710 echo "mklib: Warning shared libs not supported on Ultrix"
711 fi
712 LIBNAME="lib${LIBNAME}.a"
713 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
Brian Paul12d6cae2004-01-10 22:12:21 +0000714 rm -f ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000715 ar ru ${LIBNAME} ${OBJECTS}
716 FINAL_LIBS="${LIBNAME}"
Brian Paul12d6cae2004-01-10 22:12:21 +0000717 ;;
Brian Paulb3b725b2003-12-15 16:14:55 +0000718
Brian Paul580548d2004-04-22 16:16:42 +0000719 CYGWIN*)
720 # GCC-based environment
721 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
722 LIBNAME="lib${LIBNAME}" # prefix with "lib"
723
724 if [ $STATIC = 1 ] ; then
725 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
726 LINK="ar"
727 OPTS="-ru"
728 # make lib
729 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
730 ranlib ${LIBNAME}.a
731 # finish up
732 FINAL_LIBS=${LIBNAME}.a
733 else
734 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
735 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
736
737 if [ $CPLUSPLUS = 1 ] ; then
738 LINK="g++"
739 else
740 LINK="gcc"
741 fi
742
743 # rm any old libs
744 rm -f ${LIBNAME}-${MAJOR}.dll
745 rm -f ${LIBNAME}.dll.a
746 rm -f ${LIBNAME}.a
747
748 # make lib
749 ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
750 # make usual symlinks
751 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
752 # finish up
753 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
754 # special case for installing in bin
755 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
756 fi
757 ;;
758
Brian Paul8c20c7b2003-06-01 16:21:45 +0000759 'example')
760 # If you're adding support for a new architecture, you can
761 # start with this:
Brian Paul5396ab22004-02-12 14:48:52 +0000762 if [ $STATIC = 1 ] ; then
763 LIBNAME="lib${LIBNAME}.a"
764 echo "mklib: Making static library for example arch: " ${LIBNAME}
765 rm -f ${LIBNAME}
766 ar rv ${LIBNAME} ${OBJECTS}
767 FINAL_LIBS="${LIBNAME}"
768 else
Brian Paul7c1ab402005-07-25 23:49:50 +0000769 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul5396ab22004-02-12 14:48:52 +0000770 echo "mklib: Making shared library for example arch: " ${LIBNAME}
771 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
772 FINAL_LIBS="${LIBNAME}"
773 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000774 ;;
775
776 *)
Brian Paul5396ab22004-02-12 14:48:52 +0000777 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
778 echo "mklib: Please add necessary commands to mklib script."
Brian Paul8c20c7b2003-06-01 16:21:45 +0000779 ;;
780esac
781
782
783#
784# Put library files into installation directory if specified.
785#
786if [ ${INSTALLDIR} != "." ] ; then
787 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
788 mv ${FINAL_LIBS} ${INSTALLDIR}/
789fi