Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Make a shared library. |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 4 | # This script should be useful for projects other than Mesa. |
| 5 | # Improvements/fixes are welcome. |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 6 | |
| 7 | |
Brian Paul | 56e0ee8 | 2006-04-13 15:17:50 +0000 | [diff] [blame] | 8 | # Copyright (C) 1999-2006 Brian Paul All Rights Reserved. |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 9 | # |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 10 | # 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 Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 16 | # |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 17 | # The above copyright notice and this permission notice shall be included |
| 18 | # in all copies or substantial portions of the Software. |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 19 | # |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 20 | # 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 Paul | cc66847 | 2010-02-18 13:02:59 -0700 | [diff] [blame] | 27 | |
Keith Packard | edd85bc | 2010-02-21 14:30:00 -0800 | [diff] [blame] | 28 | # Clear CDPATH as the 'cd' command will echo stuff |
| 29 | # to stdout if it is set |
| 30 | unset CDPATH |
| 31 | |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 32 | # 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 Paul | cc66847 | 2010-02-18 13:02:59 -0700 | [diff] [blame] | 34 | # first param: name of a temp directory (to be deleted when finished) |
| 35 | # remaining params: list of .o and .a files |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 36 | expand_archives() { |
Dan Nicholson | a1de400 | 2010-01-07 17:11:37 -0800 | [diff] [blame] | 37 | DIR=$1 |
| 38 | shift |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 39 | FILES=$@ |
| 40 | NEWFILES="" |
Dan Nicholson | a1de400 | 2010-01-07 17:11:37 -0800 | [diff] [blame] | 41 | ORIG_DIR=`pwd` |
| 42 | mkdir -p "$DIR" |
| 43 | cd "$DIR" |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 44 | for FILE in $FILES ; do |
| 45 | case $FILE in |
| 46 | *.a) |
| 47 | # extract the .o files from this .a archive |
Dan Nicholson | a1de400 | 2010-01-07 17:11:37 -0800 | [diff] [blame] | 48 | case $FILE in |
| 49 | /*) ;; |
| 50 | *) FILE="$ORIG_DIR/$FILE" ;; |
| 51 | esac |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 52 | MEMBERS=`ar t $FILE` |
| 53 | ar x $FILE |
Dan Nicholson | a1de400 | 2010-01-07 17:11:37 -0800 | [diff] [blame] | 54 | for MEMBER in $MEMBERS ; do |
| 55 | NEWFILES="$NEWFILES $DIR/$MEMBER" |
| 56 | done |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 57 | ;; |
| 58 | *) |
| 59 | # other file type, just add to list |
| 60 | NEWFILES="$NEWFILES $FILE" |
| 61 | ;; |
| 62 | esac |
| 63 | done |
Dan Nicholson | a1de400 | 2010-01-07 17:11:37 -0800 | [diff] [blame] | 64 | cd "$ORIG_DIR" |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 65 | echo $NEWFILES |
| 66 | } |
| 67 | |
| 68 | |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 69 | # 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" |
| 77 | make_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 Paul | 57cce7a | 2009-12-23 16:55:37 -0700 | [diff] [blame] | 101 | # Print usage info. |
| 102 | usage() { |
| 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 Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 131 | # |
| 132 | # Option defaults |
| 133 | # |
| 134 | LIBNAME="" |
| 135 | MAJOR=1 |
| 136 | MINOR=0 |
Brian Paul | 6e450f2 | 2004-02-21 18:08:41 +0000 | [diff] [blame] | 137 | PATCH="" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 138 | DEPS="" |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 139 | LINK="" |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 140 | LDFLAGS="" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 141 | CPLUSPLUS=0 |
| 142 | STATIC=0 |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 143 | DLOPEN=0 |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 144 | INSTALLDIR="." |
| 145 | ARCH="auto" |
| 146 | ARCHOPT="" |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 147 | NOPREFIX=0 |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 148 | EXPORTS="" |
Jeremy Huddleston | ac0d196 | 2008-08-11 09:17:06 -0700 | [diff] [blame] | 149 | ID="" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 150 | |
| 151 | # |
| 152 | # Parse arguments |
| 153 | # |
| 154 | while true |
| 155 | do |
| 156 | case $1 in |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 157 | '-h' | '--help') |
Brian Paul | 57cce7a | 2009-12-23 16:55:37 -0700 | [diff] [blame] | 158 | usage |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 159 | 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 Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 181 | '-ldflags') |
| 182 | shift 1; |
| 183 | LDFLAGS=$1 |
| 184 | ;; |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 185 | -l*) |
| 186 | DEPS="$DEPS $1" |
| 187 | ;; |
| 188 | -L*) |
| 189 | DEPS="$DEPS $1" |
| 190 | ;; |
Alan Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 191 | -R*) |
| 192 | DEPS="$DEPS $1" |
| 193 | ;; |
Hasso Tepper | f9c8af3 | 2008-04-09 11:03:05 -0700 | [diff] [blame] | 194 | -Wl*) |
| 195 | DEPS="$DEPS $1" |
| 196 | ;; |
Brian | ed2fddc | 2007-05-08 14:03:04 -0600 | [diff] [blame] | 197 | -pthread) |
| 198 | # this is a special case (see bugzilla 10876) |
| 199 | DEPS="$DEPS $1" |
| 200 | ;; |
Eric Anholt | 1a413b4 | 2007-06-22 10:29:54 -0700 | [diff] [blame] | 201 | '-pthread') |
| 202 | DEPS="$DEPS -pthread" |
| 203 | ;; |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 204 | '-cplusplus') |
| 205 | CPLUSPLUS=1 |
| 206 | ;; |
| 207 | '-static') |
| 208 | STATIC=1 |
| 209 | ;; |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 210 | '-dlopen') |
| 211 | DLOPEN=1 |
| 212 | ;; |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 213 | '-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 Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 225 | '-altopts') |
| 226 | shift 1; |
| 227 | ALTOPTS=$1 |
| 228 | ;; |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 229 | '-noprefix') |
| 230 | NOPREFIX=1 |
| 231 | ;; |
| 232 | '-exports') |
| 233 | shift 1; |
| 234 | EXPORTS=$1 |
| 235 | ;; |
Jeremy Huddleston | ac0d196 | 2008-08-11 09:17:06 -0700 | [diff] [blame] | 236 | '-id') |
| 237 | shift 1; |
| 238 | ID=$1 |
| 239 | ;; |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 240 | -*) |
| 241 | echo "mklib: Unknown option: " $1 ; |
| 242 | exit 1 |
| 243 | ;; |
| 244 | *) |
| 245 | # This should be the first object file, stop parsing |
| 246 | break |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 247 | esac |
| 248 | shift 1 |
| 249 | done |
| 250 | OBJECTS=$@ |
| 251 | |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 252 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 253 | if [ ${ARCH} = "auto" ] ; then |
| 254 | ARCH=`uname` |
| 255 | fi |
| 256 | |
| 257 | |
Tormod Volden | 9cb3cde | 2009-04-30 16:52:56 -0600 | [diff] [blame] | 258 | if [ $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. Robertz | beef101 | 2011-11-10 15:21:14 -0700 | [diff] [blame] | 263 | -Wl,*|-L*|-l*) |
Tormod Volden | 9cb3cde | 2009-04-30 16:52:56 -0600 | [diff] [blame] | 264 | echo "mklib: warning: ignoring $OBJ for static library" |
| 265 | ;; |
| 266 | *) |
| 267 | NEWOBJECTS="$NEWOBJECTS $OBJ" |
| 268 | ;; |
| 269 | esac |
| 270 | done |
| 271 | OBJECTS=$NEWOBJECTS |
| 272 | fi |
| 273 | |
| 274 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 275 | # |
| 276 | # Error checking |
| 277 | # |
| 278 | if [ "x${LIBNAME}" = "x" ] ; then |
Brian Paul | 57cce7a | 2009-12-23 16:55:37 -0700 | [diff] [blame] | 279 | echo "mklib: Error: no library name specified (-h for help)" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 280 | exit 1 |
| 281 | fi |
| 282 | if [ "x${OBJECTS}" = "x" ] ; then |
Brian Paul | 57cce7a | 2009-12-23 16:55:37 -0700 | [diff] [blame] | 283 | echo "mklib: Error: no object files specified (-h for help)" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 284 | exit 1 |
| 285 | fi |
| 286 | |
| 287 | |
| 288 | # |
| 289 | # Debugging info |
| 290 | # |
| 291 | if [ ] ; 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 Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 299 | echo "EXPORTS in" $EXPORTS |
Jeremy Huddleston | ac0d196 | 2008-08-11 09:17:06 -0700 | [diff] [blame] | 300 | echo ID is $ID |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 301 | echo "-----------------" |
| 302 | fi |
| 303 | |
| 304 | |
| 305 | # |
| 306 | # OK, make the library now |
| 307 | # |
| 308 | case $ARCH in |
| 309 | |
Pierre Allegraud | 8fd8de3 | 2011-01-06 07:58:57 -0700 | [diff] [blame] | 310 | 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/* | 'NetBSD') |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 311 | # we assume gcc |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 312 | |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 313 | 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 Paul | c498742 | 2004-10-16 15:02:16 +0000 | [diff] [blame] | 320 | fi |
| 321 | |
Mike Frysinger | fafaf56 | 2012-09-11 01:57:25 -0400 | [diff] [blame] | 322 | # 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 Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 341 | if [ $NOPREFIX = 1 ] ; then |
| 342 | # No "lib" or ".so" part |
| 343 | echo "mklib: Making" $ARCH "shared library: " ${LIBNAME} |
Michel Dänzer | fc7ddea | 2007-12-04 10:46:45 +0100 | [diff] [blame] | 344 | case $ARCH in 'Linux' | 'GNU' | GNU/*) |
| 345 | OPTS="-Xlinker -Bsymbolic -shared" |
| 346 | ;; |
| 347 | *) |
| 348 | OPTS="-shared" |
| 349 | ;; |
| 350 | esac |
Ian Romanick | aba4864 | 2005-08-08 23:22:46 +0000 | [diff] [blame] | 351 | |
Mike Frysinger | fafaf56 | 2012-09-11 01:57:25 -0400 | [diff] [blame] | 352 | # Check to see if we are building for a different ABI. |
| 353 | add_abi_flag_to_opts ${OBJECTS} |
Ian Romanick | aba4864 | 2005-08-08 23:22:46 +0000 | [diff] [blame] | 354 | |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 355 | if [ "${ALTOPTS}" ] ; then |
| 356 | OPTS=${ALTOPTS} |
| 357 | fi |
| 358 | |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 359 | rm -f ${LIBNAME} |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 360 | # make lib |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 361 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 362 | # finish up |
| 363 | FINAL_LIBS="${LIBNAME}" |
| 364 | elif [ $STATIC = 1 ] ; then |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 365 | # make a static .a library |
Brian | 98abd1b | 2007-03-27 07:58:47 -0600 | [diff] [blame] | 366 | LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a" |
| 367 | echo "mklib: Making" $ARCH "static library: " ${LIBNAME} |
Brian Paul | 56e0ee8 | 2006-04-13 15:17:50 +0000 | [diff] [blame] | 368 | OPTS="-ru" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 369 | if [ "${ALTOPTS}" ] ; then |
| 370 | OPTS=${ALTOPTS} |
| 371 | fi |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 372 | |
| 373 | # expand .a into .o files |
Dan Nicholson | a1de400 | 2010-01-07 17:11:37 -0800 | [diff] [blame] | 374 | NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS` |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 375 | |
| 376 | # make static lib |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 377 | FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}` |
Brian Paul | 145d498 | 2008-10-06 10:58:16 -0600 | [diff] [blame] | 378 | |
| 379 | # remove temporary extracted .o files |
Dan Nicholson | a1de400 | 2010-01-07 17:11:37 -0800 | [diff] [blame] | 380 | rm -rf ${LIBNAME}.obj |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 381 | else |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 382 | # make dynamic library |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 383 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
Brian Paul | 5beff7c | 2006-04-19 14:03:04 +0000 | [diff] [blame] | 384 | case $ARCH in 'Linux' | 'GNU' | GNU/*) |
Brian Paul | 5b9a9d4 | 2004-01-17 18:31:12 +0000 | [diff] [blame] | 385 | OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}" |
Brian Paul | 5beff7c | 2006-04-19 14:03:04 +0000 | [diff] [blame] | 386 | ;; |
| 387 | *) |
Brian Paul | 5b9a9d4 | 2004-01-17 18:31:12 +0000 | [diff] [blame] | 388 | OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}" |
Brian Paul | 5beff7c | 2006-04-19 14:03:04 +0000 | [diff] [blame] | 389 | ;; |
| 390 | esac |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 391 | if [ $EXPORTS ] ; then |
| 392 | #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}" |
| 393 | # Make the 'exptmp' file for --version-script option |
Julien Cristau | f7eb0ce | 2008-07-13 17:13:32 +0200 | [diff] [blame] | 394 | echo "{" > exptmp |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 395 | 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 Paul | 3e19618 | 2005-03-03 01:38:13 +0000 | [diff] [blame] | 403 | |
Mike Frysinger | fafaf56 | 2012-09-11 01:57:25 -0400 | [diff] [blame] | 404 | # Check to see if we are building for a different ABI. |
| 405 | add_abi_flag_to_opts ${OBJECTS} |
| 406 | |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 407 | if [ "${ALTOPTS}" ] ; then |
| 408 | OPTS=${ALTOPTS} |
| 409 | fi |
Brian Paul | 3e19618 | 2005-03-03 01:38:13 +0000 | [diff] [blame] | 410 | |
Brian Paul | 6e450f2 | 2004-02-21 18:08:41 +0000 | [diff] [blame] | 411 | if [ x${PATCH} = "x" ] ; then |
| 412 | VERSION="${MAJOR}.${MINOR}" |
| 413 | else |
| 414 | VERSION="${MAJOR}.${MINOR}.${PATCH}" |
| 415 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 416 | |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 417 | echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 418 | |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 419 | # 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 Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 425 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 426 | # 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 Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 431 | # rm -f exptmp |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 432 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 433 | ;; |
| 434 | |
| 435 | 'SunOS') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 436 | if [ $STATIC = 1 ] ; then |
| 437 | LIBNAME="lib${LIBNAME}.a" |
| 438 | echo "mklib: Making SunOS static library: " ${LIBNAME} |
Alan Coopersmith | 77c0800 | 2010-01-19 18:13:14 -0800 | [diff] [blame] | 439 | FINAL_LIBS=`make_ar_static_lib -ruc 0 ${LIBNAME} ${OBJECTS}` |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 440 | else |
Brian Paul | 0a3a1c6 | 2006-11-10 12:47:56 +0000 | [diff] [blame] | 441 | if [ $NOPREFIX = 0 ] ; then |
| 442 | LIBNAME="lib${LIBNAME}.so" |
| 443 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 444 | echo "mklib: Making SunOS shared library: " ${LIBNAME} |
Brian Paul | 59ebe1f | 2006-04-05 13:43:02 +0000 | [diff] [blame] | 445 | |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 446 | 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 Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 457 | echo "mklib: warning: can't find C++ compiler, trying CC." |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 458 | LINK="CC" |
| 459 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 460 | else |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 461 | # use native Sun linker for C code |
| 462 | LINK="ld" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 463 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 464 | fi |
Brian Paul | 59ebe1f | 2006-04-05 13:43:02 +0000 | [diff] [blame] | 465 | |
| 466 | # linker options |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 467 | if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then |
| 468 | # SunOS tools, -G to make shared libs |
Brian Paul | 59ebe1f | 2006-04-05 13:43:02 +0000 | [diff] [blame] | 469 | 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 Coopersmith | 3cf6e62 | 2009-03-23 16:51:54 -0700 | [diff] [blame] | 483 | # 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 Coopersmith | 5d66fc6 | 2010-03-12 19:03:41 -0800 | [diff] [blame] | 507 | # Check if objects are 64-bit |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 508 | # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1 |
| 509 | set ${OBJECTS} |
Alan Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 510 | if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then |
Alan Coopersmith | 5d66fc6 | 2010-03-12 19:03:41 -0800 | [diff] [blame] | 511 | 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 Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 517 | fi |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 518 | fi |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 519 | if [ "${ALTOPTS}" ] ; then |
| 520 | OPTS=${ALTOPTS} |
| 521 | fi |
Alan Coopersmith | 3cf6e62 | 2009-03-23 16:51:54 -0700 | [diff] [blame] | 522 | |
Brian Paul | 59ebe1f | 2006-04-05 13:43:02 +0000 | [diff] [blame] | 523 | # for debug: |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 524 | #echo "mklib: linker is" ${LINK} ${OPTS} |
Brian Paul | 0a3a1c6 | 2006-11-10 12:47:56 +0000 | [diff] [blame] | 525 | if [ $NOPREFIX = 1 ] ; then |
| 526 | rm -f ${LIBNAME} |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 527 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Alan Coopersmith | 3cf6e62 | 2009-03-23 16:51:54 -0700 | [diff] [blame] | 528 | FINAL_LIBS="${LIBNAME}" |
Brian Paul | 0a3a1c6 | 2006-11-10 12:47:56 +0000 | [diff] [blame] | 529 | else |
| 530 | rm -f ${LIBNAME}.${MAJOR} ${LIBNAME} |
Alan Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 531 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS} |
Brian Paul | 0a3a1c6 | 2006-11-10 12:47:56 +0000 | [diff] [blame] | 532 | ln -s ${LIBNAME}.${MAJOR} ${LIBNAME} |
Alan Coopersmith | 3cf6e62 | 2009-03-23 16:51:54 -0700 | [diff] [blame] | 533 | FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}" |
Brian Paul | 0a3a1c6 | 2006-11-10 12:47:56 +0000 | [diff] [blame] | 534 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 535 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 536 | ;; |
| 537 | |
| 538 | 'FreeBSD') |
Eric Anholt | b83435f | 2005-10-18 23:36:40 +0000 | [diff] [blame] | 539 | # 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 Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 550 | if [ $NOPREFIX = 1 ] ; then |
| 551 | # No "lib" or ".so" part |
| 552 | echo "mklib: Making FreeBSD shared library: " ${LIBNAME} |
Eric Anholt | b83435f | 2005-10-18 23:36:40 +0000 | [diff] [blame] | 553 | OPTS="-shared" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 554 | if [ "${ALTOPTS}" ] ; then |
| 555 | OPTS=${ALTOPTS} |
| 556 | fi |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 557 | rm -f ${LIBNAME} |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 558 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 559 | FINAL_LIBS=${LIBNAME} |
| 560 | elif [ $STATIC = 1 ] ; then |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 561 | # make a static .a library |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 562 | STLIB="lib${LIBNAME}.a" |
| 563 | echo "mklib: Making FreeBSD static library: " ${STLIB} |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 564 | |
| 565 | # expand .a into .o files |
Dan Nicholson | a1de400 | 2010-01-07 17:11:37 -0800 | [diff] [blame] | 566 | NEW_OBJECTS=`expand_archives ${STLIB}.obj $OBJECTS` |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 567 | |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 568 | FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}` |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 569 | |
| 570 | # remove temporary extracted .o files |
Dan Nicholson | a1de400 | 2010-01-07 17:11:37 -0800 | [diff] [blame] | 571 | rm -rf ${STLIB}.obj |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 572 | else |
Brian Paul | 191d965 | 2009-12-23 16:50:06 -0700 | [diff] [blame] | 573 | # make dynamic library |
Eric Anholt | b83435f | 2005-10-18 23:36:40 +0000 | [diff] [blame] | 574 | SHLIB="lib${LIBNAME}.so.${MAJOR}" |
| 575 | OPTS="-shared -Wl,-soname,${SHLIB}" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 576 | if [ "${ALTOPTS}" ] ; then |
| 577 | OPTS=${ALTOPTS} |
| 578 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 579 | echo "mklib: Making FreeBSD shared library: " ${SHLIB} |
| 580 | rm -f ${SHLIB} |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 581 | ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS} |
Eric Anholt | 1c04be5 | 2005-10-22 01:41:40 +0000 | [diff] [blame] | 582 | ln -sf ${SHLIB} "lib${LIBNAME}.so" |
| 583 | FINAL_LIBS="${SHLIB} lib${LIBNAME}.so" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 584 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 585 | ;; |
| 586 | |
Brian Paul | f8c31fc | 2004-01-29 15:21:47 +0000 | [diff] [blame] | 587 | 'IRIX' | 'IRIX64') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 588 | if [ $STATIC = 1 ] ; then |
| 589 | LIBNAME="lib${LIBNAME}.a" |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 590 | FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}` |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 591 | else |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 592 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 593 | |
| 594 | # examine first object to determine ABI |
| 595 | set ${OBJECTS} |
| 596 | ABI_O32=`file $1 | grep 'ELF 32-bit'` |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 597 | ABI_N32=`file $1 | grep 'ELF N32'` |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 598 | ABI_N64=`file $1 | grep 'ELF 64-bit'` |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 599 | if [ "${ABI_O32}" ] ; then |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 600 | OPTS="-32 -shared -all" |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 601 | ABI="o32-bit" |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 602 | elif [ "${ABI_N32}" ] ; then |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 603 | OPTS="-n32 -shared -all" |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 604 | ABI="n32-bit" |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 605 | elif [ "${ABI_N64}" ] ; then |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 606 | OPTS="-64 -shared -all" |
| 607 | ABI="64-bit" |
| 608 | else |
| 609 | echo "Error: Unexpected IRIX ABI!" |
| 610 | exit 1 |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 611 | fi |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 612 | |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 613 | if [ "${ALTOPTS}" ] ; then |
| 614 | OPTS=${ALTOPTS} |
| 615 | fi |
| 616 | |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 617 | if [ $CPLUSPLUS = 1 ] ; then |
| 618 | LINK="CC" |
| 619 | else |
| 620 | LINK="ld" |
| 621 | fi |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 622 | |
| 623 | echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME} |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 624 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 625 | FINAL_LIBS=${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 626 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 627 | ;; |
| 628 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 629 | 'linux-cygwin') |
| 630 | LIBNAME="lib${LIBNAME}.a" |
| 631 | echo "mklib: Making linux-cygwin library: " ${LIBNAME} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 632 | rm -f ${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 633 | gnuwin32ar ruv ${LIBNAME} ${OBJECTS} |
| 634 | FINAL_LIBS=${LIBNAME} |
| 635 | ;; |
| 636 | |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 637 | 'HP-UX') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 638 | if [ $STATIC = 1 ] ; then |
| 639 | LIBNAME="lib${LIBNAME}.a" |
Brian Paul | 52fb07e | 2004-03-30 14:47:02 +0000 | [diff] [blame] | 640 | echo "mklib: Making HP-UX static library: " ${LIBNAME} |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 641 | FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}` |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 642 | else |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 643 | # HP uses a .2 for their current GL/GLU libraries |
| 644 | if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then |
| 645 | MAJOR=2 |
| 646 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 647 | RUNLIB="lib${LIBNAME}.${MAJOR}" |
| 648 | DEVLIB="lib${LIBNAME}.sl" |
Brian Paul | 52fb07e | 2004-03-30 14:47:02 +0000 | [diff] [blame] | 649 | echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 650 | ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS} |
| 651 | ln -s ${RUNLIB} ${DEVLIB} |
Brian Paul | ac0cfee | 2004-04-25 15:13:56 +0000 | [diff] [blame] | 652 | FINAL_LIBS="${RUNLIB} ${DEVLIB}" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 653 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 654 | ;; |
| 655 | |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 656 | '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 Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 661 | X64="-X64" |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 662 | Q64="-q64" |
| 663 | OFILE=shr_64.o |
| 664 | else |
| 665 | OFILE=shr.o #Want to be consistent with the IBM libGL.a |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 666 | fi |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 667 | |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 668 | if [ $STATIC = 1 ] ; then |
| 669 | LIBNAME="lib${LIBNAME}.a" |
| 670 | echo "mklib: Making AIX static library: " ${LIBNAME} |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 671 | FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}` |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 672 | else |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 673 | EXPFILE="lib${LIBNAME}.exp" |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 674 | LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 675 | OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}" |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 676 | rm -f ${EXPFILE} ${OFILE} |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 677 | NM="/bin/nm -eC ${X64}" |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 678 | 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 Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 693 | |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 694 | if [ "${ALTOPTS}" ] ; then |
| 695 | OPTS=${ALTOPTS} |
| 696 | fi |
| 697 | |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 698 | # On AIX a shared library is linked differently when |
| 699 | # you want to dlopen the file |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 700 | if [ $DLOPEN = "1" ] ; then |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 701 | cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 702 | else |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 703 | cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS} |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 704 | ar ${X64} -r ${LIBNAME} ${OFILE} |
| 705 | fi |
Brian Paul | 56e0ee8 | 2006-04-13 15:17:50 +0000 | [diff] [blame] | 706 | |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 707 | FINAL_LIBS="${LIBNAME}" |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 708 | fi |
| 709 | ;; |
| 710 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 711 | '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 Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 719 | if [ $STATIC = 1 ] ; then |
| 720 | LIBNAME="lib${LIBNAME}.a" |
| 721 | echo "mklib: Making OSF/1 static library: " ${LIBNAME} |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 722 | FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}` |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 723 | else |
| 724 | VERSION="${MAJOR}.${MINOR}" |
| 725 | LIBNAME="lib${LIBNAME}.so" |
| 726 | echo "mklib: Making OSF/1 shared library: " ${LIBNAME} |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 727 | if [ "x$LINK" = "x" ] ; then |
| 728 | if [ $CPLUSPLUS = 1 ] ; then |
| 729 | LINK=cxx |
| 730 | else |
| 731 | LINK=cc |
| 732 | fi |
Brian Paul | 0d5e6cc | 2004-11-29 17:23:12 +0000 | [diff] [blame] | 733 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 734 | rm -f ${LIBNAME}.${VERSION} |
Brian Paul | 0d5e6cc | 2004-11-29 17:23:12 +0000 | [diff] [blame] | 735 | ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 736 | ln -sf ${LIBNAME}.${VERSION} ${LIBNAME} |
| 737 | FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}" |
| 738 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 739 | ;; |
| 740 | |
| 741 | 'Darwin') |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 742 | if [ $STATIC = 1 ] ; then |
| 743 | LIBNAME="lib${LIBNAME}.a" |
| 744 | echo "mklib: Making Darwin static library: " ${LIBNAME} |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 745 | OPTS="-ruvs" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 746 | if [ "${ALTOPTS}" ] ; then |
| 747 | OPTS=${ALTOPTS} |
| 748 | fi |
Alex Weiss | 54f9c50 | 2010-02-27 14:47:43 -0500 | [diff] [blame] | 749 | |
| 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 Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 759 | FINAL_LIBS=${LIBNAME} |
| 760 | else |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 761 | # On Darwin a .bundle is used for a library that you want to dlopen |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 762 | if [ $DLOPEN = "1" ] ; then |
| 763 | LIBSUFFIX="bundle" |
| 764 | OPTS="${ARCHOPT} -bundle -multiply_defined suppress" |
| 765 | else |
Jeremy Huddleston | ac0d196 | 2008-08-11 09:17:06 -0700 | [diff] [blame] | 766 | 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 Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 771 | fi |
Jeremy Huddleston | 9993ccc | 2008-02-19 00:54:35 -0800 | [diff] [blame] | 772 | |
| 773 | if [ ${EXPORTS} ] ; then |
Jeremy Huddleston | ac0d196 | 2008-08-11 09:17:06 -0700 | [diff] [blame] | 774 | if [ -f ${EXPORTS}".darwin" ] ; then |
| 775 | EXPORTS=$EXPORTS".darwin" |
| 776 | fi |
Jeremy Huddleston | 9993ccc | 2008-02-19 00:54:35 -0800 | [diff] [blame] | 777 | OPTS="${OPTS} -exported_symbols_list ${EXPORTS}" |
Jeremy Huddleston | ac0d196 | 2008-08-11 09:17:06 -0700 | [diff] [blame] | 778 | fi |
Jeremy Huddleston | 9993ccc | 2008-02-19 00:54:35 -0800 | [diff] [blame] | 779 | |
Jeremy Huddleston | 2835c51 | 2011-06-08 11:20:38 -0700 | [diff] [blame] | 780 | LINKNAME="lib${LIBNAME}.${LIBSUFFIX}" |
| 781 | LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}" |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 782 | |
| 783 | # examine first object to determine ABI |
| 784 | set ${OBJECTS} |
Jeremy Huddleston | ad7f9d7 | 2009-12-20 21:34:27 -0800 | [diff] [blame] | 785 | ABIS=`lipo -info $1 | sed s/.*://` |
| 786 | for ABI in $ABIS; do |
| 787 | OPTS="${OPTS} -arch ${ABI}" |
| 788 | done |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 789 | |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 790 | if [ "${ALTOPTS}" ] ; then |
| 791 | OPTS=${ALTOPTS} |
| 792 | fi |
| 793 | |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 794 | # determine linker |
Brian Paul | 56e0ee8 | 2006-04-13 15:17:50 +0000 | [diff] [blame] | 795 | if [ $CPLUSPLUS = 1 ] ; then |
| 796 | LINK="g++" |
| 797 | else |
| 798 | LINK="cc" |
| 799 | fi |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 800 | |
Brian Paul | c50d77a | 2004-04-13 17:35:17 +0000 | [diff] [blame] | 801 | echo "mklib: Making Darwin shared library: " ${LIBNAME} |
Jeremy Huddleston | 9993ccc | 2008-02-19 00:54:35 -0800 | [diff] [blame] | 802 | |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 803 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 804 | ln -s ${LIBNAME} ${LINKNAME} |
Jeremy Huddleston | 2835c51 | 2011-06-08 11:20:38 -0700 | [diff] [blame] | 805 | FINAL_LIBS="${LIBNAME} ${LINKNAME}" |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 806 | fi |
| 807 | ;; |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 808 | |
| 809 | 'LynxOS') |
| 810 | LIBNAME="lib${LIBNAME}.a" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 811 | echo "mklib: Making LynxOS static library: " ${LIBNAME} |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 812 | FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}` |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 813 | ;; |
| 814 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 815 | 'QNX') |
| 816 | LIBNAME="lib${LIBNAME}.a" |
| 817 | echo "mklib: Making QNX library: " ${LIBNAME} |
| 818 | wlib ${LIBNAME} ${OBJECTS} |
| 819 | FINAL_LIBS=${LIBNAME} |
| 820 | ;; |
| 821 | |
Brian Paul | 65e2ab3 | 2003-10-27 18:13:37 +0000 | [diff] [blame] | 822 | '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 Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 829 | 'icc' | 'icc-istatic') |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 830 | # Intel C compiler |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 831 | # This should get merged into the Linux code, above, since this isn't |
| 832 | # really a different architecture. |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 833 | 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 Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 839 | if [ "${ALTOPTS}" ] ; then |
| 840 | OPTS=${ALTOPTS} |
| 841 | fi |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 842 | # make lib |
| 843 | ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS} |
| 844 | # finish up |
| 845 | FINAL_LIBS="${LIBNAME}.a" |
| 846 | else |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 847 | if [ $ARCH = icc-istatic ] ; then |
| 848 | OPTS="-shared -i-static -cxxlib-icc" |
| 849 | else |
| 850 | OPTS="-shared" |
| 851 | fi |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 852 | if [ "${ALTOPTS}" ] ; then |
| 853 | OPTS=${ALTOPTS} |
| 854 | fi |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 855 | VERSION="${MAJOR}.${MINOR}.${PATCH}" |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 856 | echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION} |
| 857 | |
| 858 | if [ $CPLUSPLUS = 1 ] ; then |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 859 | LINK="icpc" |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 860 | else |
| 861 | LINK="icc" |
| 862 | fi |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 863 | # rm any old libs |
| 864 | rm -f ${LIBNAME}.so.${VERSION} |
| 865 | rm -f ${LIBNAME}.so.${MAJOR} |
| 866 | rm -f ${LIBNAME}.so |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 867 | # make lib |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 868 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 869 | # 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 Paul | 12d6cae | 2004-01-10 22:12:21 +0000 | [diff] [blame] | 877 | 'aix-gcc') |
| 878 | # AIX with gcc |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 879 | if [ $STATIC = 1 ] ; then |
| 880 | LIBNAME="lib${LIBNAME}.a" |
| 881 | echo "mklib: Making AIX GCC static library: " ${LIBNAME} |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 882 | FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}` |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 883 | 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 Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 890 | # NOTE: the application linking with this library must specify |
| 891 | # the -Wl,-brtl flags to gcc |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 892 | 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 Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 903 | FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}` |
Brian Paul | 12d6cae | 2004-01-10 22:12:21 +0000 | [diff] [blame] | 904 | ;; |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 905 | |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 906 | CYGWIN*) |
| 907 | # GCC-based environment |
Jon TURNEY | c085cd6 | 2010-08-27 22:52:41 +0100 | [diff] [blame] | 908 | |
| 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 TURNEY | 7eed6ab | 2009-06-08 16:02:18 +0100 | [diff] [blame] | 918 | 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 TURNEY | 8fee182 | 2010-02-19 22:38:57 +0000 | [diff] [blame] | 926 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} || exit $? |
Jon TURNEY | 7eed6ab | 2009-06-08 16:02:18 +0100 | [diff] [blame] | 927 | FINAL_LIBS=${LIBNAME} |
| 928 | else |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 929 | CYGNAME="cyg${LIBNAME}" # prefix with "cyg" |
| 930 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
| 931 | |
| 932 | if [ $STATIC = 1 ] ; then |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 933 | LIBNAME=${LIBNAME}.a |
Jon TURNEY | 36b1953 | 2010-07-24 12:06:23 +0100 | [diff] [blame] | 934 | echo "mklib: Making CYGWIN static library: " ${LIBNAME} |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 935 | OPTS="-ru" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 936 | if [ "${ALTOPTS}" ] ; then |
| 937 | OPTS=${ALTOPTS} |
| 938 | fi |
Jon TURNEY | e3114d3 | 2010-02-19 22:38:00 +0000 | [diff] [blame] | 939 | |
| 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 Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 947 | else |
Jon TURNEY | 7eed6ab | 2009-06-08 16:02:18 +0100 | [diff] [blame] | 948 | OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 949 | if [ "${ALTOPTS}" ] ; then |
| 950 | OPTS=${ALTOPTS} |
| 951 | fi |
Jon TURNEY | 36b1953 | 2010-07-24 12:06:23 +0100 | [diff] [blame] | 952 | echo "mklib: Making CYGWIN shared library: " ${CYGNAME}-${MAJOR}.dll |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 953 | |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 954 | # rm any old libs |
Jon TURNEY | 7eed6ab | 2009-06-08 16:02:18 +0100 | [diff] [blame] | 955 | rm -f ${CYGNAME}-${MAJOR}.dll |
| 956 | rm -f ${LIBNAME}-${MAJOR}.dll.a |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 957 | rm -f ${LIBNAME}.dll.a |
| 958 | rm -f ${LIBNAME}.a |
| 959 | |
| 960 | # make lib |
Jon TURNEY | 8fee182 | 2010-02-19 22:38:57 +0000 | [diff] [blame] | 961 | ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} || exit $? |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 962 | # 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 TURNEY | 7eed6ab | 2009-06-08 16:02:18 +0100 | [diff] [blame] | 969 | fi |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 970 | ;; |
| 971 | |
Alexander von Gluck | a5608a5 | 2011-12-26 16:23:03 -0700 | [diff] [blame] | 972 | '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 Gluck | ac8a933 | 2011-12-27 09:18:18 -0700 | [diff] [blame] | 999 | else |
Alexander von Gluck | a5608a5 | 2011-12-26 16:23:03 -0700 | [diff] [blame] | 1000 | 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 Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 1009 | 'example') |
| 1010 | # If you're adding support for a new architecture, you can |
| 1011 | # start with this: |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 1012 | if [ $STATIC = 1 ] ; then |
| 1013 | LIBNAME="lib${LIBNAME}.a" |
| 1014 | echo "mklib: Making static library for example arch: " ${LIBNAME} |
Brian Paul | 12039aa | 2009-12-28 15:12:14 -0700 | [diff] [blame] | 1015 | FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}` |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 1016 | else |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 1017 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 1018 | echo "mklib: Making shared library for example arch: " ${LIBNAME} |
| 1019 | ld -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 1020 | FINAL_LIBS="${LIBNAME}" |
| 1021 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 1022 | ;; |
| 1023 | |
| 1024 | *) |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 1025 | 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 Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 1027 | ;; |
| 1028 | esac |
| 1029 | |
| 1030 | |
| 1031 | # |
| 1032 | # Put library files into installation directory if specified. |
| 1033 | # |
| 1034 | if [ ${INSTALLDIR} != "." ] ; then |
| 1035 | echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR} |
Dan Nicholson | 23671e5 | 2009-08-03 08:35:43 -0700 | [diff] [blame] | 1036 | test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 1037 | mv ${FINAL_LIBS} ${INSTALLDIR}/ |
Jon TURNEY | c55a8a7 | 2010-07-24 12:05:34 +0100 | [diff] [blame] | 1038 | |
| 1039 | if [ "x${FINAL_BINS}" != "x" ] ; then |
| 1040 | echo "mklib: Installing" ${FINAL_BINS} "in" ${INSTALLDIR} |
| 1041 | mv ${FINAL_BINS} ${INSTALLDIR}/ |
| 1042 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 1043 | fi |