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