blob: 3b55d732ed8122fc1b2adcf945e605981435a8c5 [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 Paul7c1ab402005-07-25 23:49:50 +00008# Copyright (C) 1999-2005 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"
Brian Pauldd74e362004-04-08 22:26:22 +0000195 rm -f ${LIBNAME}
Brian Pauldd74e362004-04-08 22:26:22 +0000196 # make lib
197 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
198 # finish up
199 FINAL_LIBS="${LIBNAME}"
200 elif [ $STATIC = 1 ] ; then
201 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5b9a9d42004-01-17 18:31:12 +0000202 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
Brian Paul1c4b7112003-10-10 17:58:38 +0000203 LINK="ar"
Brian Paul6e450f22004-02-21 18:08:41 +0000204 OPTS="-ru"
Brian Paul1c4b7112003-10-10 17:58:38 +0000205 # make lib
206 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
Brian Paul6e450f22004-02-21 18:08:41 +0000207 ranlib ${LIBNAME}.a
Brian Paul1c4b7112003-10-10 17:58:38 +0000208 # finish up
Brian Paul6e450f22004-02-21 18:08:41 +0000209 FINAL_LIBS=${LIBNAME}.a
Brian Paul1c4b7112003-10-10 17:58:38 +0000210 else
Brian Pauldd74e362004-04-08 22:26:22 +0000211 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5b9a9d42004-01-17 18:31:12 +0000212 if [ $ARCH = 'Linux' ] ; then
213 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
214 else
215 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
216 fi
Brian Paul158a2512004-10-16 15:10:45 +0000217 if [ $EXPORTS ] ; then
218 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
219 # Make the 'exptmp' file for --version-script option
220 echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
221 echo "global:" >> exptmp
222 sed 's/$/;/' ${EXPORTS} >> exptmp
223 echo "local:" >> exptmp
224 echo "*;" >> exptmp
225 echo "};" >> exptmp
226 OPTS="${OPTS} -Xlinker --version-script=exptmp"
227 # exptmp is removed below
228 fi
Brian Paul3e196182005-03-03 01:38:13 +0000229
230 # Check if objects are 32-bit and we're running in 64-bit
231 # environment. If so, pass -m32 flag to linker.
232 set ${OBJECTS}
233 ABI32=`file $1 | grep 32-bit`
234 if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
235 OPTS="-m32 ${OPTS}"
236 fi
237
Brian Paul6e450f22004-02-21 18:08:41 +0000238 if [ x${PATCH} = "x" ] ; then
239 VERSION="${MAJOR}.${MINOR}"
240 else
241 VERSION="${MAJOR}.${MINOR}.${PATCH}"
242 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000243
Brian Paul5396ab22004-02-12 14:48:52 +0000244 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000245
Brian Paul1c4b7112003-10-10 17:58:38 +0000246 # rm any old libs
247 rm -f ${LIBNAME}.so.${VERSION}
248 rm -f ${LIBNAME}.so.${MAJOR}
249 rm -f ${LIBNAME}.so
250
251 # make lib
252 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
253 # make usual symlinks
254 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
255 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
256 # finish up
257 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
Brian Paulb17a1a12004-11-01 22:28:42 +0000258# rm -f exptmp
Brian Paul1c4b7112003-10-10 17:58:38 +0000259 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000260 ;;
261
262 'SunOS')
Brian Paul5396ab22004-02-12 14:48:52 +0000263 if [ $STATIC = 1 ] ; then
264 LIBNAME="lib${LIBNAME}.a"
265 echo "mklib: Making SunOS static library: " ${LIBNAME}
266 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000267 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000268 FINAL_LIBS=${LIBNAME}
269 else
270 LIBNAME="lib${LIBNAME}.so"
271 echo "mklib: Making SunOS shared library: " ${LIBNAME}
272 # XXX OPTS for gcc should be -shared, but that doesn't work.
273 # Using -G does work though.
Brian Paul8dcc6732005-07-25 22:59:58 +0000274 OPTS="-G"
275 if [ "x$LINK" = "x" ] ; then
276 # -linker was not specified, choose default linker now
277 if [ $CPLUSPLUS = 1 ] ; then
278 # determine linker and options for C++ code
279 if [ `which c++` ] ; then
280 # use Sun c++
281 LINK="c++"
282 elif [ `type g++` ] ; then
283 # use g++
284 LINK="g++"
285 else
286 echo "mklib: warning: can't find C++ comiler, trying CC."
287 LINK="CC"
288 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000289 else
Brian Paul8dcc6732005-07-25 22:59:58 +0000290 # use native Sun linker for C code
291 LINK="ld"
Brian Paul5396ab22004-02-12 14:48:52 +0000292 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000293 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000294 echo "mklib: linker is" ${LINK} ${OPTS}
295 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
296 ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
297 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
298 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000299 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000300 ;;
301
302 'FreeBSD')
Brian Pauldd74e362004-04-08 22:26:22 +0000303 if [ $NOPREFIX = 1 ] ; then
304 # No "lib" or ".so" part
305 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
306 rm -f ${LIBNAME}
307 ld -Bshareable -o ${LIBNAME} ${OBJECTS}
308 FINAL_LIBS=${LIBNAME}
309 elif [ $STATIC = 1 ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000310 STLIB="lib${LIBNAME}.a"
311 echo "mklib: Making FreeBSD static library: " ${STLIB}
312 rm -f ${STLIB}
313 ar cq ${STLIB} ${OBJECTS}
314 ranlib ${STLIB}
315 FINAL_LIBS=${STLIB}
316 else
317 SHLIB="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
318 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
319 rm -f ${SHLIB}
320 ld -Bshareable -o ${SHLIB} ${OBJECTS}
321 # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
322 FINAL_LIBS=${SHLIB}
323 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000324 ;;
325
Brian Paul8c20c7b2003-06-01 16:21:45 +0000326 'NetBSD')
Brian Paul5396ab22004-02-12 14:48:52 +0000327 if [ $STATIC = 1 ] ; then
328 LIBNAME="lib${LIBNAME}_pic.a"
329 echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
330 rm -f ${LIBNAME}
331 ar cq ${LIBNAME} ${OBJECTS}
332 ranlib ${LIBNAME}
333 FINAL_LIBS=${LIBNAME}
334 else
335 LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
336 echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
337 rm -f ${LIBNAME}
338 ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
339 FINAL_LIBS=${LIBNAME}
340 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000341 ;;
342
Brian Paulf8c31fc2004-01-29 15:21:47 +0000343 'IRIX' | 'IRIX64')
Brian Paul5396ab22004-02-12 14:48:52 +0000344 if [ $STATIC = 1 ] ; then
345 LIBNAME="lib${LIBNAME}.a"
346 rm -f ${LIBNAME}
347 ar rc ${LIBNAME} ${OBJECTS}
348 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000349 else
Brian Paul5396ab22004-02-12 14:48:52 +0000350 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul8dcc6732005-07-25 22:59:58 +0000351 # XXX we should run 'file' on the first object file to determine
352 # if it's o32, n32 or 64 format, as we do for Linux above.
Brian Paul5396ab22004-02-12 14:48:52 +0000353 if [ $ARCHOPT = "64" ] ; then
354 # 64-bit ABI
355 OPTS="-64 -shared -all"
356 echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
357 elif [ $ARCHOPT = "o32" ] ; then
358 # old 32-bit ABI
359 OPTS="-32 -shared -all"
360 echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
361 else
362 # new 32-bit ABI
363 OPTS="-n32 -shared -all"
364 echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
365 fi
366 if [ $CPLUSPLUS = 1 ] ; then
367 LINK="CC"
368 else
369 LINK="ld"
370 fi
371 ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
372 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000373 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000374 ;;
375
Brian Paul8c20c7b2003-06-01 16:21:45 +0000376 'linux-cygwin')
377 LIBNAME="lib${LIBNAME}.a"
378 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000379 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000380 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
381 FINAL_LIBS=${LIBNAME}
382 ;;
383
Brian Paulc193bd02004-03-18 15:41:59 +0000384 'HP-UX')
Brian Paul5396ab22004-02-12 14:48:52 +0000385 if [ $STATIC = 1 ] ; then
386 LIBNAME="lib${LIBNAME}.a"
Brian Paul52fb07e2004-03-30 14:47:02 +0000387 echo "mklib: Making HP-UX static library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000388 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000389 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000390 FINAL_LIBS=${LIBNAME}
391 else
392 RUNLIB="lib${LIBNAME}.${MAJOR}"
393 DEVLIB="lib${LIBNAME}.sl"
Brian Paul52fb07e2004-03-30 14:47:02 +0000394 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
Brian Paul5396ab22004-02-12 14:48:52 +0000395 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
396 ln -s ${RUNLIB} ${DEVLIB}
Brian Paulac0cfee2004-04-25 15:13:56 +0000397 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000398 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000399 ;;
400
Brian Paulb17a1a12004-11-01 22:28:42 +0000401 'AIX' | 'AIX64')
402 if [ $ARCH = "AIX64" ] ; then
403 X64="-X64"
404 fi
Brian Paulc193bd02004-03-18 15:41:59 +0000405
Brian Paulc193bd02004-03-18 15:41:59 +0000406 if [ $STATIC = 1 ] ; then
407 LIBNAME="lib${LIBNAME}.a"
408 echo "mklib: Making AIX static library: " ${LIBNAME}
Brian Paulb17a1a12004-11-01 22:28:42 +0000409 ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
Brian Paulc193bd02004-03-18 15:41:59 +0000410 FINAL_LIBS=${LIBNAME}
411 else
Karl Schultza16bdb52004-10-01 13:33:26 +0000412 EXPFILE="lib${LIBNAME}.exp"
413 OFILE=shr.o #Want to be consistent with the IBM libGL.a
414 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
Brian Paulb17a1a12004-11-01 22:28:42 +0000415 if [ $ARCH = "AIX64" ] ; then
416 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry -q64"
417 else
418 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry"
419 fi
Karl Schultza16bdb52004-10-01 13:33:26 +0000420 rm -f ${EXPFILE} ${OFILE}
Brian Paulb17a1a12004-11-01 22:28:42 +0000421 NM="/bin/nm -eC ${X64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000422 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
423 ${NM} ${OBJECTS} | awk '{
424 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
425 && ( substr($1,1,1) != ".")) {
426 if (substr ($1, 1, 7) != "__sinit" &&
427 substr ($1, 1, 7) != "__sterm") {
428 if (substr ($1, 1, 5) == "__tf1")
429 print (substr ($1, 7))
430 else if (substr ($1, 1, 5) == "__tf9")
431 print (substr ($1, 15))
432 else
433 print $1
434 }
435 }
436 }' | sort -u >> ${EXPFILE}
437 cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
Brian Paulb17a1a12004-11-01 22:28:42 +0000438 ar ${X64} -r ${LIBNAME} ${OFILE}
Karl Schultza16bdb52004-10-01 13:33:26 +0000439 FINAL_LIBS="${LIBNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000440 fi
441 ;;
442
Brian Paul8c20c7b2003-06-01 16:21:45 +0000443 'OpenSTEP')
444 LIBNAME="lib${LIBNAME}.a"
445 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
446 libtool -static -o ${LIBNAME} - ${OBJECTS}
447 FINAL_LIBS=${LIBNAME}
448 ;;
449
450 'OSF1')
Brian Paul5396ab22004-02-12 14:48:52 +0000451 if [ $STATIC = 1 ] ; then
452 LIBNAME="lib${LIBNAME}.a"
453 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
454 rm -f ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000455 ar -ruv ${LIBNAME} ${OBJECTS}
Brian Paul5396ab22004-02-12 14:48:52 +0000456 FINAL_LIBS=${LIBNAME}
457 else
458 VERSION="${MAJOR}.${MINOR}"
459 LIBNAME="lib${LIBNAME}.so"
460 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
Brian Paul8dcc6732005-07-25 22:59:58 +0000461 if [ "x$LINK" = "x" ] ; then
462 if [ $CPLUSPLUS = 1 ] ; then
463 LINK=cxx
464 else
465 LINK=cc
466 fi
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000467 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000468 rm -f ${LIBNAME}.${VERSION}
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000469 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000470 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
471 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
472 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000473 ;;
474
475 'Darwin')
Brian Paulc193bd02004-03-18 15:41:59 +0000476 if [ $STATIC = 1 ] ; then
477 LIBNAME="lib${LIBNAME}.a"
478 echo "mklib: Making Darwin static library: " ${LIBNAME}
479 LINK="ar"
480 OPTS="-ruv"
481 ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
482 FINAL_LIBS=${LIBNAME}
483 else
Brian Paulccda2162005-06-30 02:33:25 +0000484 LIBNAME="lib${LIBNAME}.dylib"
Brian Paulc50d77a2004-04-13 17:35:17 +0000485 echo "mklib: Making Darwin shared library: " ${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000486 FLAGS="-dynamiclib -multiply_defined suppress"
Brian Paulc05658d2004-03-25 21:18:32 +0000487 if [ $CPLUSPLUS = 1 ] ; then
488 LINK="g++"
489 else
490 LINK="cc"
491 fi
492 ${LINK} ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paulaaba0752004-03-23 23:25:47 +0000493 FINAL_LIBS=${LIBNAME}
Brian Paulc193bd02004-03-18 15:41:59 +0000494 fi
495 ;;
Brian Paul8c20c7b2003-06-01 16:21:45 +0000496
497 'LynxOS')
498 LIBNAME="lib${LIBNAME}.a"
Brian Paul5396ab22004-02-12 14:48:52 +0000499 echo "mklib: Making LynxOS static library: " ${LIBNAME}
500 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000501 ar ru ${LIBNAME} ${OBJECTS}
502 FINAL_LIBS=${LIBNAME}
503 ;;
504
505 'BeOS')
Philippe Houdoinef4dd5a2004-08-14 10:12:38 +0000506 if [ $STATIC = 1 ] ; then
507 LIBNAME="lib${LIBNAME}.a"
508 echo "mklib: Making BeOS static library: " ${LIBNAME}
509 ar -cru "${LIBNAME}" ${OBJECTS}
510 else
Brian Paulb784b8f2004-08-14 14:30:36 +0000511 LIBNAME="lib${LIBNAME}.so"
512 echo "mklib: Making BeOS shared library: " ${LIBNAME}
513 gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
514 mimeset -f "${LIBNAME}"
Brian Paul8dcc6732005-07-25 22:59:58 +0000515 # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
Brian Paulb784b8f2004-08-14 14:30:36 +0000516 setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
517 fi
518 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000519 ;;
520
521 'QNX')
522 LIBNAME="lib${LIBNAME}.a"
523 echo "mklib: Making QNX library: " ${LIBNAME}
524 wlib ${LIBNAME} ${OBJECTS}
525 FINAL_LIBS=${LIBNAME}
526 ;;
527
Brian Paul65e2ab32003-10-27 18:13:37 +0000528 'MorphOS')
529 LIBNAME="lib${LIBNAME}.a"
530 echo "mklib: Making MorphOS library: " ${LIBNAME}
531 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
532 FINAL_LIBS="${LIBNAME}"
533 ;;
534
Brian Paulb3b725b2003-12-15 16:14:55 +0000535 'icc')
536 # Intel C compiler
Brian Paul7c1ab402005-07-25 23:49:50 +0000537 # This should get merged into the Linux code, above, since this isn't
538 # really a different architecture.
Brian Paulb3b725b2003-12-15 16:14:55 +0000539 LIBNAME="lib${LIBNAME}" # prefix with "lib"
540
541 if [ $STATIC = 1 ] ; then
542 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
543 LINK="ar"
544 OPTS="-ruv"
545 # make lib
546 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
547 # finish up
548 FINAL_LIBS="${LIBNAME}.a"
549 else
550 OPTS="-shared"
551 VERSION="${MAJOR}.${MINOR}.${PATCH}"
Brian Paulb3b725b2003-12-15 16:14:55 +0000552 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
553
554 if [ $CPLUSPLUS = 1 ] ; then
555 LINK="icc"
556 else
557 LINK="icc"
558 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000559 # rm any old libs
560 rm -f ${LIBNAME}.so.${VERSION}
561 rm -f ${LIBNAME}.so.${MAJOR}
562 rm -f ${LIBNAME}.so
Brian Paulb3b725b2003-12-15 16:14:55 +0000563 # make lib
564 ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
565 # make usual symlinks
566 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
567 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
568 # finish up
569 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
570 fi
571 ;;
572
Brian Paul12d6cae2004-01-10 22:12:21 +0000573 'aix-gcc')
574 # AIX with gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000575 if [ $STATIC = 1 ] ; then
576 LIBNAME="lib${LIBNAME}.a"
577 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
578 rm -f ${LIBNAME}
579 ar ru ${LIBNAME} ${OBJECTS}
580 FINAL_LIBS=${LIBNAME}
581 else
582 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
583 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
584 # remove old lib
585 rm -f ${LIBNAME}
586 # make the lib
587 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000588 # NOTE: the application linking with this library must specify
589 # the -Wl,-brtl flags to gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000590 FINAL_LIBS=${LIBNAME}
591 fi
592 ;;
593
594 'ultrix')
595 # XXX untested
596 if [ $STATIC = 0 ] ; then
597 echo "mklib: Warning shared libs not supported on Ultrix"
598 fi
599 LIBNAME="lib${LIBNAME}.a"
600 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
Brian Paul12d6cae2004-01-10 22:12:21 +0000601 rm -f ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000602 ar ru ${LIBNAME} ${OBJECTS}
603 FINAL_LIBS="${LIBNAME}"
Brian Paul12d6cae2004-01-10 22:12:21 +0000604 ;;
Brian Paulb3b725b2003-12-15 16:14:55 +0000605
Brian Paul580548d2004-04-22 16:16:42 +0000606 CYGWIN*)
607 # GCC-based environment
608 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
609 LIBNAME="lib${LIBNAME}" # prefix with "lib"
610
611 if [ $STATIC = 1 ] ; then
612 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
613 LINK="ar"
614 OPTS="-ru"
615 # make lib
616 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
617 ranlib ${LIBNAME}.a
618 # finish up
619 FINAL_LIBS=${LIBNAME}.a
620 else
621 OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
622 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
623
624 if [ $CPLUSPLUS = 1 ] ; then
625 LINK="g++"
626 else
627 LINK="gcc"
628 fi
629
630 # rm any old libs
631 rm -f ${LIBNAME}-${MAJOR}.dll
632 rm -f ${LIBNAME}.dll.a
633 rm -f ${LIBNAME}.a
634
635 # make lib
636 ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
637 # make usual symlinks
638 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
639 # finish up
640 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
641 # special case for installing in bin
642 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
643 fi
644 ;;
645
Brian Paul8c20c7b2003-06-01 16:21:45 +0000646 'example')
647 # If you're adding support for a new architecture, you can
648 # start with this:
Brian Paul5396ab22004-02-12 14:48:52 +0000649 if [ $STATIC = 1 ] ; then
650 LIBNAME="lib${LIBNAME}.a"
651 echo "mklib: Making static library for example arch: " ${LIBNAME}
652 rm -f ${LIBNAME}
653 ar rv ${LIBNAME} ${OBJECTS}
654 FINAL_LIBS="${LIBNAME}"
655 else
Brian Paul7c1ab402005-07-25 23:49:50 +0000656 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul5396ab22004-02-12 14:48:52 +0000657 echo "mklib: Making shared library for example arch: " ${LIBNAME}
658 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
659 FINAL_LIBS="${LIBNAME}"
660 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000661 ;;
662
663 *)
Brian Paul5396ab22004-02-12 14:48:52 +0000664 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
665 echo "mklib: Please add necessary commands to mklib script."
Brian Paul8c20c7b2003-06-01 16:21:45 +0000666 ;;
667esac
668
669
670#
671# Put library files into installation directory if specified.
672#
673if [ ${INSTALLDIR} != "." ] ; then
674 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
675 mv ${FINAL_LIBS} ${INSTALLDIR}/
676fi