blob: 32e43987b3795344a5cc35f56823b8518b8a66ad [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
39INSTALLDIR="."
40ARCH="auto"
41ARCHOPT=""
Brian Pauldd74e362004-04-08 22:26:22 +000042NOPREFIX=0
Brian Paul158a2512004-10-16 15:10:45 +000043EXPORTS=""
Brian Paul8c20c7b2003-06-01 16:21:45 +000044
45
46#
47# Parse arguments
48#
49while true
50do
51 case $1 in
Brian Paul7c1ab402005-07-25 23:49:50 +000052 '-h' | '--help')
Eric Anholtf1a26132005-08-08 03:26:18 +000053 echo 'Usage: mklib [options] objects'
54 echo 'Create a shared library from object files.'
55 echo ' -o LIBRARY specifies the name of the resulting library, without'
56 echo ' the leading "lib" or any suffix.'
57 echo ' (eg: "-o GL" might result in "libGL.so" being made)'
58 echo ' -major N specifies major version number (default is 1)'
59 echo ' -minor N specifies minor version number (default is 0)'
60 echo ' -patch N specifies patch version number (default is 0)'
61 echo ' -lLIBRARY specifies a dependency on LIBRARY'
62 echo ' -LDIR search in DIR for library dependencies'
63 echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
64 echo ' Not observed on all systems at this time.'
65 echo ' -cplusplus link with C++ runtime'
66 echo ' -static make a static library (default is dynamic/shared)'
67 echo ' -install DIR put resulting library file(s) in DIR'
68 echo ' -arch ARCH override using `uname` to determine host system'
69 echo ' -archopt OPT specify an extra achitecture-specific option OPT'
70 echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
71 echo ' -exports FILE only export the symbols listed in FILE'
72 echo ' -h, --help display this information and exit'
Brian Paul7c1ab402005-07-25 23:49:50 +000073 exit 1
74 ;;
75 '-o')
76 shift 1;
77 LIBNAME=$1
78 ;;
79 '-major')
80 shift 1;
81 MAJOR=$1
82 ;;
83 '-minor')
84 shift 1;
85 MINOR=$1
86 ;;
87 '-patch')
88 shift 1;
89 PATCH=$1
90 ;;
91 '-linker')
92 shift 1;
93 LINK=$1
94 ;;
95 -l*)
96 DEPS="$DEPS $1"
97 ;;
98 -L*)
99 DEPS="$DEPS $1"
100 ;;
101 '-cplusplus')
102 CPLUSPLUS=1
103 ;;
104 '-static')
105 STATIC=1
106 ;;
107 '-install')
108 shift 1;
109 INSTALLDIR=$1
110 ;;
111 '-arch')
112 shift 1;
113 ARCH=$1
114 ;;
115 '-archopt')
116 shift 1;
117 ARCHOPT=$1
118 ;;
119 '-noprefix')
120 NOPREFIX=1
121 ;;
122 '-exports')
123 shift 1;
124 EXPORTS=$1
125 ;;
126 -*)
127 echo "mklib: Unknown option: " $1 ;
128 exit 1
129 ;;
130 *)
131 # This should be the first object file, stop parsing
132 break
Brian Paul8c20c7b2003-06-01 16:21:45 +0000133 esac
134 shift 1
135done
136OBJECTS=$@
137
Brian Paul7c1ab402005-07-25 23:49:50 +0000138
Brian Paul8c20c7b2003-06-01 16:21:45 +0000139if [ ${ARCH} = "auto" ] ; then
140 ARCH=`uname`
141fi
142
143
144#
145# Error checking
146#
147if [ "x${LIBNAME}" = "x" ] ; then
148 echo "mklib: Error: no library name specified"
149 exit 1
150fi
151if [ "x${OBJECTS}" = "x" ] ; then
152 echo "mklib: Error: no object files specified"
153 exit 1
154fi
155
156
157#
158# Debugging info
159#
160if [ ] ; then
161 echo "-----------------"
162 echo ARCH is $ARCH
163 echo LIBNAME is $LIBNAME
164 echo MAJOR is $MAJOR
165 echo MINOR is $MINOR
166 echo PATCH is $PATCH
167 echo DEPS are $DEPS
Brian Paul158a2512004-10-16 15:10:45 +0000168 echo "EXPORTS in" $EXPORTS
Brian Paul8c20c7b2003-06-01 16:21:45 +0000169 echo "-----------------"
170fi
171
172
173#
174# OK, make the library now
175#
176case $ARCH in
177
Brian Paul12d6cae2004-01-10 22:12:21 +0000178 'Linux' | 'OpenBSD')
Brian Paul158a2512004-10-16 15:10:45 +0000179 # we assume gcc
Brian Paul8c20c7b2003-06-01 16:21:45 +0000180
Brian Paul8dcc6732005-07-25 22:59:58 +0000181 if [ "x$LINK" = "x" ] ; then
182 # -linker was not specified so set default link command now
183 if [ $CPLUSPLUS = 1 ] ; then
184 LINK=g++
185 else
186 LINK=gcc
187 fi
Brian Paulc4987422004-10-16 15:02:16 +0000188 fi
189
Brian Pauldd74e362004-04-08 22:26:22 +0000190 if [ $NOPREFIX = 1 ] ; then
191 # No "lib" or ".so" part
192 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
193 #OPTS="-shared -Wl,-soname,${LIBNAME}" # soname???
194 OPTS="-shared"
Ian Romanickaba48642005-08-08 23:22:46 +0000195
196 # Check if objects are 32-bit and we're running in 64-bit
197 # environment. If so, pass -m32 flag to linker.
198 set ${OBJECTS}
199 ABI32=`file $1 | grep 32-bit`
200 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
201 OPTS="-m32 ${OPTS}"
202 fi
203
Brian Pauldd74e362004-04-08 22:26:22 +0000204 rm -f ${LIBNAME}
Brian Pauldd74e362004-04-08 22:26:22 +0000205 # make lib
206 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
207 # finish up
208 FINAL_LIBS="${LIBNAME}"
209 elif [ $STATIC = 1 ] ; then
210 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5b9a9d42004-01-17 18:31:12 +0000211 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
Brian Paul56e0ee82006-04-13 15:17:50 +0000212 LINK="ar"
213 OPTS="-ru"
214 # make lib
215 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
Brian Paul6e450f22004-02-21 18:08:41 +0000216 ranlib ${LIBNAME}.a
Brian Paul1c4b7112003-10-10 17:58:38 +0000217 # finish up
Brian Paul6e450f22004-02-21 18:08:41 +0000218 FINAL_LIBS=${LIBNAME}.a
Brian Paul1c4b7112003-10-10 17:58:38 +0000219 else
Brian Pauldd74e362004-04-08 22:26:22 +0000220 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5b9a9d42004-01-17 18:31:12 +0000221 if [ $ARCH = 'Linux' ] ; then
222 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
223 else
224 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
225 fi
Brian Paul158a2512004-10-16 15:10:45 +0000226 if [ $EXPORTS ] ; then
227 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
228 # Make the 'exptmp' file for --version-script option
229 echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
230 echo "global:" >> exptmp
231 sed 's/$/;/' ${EXPORTS} >> exptmp
232 echo "local:" >> exptmp
233 echo "*;" >> exptmp
234 echo "};" >> exptmp
235 OPTS="${OPTS} -Xlinker --version-script=exptmp"
236 # exptmp is removed below
237 fi
Brian Paul3e196182005-03-03 01:38:13 +0000238
239 # Check if objects are 32-bit and we're running in 64-bit
240 # environment. If so, pass -m32 flag to linker.
241 set ${OBJECTS}
242 ABI32=`file $1 | grep 32-bit`
243 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
244 OPTS="-m32 ${OPTS}"
245 fi
246
Brian Paul6e450f22004-02-21 18:08:41 +0000247 if [ x${PATCH} = "x" ] ; then
248 VERSION="${MAJOR}.${MINOR}"
249 else
250 VERSION="${MAJOR}.${MINOR}.${PATCH}"
251 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000252
Brian Paul5396ab22004-02-12 14:48:52 +0000253 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000254
Brian Paul1c4b7112003-10-10 17:58:38 +0000255 # rm any old libs
256 rm -f ${LIBNAME}.so.${VERSION}
257 rm -f ${LIBNAME}.so.${MAJOR}
258 rm -f ${LIBNAME}.so
259
260 # make lib
261 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
262 # make usual symlinks
263 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
264 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
265 # finish up
266 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
Brian Paulb17a1a12004-11-01 22:28:42 +0000267# rm -f exptmp
Brian Paul1c4b7112003-10-10 17:58:38 +0000268 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000269 ;;
270
271 'SunOS')
Brian Paul5396ab22004-02-12 14:48:52 +0000272 if [ $STATIC = 1 ] ; then
273 LIBNAME="lib${LIBNAME}.a"
274 echo "mklib: Making SunOS static library: " ${LIBNAME}
275 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000276 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000277 FINAL_LIBS=${LIBNAME}
278 else
279 LIBNAME="lib${LIBNAME}.so"
280 echo "mklib: Making SunOS shared library: " ${LIBNAME}
Brian Paul59ebe1f2006-04-05 13:43:02 +0000281
Brian Paul8dcc6732005-07-25 22:59:58 +0000282 if [ "x$LINK" = "x" ] ; then
283 # -linker was not specified, choose default linker now
284 if [ $CPLUSPLUS = 1 ] ; then
285 # determine linker and options for C++ code
286 if [ `which c++` ] ; then
287 # use Sun c++
288 LINK="c++"
289 elif [ `type g++` ] ; then
290 # use g++
291 LINK="g++"
292 else
293 echo "mklib: warning: can't find C++ comiler, trying CC."
294 LINK="CC"
295 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000296 else
Brian Paul8dcc6732005-07-25 22:59:58 +0000297 # use native Sun linker for C code
298 LINK="ld"
Brian Paul5396ab22004-02-12 14:48:52 +0000299 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000300 fi
Brian Paul59ebe1f2006-04-05 13:43:02 +0000301
302 # linker options
303 if [ ${LINK} = "ld" ] ; then
304 # SunOS linker, -G to make shared libs
305 OPTS="-G"
306 else
307 # gcc linker
308 # Check if objects are 32-bit and we're running in 64-bit
309 # environment. If so, pass -m32 flag to linker.
310 set ${OBJECTS}
311 ABI32=`file $1 | grep 32-bit`
312 if [ "${ABI32}" ] ; then
313 OPTS="-m32 -shared -Wl,-Bdynamic"
314 else
315 OPTS="-m64 -shared -Wl,-Bdynamic"
316 fi
317 fi
318
Brian Paulfe14cf62006-04-13 02:23:25 +0000319 ARCHOPTS=""
320 if [ "$ARCHOPT" = "SUNV9" ] ; then
321 ARCHOPTS="-xarch=v9"
322 fi
Brian Paul59ebe1f2006-04-05 13:43:02 +0000323 # for debug:
Brian Paul56e0ee82006-04-13 15:17:50 +0000324 #echo "mklib: linker is" ${LINK} ${OPTS} ${ARCHOPTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000325 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
Brian Paulfe14cf62006-04-13 02:23:25 +0000326 ${LINK} ${OPTS} ${ARCHOPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000327 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
328 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000329 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000330 ;;
331
332 'FreeBSD')
Eric Anholtb83435f2005-10-18 23:36:40 +0000333 # we assume gcc
334
335 if [ "x$LINK" = "x" ] ; then
336 # -linker was not specified so set default link command now
337 if [ $CPLUSPLUS = 1 ] ; then
338 LINK=g++
339 else
340 LINK=gcc
341 fi
342 fi
343
Brian Pauldd74e362004-04-08 22:26:22 +0000344 if [ $NOPREFIX = 1 ] ; then
345 # No "lib" or ".so" part
346 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
Eric Anholtb83435f2005-10-18 23:36:40 +0000347 OPTS="-shared"
Brian Pauldd74e362004-04-08 22:26:22 +0000348 rm -f ${LIBNAME}
Eric Anholtb83435f2005-10-18 23:36:40 +0000349 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Pauldd74e362004-04-08 22:26:22 +0000350 FINAL_LIBS=${LIBNAME}
351 elif [ $STATIC = 1 ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000352 STLIB="lib${LIBNAME}.a"
353 echo "mklib: Making FreeBSD static library: " ${STLIB}
354 rm -f ${STLIB}
355 ar cq ${STLIB} ${OBJECTS}
356 ranlib ${STLIB}
357 FINAL_LIBS=${STLIB}
358 else
Eric Anholtb83435f2005-10-18 23:36:40 +0000359 SHLIB="lib${LIBNAME}.so.${MAJOR}"
360 OPTS="-shared -Wl,-soname,${SHLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000361 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
362 rm -f ${SHLIB}
Eric Anholtb83435f2005-10-18 23:36:40 +0000363 ${LINK} ${OPTS} -o ${SHLIB} ${OBJECTS} ${DEPS}
Eric Anholt1c04be52005-10-22 01:41:40 +0000364 ln -sf ${SHLIB} "lib${LIBNAME}.so"
365 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
Brian Paul5396ab22004-02-12 14:48:52 +0000366 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000367 ;;
368
Brian Paul8c20c7b2003-06-01 16:21:45 +0000369 'NetBSD')
Brian Paul5396ab22004-02-12 14:48:52 +0000370 if [ $STATIC = 1 ] ; then
371 LIBNAME="lib${LIBNAME}_pic.a"
372 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
373 rm -f ${LIBNAME}
374 ar cq ${LIBNAME} ${OBJECTS}
375 ranlib ${LIBNAME}
376 FINAL_LIBS=${LIBNAME}
377 else
378 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
379 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
380 rm -f ${LIBNAME}
381 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
382 FINAL_LIBS=${LIBNAME}
383 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000384 ;;
385
Brian Paulf8c31fc2004-01-29 15:21:47 +0000386 'IRIX' | 'IRIX64')
Brian Paul5396ab22004-02-12 14:48:52 +0000387 if [ $STATIC = 1 ] ; then
388 LIBNAME="lib${LIBNAME}.a"
389 rm -f ${LIBNAME}
390 ar rc ${LIBNAME} ${OBJECTS}
391 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000392 else
Brian Paul5396ab22004-02-12 14:48:52 +0000393 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul8dcc6732005-07-25 22:59:58 +0000394 # XXX we should run 'file' on the first object file to determine
395 # if it's o32, n32 or 64 format, as we do for Linux above.
Brian Paul5396ab22004-02-12 14:48:52 +0000396 if [ $ARCHOPT = "64" ] ; then
397 # 64-bit ABI
398 OPTS="-64 -shared -all"
399 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
400 elif [ $ARCHOPT = "o32" ] ; then
401 # old 32-bit ABI
402 OPTS="-32 -shared -all"
403 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
404 else
405 # new 32-bit ABI
406 OPTS="-n32 -shared -all"
407 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
408 fi
409 if [ $CPLUSPLUS = 1 ] ; then
410 LINK="CC"
411 else
412 LINK="ld"
413 fi
414 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
415 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000416 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000417 ;;
418
Brian Paul8c20c7b2003-06-01 16:21:45 +0000419 'linux-cygwin')
420 LIBNAME="lib${LIBNAME}.a"
421 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000422 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000423 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
424 FINAL_LIBS=${LIBNAME}
425 ;;
426
Brian Paulc193bd02004-03-18 15:41:59 +0000427 'HP-UX')
Brian Paul5396ab22004-02-12 14:48:52 +0000428 if [ $STATIC = 1 ] ; then
429 LIBNAME="lib${LIBNAME}.a"
Brian Paul52fb07e2004-03-30 14:47:02 +0000430 echo "mklib: Making HP-UX static library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000431 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000432 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000433 FINAL_LIBS=${LIBNAME}
434 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000435 # HP uses a .2 for their current GL/GLU libraries
436 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
437 MAJOR=2
438 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000439 RUNLIB="lib${LIBNAME}.${MAJOR}"
440 DEVLIB="lib${LIBNAME}.sl"
Brian Paul52fb07e2004-03-30 14:47:02 +0000441 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
Brian Paul5396ab22004-02-12 14:48:52 +0000442 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
443 ln -s ${RUNLIB} ${DEVLIB}
Brian Paulac0cfee2004-04-25 15:13:56 +0000444 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000445 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000446 ;;
447
Brian Paulb17a1a12004-11-01 22:28:42 +0000448 'AIX' | 'AIX64')
449 if [ $ARCH = "AIX64" ] ; then
450 X64="-X64"
451 fi
Brian Paulc193bd02004-03-18 15:41:59 +0000452
Brian Paulc193bd02004-03-18 15:41:59 +0000453 if [ $STATIC = 1 ] ; then
454 LIBNAME="lib${LIBNAME}.a"
455 echo "mklib: Making AIX static library: " ${LIBNAME}
Brian Paulb17a1a12004-11-01 22:28:42 +0000456 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
Brian Paulc193bd02004-03-18 15:41:59 +0000457 FINAL_LIBS=${LIBNAME}
458 else
Brian Paul56e0ee82006-04-13 15:17:50 +0000459 # We make both .a (normal shared lib) and .so (which can be
460 # loaded with dlopen).
Karl Schultza16bdb52004-10-01 13:33:26 +0000461 EXPFILE="lib${LIBNAME}.exp"
Brian Paulfe14cf62006-04-13 02:23:25 +0000462 if [ $ARCH = "AIX64" ] ; then
463 OFILE=shr_64.o
464 else
465 OFILE=shr.o #Want to be consistent with the IBM libGL.a
466 fi
Brian Paul56e0ee82006-04-13 15:17:50 +0000467 DLOPENLIBNAME="lib${LIBNAME}.so" # different libs required for dlopen
Karl Schultza16bdb52004-10-01 13:33:26 +0000468 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
Brian Paulb17a1a12004-11-01 22:28:42 +0000469 if [ $ARCH = "AIX64" ] ; then
470 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry -q64"
471 else
472 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry"
473 fi
Karl Schultza16bdb52004-10-01 13:33:26 +0000474 rm -f ${EXPFILE} ${OFILE}
Brian Paulb17a1a12004-11-01 22:28:42 +0000475 NM="/bin/nm -eC ${X64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000476 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
477 ${NM} ${OBJECTS} | awk '{
478 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
479 && ( substr($1,1,1) != ".")) {
480 if (substr ($1, 1, 7) != "__sinit" &&
481 substr ($1, 1, 7) != "__sterm") {
482 if (substr ($1, 1, 5) == "__tf1")
483 print (substr ($1, 7))
484 else if (substr ($1, 1, 5) == "__tf9")
485 print (substr ($1, 15))
486 else
487 print $1
488 }
489 }
490 }' | sort -u >> ${EXPFILE}
Brian Paulfe14cf62006-04-13 02:23:25 +0000491
492 # On AIX a shared library is linked differently when
493 # you want to dlopen the file
Brian Paul56e0ee82006-04-13 15:17:50 +0000494 cc -G ${OPTS} -o ${DLOPENLIBNAME} ${OBJECTS} ${DEPS}
495
496 # Traditional link-time binding compatible with system lib
497 cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
498 ar ${X64} -r ${LIBNAME} ${OFILE}
499
500 FINAL_LIBS="${LIBNAME} ${DLOPENLIBNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000501 fi
502 ;;
503
Brian Paul8c20c7b2003-06-01 16:21:45 +0000504 'OpenSTEP')
505 LIBNAME="lib${LIBNAME}.a"
506 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
507 libtool -static -o ${LIBNAME} - ${OBJECTS}
508 FINAL_LIBS=${LIBNAME}
509 ;;
510
511 'OSF1')
Brian Paul5396ab22004-02-12 14:48:52 +0000512 if [ $STATIC = 1 ] ; then
513 LIBNAME="lib${LIBNAME}.a"
514 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
515 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000516 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000517 FINAL_LIBS=${LIBNAME}
518 else
519 VERSION="${MAJOR}.${MINOR}"
520 LIBNAME="lib${LIBNAME}.so"
521 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
Brian Paul8dcc6732005-07-25 22:59:58 +0000522 if [ "x$LINK" = "x" ] ; then
523 if [ $CPLUSPLUS = 1 ] ; then
524 LINK=cxx
525 else
526 LINK=cc
527 fi
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000528 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000529 rm -f ${LIBNAME}.${VERSION}
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000530 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000531 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
532 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
533 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000534 ;;
535
536 'Darwin')
Brian Paulc193bd02004-03-18 15:41:59 +0000537 if [ $STATIC = 1 ] ; then
538 LIBNAME="lib${LIBNAME}.a"
539 echo "mklib: Making Darwin static library: " ${LIBNAME}
540 LINK="ar"
Brian Paulfe14cf62006-04-13 02:23:25 +0000541 OPTS="-ruvs"
Brian Paulc193bd02004-03-18 15:41:59 +0000542 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
543 FINAL_LIBS=${LIBNAME}
544 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000545 # On Darwin a .bundle is used for a library that you want to dlopen
Brian Paul56e0ee82006-04-13 15:17:50 +0000546 FLAGS="${ARCHOPT} -bundle -multiply_defined suppress"
547 BLINKNAME="lib${LIBNAME}.bundle"
548 BLIBNAME="lib${LIBNAME}.${MAJOR}.bundle"
549 echo "mklib: Making Darwin bundle: " ${BLIBNAME}
550 if [ $CPLUSPLUS = 1 ] ; then
551 LINK="g++"
552 else
553 LINK="cc"
554 fi
555 ${LINK} ${FLAGS} -o ${BLIBNAME} ${OBJECTS} ${DEPS}
556 ln -s ${BLIBNAME} ${BLINKNAME}
Brian Paulfe14cf62006-04-13 02:23:25 +0000557
Brian Paul56e0ee82006-04-13 15:17:50 +0000558 # A .dylib is for link-time binding
559 FLAGS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
560 LINKNAME="lib${LIBNAME}.dylib"
561 LIBNAME="lib${LIBNAME}.${MAJOR}.dylib"
Brian Paulc50d77a2004-04-13 17:35:17 +0000562 echo "mklib: Making Darwin shared library: " ${LIBNAME}
Brian Paulc05658d2004-03-25 21:18:32 +0000563 if [ $CPLUSPLUS = 1 ] ; then
564 LINK="g++"
565 else
566 LINK="cc"
567 fi
568 ${LINK} ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paulfe14cf62006-04-13 02:23:25 +0000569 ln -s ${LIBNAME} ${LINKNAME}
Brian Paul56e0ee82006-04-13 15:17:50 +0000570
571 FINAL_LIBS="${LIBNAME} ${LINKNAME} ${BLIBNAME} ${BLINKNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000572 fi
573 ;;
Brian Paul8c20c7b2003-06-01 16:21:45 +0000574
575 'LynxOS')
576 LIBNAME="lib${LIBNAME}.a"
Brian Paul5396ab22004-02-12 14:48:52 +0000577 echo "mklib: Making LynxOS static library: " ${LIBNAME}
578 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000579 ar ru ${LIBNAME} ${OBJECTS}
580 FINAL_LIBS=${LIBNAME}
581 ;;
582
583 'BeOS')
Philippe Houdoinef4dd5a2004-08-14 10:12:38 +0000584 if [ $STATIC = 1 ] ; then
585 LIBNAME="lib${LIBNAME}.a"
586 echo "mklib: Making BeOS static library: " ${LIBNAME}
587 ar -cru "${LIBNAME}" ${OBJECTS}
588 else
Brian Paulb784b8f2004-08-14 14:30:36 +0000589 LIBNAME="lib${LIBNAME}.so"
590 echo "mklib: Making BeOS shared library: " ${LIBNAME}
591 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
592 mimeset -f "${LIBNAME}"
Brian Paul8dcc6732005-07-25 22:59:58 +0000593 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
Brian Paulb784b8f2004-08-14 14:30:36 +0000594 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
595 fi
596 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000597 ;;
598
599 'QNX')
600 LIBNAME="lib${LIBNAME}.a"
601 echo "mklib: Making QNX library: " ${LIBNAME}
602 wlib ${LIBNAME} ${OBJECTS}
603 FINAL_LIBS=${LIBNAME}
604 ;;
605
Brian Paul65e2ab32003-10-27 18:13:37 +0000606 'MorphOS')
607 LIBNAME="lib${LIBNAME}.a"
608 echo "mklib: Making MorphOS library: " ${LIBNAME}
609 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
610 FINAL_LIBS="${LIBNAME}"
611 ;;
612
Brian Paulfe14cf62006-04-13 02:23:25 +0000613 'icc' | 'icc-istatic')
Brian Paulb3b725b2003-12-15 16:14:55 +0000614 # Intel C compiler
Brian Paul7c1ab402005-07-25 23:49:50 +0000615 # This should get merged into the Linux code, above, since this isn't
616 # really a different architecture.
Brian Paulb3b725b2003-12-15 16:14:55 +0000617 LIBNAME="lib${LIBNAME}" # prefix with "lib"
618
619 if [ $STATIC = 1 ] ; then
620 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
621 LINK="ar"
622 OPTS="-ruv"
623 # make lib
624 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
625 # finish up
626 FINAL_LIBS="${LIBNAME}.a"
627 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000628 if [ $ARCH = icc-istatic ] ; then
629 OPTS="-shared -i-static -cxxlib-icc"
630 else
631 OPTS="-shared"
632 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000633 VERSION="${MAJOR}.${MINOR}.${PATCH}"
Brian Paulb3b725b2003-12-15 16:14:55 +0000634 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
635
636 if [ $CPLUSPLUS = 1 ] ; then
Brian Paulfe14cf62006-04-13 02:23:25 +0000637 LINK="icpc"
Brian Paulb3b725b2003-12-15 16:14:55 +0000638 else
639 LINK="icc"
640 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000641 # rm any old libs
642 rm -f ${LIBNAME}.so.${VERSION}
643 rm -f ${LIBNAME}.so.${MAJOR}
644 rm -f ${LIBNAME}.so
Brian Paulb3b725b2003-12-15 16:14:55 +0000645 # make lib
646 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
647 # make usual symlinks
648 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
649 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
650 # finish up
651 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
652 fi
653 ;;
654
Brian Paul12d6cae2004-01-10 22:12:21 +0000655 'aix-gcc')
656 # AIX with gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000657 if [ $STATIC = 1 ] ; then
658 LIBNAME="lib${LIBNAME}.a"
659 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
660 rm -f ${LIBNAME}
661 ar ru ${LIBNAME} ${OBJECTS}
662 FINAL_LIBS=${LIBNAME}
663 else
664 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
665 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
666 # remove old lib
667 rm -f ${LIBNAME}
668 # make the lib
669 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000670 # NOTE: the application linking with this library must specify
671 # the -Wl,-brtl flags to gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000672 FINAL_LIBS=${LIBNAME}
673 fi
674 ;;
675
676 'ultrix')
677 # XXX untested
678 if [ $STATIC = 0 ] ; then
679 echo "mklib: Warning shared libs not supported on Ultrix"
680 fi
681 LIBNAME="lib${LIBNAME}.a"
682 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
Brian Paul12d6cae2004-01-10 22:12:21 +0000683 rm -f ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000684 ar ru ${LIBNAME} ${OBJECTS}
685 FINAL_LIBS="${LIBNAME}"
Brian Paul12d6cae2004-01-10 22:12:21 +0000686 ;;
Brian Paulb3b725b2003-12-15 16:14:55 +0000687
Brian Paul580548d2004-04-22 16:16:42 +0000688 CYGWIN*)
689 # GCC-based environment
690 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
691 LIBNAME="lib${LIBNAME}" # prefix with "lib"
692
693 if [ $STATIC = 1 ] ; then
694 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
695 LINK="ar"
696 OPTS="-ru"
697 # make lib
698 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
699 ranlib ${LIBNAME}.a
700 # finish up
701 FINAL_LIBS=${LIBNAME}.a
702 else
703 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
704 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
705
706 if [ $CPLUSPLUS = 1 ] ; then
707 LINK="g++"
708 else
709 LINK="gcc"
710 fi
711
712 # rm any old libs
713 rm -f ${LIBNAME}-${MAJOR}.dll
714 rm -f ${LIBNAME}.dll.a
715 rm -f ${LIBNAME}.a
716
717 # make lib
718 ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
719 # make usual symlinks
720 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
721 # finish up
722 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
723 # special case for installing in bin
724 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
725 fi
726 ;;
727
Brian Paul8c20c7b2003-06-01 16:21:45 +0000728 'example')
729 # If you're adding support for a new architecture, you can
730 # start with this:
Brian Paul5396ab22004-02-12 14:48:52 +0000731 if [ $STATIC = 1 ] ; then
732 LIBNAME="lib${LIBNAME}.a"
733 echo "mklib: Making static library for example arch: " ${LIBNAME}
734 rm -f ${LIBNAME}
735 ar rv ${LIBNAME} ${OBJECTS}
736 FINAL_LIBS="${LIBNAME}"
737 else
Brian Paul7c1ab402005-07-25 23:49:50 +0000738 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul5396ab22004-02-12 14:48:52 +0000739 echo "mklib: Making shared library for example arch: " ${LIBNAME}
740 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
741 FINAL_LIBS="${LIBNAME}"
742 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000743 ;;
744
745 *)
Brian Paul5396ab22004-02-12 14:48:52 +0000746 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
747 echo "mklib: Please add necessary commands to mklib script."
Brian Paul8c20c7b2003-06-01 16:21:45 +0000748 ;;
749esac
750
751
752#
753# Put library files into installation directory if specified.
754#
755if [ ${INSTALLDIR} != "." ] ; then
756 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
757 mv ${FINAL_LIBS} ${INSTALLDIR}/
758fi