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 | |
| 27 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 28 | # |
| 29 | # Option defaults |
| 30 | # |
| 31 | LIBNAME="" |
| 32 | MAJOR=1 |
| 33 | MINOR=0 |
Brian Paul | 6e450f2 | 2004-02-21 18:08:41 +0000 | [diff] [blame] | 34 | PATCH="" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 35 | DEPS="" |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 36 | LINK="" |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 37 | LDFLAGS="" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 38 | CPLUSPLUS=0 |
| 39 | STATIC=0 |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 40 | DLOPEN=0 |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 41 | INSTALLDIR="." |
| 42 | ARCH="auto" |
| 43 | ARCHOPT="" |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 44 | NOPREFIX=0 |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 45 | EXPORTS="" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 46 | |
| 47 | |
| 48 | # |
| 49 | # Parse arguments |
| 50 | # |
| 51 | while true |
| 52 | do |
| 53 | case $1 in |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 54 | '-h' | '--help') |
Eric Anholt | f1a2613 | 2005-08-08 03:26:18 +0000 | [diff] [blame] | 55 | echo 'Usage: mklib [options] objects' |
| 56 | echo 'Create a shared library from object files.' |
| 57 | echo ' -o LIBRARY specifies the name of the resulting library, without' |
| 58 | echo ' the leading "lib" or any suffix.' |
| 59 | echo ' (eg: "-o GL" might result in "libGL.so" being made)' |
| 60 | echo ' -major N specifies major version number (default is 1)' |
| 61 | echo ' -minor N specifies minor version number (default is 0)' |
| 62 | echo ' -patch N specifies patch version number (default is 0)' |
| 63 | echo ' -lLIBRARY specifies a dependency on LIBRARY' |
Alan Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 64 | echo ' -LDIR search in DIR for library dependencies at build time' |
| 65 | echo ' -RDIR search in DIR for library dependencies at run time' |
Eric Anholt | f1a2613 | 2005-08-08 03:26:18 +0000 | [diff] [blame] | 66 | echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)' |
| 67 | echo ' Not observed on all systems at this time.' |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 68 | echo ' -ldflags OPT specify any additional linker flags in OPT' |
Eric Anholt | f1a2613 | 2005-08-08 03:26:18 +0000 | [diff] [blame] | 69 | echo ' -cplusplus link with C++ runtime' |
| 70 | echo ' -static make a static library (default is dynamic/shared)' |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 71 | echo ' -dlopen make a shared library suitable for dynamic loading' |
Eric Anholt | f1a2613 | 2005-08-08 03:26:18 +0000 | [diff] [blame] | 72 | echo ' -install DIR put resulting library file(s) in DIR' |
| 73 | echo ' -arch ARCH override using `uname` to determine host system' |
| 74 | echo ' -archopt OPT specify an extra achitecture-specific option OPT' |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 75 | echo ' -altopts OPTS alternate options to override all others' |
Eric Anholt | f1a2613 | 2005-08-08 03:26:18 +0000 | [diff] [blame] | 76 | echo " -noprefix don't prefix library name with 'lib' nor add any suffix" |
| 77 | echo ' -exports FILE only export the symbols listed in FILE' |
| 78 | echo ' -h, --help display this information and exit' |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 79 | exit 1 |
| 80 | ;; |
| 81 | '-o') |
| 82 | shift 1; |
| 83 | LIBNAME=$1 |
| 84 | ;; |
| 85 | '-major') |
| 86 | shift 1; |
| 87 | MAJOR=$1 |
| 88 | ;; |
| 89 | '-minor') |
| 90 | shift 1; |
| 91 | MINOR=$1 |
| 92 | ;; |
| 93 | '-patch') |
| 94 | shift 1; |
| 95 | PATCH=$1 |
| 96 | ;; |
| 97 | '-linker') |
| 98 | shift 1; |
| 99 | LINK=$1 |
| 100 | ;; |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 101 | '-ldflags') |
| 102 | shift 1; |
| 103 | LDFLAGS=$1 |
| 104 | ;; |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 105 | -l*) |
| 106 | DEPS="$DEPS $1" |
| 107 | ;; |
| 108 | -L*) |
| 109 | DEPS="$DEPS $1" |
| 110 | ;; |
Alan Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 111 | -R*) |
| 112 | DEPS="$DEPS $1" |
| 113 | ;; |
Hasso Tepper | f9c8af3 | 2008-04-09 11:03:05 -0700 | [diff] [blame] | 114 | -Wl*) |
| 115 | DEPS="$DEPS $1" |
| 116 | ;; |
Brian | ed2fddc | 2007-05-08 14:03:04 -0600 | [diff] [blame] | 117 | -pthread) |
| 118 | # this is a special case (see bugzilla 10876) |
| 119 | DEPS="$DEPS $1" |
| 120 | ;; |
Eric Anholt | 1a413b4 | 2007-06-22 10:29:54 -0700 | [diff] [blame] | 121 | '-pthread') |
| 122 | DEPS="$DEPS -pthread" |
| 123 | ;; |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 124 | '-cplusplus') |
| 125 | CPLUSPLUS=1 |
| 126 | ;; |
| 127 | '-static') |
| 128 | STATIC=1 |
| 129 | ;; |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 130 | '-dlopen') |
| 131 | DLOPEN=1 |
| 132 | ;; |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 133 | '-install') |
| 134 | shift 1; |
| 135 | INSTALLDIR=$1 |
| 136 | ;; |
| 137 | '-arch') |
| 138 | shift 1; |
| 139 | ARCH=$1 |
| 140 | ;; |
| 141 | '-archopt') |
| 142 | shift 1; |
| 143 | ARCHOPT=$1 |
| 144 | ;; |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 145 | '-altopts') |
| 146 | shift 1; |
| 147 | ALTOPTS=$1 |
| 148 | ;; |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 149 | '-noprefix') |
| 150 | NOPREFIX=1 |
| 151 | ;; |
| 152 | '-exports') |
| 153 | shift 1; |
| 154 | EXPORTS=$1 |
| 155 | ;; |
| 156 | -*) |
| 157 | echo "mklib: Unknown option: " $1 ; |
| 158 | exit 1 |
| 159 | ;; |
| 160 | *) |
| 161 | # This should be the first object file, stop parsing |
| 162 | break |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 163 | esac |
| 164 | shift 1 |
| 165 | done |
| 166 | OBJECTS=$@ |
| 167 | |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 168 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 169 | if [ ${ARCH} = "auto" ] ; then |
| 170 | ARCH=`uname` |
| 171 | fi |
| 172 | |
| 173 | |
| 174 | # |
| 175 | # Error checking |
| 176 | # |
| 177 | if [ "x${LIBNAME}" = "x" ] ; then |
| 178 | echo "mklib: Error: no library name specified" |
| 179 | exit 1 |
| 180 | fi |
| 181 | if [ "x${OBJECTS}" = "x" ] ; then |
| 182 | echo "mklib: Error: no object files specified" |
| 183 | exit 1 |
| 184 | fi |
| 185 | |
| 186 | |
| 187 | # |
| 188 | # Debugging info |
| 189 | # |
| 190 | if [ ] ; then |
| 191 | echo "-----------------" |
| 192 | echo ARCH is $ARCH |
| 193 | echo LIBNAME is $LIBNAME |
| 194 | echo MAJOR is $MAJOR |
| 195 | echo MINOR is $MINOR |
| 196 | echo PATCH is $PATCH |
| 197 | echo DEPS are $DEPS |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 198 | echo "EXPORTS in" $EXPORTS |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 199 | echo "-----------------" |
| 200 | fi |
| 201 | |
| 202 | |
| 203 | # |
| 204 | # OK, make the library now |
| 205 | # |
| 206 | case $ARCH in |
| 207 | |
Hasso Tepper | f9c8af3 | 2008-04-09 11:03:05 -0700 | [diff] [blame] | 208 | 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*) |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 209 | # we assume gcc |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 210 | |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 211 | if [ "x$LINK" = "x" ] ; then |
| 212 | # -linker was not specified so set default link command now |
| 213 | if [ $CPLUSPLUS = 1 ] ; then |
| 214 | LINK=g++ |
| 215 | else |
| 216 | LINK=gcc |
| 217 | fi |
Brian Paul | c498742 | 2004-10-16 15:02:16 +0000 | [diff] [blame] | 218 | fi |
| 219 | |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 220 | if [ $NOPREFIX = 1 ] ; then |
| 221 | # No "lib" or ".so" part |
| 222 | echo "mklib: Making" $ARCH "shared library: " ${LIBNAME} |
Michel Dänzer | fc7ddea | 2007-12-04 10:46:45 +0100 | [diff] [blame] | 223 | case $ARCH in 'Linux' | 'GNU' | GNU/*) |
| 224 | OPTS="-Xlinker -Bsymbolic -shared" |
| 225 | ;; |
| 226 | *) |
| 227 | OPTS="-shared" |
| 228 | ;; |
| 229 | esac |
Ian Romanick | aba4864 | 2005-08-08 23:22:46 +0000 | [diff] [blame] | 230 | |
| 231 | # Check if objects are 32-bit and we're running in 64-bit |
| 232 | # environment. If so, pass -m32 flag to linker. |
| 233 | set ${OBJECTS} |
| 234 | ABI32=`file $1 | grep 32-bit` |
| 235 | if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then |
| 236 | OPTS="-m32 ${OPTS}" |
| 237 | fi |
| 238 | |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 239 | if [ "${ALTOPTS}" ] ; then |
| 240 | OPTS=${ALTOPTS} |
| 241 | fi |
| 242 | |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 243 | rm -f ${LIBNAME} |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 244 | # make lib |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 245 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 246 | # finish up |
| 247 | FINAL_LIBS="${LIBNAME}" |
| 248 | elif [ $STATIC = 1 ] ; then |
Brian | 98abd1b | 2007-03-27 07:58:47 -0600 | [diff] [blame] | 249 | LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a" |
| 250 | echo "mklib: Making" $ARCH "static library: " ${LIBNAME} |
Brian Paul | 56e0ee8 | 2006-04-13 15:17:50 +0000 | [diff] [blame] | 251 | LINK="ar" |
| 252 | OPTS="-ru" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 253 | if [ "${ALTOPTS}" ] ; then |
| 254 | OPTS=${ALTOPTS} |
| 255 | fi |
Brian | 98abd1b | 2007-03-27 07:58:47 -0600 | [diff] [blame] | 256 | rm -f ${LIBNAME} |
Brian Paul | 56e0ee8 | 2006-04-13 15:17:50 +0000 | [diff] [blame] | 257 | # make lib |
Brian | 98abd1b | 2007-03-27 07:58:47 -0600 | [diff] [blame] | 258 | ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS} |
| 259 | ranlib ${LIBNAME} |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 260 | # finish up |
Brian | 98abd1b | 2007-03-27 07:58:47 -0600 | [diff] [blame] | 261 | FINAL_LIBS=${LIBNAME} |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 262 | else |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 263 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
Brian Paul | 5beff7c | 2006-04-19 14:03:04 +0000 | [diff] [blame] | 264 | case $ARCH in 'Linux' | 'GNU' | GNU/*) |
Brian Paul | 5b9a9d4 | 2004-01-17 18:31:12 +0000 | [diff] [blame] | 265 | OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}" |
Brian Paul | 5beff7c | 2006-04-19 14:03:04 +0000 | [diff] [blame] | 266 | ;; |
| 267 | *) |
Brian Paul | 5b9a9d4 | 2004-01-17 18:31:12 +0000 | [diff] [blame] | 268 | OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}" |
Brian Paul | 5beff7c | 2006-04-19 14:03:04 +0000 | [diff] [blame] | 269 | ;; |
| 270 | esac |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 271 | if [ $EXPORTS ] ; then |
| 272 | #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}" |
| 273 | # Make the 'exptmp' file for --version-script option |
Julien Cristau | f7eb0ce | 2008-07-13 17:13:32 +0200 | [diff] [blame^] | 274 | echo "{" > exptmp |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 275 | echo "global:" >> exptmp |
| 276 | sed 's/$/;/' ${EXPORTS} >> exptmp |
| 277 | echo "local:" >> exptmp |
| 278 | echo "*;" >> exptmp |
| 279 | echo "};" >> exptmp |
| 280 | OPTS="${OPTS} -Xlinker --version-script=exptmp" |
| 281 | # exptmp is removed below |
| 282 | fi |
Brian Paul | 3e19618 | 2005-03-03 01:38:13 +0000 | [diff] [blame] | 283 | |
| 284 | # Check if objects are 32-bit and we're running in 64-bit |
| 285 | # environment. If so, pass -m32 flag to linker. |
| 286 | set ${OBJECTS} |
| 287 | ABI32=`file $1 | grep 32-bit` |
| 288 | if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then |
| 289 | OPTS="-m32 ${OPTS}" |
| 290 | fi |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 291 | if [ "${ALTOPTS}" ] ; then |
| 292 | OPTS=${ALTOPTS} |
| 293 | fi |
Brian Paul | 3e19618 | 2005-03-03 01:38:13 +0000 | [diff] [blame] | 294 | |
Brian Paul | 6e450f2 | 2004-02-21 18:08:41 +0000 | [diff] [blame] | 295 | if [ x${PATCH} = "x" ] ; then |
| 296 | VERSION="${MAJOR}.${MINOR}" |
| 297 | else |
| 298 | VERSION="${MAJOR}.${MINOR}.${PATCH}" |
| 299 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 300 | |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 301 | echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 302 | |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 303 | # rm any old libs |
| 304 | rm -f ${LIBNAME}.so.${VERSION} |
| 305 | rm -f ${LIBNAME}.so.${MAJOR} |
| 306 | rm -f ${LIBNAME}.so |
| 307 | |
| 308 | # make lib |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 309 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 310 | # make usual symlinks |
| 311 | ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} |
| 312 | ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so |
| 313 | # finish up |
| 314 | FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so" |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 315 | # rm -f exptmp |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 316 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 317 | ;; |
| 318 | |
| 319 | 'SunOS') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 320 | if [ $STATIC = 1 ] ; then |
| 321 | LIBNAME="lib${LIBNAME}.a" |
| 322 | echo "mklib: Making SunOS static library: " ${LIBNAME} |
| 323 | rm -f ${LIBNAME} |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 324 | ar -ruv ${LIBNAME} ${OBJECTS} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 325 | FINAL_LIBS=${LIBNAME} |
| 326 | else |
Brian Paul | 0a3a1c6 | 2006-11-10 12:47:56 +0000 | [diff] [blame] | 327 | if [ $NOPREFIX = 0 ] ; then |
| 328 | LIBNAME="lib${LIBNAME}.so" |
| 329 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 330 | echo "mklib: Making SunOS shared library: " ${LIBNAME} |
Brian Paul | 59ebe1f | 2006-04-05 13:43:02 +0000 | [diff] [blame] | 331 | |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 332 | if [ "x$LINK" = "x" ] ; then |
| 333 | # -linker was not specified, choose default linker now |
| 334 | if [ $CPLUSPLUS = 1 ] ; then |
| 335 | # determine linker and options for C++ code |
| 336 | if [ `which c++` ] ; then |
| 337 | # use Sun c++ |
| 338 | LINK="c++" |
| 339 | elif [ `type g++` ] ; then |
| 340 | # use g++ |
| 341 | LINK="g++" |
| 342 | else |
Alan Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 343 | echo "mklib: warning: can't find C++ compiler, trying CC." |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 344 | LINK="CC" |
| 345 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 346 | else |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 347 | # use native Sun linker for C code |
| 348 | LINK="ld" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 349 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 350 | fi |
Brian Paul | 59ebe1f | 2006-04-05 13:43:02 +0000 | [diff] [blame] | 351 | |
| 352 | # linker options |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 353 | if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then |
| 354 | # SunOS tools, -G to make shared libs |
Brian Paul | 59ebe1f | 2006-04-05 13:43:02 +0000 | [diff] [blame] | 355 | OPTS="-G" |
| 356 | else |
| 357 | # gcc linker |
| 358 | # Check if objects are 32-bit and we're running in 64-bit |
| 359 | # environment. If so, pass -m32 flag to linker. |
| 360 | set ${OBJECTS} |
| 361 | ABI32=`file $1 | grep 32-bit` |
| 362 | if [ "${ABI32}" ] ; then |
| 363 | OPTS="-m32 -shared -Wl,-Bdynamic" |
| 364 | else |
| 365 | OPTS="-m64 -shared -Wl,-Bdynamic" |
| 366 | fi |
| 367 | fi |
| 368 | |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 369 | # Check if objects are SPARC v9 |
| 370 | # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1 |
| 371 | set ${OBJECTS} |
Alan Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 372 | if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then |
| 373 | SPARCV9=`file $1 | grep SPARCV9` |
| 374 | if [ "${SPARCV9}" ] ; then |
| 375 | OPTS="${OPTS} -xarch=v9" |
| 376 | fi |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 377 | fi |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 378 | if [ "${ALTOPTS}" ] ; then |
| 379 | OPTS=${ALTOPTS} |
| 380 | fi |
Brian Paul | 59ebe1f | 2006-04-05 13:43:02 +0000 | [diff] [blame] | 381 | # for debug: |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 382 | #echo "mklib: linker is" ${LINK} ${OPTS} |
Brian Paul | 0a3a1c6 | 2006-11-10 12:47:56 +0000 | [diff] [blame] | 383 | if [ $NOPREFIX = 1 ] ; then |
| 384 | rm -f ${LIBNAME} |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 385 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | 0a3a1c6 | 2006-11-10 12:47:56 +0000 | [diff] [blame] | 386 | else |
| 387 | rm -f ${LIBNAME}.${MAJOR} ${LIBNAME} |
Alan Coopersmith | e1f9adc | 2008-06-20 17:58:53 -0700 | [diff] [blame] | 388 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS} |
Brian Paul | 0a3a1c6 | 2006-11-10 12:47:56 +0000 | [diff] [blame] | 389 | ln -s ${LIBNAME}.${MAJOR} ${LIBNAME} |
| 390 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 391 | FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 392 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 393 | ;; |
| 394 | |
| 395 | 'FreeBSD') |
Eric Anholt | b83435f | 2005-10-18 23:36:40 +0000 | [diff] [blame] | 396 | # we assume gcc |
| 397 | |
| 398 | if [ "x$LINK" = "x" ] ; then |
| 399 | # -linker was not specified so set default link command now |
| 400 | if [ $CPLUSPLUS = 1 ] ; then |
| 401 | LINK=g++ |
| 402 | else |
| 403 | LINK=gcc |
| 404 | fi |
| 405 | fi |
| 406 | |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 407 | if [ $NOPREFIX = 1 ] ; then |
| 408 | # No "lib" or ".so" part |
| 409 | echo "mklib: Making FreeBSD shared library: " ${LIBNAME} |
Eric Anholt | b83435f | 2005-10-18 23:36:40 +0000 | [diff] [blame] | 410 | OPTS="-shared" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 411 | if [ "${ALTOPTS}" ] ; then |
| 412 | OPTS=${ALTOPTS} |
| 413 | fi |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 414 | rm -f ${LIBNAME} |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 415 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 416 | FINAL_LIBS=${LIBNAME} |
| 417 | elif [ $STATIC = 1 ] ; then |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 418 | STLIB="lib${LIBNAME}.a" |
| 419 | echo "mklib: Making FreeBSD static library: " ${STLIB} |
| 420 | rm -f ${STLIB} |
| 421 | ar cq ${STLIB} ${OBJECTS} |
| 422 | ranlib ${STLIB} |
| 423 | FINAL_LIBS=${STLIB} |
| 424 | else |
Eric Anholt | b83435f | 2005-10-18 23:36:40 +0000 | [diff] [blame] | 425 | SHLIB="lib${LIBNAME}.so.${MAJOR}" |
| 426 | OPTS="-shared -Wl,-soname,${SHLIB}" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 427 | if [ "${ALTOPTS}" ] ; then |
| 428 | OPTS=${ALTOPTS} |
| 429 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 430 | echo "mklib: Making FreeBSD shared library: " ${SHLIB} |
| 431 | rm -f ${SHLIB} |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 432 | ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS} |
Eric Anholt | 1c04be5 | 2005-10-22 01:41:40 +0000 | [diff] [blame] | 433 | ln -sf ${SHLIB} "lib${LIBNAME}.so" |
| 434 | FINAL_LIBS="${SHLIB} lib${LIBNAME}.so" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 435 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 436 | ;; |
| 437 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 438 | 'NetBSD') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 439 | if [ $STATIC = 1 ] ; then |
| 440 | LIBNAME="lib${LIBNAME}_pic.a" |
| 441 | echo "mklib: Making NetBSD PIC static library: " ${LIBNAME} |
| 442 | rm -f ${LIBNAME} |
| 443 | ar cq ${LIBNAME} ${OBJECTS} |
| 444 | ranlib ${LIBNAME} |
| 445 | FINAL_LIBS=${LIBNAME} |
| 446 | else |
| 447 | LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}" |
| 448 | echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME} |
| 449 | rm -f ${LIBNAME} |
| 450 | ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS} |
| 451 | FINAL_LIBS=${LIBNAME} |
| 452 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 453 | ;; |
| 454 | |
Brian Paul | f8c31fc | 2004-01-29 15:21:47 +0000 | [diff] [blame] | 455 | 'IRIX' | 'IRIX64') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 456 | if [ $STATIC = 1 ] ; then |
| 457 | LIBNAME="lib${LIBNAME}.a" |
| 458 | rm -f ${LIBNAME} |
| 459 | ar rc ${LIBNAME} ${OBJECTS} |
| 460 | FINAL_LIBS=${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 461 | else |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 462 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 463 | |
| 464 | # examine first object to determine ABI |
| 465 | set ${OBJECTS} |
| 466 | ABI_O32=`file $1 | grep 'ELF 32-bit'` |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 467 | ABI_N32=`file $1 | grep 'ELF N32'` |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 468 | ABI_N64=`file $1 | grep 'ELF 64-bit'` |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 469 | if [ "${ABI_O32}" ] ; then |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 470 | OPTS="-32 -shared -all" |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 471 | ABI="o32-bit" |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 472 | elif [ "${ABI_N32}" ] ; then |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 473 | OPTS="-n32 -shared -all" |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 474 | ABI="n32-bit" |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 475 | elif [ "${ABI_N64}" ] ; then |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 476 | OPTS="-64 -shared -all" |
| 477 | ABI="64-bit" |
| 478 | else |
| 479 | echo "Error: Unexpected IRIX ABI!" |
| 480 | exit 1 |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 481 | fi |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 482 | |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 483 | if [ "${ALTOPTS}" ] ; then |
| 484 | OPTS=${ALTOPTS} |
| 485 | fi |
| 486 | |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 487 | if [ $CPLUSPLUS = 1 ] ; then |
| 488 | LINK="CC" |
| 489 | else |
| 490 | LINK="ld" |
| 491 | fi |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 492 | |
| 493 | echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME} |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 494 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 495 | FINAL_LIBS=${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 496 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 497 | ;; |
| 498 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 499 | 'linux-cygwin') |
| 500 | LIBNAME="lib${LIBNAME}.a" |
| 501 | echo "mklib: Making linux-cygwin library: " ${LIBNAME} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 502 | rm -f ${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 503 | gnuwin32ar ruv ${LIBNAME} ${OBJECTS} |
| 504 | FINAL_LIBS=${LIBNAME} |
| 505 | ;; |
| 506 | |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 507 | 'HP-UX') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 508 | if [ $STATIC = 1 ] ; then |
| 509 | LIBNAME="lib${LIBNAME}.a" |
Brian Paul | 52fb07e | 2004-03-30 14:47:02 +0000 | [diff] [blame] | 510 | echo "mklib: Making HP-UX static library: " ${LIBNAME} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 511 | rm -f ${LIBNAME} |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 512 | ar -ruv ${LIBNAME} ${OBJECTS} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 513 | FINAL_LIBS=${LIBNAME} |
| 514 | else |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 515 | # HP uses a .2 for their current GL/GLU libraries |
| 516 | if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then |
| 517 | MAJOR=2 |
| 518 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 519 | RUNLIB="lib${LIBNAME}.${MAJOR}" |
| 520 | DEVLIB="lib${LIBNAME}.sl" |
Brian Paul | 52fb07e | 2004-03-30 14:47:02 +0000 | [diff] [blame] | 521 | echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 522 | ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS} |
| 523 | ln -s ${RUNLIB} ${DEVLIB} |
Brian Paul | ac0cfee | 2004-04-25 15:13:56 +0000 | [diff] [blame] | 524 | FINAL_LIBS="${RUNLIB} ${DEVLIB}" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 525 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 526 | ;; |
| 527 | |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 528 | 'AIX' ) |
| 529 | # examine first object to determine ABI |
| 530 | set ${OBJECTS} |
| 531 | ABI_64=`file $1 | grep '64-bit'` |
| 532 | if [ "${ABI_64}" ] ; then |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 533 | X64="-X64" |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 534 | Q64="-q64" |
| 535 | OFILE=shr_64.o |
| 536 | else |
| 537 | OFILE=shr.o #Want to be consistent with the IBM libGL.a |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 538 | fi |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 539 | |
Brian Paul | b3282a3 | 2006-04-18 12:56:11 +0000 | [diff] [blame] | 540 | if [ $STATIC = 1 ] ; then |
| 541 | LIBNAME="lib${LIBNAME}.a" |
| 542 | echo "mklib: Making AIX static library: " ${LIBNAME} |
| 543 | ar -ruv ${X64} ${LIBNAME} ${OBJECTS} |
| 544 | FINAL_LIBS=${LIBNAME} |
| 545 | else |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 546 | EXPFILE="lib${LIBNAME}.exp" |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 547 | 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] | 548 | OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}" |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 549 | rm -f ${EXPFILE} ${OFILE} |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 550 | NM="/bin/nm -eC ${X64}" |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 551 | echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE} |
| 552 | ${NM} ${OBJECTS} | awk '{ |
| 553 | if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \ |
| 554 | && ( substr($1,1,1) != ".")) { |
| 555 | if (substr ($1, 1, 7) != "__sinit" && |
| 556 | substr ($1, 1, 7) != "__sterm") { |
| 557 | if (substr ($1, 1, 5) == "__tf1") |
| 558 | print (substr ($1, 7)) |
| 559 | else if (substr ($1, 1, 5) == "__tf9") |
| 560 | print (substr ($1, 15)) |
| 561 | else |
| 562 | print $1 |
| 563 | } |
| 564 | } |
| 565 | }' | sort -u >> ${EXPFILE} |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 566 | |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 567 | if [ "${ALTOPTS}" ] ; then |
| 568 | OPTS=${ALTOPTS} |
| 569 | fi |
| 570 | |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 571 | # On AIX a shared library is linked differently when |
| 572 | # you want to dlopen the file |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 573 | if [ $DLOPEN = "1" ] ; then |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 574 | cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 575 | else |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 576 | cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS} |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 577 | ar ${X64} -r ${LIBNAME} ${OFILE} |
| 578 | fi |
Brian Paul | 56e0ee8 | 2006-04-13 15:17:50 +0000 | [diff] [blame] | 579 | |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 580 | FINAL_LIBS="${LIBNAME}" |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 581 | fi |
| 582 | ;; |
| 583 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 584 | 'OpenSTEP') |
| 585 | LIBNAME="lib${LIBNAME}.a" |
| 586 | echo "mklib: Making OpenSTEP static library: " ${LIBNAME} |
| 587 | libtool -static -o ${LIBNAME} - ${OBJECTS} |
| 588 | FINAL_LIBS=${LIBNAME} |
| 589 | ;; |
| 590 | |
| 591 | 'OSF1') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 592 | if [ $STATIC = 1 ] ; then |
| 593 | LIBNAME="lib${LIBNAME}.a" |
| 594 | echo "mklib: Making OSF/1 static library: " ${LIBNAME} |
| 595 | rm -f ${LIBNAME} |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 596 | ar -ruv ${LIBNAME} ${OBJECTS} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 597 | FINAL_LIBS=${LIBNAME} |
| 598 | else |
| 599 | VERSION="${MAJOR}.${MINOR}" |
| 600 | LIBNAME="lib${LIBNAME}.so" |
| 601 | echo "mklib: Making OSF/1 shared library: " ${LIBNAME} |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 602 | if [ "x$LINK" = "x" ] ; then |
| 603 | if [ $CPLUSPLUS = 1 ] ; then |
| 604 | LINK=cxx |
| 605 | else |
| 606 | LINK=cc |
| 607 | fi |
Brian Paul | 0d5e6cc | 2004-11-29 17:23:12 +0000 | [diff] [blame] | 608 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 609 | rm -f ${LIBNAME}.${VERSION} |
Brian Paul | 0d5e6cc | 2004-11-29 17:23:12 +0000 | [diff] [blame] | 610 | ${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] | 611 | ln -sf ${LIBNAME}.${VERSION} ${LIBNAME} |
| 612 | FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}" |
| 613 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 614 | ;; |
| 615 | |
| 616 | 'Darwin') |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 617 | if [ $STATIC = 1 ] ; then |
| 618 | LIBNAME="lib${LIBNAME}.a" |
| 619 | echo "mklib: Making Darwin static library: " ${LIBNAME} |
| 620 | LINK="ar" |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 621 | OPTS="-ruvs" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 622 | if [ "${ALTOPTS}" ] ; then |
| 623 | OPTS=${ALTOPTS} |
| 624 | fi |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 625 | ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS} |
| 626 | FINAL_LIBS=${LIBNAME} |
| 627 | else |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 628 | # 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] | 629 | if [ $DLOPEN = "1" ] ; then |
| 630 | LIBSUFFIX="bundle" |
| 631 | OPTS="${ARCHOPT} -bundle -multiply_defined suppress" |
| 632 | else |
| 633 | LIBSUFFIX="dylib" |
| 634 | OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}" |
| 635 | fi |
Jeremy Huddleston | 9993ccc | 2008-02-19 00:54:35 -0800 | [diff] [blame] | 636 | |
| 637 | if [ ${EXPORTS} ] ; then |
| 638 | OPTS="${OPTS} -exported_symbols_list ${EXPORTS}" |
| 639 | fi |
| 640 | |
| 641 | LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}" |
| 642 | LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}" |
| 643 | LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}" |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 644 | |
| 645 | # examine first object to determine ABI |
| 646 | set ${OBJECTS} |
Jeremy Huddleston | 9993ccc | 2008-02-19 00:54:35 -0800 | [diff] [blame] | 647 | ABI_PPC=`file $1 | grep ' ppc'` |
| 648 | ABI_I386=`file $1 | grep ' i386'` |
| 649 | ABI_PPC64=`file $1 | grep ' ppc64'` |
| 650 | ABI_X86_64=`file $1 | grep ' x86_64'` |
| 651 | if [ "${ABI_PPC}" ] ; then |
| 652 | OPTS="${OPTS} -arch ppc" |
| 653 | fi |
| 654 | if [ "${ABI_I386}" ] ; then |
| 655 | OPTS="${OPTS} -arch i386" |
| 656 | fi |
| 657 | if [ "${ABI_PPC64}" ] ; then |
| 658 | OPTS="${OPTS} -arch ppc64" |
| 659 | fi |
| 660 | if [ "${ABI_X86_64}" ] ; then |
| 661 | OPTS="${OPTS} -arch x86_64" |
| 662 | fi |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 663 | |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 664 | if [ "${ALTOPTS}" ] ; then |
| 665 | OPTS=${ALTOPTS} |
| 666 | fi |
| 667 | |
Brian Paul | 1e1af99 | 2006-04-14 14:14:51 +0000 | [diff] [blame] | 668 | # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk |
| 669 | # to OPTS here? |
| 670 | |
| 671 | # determine linker |
Brian Paul | 56e0ee8 | 2006-04-13 15:17:50 +0000 | [diff] [blame] | 672 | if [ $CPLUSPLUS = 1 ] ; then |
| 673 | LINK="g++" |
| 674 | else |
| 675 | LINK="cc" |
| 676 | fi |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 677 | |
Brian Paul | c50d77a | 2004-04-13 17:35:17 +0000 | [diff] [blame] | 678 | echo "mklib: Making Darwin shared library: " ${LIBNAME} |
Jeremy Huddleston | 9993ccc | 2008-02-19 00:54:35 -0800 | [diff] [blame] | 679 | |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 680 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 681 | ln -s ${LIBNAME} ${LINKNAME} |
Jeremy Huddleston | 9993ccc | 2008-02-19 00:54:35 -0800 | [diff] [blame] | 682 | ln -s ${LIBNAME} ${LINKNAME2} |
| 683 | FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}" |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 684 | fi |
| 685 | ;; |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 686 | |
| 687 | 'LynxOS') |
| 688 | LIBNAME="lib${LIBNAME}.a" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 689 | echo "mklib: Making LynxOS static library: " ${LIBNAME} |
| 690 | rm -f ${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 691 | ar ru ${LIBNAME} ${OBJECTS} |
| 692 | FINAL_LIBS=${LIBNAME} |
| 693 | ;; |
| 694 | |
| 695 | 'BeOS') |
Philippe Houdoin | ef4dd5a | 2004-08-14 10:12:38 +0000 | [diff] [blame] | 696 | if [ $STATIC = 1 ] ; then |
| 697 | LIBNAME="lib${LIBNAME}.a" |
| 698 | echo "mklib: Making BeOS static library: " ${LIBNAME} |
| 699 | ar -cru "${LIBNAME}" ${OBJECTS} |
| 700 | else |
Brian Paul | b784b8f | 2004-08-14 14:30:36 +0000 | [diff] [blame] | 701 | LIBNAME="lib${LIBNAME}.so" |
| 702 | echo "mklib: Making BeOS shared library: " ${LIBNAME} |
| 703 | gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}" |
| 704 | mimeset -f "${LIBNAME}" |
Brian Paul | 8dcc673 | 2005-07-25 22:59:58 +0000 | [diff] [blame] | 705 | # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific. |
Brian Paul | b784b8f | 2004-08-14 14:30:36 +0000 | [diff] [blame] | 706 | setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!" |
| 707 | fi |
| 708 | FINAL_LIBS=${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 709 | ;; |
| 710 | |
| 711 | 'QNX') |
| 712 | LIBNAME="lib${LIBNAME}.a" |
| 713 | echo "mklib: Making QNX library: " ${LIBNAME} |
| 714 | wlib ${LIBNAME} ${OBJECTS} |
| 715 | FINAL_LIBS=${LIBNAME} |
| 716 | ;; |
| 717 | |
Brian Paul | 65e2ab3 | 2003-10-27 18:13:37 +0000 | [diff] [blame] | 718 | 'MorphOS') |
| 719 | LIBNAME="lib${LIBNAME}.a" |
| 720 | echo "mklib: Making MorphOS library: " ${LIBNAME} |
| 721 | ppc-morphos-ar rc ${LIBNAME} ${OBJECTS} |
| 722 | FINAL_LIBS="${LIBNAME}" |
| 723 | ;; |
| 724 | |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 725 | 'icc' | 'icc-istatic') |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 726 | # Intel C compiler |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 727 | # This should get merged into the Linux code, above, since this isn't |
| 728 | # really a different architecture. |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 729 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
| 730 | |
| 731 | if [ $STATIC = 1 ] ; then |
| 732 | echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a |
| 733 | LINK="ar" |
| 734 | OPTS="-ruv" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 735 | if [ "${ALTOPTS}" ] ; then |
| 736 | OPTS=${ALTOPTS} |
| 737 | fi |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 738 | # make lib |
| 739 | ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS} |
| 740 | # finish up |
| 741 | FINAL_LIBS="${LIBNAME}.a" |
| 742 | else |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 743 | if [ $ARCH = icc-istatic ] ; then |
| 744 | OPTS="-shared -i-static -cxxlib-icc" |
| 745 | else |
| 746 | OPTS="-shared" |
| 747 | fi |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 748 | if [ "${ALTOPTS}" ] ; then |
| 749 | OPTS=${ALTOPTS} |
| 750 | fi |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 751 | VERSION="${MAJOR}.${MINOR}.${PATCH}" |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 752 | echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION} |
| 753 | |
| 754 | if [ $CPLUSPLUS = 1 ] ; then |
Brian Paul | fe14cf6 | 2006-04-13 02:23:25 +0000 | [diff] [blame] | 755 | LINK="icpc" |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 756 | else |
| 757 | LINK="icc" |
| 758 | fi |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 759 | # rm any old libs |
| 760 | rm -f ${LIBNAME}.so.${VERSION} |
| 761 | rm -f ${LIBNAME}.so.${MAJOR} |
| 762 | rm -f ${LIBNAME}.so |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 763 | # make lib |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 764 | ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 765 | # make usual symlinks |
| 766 | ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} |
| 767 | ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so |
| 768 | # finish up |
| 769 | FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so" |
| 770 | fi |
| 771 | ;; |
| 772 | |
Brian Paul | 12d6cae | 2004-01-10 22:12:21 +0000 | [diff] [blame] | 773 | 'aix-gcc') |
| 774 | # AIX with gcc |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 775 | if [ $STATIC = 1 ] ; then |
| 776 | LIBNAME="lib${LIBNAME}.a" |
| 777 | echo "mklib: Making AIX GCC static library: " ${LIBNAME} |
| 778 | rm -f ${LIBNAME} |
| 779 | ar ru ${LIBNAME} ${OBJECTS} |
| 780 | FINAL_LIBS=${LIBNAME} |
| 781 | else |
| 782 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" |
| 783 | echo "mklib: Making AIX GCC shared library: " ${LIBNAME} |
| 784 | # remove old lib |
| 785 | rm -f ${LIBNAME} |
| 786 | # make the lib |
| 787 | gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 788 | # NOTE: the application linking with this library must specify |
| 789 | # the -Wl,-brtl flags to gcc |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 790 | FINAL_LIBS=${LIBNAME} |
| 791 | fi |
| 792 | ;; |
| 793 | |
| 794 | 'ultrix') |
| 795 | # XXX untested |
| 796 | if [ $STATIC = 0 ] ; then |
| 797 | echo "mklib: Warning shared libs not supported on Ultrix" |
| 798 | fi |
| 799 | LIBNAME="lib${LIBNAME}.a" |
| 800 | echo "mklib: Making static library for Ultrix: " ${LIBNAME} |
Brian Paul | 12d6cae | 2004-01-10 22:12:21 +0000 | [diff] [blame] | 801 | rm -f ${LIBNAME} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 802 | ar ru ${LIBNAME} ${OBJECTS} |
| 803 | FINAL_LIBS="${LIBNAME}" |
Brian Paul | 12d6cae | 2004-01-10 22:12:21 +0000 | [diff] [blame] | 804 | ;; |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 805 | |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 806 | CYGWIN*) |
| 807 | # GCC-based environment |
| 808 | CYGNAME="cyg${LIBNAME}" # prefix with "cyg" |
| 809 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
| 810 | |
| 811 | if [ $STATIC = 1 ] ; then |
| 812 | echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a |
| 813 | LINK="ar" |
| 814 | OPTS="-ru" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 815 | if [ "${ALTOPTS}" ] ; then |
| 816 | OPTS=${ALTOPTS} |
| 817 | fi |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 818 | # make lib |
| 819 | ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS} |
| 820 | ranlib ${LIBNAME}.a |
| 821 | # finish up |
| 822 | FINAL_LIBS=${LIBNAME}.a |
| 823 | else |
| 824 | OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a" |
Andy Skinner | 5c0c883 | 2008-02-07 13:20:06 -0700 | [diff] [blame] | 825 | if [ "${ALTOPTS}" ] ; then |
| 826 | OPTS=${ALTOPTS} |
| 827 | fi |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 828 | echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll |
| 829 | |
| 830 | if [ $CPLUSPLUS = 1 ] ; then |
| 831 | LINK="g++" |
| 832 | else |
| 833 | LINK="gcc" |
| 834 | fi |
| 835 | |
| 836 | # rm any old libs |
| 837 | rm -f ${LIBNAME}-${MAJOR}.dll |
| 838 | rm -f ${LIBNAME}.dll.a |
| 839 | rm -f ${LIBNAME}.a |
| 840 | |
| 841 | # make lib |
Dan Nicholson | 2a3e338 | 2007-09-28 18:42:21 -0600 | [diff] [blame] | 842 | ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 843 | # make usual symlinks |
| 844 | ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a |
| 845 | # finish up |
| 846 | FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a" |
| 847 | # special case for installing in bin |
| 848 | FINAL_BINS="${CYGNAME}-${MAJOR}.dll" |
| 849 | fi |
| 850 | ;; |
| 851 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 852 | 'example') |
| 853 | # If you're adding support for a new architecture, you can |
| 854 | # start with this: |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 855 | if [ $STATIC = 1 ] ; then |
| 856 | LIBNAME="lib${LIBNAME}.a" |
| 857 | echo "mklib: Making static library for example arch: " ${LIBNAME} |
| 858 | rm -f ${LIBNAME} |
| 859 | ar rv ${LIBNAME} ${OBJECTS} |
| 860 | FINAL_LIBS="${LIBNAME}" |
| 861 | else |
Brian Paul | 7c1ab40 | 2005-07-25 23:49:50 +0000 | [diff] [blame] | 862 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 863 | echo "mklib: Making shared library for example arch: " ${LIBNAME} |
| 864 | ld -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 865 | FINAL_LIBS="${LIBNAME}" |
| 866 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 867 | ;; |
| 868 | |
| 869 | *) |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 870 | echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH} |
| 871 | echo "mklib: Please add necessary commands to mklib script." |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 872 | ;; |
| 873 | esac |
| 874 | |
| 875 | |
| 876 | # |
| 877 | # Put library files into installation directory if specified. |
| 878 | # |
| 879 | if [ ${INSTALLDIR} != "." ] ; then |
| 880 | echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR} |
| 881 | mv ${FINAL_LIBS} ${INSTALLDIR}/ |
| 882 | fi |