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