blob: 086b2689885a5c031c51ec54939db8f00befa978 [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
Brian Paulcc668472010-02-18 13:02:59 -070027
Keith Packardedd85bc2010-02-21 14:30:00 -080028# Clear CDPATH as the 'cd' command will echo stuff
29# to stdout if it is set
30unset CDPATH
31
Brian Paul191d9652009-12-23 16:50:06 -070032# Given a list of files, look for .a archives and unpack them.
33# Return the original list of files minus the .a files plus the unpacked files.
Brian Paulcc668472010-02-18 13:02:59 -070034# first param: name of a temp directory (to be deleted when finished)
35# remaining params: list of .o and .a files
Brian Paul191d9652009-12-23 16:50:06 -070036expand_archives() {
Dan Nicholsona1de4002010-01-07 17:11:37 -080037 DIR=$1
38 shift
Brian Paul191d9652009-12-23 16:50:06 -070039 FILES=$@
40 NEWFILES=""
Dan Nicholsona1de4002010-01-07 17:11:37 -080041 ORIG_DIR=`pwd`
42 mkdir -p "$DIR"
43 cd "$DIR"
Brian Paul191d9652009-12-23 16:50:06 -070044 for FILE in $FILES ; do
45 case $FILE in
46 *.a)
47 # extract the .o files from this .a archive
Dan Nicholsona1de4002010-01-07 17:11:37 -080048 case $FILE in
49 /*) ;;
50 *) FILE="$ORIG_DIR/$FILE" ;;
51 esac
Brian Paul191d9652009-12-23 16:50:06 -070052 MEMBERS=`ar t $FILE`
53 ar x $FILE
Dan Nicholsona1de4002010-01-07 17:11:37 -080054 for MEMBER in $MEMBERS ; do
55 NEWFILES="$NEWFILES $DIR/$MEMBER"
56 done
Brian Paul191d9652009-12-23 16:50:06 -070057 ;;
58 *)
59 # other file type, just add to list
60 NEWFILES="$NEWFILES $FILE"
61 ;;
62 esac
63 done
Dan Nicholsona1de4002010-01-07 17:11:37 -080064 cd "$ORIG_DIR"
Brian Paul191d9652009-12-23 16:50:06 -070065 echo $NEWFILES
66}
67
68
Brian Paul12039aa2009-12-28 15:12:14 -070069# Make static library with 'ar'
70# params:
71# options to ar
72# 1 or 0 to indicate if ranlib should be run
73# libname to make
74# list of object files
75# Return name of library we made
76# Example: "make_ar_static_lib -ru 1 libfoo.a foo.o bar.o"
77make_ar_static_lib() {
78 OPTS=$1
79 shift;
80 RANLIB=$1
81 shift;
82 LIBNAME=$1
83 shift;
84 OBJECTS=$@
85
86 # remove existing lib, if present
87 rm -f ${LIBNAME}
88
89 # make static lib
90 ar ${OPTS} ${LIBNAME} ${OBJECTS}
91
92 # run ranlib
93 if [ ${RANLIB} = 1 ] ; then
94 ranlib ${LIBNAME}
95 fi
96
97 echo ${LIBNAME}
98}
99
100
Brian Paul57cce7a2009-12-23 16:55:37 -0700101# Print usage info.
102usage() {
103 echo 'Usage: mklib [options] objects'
104 echo 'Create a shared library from object files.'
105 echo ' -o LIBRARY specifies the name of the resulting library, without'
106 echo ' the leading "lib" or any suffix.'
107 echo ' (eg: "-o GL" might result in "libGL.so" being made)'
108 echo ' -major N specifies major version number (default is 1)'
109 echo ' -minor N specifies minor version number (default is 0)'
110 echo ' -patch N specifies patch version number (default is 0)'
111 echo ' -lLIBRARY specifies a dependency on LIBRARY'
112 echo ' -LDIR search in DIR for library dependencies at build time'
113 echo ' -RDIR search in DIR for library dependencies at run time'
114 echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
115 echo ' Not observed on all systems at this time.'
116 echo ' -ldflags OPT specify any additional linker flags in OPT'
117 echo ' -cplusplus link with C++ runtime'
118 echo ' -static make a static library (default is dynamic/shared)'
119 echo ' -dlopen make a shared library suitable for dynamic loading'
120 echo ' -install DIR put resulting library file(s) in DIR'
121 echo ' -arch ARCH override using `uname` to determine host system'
122 echo ' -archopt OPT specify an extra achitecture-specific option OPT'
123 echo ' -altopts OPTS alternate options to override all others'
124 echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
125 echo ' -exports FILE only export the symbols listed in FILE'
126 echo ' -id NAME Sets the id of the dylib (Darwin)'
127 echo ' -h, --help display this information and exit'
128}
129
130
Brian Paul8c20c7b2003-06-01 16:21:45 +0000131#
132# Option defaults
133#
134LIBNAME=""
135MAJOR=1
136MINOR=0
Brian Paul6e450f22004-02-21 18:08:41 +0000137PATCH=""
Brian Paul8c20c7b2003-06-01 16:21:45 +0000138DEPS=""
Brian Paul8dcc6732005-07-25 22:59:58 +0000139LINK=""
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600140LDFLAGS=""
Brian Paul8c20c7b2003-06-01 16:21:45 +0000141CPLUSPLUS=0
142STATIC=0
Brian Paul1e1af992006-04-14 14:14:51 +0000143DLOPEN=0
Brian Paul8c20c7b2003-06-01 16:21:45 +0000144INSTALLDIR="."
145ARCH="auto"
146ARCHOPT=""
Brian Pauldd74e362004-04-08 22:26:22 +0000147NOPREFIX=0
Brian Paul158a2512004-10-16 15:10:45 +0000148EXPORTS=""
Jeremy Huddlestonac0d1962008-08-11 09:17:06 -0700149ID=""
Brian Paul8c20c7b2003-06-01 16:21:45 +0000150
151#
152# Parse arguments
153#
154while true
155do
156 case $1 in
Brian Paul7c1ab402005-07-25 23:49:50 +0000157 '-h' | '--help')
Brian Paul57cce7a2009-12-23 16:55:37 -0700158 usage
Brian Paul7c1ab402005-07-25 23:49:50 +0000159 exit 1
160 ;;
161 '-o')
162 shift 1;
163 LIBNAME=$1
164 ;;
165 '-major')
166 shift 1;
167 MAJOR=$1
168 ;;
169 '-minor')
170 shift 1;
171 MINOR=$1
172 ;;
173 '-patch')
174 shift 1;
175 PATCH=$1
176 ;;
177 '-linker')
178 shift 1;
179 LINK=$1
180 ;;
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600181 '-ldflags')
182 shift 1;
183 LDFLAGS=$1
184 ;;
Brian Paul7c1ab402005-07-25 23:49:50 +0000185 -l*)
186 DEPS="$DEPS $1"
187 ;;
188 -L*)
189 DEPS="$DEPS $1"
190 ;;
Alan Coopersmithe1f9adc2008-06-20 17:58:53 -0700191 -R*)
192 DEPS="$DEPS $1"
193 ;;
Hasso Tepperf9c8af32008-04-09 11:03:05 -0700194 -Wl*)
195 DEPS="$DEPS $1"
196 ;;
Brianed2fddc2007-05-08 14:03:04 -0600197 -pthread)
198 # this is a special case (see bugzilla 10876)
199 DEPS="$DEPS $1"
200 ;;
Eric Anholt1a413b42007-06-22 10:29:54 -0700201 '-pthread')
202 DEPS="$DEPS -pthread"
203 ;;
Brian Paul7c1ab402005-07-25 23:49:50 +0000204 '-cplusplus')
205 CPLUSPLUS=1
206 ;;
207 '-static')
208 STATIC=1
209 ;;
Brian Paul1e1af992006-04-14 14:14:51 +0000210 '-dlopen')
211 DLOPEN=1
212 ;;
Brian Paul7c1ab402005-07-25 23:49:50 +0000213 '-install')
214 shift 1;
215 INSTALLDIR=$1
216 ;;
217 '-arch')
218 shift 1;
219 ARCH=$1
220 ;;
221 '-archopt')
222 shift 1;
223 ARCHOPT=$1
224 ;;
Andy Skinner5c0c8832008-02-07 13:20:06 -0700225 '-altopts')
226 shift 1;
227 ALTOPTS=$1
228 ;;
Brian Paul7c1ab402005-07-25 23:49:50 +0000229 '-noprefix')
230 NOPREFIX=1
231 ;;
232 '-exports')
233 shift 1;
234 EXPORTS=$1
235 ;;
Jeremy Huddlestonac0d1962008-08-11 09:17:06 -0700236 '-id')
237 shift 1;
238 ID=$1
239 ;;
Brian Paul7c1ab402005-07-25 23:49:50 +0000240 -*)
241 echo "mklib: Unknown option: " $1 ;
242 exit 1
243 ;;
244 *)
245 # This should be the first object file, stop parsing
246 break
Brian Paul8c20c7b2003-06-01 16:21:45 +0000247 esac
248 shift 1
249done
250OBJECTS=$@
251
Brian Paul7c1ab402005-07-25 23:49:50 +0000252
Brian Paul8c20c7b2003-06-01 16:21:45 +0000253if [ ${ARCH} = "auto" ] ; then
254 ARCH=`uname`
255fi
256
257
Tormod Volden9cb3cde2009-04-30 16:52:56 -0600258if [ $STATIC = 1 ]; then
259 # filter out linker options inside object list
260 NEWOBJECTS=""
261 for OBJ in $OBJECTS ; do
262 case $OBJ in
Wayne E. Robertzbeef1012011-11-10 15:21:14 -0700263 -Wl,*|-L*|-l*)
Tormod Volden9cb3cde2009-04-30 16:52:56 -0600264 echo "mklib: warning: ignoring $OBJ for static library"
265 ;;
266 *)
267 NEWOBJECTS="$NEWOBJECTS $OBJ"
268 ;;
269 esac
270 done
271 OBJECTS=$NEWOBJECTS
272fi
273
274
Brian Paul8c20c7b2003-06-01 16:21:45 +0000275#
276# Error checking
277#
278if [ "x${LIBNAME}" = "x" ] ; then
Brian Paul57cce7a2009-12-23 16:55:37 -0700279 echo "mklib: Error: no library name specified (-h for help)"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000280 exit 1
281fi
282if [ "x${OBJECTS}" = "x" ] ; then
Brian Paul57cce7a2009-12-23 16:55:37 -0700283 echo "mklib: Error: no object files specified (-h for help)"
Brian Paul8c20c7b2003-06-01 16:21:45 +0000284 exit 1
285fi
286
287
288#
289# Debugging info
290#
291if [ ] ; then
292 echo "-----------------"
293 echo ARCH is $ARCH
294 echo LIBNAME is $LIBNAME
295 echo MAJOR is $MAJOR
296 echo MINOR is $MINOR
297 echo PATCH is $PATCH
298 echo DEPS are $DEPS
Brian Paul158a2512004-10-16 15:10:45 +0000299 echo "EXPORTS in" $EXPORTS
Jeremy Huddlestonac0d1962008-08-11 09:17:06 -0700300 echo ID is $ID
Brian Paul8c20c7b2003-06-01 16:21:45 +0000301 echo "-----------------"
302fi
303
304
305#
306# OK, make the library now
307#
308case $ARCH in
309
Pierre Allegraud8fd8de32011-01-06 07:58:57 -0700310 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/* | 'NetBSD')
Brian Paul158a2512004-10-16 15:10:45 +0000311 # we assume gcc
Brian Paul8c20c7b2003-06-01 16:21:45 +0000312
Brian Paul8dcc6732005-07-25 22:59:58 +0000313 if [ "x$LINK" = "x" ] ; then
314 # -linker was not specified so set default link command now
315 if [ $CPLUSPLUS = 1 ] ; then
316 LINK=g++
317 else
318 LINK=gcc
319 fi
Brian Paulc4987422004-10-16 15:02:16 +0000320 fi
321
Mike Frysingerfafaf562012-09-11 01:57:25 -0400322 # Check if objects are 32-bit and we're running in 64-bit
323 # environment. If so, pass -m32 flag to linker.
324 add_abi_flag_to_opts() {
325 case $(file $1) in
326 *32-bit*x86-64*)
327 # x86_64 x32 ABI.
328 OPTS="-mx32 ${OPTS}"
329 ;;
330 *64-bit*x86-64*)
331 # x86_64 64-bit ABI.
332 OPTS="-m64 ${OPTS}"
333 ;;
334 *32-bit*Intel*)
335 # x86 32-bit ABI.
336 OPTS="-m32 ${OPTS}"
337 ;;
338 esac
339 }
340
Brian Pauldd74e362004-04-08 22:26:22 +0000341 if [ $NOPREFIX = 1 ] ; then
342 # No "lib" or ".so" part
343 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
Michel Dänzerfc7ddea2007-12-04 10:46:45 +0100344 case $ARCH in 'Linux' | 'GNU' | GNU/*)
345 OPTS="-Xlinker -Bsymbolic -shared"
346 ;;
347 *)
348 OPTS="-shared"
349 ;;
350 esac
Ian Romanickaba48642005-08-08 23:22:46 +0000351
Mike Frysingerfafaf562012-09-11 01:57:25 -0400352 # Check to see if we are building for a different ABI.
353 add_abi_flag_to_opts ${OBJECTS}
Ian Romanickaba48642005-08-08 23:22:46 +0000354
Andy Skinner5c0c8832008-02-07 13:20:06 -0700355 if [ "${ALTOPTS}" ] ; then
356 OPTS=${ALTOPTS}
357 fi
358
Brian Pauldd74e362004-04-08 22:26:22 +0000359 rm -f ${LIBNAME}
Brian Pauldd74e362004-04-08 22:26:22 +0000360 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600361 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Pauldd74e362004-04-08 22:26:22 +0000362 # finish up
363 FINAL_LIBS="${LIBNAME}"
364 elif [ $STATIC = 1 ] ; then
Brian Paul191d9652009-12-23 16:50:06 -0700365 # make a static .a library
Brian98abd1b2007-03-27 07:58:47 -0600366 LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
367 echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
Brian Paul56e0ee82006-04-13 15:17:50 +0000368 OPTS="-ru"
Andy Skinner5c0c8832008-02-07 13:20:06 -0700369 if [ "${ALTOPTS}" ] ; then
370 OPTS=${ALTOPTS}
371 fi
Brian Paul191d9652009-12-23 16:50:06 -0700372
373 # expand .a into .o files
Dan Nicholsona1de4002010-01-07 17:11:37 -0800374 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
Brian Paul191d9652009-12-23 16:50:06 -0700375
376 # make static lib
Brian Paul12039aa2009-12-28 15:12:14 -0700377 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
Brian Paul145d4982008-10-06 10:58:16 -0600378
379 # remove temporary extracted .o files
Dan Nicholsona1de4002010-01-07 17:11:37 -0800380 rm -rf ${LIBNAME}.obj
Brian Paul1c4b7112003-10-10 17:58:38 +0000381 else
Brian Paul191d9652009-12-23 16:50:06 -0700382 # make dynamic library
Brian Pauldd74e362004-04-08 22:26:22 +0000383 LIBNAME="lib${LIBNAME}" # prefix with "lib"
Brian Paul5beff7c2006-04-19 14:03:04 +0000384 case $ARCH in 'Linux' | 'GNU' | GNU/*)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000385 OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000386 ;;
387 *)
Brian Paul5b9a9d42004-01-17 18:31:12 +0000388 OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
Brian Paul5beff7c2006-04-19 14:03:04 +0000389 ;;
390 esac
Brian Paul158a2512004-10-16 15:10:45 +0000391 if [ $EXPORTS ] ; then
392 #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
393 # Make the 'exptmp' file for --version-script option
Julien Cristauf7eb0ce2008-07-13 17:13:32 +0200394 echo "{" > exptmp
Brian Paul158a2512004-10-16 15:10:45 +0000395 echo "global:" >> exptmp
396 sed 's/$/;/' ${EXPORTS} >> exptmp
397 echo "local:" >> exptmp
398 echo "*;" >> exptmp
399 echo "};" >> exptmp
400 OPTS="${OPTS} -Xlinker --version-script=exptmp"
401 # exptmp is removed below
402 fi
Brian Paul3e196182005-03-03 01:38:13 +0000403
Mike Frysingerfafaf562012-09-11 01:57:25 -0400404 # Check to see if we are building for a different ABI.
405 add_abi_flag_to_opts ${OBJECTS}
406
Andy Skinner5c0c8832008-02-07 13:20:06 -0700407 if [ "${ALTOPTS}" ] ; then
408 OPTS=${ALTOPTS}
409 fi
Brian Paul3e196182005-03-03 01:38:13 +0000410
Brian Paul6e450f22004-02-21 18:08:41 +0000411 if [ x${PATCH} = "x" ] ; then
412 VERSION="${MAJOR}.${MINOR}"
413 else
414 VERSION="${MAJOR}.${MINOR}.${PATCH}"
415 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000416
Brian Paul5396ab22004-02-12 14:48:52 +0000417 echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000418
Brian Paul1c4b7112003-10-10 17:58:38 +0000419 # rm any old libs
420 rm -f ${LIBNAME}.so.${VERSION}
421 rm -f ${LIBNAME}.so.${MAJOR}
422 rm -f ${LIBNAME}.so
423
424 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600425 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
Brian Paul1c4b7112003-10-10 17:58:38 +0000426 # make usual symlinks
427 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
428 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
429 # finish up
430 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
Brian Paulb17a1a12004-11-01 22:28:42 +0000431# rm -f exptmp
Brian Paul1c4b7112003-10-10 17:58:38 +0000432 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000433 ;;
434
435 'SunOS')
Brian Paul5396ab22004-02-12 14:48:52 +0000436 if [ $STATIC = 1 ] ; then
437 LIBNAME="lib${LIBNAME}.a"
438 echo "mklib: Making SunOS static library: " ${LIBNAME}
Alan Coopersmith77c08002010-01-19 18:13:14 -0800439 FINAL_LIBS=`make_ar_static_lib -ruc 0 ${LIBNAME} ${OBJECTS}`
Brian Paul5396ab22004-02-12 14:48:52 +0000440 else
Brian Paul0a3a1c62006-11-10 12:47:56 +0000441 if [ $NOPREFIX = 0 ] ; then
442 LIBNAME="lib${LIBNAME}.so"
443 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000444 echo "mklib: Making SunOS shared library: " ${LIBNAME}
Brian Paul59ebe1f2006-04-05 13:43:02 +0000445
Brian Paul8dcc6732005-07-25 22:59:58 +0000446 if [ "x$LINK" = "x" ] ; then
447 # -linker was not specified, choose default linker now
448 if [ $CPLUSPLUS = 1 ] ; then
449 # determine linker and options for C++ code
450 if [ `which c++` ] ; then
451 # use Sun c++
452 LINK="c++"
453 elif [ `type g++` ] ; then
454 # use g++
455 LINK="g++"
456 else
Alan Coopersmithe1f9adc2008-06-20 17:58:53 -0700457 echo "mklib: warning: can't find C++ compiler, trying CC."
Brian Paul8dcc6732005-07-25 22:59:58 +0000458 LINK="CC"
459 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000460 else
Brian Paul8dcc6732005-07-25 22:59:58 +0000461 # use native Sun linker for C code
462 LINK="ld"
Brian Paul5396ab22004-02-12 14:48:52 +0000463 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000464 fi
Brian Paul59ebe1f2006-04-05 13:43:02 +0000465
466 # linker options
Brian Paulb3282a32006-04-18 12:56:11 +0000467 if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
468 # SunOS tools, -G to make shared libs
Brian Paul59ebe1f2006-04-05 13:43:02 +0000469 OPTS="-G"
470 else
471 # gcc linker
472 # Check if objects are 32-bit and we're running in 64-bit
473 # environment. If so, pass -m32 flag to linker.
474 set ${OBJECTS}
475 ABI32=`file $1 | grep 32-bit`
476 if [ "${ABI32}" ] ; then
477 OPTS="-m32 -shared -Wl,-Bdynamic"
478 else
479 OPTS="-m64 -shared -Wl,-Bdynamic"
480 fi
481 fi
482
Alan Coopersmith3cf6e622009-03-23 16:51:54 -0700483 # If using Sun C++ compiler, need to tell it not to add runpaths
484 # that are specific to the build machine
485 if [ ${LINK} = "CC" ] ; then
486 OPTS="${OPTS} -norunpath"
487 fi
488
489 # Solaris linker requires explicitly listing the Standard C & C++
490 # libraries in the link path when building shared objects
491 if [ ${LINK} = "CC" ] ; then
492 DEPS="${DEPS} -lCrun"
493 fi
494 DEPS="${DEPS} -lc"
495
496 if [ $EXPORTS ] ; then
497 # Make the 'mapfile.scope' linker mapfile
498 echo "{" > mapfile.scope
499 echo "global:" >> mapfile.scope
500 sed 's/$/;/' ${EXPORTS} >> mapfile.scope
501 echo "local:" >> mapfile.scope
502 echo " *;" >> mapfile.scope
503 echo "};" >> mapfile.scope
504 OPTS="${OPTS} -Wl,-Mmapfile.scope"
505 fi
506
Alan Coopersmith5d66fc62010-03-12 19:03:41 -0800507 # Check if objects are 64-bit
Brian Paul1e1af992006-04-14 14:14:51 +0000508 # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
509 set ${OBJECTS}
Alan Coopersmithe1f9adc2008-06-20 17:58:53 -0700510 if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
Alan Coopersmith5d66fc62010-03-12 19:03:41 -0800511 ABI64=`file $1 | grep "ELF 64-bit"`
512 if [ "${ABI64}" ] ; then
513 case `uname -p` in
514 sparc) OPTS="${OPTS} -xarch=v9" ;;
515 i386) OPTS="${OPTS} -xarch=amd64" ;;
516 esac
Alan Coopersmithe1f9adc2008-06-20 17:58:53 -0700517 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000518 fi
Andy Skinner5c0c8832008-02-07 13:20:06 -0700519 if [ "${ALTOPTS}" ] ; then
520 OPTS=${ALTOPTS}
521 fi
Alan Coopersmith3cf6e622009-03-23 16:51:54 -0700522
Brian Paul59ebe1f2006-04-05 13:43:02 +0000523 # for debug:
Brian Paul1e1af992006-04-14 14:14:51 +0000524 #echo "mklib: linker is" ${LINK} ${OPTS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000525 if [ $NOPREFIX = 1 ] ; then
526 rm -f ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600527 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Alan Coopersmith3cf6e622009-03-23 16:51:54 -0700528 FINAL_LIBS="${LIBNAME}"
Brian Paul0a3a1c62006-11-10 12:47:56 +0000529 else
530 rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
Alan Coopersmithe1f9adc2008-06-20 17:58:53 -0700531 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
Brian Paul0a3a1c62006-11-10 12:47:56 +0000532 ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
Alan Coopersmith3cf6e622009-03-23 16:51:54 -0700533 FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
Brian Paul0a3a1c62006-11-10 12:47:56 +0000534 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000535 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000536 ;;
537
538 'FreeBSD')
Eric Anholtb83435f2005-10-18 23:36:40 +0000539 # we assume gcc
540
541 if [ "x$LINK" = "x" ] ; then
542 # -linker was not specified so set default link command now
543 if [ $CPLUSPLUS = 1 ] ; then
544 LINK=g++
545 else
546 LINK=gcc
547 fi
548 fi
549
Brian Pauldd74e362004-04-08 22:26:22 +0000550 if [ $NOPREFIX = 1 ] ; then
551 # No "lib" or ".so" part
552 echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
Eric Anholtb83435f2005-10-18 23:36:40 +0000553 OPTS="-shared"
Andy Skinner5c0c8832008-02-07 13:20:06 -0700554 if [ "${ALTOPTS}" ] ; then
555 OPTS=${ALTOPTS}
556 fi
Brian Pauldd74e362004-04-08 22:26:22 +0000557 rm -f ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600558 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Pauldd74e362004-04-08 22:26:22 +0000559 FINAL_LIBS=${LIBNAME}
560 elif [ $STATIC = 1 ] ; then
Brian Paul191d9652009-12-23 16:50:06 -0700561 # make a static .a library
Brian Paul5396ab22004-02-12 14:48:52 +0000562 STLIB="lib${LIBNAME}.a"
563 echo "mklib: Making FreeBSD static library: " ${STLIB}
Brian Paul191d9652009-12-23 16:50:06 -0700564
565 # expand .a into .o files
Dan Nicholsona1de4002010-01-07 17:11:37 -0800566 NEW_OBJECTS=`expand_archives ${STLIB}.obj $OBJECTS`
Brian Paul191d9652009-12-23 16:50:06 -0700567
Brian Paul12039aa2009-12-28 15:12:14 -0700568 FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
Brian Paul191d9652009-12-23 16:50:06 -0700569
570 # remove temporary extracted .o files
Dan Nicholsona1de4002010-01-07 17:11:37 -0800571 rm -rf ${STLIB}.obj
Brian Paul5396ab22004-02-12 14:48:52 +0000572 else
Brian Paul191d9652009-12-23 16:50:06 -0700573 # make dynamic library
Eric Anholtb83435f2005-10-18 23:36:40 +0000574 SHLIB="lib${LIBNAME}.so.${MAJOR}"
575 OPTS="-shared -Wl,-soname,${SHLIB}"
Andy Skinner5c0c8832008-02-07 13:20:06 -0700576 if [ "${ALTOPTS}" ] ; then
577 OPTS=${ALTOPTS}
578 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000579 echo "mklib: Making FreeBSD shared library: " ${SHLIB}
580 rm -f ${SHLIB}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600581 ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
Eric Anholt1c04be52005-10-22 01:41:40 +0000582 ln -sf ${SHLIB} "lib${LIBNAME}.so"
583 FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
Brian Paul5396ab22004-02-12 14:48:52 +0000584 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000585 ;;
586
Brian Paulf8c31fc2004-01-29 15:21:47 +0000587 'IRIX' | 'IRIX64')
Brian Paul5396ab22004-02-12 14:48:52 +0000588 if [ $STATIC = 1 ] ; then
589 LIBNAME="lib${LIBNAME}.a"
Brian Paul12039aa2009-12-28 15:12:14 -0700590 FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
Brian Paul8c20c7b2003-06-01 16:21:45 +0000591 else
Brian Paul5396ab22004-02-12 14:48:52 +0000592 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul1e1af992006-04-14 14:14:51 +0000593
594 # examine first object to determine ABI
595 set ${OBJECTS}
596 ABI_O32=`file $1 | grep 'ELF 32-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000597 ABI_N32=`file $1 | grep 'ELF N32'`
Brian Paul1e1af992006-04-14 14:14:51 +0000598 ABI_N64=`file $1 | grep 'ELF 64-bit'`
Brian Paulb3282a32006-04-18 12:56:11 +0000599 if [ "${ABI_O32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000600 OPTS="-32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000601 ABI="o32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000602 elif [ "${ABI_N32}" ] ; then
Brian Paul5396ab22004-02-12 14:48:52 +0000603 OPTS="-n32 -shared -all"
Brian Paul1e1af992006-04-14 14:14:51 +0000604 ABI="n32-bit"
Brian Paulb3282a32006-04-18 12:56:11 +0000605 elif [ "${ABI_N64}" ] ; then
Brian Paul1e1af992006-04-14 14:14:51 +0000606 OPTS="-64 -shared -all"
607 ABI="64-bit"
608 else
609 echo "Error: Unexpected IRIX ABI!"
610 exit 1
Brian Paul5396ab22004-02-12 14:48:52 +0000611 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000612
Andy Skinner5c0c8832008-02-07 13:20:06 -0700613 if [ "${ALTOPTS}" ] ; then
614 OPTS=${ALTOPTS}
615 fi
616
Brian Paul5396ab22004-02-12 14:48:52 +0000617 if [ $CPLUSPLUS = 1 ] ; then
618 LINK="CC"
619 else
620 LINK="ld"
621 fi
Brian Paul1e1af992006-04-14 14:14:51 +0000622
623 echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600624 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000625 FINAL_LIBS=${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000626 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000627 ;;
628
Brian Paul8c20c7b2003-06-01 16:21:45 +0000629 'linux-cygwin')
630 LIBNAME="lib${LIBNAME}.a"
631 echo "mklib: Making linux-cygwin library: " ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000632 rm -f ${LIBNAME}
Brian Paul8c20c7b2003-06-01 16:21:45 +0000633 gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
634 FINAL_LIBS=${LIBNAME}
635 ;;
636
Brian Paulc193bd02004-03-18 15:41:59 +0000637 'HP-UX')
Brian Paul5396ab22004-02-12 14:48:52 +0000638 if [ $STATIC = 1 ] ; then
639 LIBNAME="lib${LIBNAME}.a"
Brian Paul52fb07e2004-03-30 14:47:02 +0000640 echo "mklib: Making HP-UX static library: " ${LIBNAME}
Brian Paul12039aa2009-12-28 15:12:14 -0700641 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
Brian Paul5396ab22004-02-12 14:48:52 +0000642 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000643 # HP uses a .2 for their current GL/GLU libraries
644 if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
645 MAJOR=2
646 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000647 RUNLIB="lib${LIBNAME}.${MAJOR}"
648 DEVLIB="lib${LIBNAME}.sl"
Brian Paul52fb07e2004-03-30 14:47:02 +0000649 echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
Brian Paul5396ab22004-02-12 14:48:52 +0000650 ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
651 ln -s ${RUNLIB} ${DEVLIB}
Brian Paulac0cfee2004-04-25 15:13:56 +0000652 FINAL_LIBS="${RUNLIB} ${DEVLIB}"
Brian Paul5396ab22004-02-12 14:48:52 +0000653 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000654 ;;
655
Brian Paulb3282a32006-04-18 12:56:11 +0000656 'AIX' )
657 # examine first object to determine ABI
658 set ${OBJECTS}
659 ABI_64=`file $1 | grep '64-bit'`
660 if [ "${ABI_64}" ] ; then
Brian Paulb17a1a12004-11-01 22:28:42 +0000661 X64="-X64"
Brian Paulb3282a32006-04-18 12:56:11 +0000662 Q64="-q64"
663 OFILE=shr_64.o
664 else
665 OFILE=shr.o #Want to be consistent with the IBM libGL.a
Brian Paulb17a1a12004-11-01 22:28:42 +0000666 fi
Brian Paulc193bd02004-03-18 15:41:59 +0000667
Brian Paulb3282a32006-04-18 12:56:11 +0000668 if [ $STATIC = 1 ] ; then
669 LIBNAME="lib${LIBNAME}.a"
670 echo "mklib: Making AIX static library: " ${LIBNAME}
Brian Paul12039aa2009-12-28 15:12:14 -0700671 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
Brian Paulb3282a32006-04-18 12:56:11 +0000672 else
Karl Schultza16bdb52004-10-01 13:33:26 +0000673 EXPFILE="lib${LIBNAME}.exp"
Karl Schultza16bdb52004-10-01 13:33:26 +0000674 LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
Brian Paulb3282a32006-04-18 12:56:11 +0000675 OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000676 rm -f ${EXPFILE} ${OFILE}
Brian Paulb17a1a12004-11-01 22:28:42 +0000677 NM="/bin/nm -eC ${X64}"
Karl Schultza16bdb52004-10-01 13:33:26 +0000678 echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
679 ${NM} ${OBJECTS} | awk '{
680 if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
681 && ( substr($1,1,1) != ".")) {
682 if (substr ($1, 1, 7) != "__sinit" &&
683 substr ($1, 1, 7) != "__sterm") {
684 if (substr ($1, 1, 5) == "__tf1")
685 print (substr ($1, 7))
686 else if (substr ($1, 1, 5) == "__tf9")
687 print (substr ($1, 15))
688 else
689 print $1
690 }
691 }
692 }' | sort -u >> ${EXPFILE}
Brian Paulfe14cf62006-04-13 02:23:25 +0000693
Andy Skinner5c0c8832008-02-07 13:20:06 -0700694 if [ "${ALTOPTS}" ] ; then
695 OPTS=${ALTOPTS}
696 fi
697
Brian Paulfe14cf62006-04-13 02:23:25 +0000698 # On AIX a shared library is linked differently when
699 # you want to dlopen the file
Brian Paul1e1af992006-04-14 14:14:51 +0000700 if [ $DLOPEN = "1" ] ; then
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600701 cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paul1e1af992006-04-14 14:14:51 +0000702 else
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600703 cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
Brian Paul1e1af992006-04-14 14:14:51 +0000704 ar ${X64} -r ${LIBNAME} ${OFILE}
705 fi
Brian Paul56e0ee82006-04-13 15:17:50 +0000706
Brian Paul1e1af992006-04-14 14:14:51 +0000707 FINAL_LIBS="${LIBNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000708 fi
709 ;;
710
Brian Paul8c20c7b2003-06-01 16:21:45 +0000711 'OpenSTEP')
712 LIBNAME="lib${LIBNAME}.a"
713 echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
714 libtool -static -o ${LIBNAME} - ${OBJECTS}
715 FINAL_LIBS=${LIBNAME}
716 ;;
717
718 'OSF1')
Brian Paul5396ab22004-02-12 14:48:52 +0000719 if [ $STATIC = 1 ] ; then
720 LIBNAME="lib${LIBNAME}.a"
721 echo "mklib: Making OSF/1 static library: " ${LIBNAME}
Brian Paul12039aa2009-12-28 15:12:14 -0700722 FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
Brian Paul5396ab22004-02-12 14:48:52 +0000723 else
724 VERSION="${MAJOR}.${MINOR}"
725 LIBNAME="lib${LIBNAME}.so"
726 echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
Brian Paul8dcc6732005-07-25 22:59:58 +0000727 if [ "x$LINK" = "x" ] ; then
728 if [ $CPLUSPLUS = 1 ] ; then
729 LINK=cxx
730 else
731 LINK=cc
732 fi
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000733 fi
Brian Paul5396ab22004-02-12 14:48:52 +0000734 rm -f ${LIBNAME}.${VERSION}
Brian Paul0d5e6cc2004-11-29 17:23:12 +0000735 ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
Brian Paul5396ab22004-02-12 14:48:52 +0000736 ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
737 FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
738 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +0000739 ;;
740
741 'Darwin')
Brian Paulc193bd02004-03-18 15:41:59 +0000742 if [ $STATIC = 1 ] ; then
743 LIBNAME="lib${LIBNAME}.a"
744 echo "mklib: Making Darwin static library: " ${LIBNAME}
Brian Paulfe14cf62006-04-13 02:23:25 +0000745 OPTS="-ruvs"
Andy Skinner5c0c8832008-02-07 13:20:06 -0700746 if [ "${ALTOPTS}" ] ; then
747 OPTS=${ALTOPTS}
748 fi
Alex Weiss54f9c502010-02-27 14:47:43 -0500749
750 # expand .a into .o files
751 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
752
753 # make static lib
754 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
755
756 # remove temporary extracted .o files
757 rm -rf ${LIBNAME}.obj
758
Brian Paulc193bd02004-03-18 15:41:59 +0000759 FINAL_LIBS=${LIBNAME}
760 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000761 # On Darwin a .bundle is used for a library that you want to dlopen
Brian Paul1e1af992006-04-14 14:14:51 +0000762 if [ $DLOPEN = "1" ] ; then
763 LIBSUFFIX="bundle"
764 OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
765 else
Jeremy Huddlestonac0d1962008-08-11 09:17:06 -0700766 LIBSUFFIX="dylib"
767 if [ -z "$ID" ] ; then
768 ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
769 fi
770 OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
Brian Paul1e1af992006-04-14 14:14:51 +0000771 fi
Jeremy Huddleston9993ccc2008-02-19 00:54:35 -0800772
773 if [ ${EXPORTS} ] ; then
Jeremy Huddlestonac0d1962008-08-11 09:17:06 -0700774 if [ -f ${EXPORTS}".darwin" ] ; then
775 EXPORTS=$EXPORTS".darwin"
776 fi
Jeremy Huddleston9993ccc2008-02-19 00:54:35 -0800777 OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
Jeremy Huddlestonac0d1962008-08-11 09:17:06 -0700778 fi
Jeremy Huddleston9993ccc2008-02-19 00:54:35 -0800779
Jeremy Huddleston2835c512011-06-08 11:20:38 -0700780 LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
781 LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
Brian Paul1e1af992006-04-14 14:14:51 +0000782
783 # examine first object to determine ABI
784 set ${OBJECTS}
Jeremy Huddlestonad7f9d72009-12-20 21:34:27 -0800785 ABIS=`lipo -info $1 | sed s/.*://`
786 for ABI in $ABIS; do
787 OPTS="${OPTS} -arch ${ABI}"
788 done
Brian Paul1e1af992006-04-14 14:14:51 +0000789
Andy Skinner5c0c8832008-02-07 13:20:06 -0700790 if [ "${ALTOPTS}" ] ; then
791 OPTS=${ALTOPTS}
792 fi
793
Brian Paul1e1af992006-04-14 14:14:51 +0000794 # determine linker
Brian Paul56e0ee82006-04-13 15:17:50 +0000795 if [ $CPLUSPLUS = 1 ] ; then
796 LINK="g++"
797 else
798 LINK="cc"
799 fi
Brian Paulfe14cf62006-04-13 02:23:25 +0000800
Brian Paulc50d77a2004-04-13 17:35:17 +0000801 echo "mklib: Making Darwin shared library: " ${LIBNAME}
Jeremy Huddleston9993ccc2008-02-19 00:54:35 -0800802
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600803 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
Brian Paulfe14cf62006-04-13 02:23:25 +0000804 ln -s ${LIBNAME} ${LINKNAME}
Jeremy Huddleston2835c512011-06-08 11:20:38 -0700805 FINAL_LIBS="${LIBNAME} ${LINKNAME}"
Brian Paulc193bd02004-03-18 15:41:59 +0000806 fi
807 ;;
Brian Paul8c20c7b2003-06-01 16:21:45 +0000808
809 'LynxOS')
810 LIBNAME="lib${LIBNAME}.a"
Brian Paul5396ab22004-02-12 14:48:52 +0000811 echo "mklib: Making LynxOS static library: " ${LIBNAME}
Brian Paul12039aa2009-12-28 15:12:14 -0700812 FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
Brian Paul8c20c7b2003-06-01 16:21:45 +0000813 ;;
814
Brian Paul8c20c7b2003-06-01 16:21:45 +0000815 'QNX')
816 LIBNAME="lib${LIBNAME}.a"
817 echo "mklib: Making QNX library: " ${LIBNAME}
818 wlib ${LIBNAME} ${OBJECTS}
819 FINAL_LIBS=${LIBNAME}
820 ;;
821
Brian Paul65e2ab32003-10-27 18:13:37 +0000822 'MorphOS')
823 LIBNAME="lib${LIBNAME}.a"
824 echo "mklib: Making MorphOS library: " ${LIBNAME}
825 ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
826 FINAL_LIBS="${LIBNAME}"
827 ;;
828
Brian Paulfe14cf62006-04-13 02:23:25 +0000829 'icc' | 'icc-istatic')
Brian Paulb3b725b2003-12-15 16:14:55 +0000830 # Intel C compiler
Brian Paul7c1ab402005-07-25 23:49:50 +0000831 # This should get merged into the Linux code, above, since this isn't
832 # really a different architecture.
Brian Paulb3b725b2003-12-15 16:14:55 +0000833 LIBNAME="lib${LIBNAME}" # prefix with "lib"
834
835 if [ $STATIC = 1 ] ; then
836 echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
837 LINK="ar"
838 OPTS="-ruv"
Andy Skinner5c0c8832008-02-07 13:20:06 -0700839 if [ "${ALTOPTS}" ] ; then
840 OPTS=${ALTOPTS}
841 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000842 # make lib
843 ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
844 # finish up
845 FINAL_LIBS="${LIBNAME}.a"
846 else
Brian Paulfe14cf62006-04-13 02:23:25 +0000847 if [ $ARCH = icc-istatic ] ; then
848 OPTS="-shared -i-static -cxxlib-icc"
849 else
850 OPTS="-shared"
851 fi
Andy Skinner5c0c8832008-02-07 13:20:06 -0700852 if [ "${ALTOPTS}" ] ; then
853 OPTS=${ALTOPTS}
854 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000855 VERSION="${MAJOR}.${MINOR}.${PATCH}"
Brian Paulb3b725b2003-12-15 16:14:55 +0000856 echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
857
858 if [ $CPLUSPLUS = 1 ] ; then
Brian Paulfe14cf62006-04-13 02:23:25 +0000859 LINK="icpc"
Brian Paulb3b725b2003-12-15 16:14:55 +0000860 else
861 LINK="icc"
862 fi
Brian Paulb3b725b2003-12-15 16:14:55 +0000863 # rm any old libs
864 rm -f ${LIBNAME}.so.${VERSION}
865 rm -f ${LIBNAME}.so.${MAJOR}
866 rm -f ${LIBNAME}.so
Brian Paulb3b725b2003-12-15 16:14:55 +0000867 # make lib
Dan Nicholson2a3e3382007-09-28 18:42:21 -0600868 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
Brian Paulb3b725b2003-12-15 16:14:55 +0000869 # make usual symlinks
870 ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
871 ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
872 # finish up
873 FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
874 fi
875 ;;
876
Brian Paul12d6cae2004-01-10 22:12:21 +0000877 'aix-gcc')
878 # AIX with gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000879 if [ $STATIC = 1 ] ; then
880 LIBNAME="lib${LIBNAME}.a"
881 echo "mklib: Making AIX GCC static library: " ${LIBNAME}
Brian Paul12039aa2009-12-28 15:12:14 -0700882 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
Brian Paul5396ab22004-02-12 14:48:52 +0000883 else
884 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
885 echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
886 # remove old lib
887 rm -f ${LIBNAME}
888 # make the lib
889 gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
Brian Paul5396ab22004-02-12 14:48:52 +0000890 # NOTE: the application linking with this library must specify
891 # the -Wl,-brtl flags to gcc
Brian Paul5396ab22004-02-12 14:48:52 +0000892 FINAL_LIBS=${LIBNAME}
893 fi
894 ;;
895
896 'ultrix')
897 # XXX untested
898 if [ $STATIC = 0 ] ; then
899 echo "mklib: Warning shared libs not supported on Ultrix"
900 fi
901 LIBNAME="lib${LIBNAME}.a"
902 echo "mklib: Making static library for Ultrix: " ${LIBNAME}
Brian Paul12039aa2009-12-28 15:12:14 -0700903 FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
Brian Paul12d6cae2004-01-10 22:12:21 +0000904 ;;
Brian Paulb3b725b2003-12-15 16:14:55 +0000905
Brian Paul580548d2004-04-22 16:16:42 +0000906 CYGWIN*)
907 # GCC-based environment
Jon TURNEYc085cd62010-08-27 22:52:41 +0100908
909 if [ "x$LINK" = "x" ] ; then
910 # -linker was not specified so set default link command now
911 if [ $CPLUSPLUS = 1 ] ; then
912 LINK=g++
913 else
914 LINK=gcc
915 fi
916 fi
917
Jon TURNEY7eed6ab2009-06-08 16:02:18 +0100918 if [ $NOPREFIX = 1 ] ; then
919 # No "lib" or ".so" part
920 echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
921 OPTS="-shared -Wl,--enable-auto-image-base"
922 if [ "${ALTOPTS}" ] ; then
923 OPTS=${ALTOPTS}
924 fi
925 rm -f ${LIBNAME}
Jon TURNEY8fee1822010-02-19 22:38:57 +0000926 ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} || exit $?
Jon TURNEY7eed6ab2009-06-08 16:02:18 +0100927 FINAL_LIBS=${LIBNAME}
928 else
Brian Paul580548d2004-04-22 16:16:42 +0000929 CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
930 LIBNAME="lib${LIBNAME}" # prefix with "lib"
931
932 if [ $STATIC = 1 ] ; then
Brian Paul12039aa2009-12-28 15:12:14 -0700933 LIBNAME=${LIBNAME}.a
Jon TURNEY36b19532010-07-24 12:06:23 +0100934 echo "mklib: Making CYGWIN static library: " ${LIBNAME}
Brian Paul580548d2004-04-22 16:16:42 +0000935 OPTS="-ru"
Andy Skinner5c0c8832008-02-07 13:20:06 -0700936 if [ "${ALTOPTS}" ] ; then
937 OPTS=${ALTOPTS}
938 fi
Jon TURNEYe3114d32010-02-19 22:38:00 +0000939
940 # expand .a into .o files
941 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
942
943 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
944
945 # remove temporary extracted .o files
946 rm -rf ${LIBNAME}.obj
Brian Paul580548d2004-04-22 16:16:42 +0000947 else
Jon TURNEY7eed6ab2009-06-08 16:02:18 +0100948 OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
Andy Skinner5c0c8832008-02-07 13:20:06 -0700949 if [ "${ALTOPTS}" ] ; then
950 OPTS=${ALTOPTS}
951 fi
Jon TURNEY36b19532010-07-24 12:06:23 +0100952 echo "mklib: Making CYGWIN shared library: " ${CYGNAME}-${MAJOR}.dll
Brian Paul580548d2004-04-22 16:16:42 +0000953
Brian Paul580548d2004-04-22 16:16:42 +0000954 # rm any old libs
Jon TURNEY7eed6ab2009-06-08 16:02:18 +0100955 rm -f ${CYGNAME}-${MAJOR}.dll
956 rm -f ${LIBNAME}-${MAJOR}.dll.a
Brian Paul580548d2004-04-22 16:16:42 +0000957 rm -f ${LIBNAME}.dll.a
958 rm -f ${LIBNAME}.a
959
960 # make lib
Jon TURNEY8fee1822010-02-19 22:38:57 +0000961 ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} || exit $?
Brian Paul580548d2004-04-22 16:16:42 +0000962 # make usual symlinks
963 ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
964 # finish up
965 FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
966 # special case for installing in bin
967 FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
968 fi
Jon TURNEY7eed6ab2009-06-08 16:02:18 +0100969 fi
Brian Paul580548d2004-04-22 16:16:42 +0000970 ;;
971
Alexander von Glucka5608a52011-12-26 16:23:03 -0700972 'Haiku')
973 if [ $STATIC = 1 ] ; then
974 LIBNAME="lib${LIBNAME}.a"
975 if [ "x$LINK" = "x" ] ; then
976 # -linker was not specified so set default link command now
977 if [ $CPLUSPLUS = 1 ] ; then
978 LINK=g++
979 else
980 LINK=gcc
981 fi
982 fi
983
984 OPTS="-ru"
985 if [ "${ALTOPTS}" ] ; then
986 OPTS=${ALTOPTS}
987 fi
988
989 echo "mklib: Making static library for Haiku: " ${LIBNAME}
990
991 # expand .a into .o files
992 NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
993
994 # make static lib
995 FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
996
997 # remove temporary extracted .o files
998 rm -rf ${LIBNAME}.obj
Alexander von Gluckac8a9332011-12-27 09:18:18 -0700999 else
Alexander von Glucka5608a52011-12-26 16:23:03 -07001000 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
1001 OPTS="-shared"
1002
1003 echo "mklib: Making shared library for Haiku: " ${LIBNAME}
1004 ${LINK} ${OPTS} ${LDFLAGS} ${OBJECTS} ${DEPS} -o ${LIBNAME}
1005 FINAL_LIBS="${LIBNAME}"
1006 fi
1007 ;;
1008
Brian Paul8c20c7b2003-06-01 16:21:45 +00001009 'example')
1010 # If you're adding support for a new architecture, you can
1011 # start with this:
Brian Paul5396ab22004-02-12 14:48:52 +00001012 if [ $STATIC = 1 ] ; then
1013 LIBNAME="lib${LIBNAME}.a"
1014 echo "mklib: Making static library for example arch: " ${LIBNAME}
Brian Paul12039aa2009-12-28 15:12:14 -07001015 FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
Brian Paul5396ab22004-02-12 14:48:52 +00001016 else
Brian Paul7c1ab402005-07-25 23:49:50 +00001017 LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
Brian Paul5396ab22004-02-12 14:48:52 +00001018 echo "mklib: Making shared library for example arch: " ${LIBNAME}
1019 ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
1020 FINAL_LIBS="${LIBNAME}"
1021 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +00001022 ;;
1023
1024 *)
Brian Paul5396ab22004-02-12 14:48:52 +00001025 echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
1026 echo "mklib: Please add necessary commands to mklib script."
Brian Paul8c20c7b2003-06-01 16:21:45 +00001027 ;;
1028esac
1029
1030
1031#
1032# Put library files into installation directory if specified.
1033#
1034if [ ${INSTALLDIR} != "." ] ; then
1035 echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
Dan Nicholson23671e52009-08-03 08:35:43 -07001036 test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
Brian Paul8c20c7b2003-06-01 16:21:45 +00001037 mv ${FINAL_LIBS} ${INSTALLDIR}/
Jon TURNEYc55a8a72010-07-24 12:05:34 +01001038
1039 if [ "x${FINAL_BINS}" != "x" ] ; then
1040 echo "mklib: Installing" ${FINAL_BINS} "in" ${INSTALLDIR}
1041 mv ${FINAL_BINS} ${INSTALLDIR}/
1042 fi
Brian Paul8c20c7b2003-06-01 16:21:45 +00001043fi