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