Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Make a shared library. |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 4 | # Basically do a switch/case depending on the OS and make a shared (or static) |
| 5 | # library conforming to that OS. |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 6 | |
| 7 | |
| 8 | # Usage: |
| 9 | # mklib [options] objects ... |
| 10 | # Options: |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame] | 11 | # -o LIBRARY specifies the name of resulting library |
| 12 | # ("-o GL" for example, might result in "libGL.so" being made) |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 13 | # -major N specifies major version number (default is 1) |
| 14 | # -minor N specifies minor version number (default is 0) |
| 15 | # -patch N specifies patch version number (default is 0) |
| 16 | # -lLIBRARY specifies a dependency on LIBRARY |
| 17 | # -LDIR search in DIR for library dependencies |
| 18 | # -cplusplus link with C++ runtime |
| 19 | # -static make a static library (default is dynamic/shared) |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 20 | # -install DIR move resulting library file(s) to DIR |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 21 | # -arch ARCH override using `uname` to determine architecture |
| 22 | # -archopt OPT specify an extra achitecture-specific option OPT |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 23 | # -noprefix don't prefix library name with "lib" or any suffix |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 24 | # -exports FILE only export the symbols listed in FILE |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 25 | # |
| 26 | # The library name should just be "GL" or "GLU", etc. The 'lib' prefix |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 27 | # will be added here if needed, as well as the ".so" or ".a" suffix, |
| 28 | # etc (unless the -noprefix option is used). |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 29 | # |
| 30 | # objects should be: foo.o bar.o etc.o |
| 31 | # |
| 32 | # Environment variables recognized: |
| 33 | # CC C compiler command |
| 34 | # CXX C++ compiler command |
| 35 | # |
| 36 | |
| 37 | |
| 38 | # |
| 39 | # Option defaults |
| 40 | # |
| 41 | LIBNAME="" |
| 42 | MAJOR=1 |
| 43 | MINOR=0 |
Brian Paul | 6e450f2 | 2004-02-21 18:08:41 +0000 | [diff] [blame] | 44 | PATCH="" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 45 | DEPS="" |
| 46 | CPLUSPLUS=0 |
| 47 | STATIC=0 |
| 48 | INSTALLDIR="." |
| 49 | ARCH="auto" |
| 50 | ARCHOPT="" |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 51 | NOPREFIX=0 |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 52 | EXPORTS="" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 53 | |
| 54 | |
| 55 | # |
| 56 | # Parse arguments |
| 57 | # |
| 58 | while true |
| 59 | do |
| 60 | case $1 in |
| 61 | '-o') shift 1; LIBNAME=$1;; |
| 62 | '-major') shift 1; MAJOR=$1;; |
| 63 | '-minor') shift 1; MINOR=$1;; |
| 64 | '-patch') shift 1; PATCH=$1;; |
| 65 | -l*) DEPS="$DEPS $1";; |
| 66 | -L*) DEPS="$DEPS $1";; |
| 67 | '-cplusplus') CPLUSPLUS=1;; |
| 68 | '-static') STATIC=1;; |
| 69 | '-install') shift 1; INSTALLDIR=$1;; |
| 70 | '-arch') shift 1; ARCH=$1;; |
| 71 | '-archopt') shift 1; ARCHOPT=$1;; |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 72 | '-noprefix') NOPREFIX=1;; |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 73 | '-exports') shift 1; EXPORTS=$1;; |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 74 | -*) echo "mklib: Unknown option: " $1 ; exit 1;; |
| 75 | *) break |
| 76 | esac |
| 77 | shift 1 |
| 78 | done |
| 79 | OBJECTS=$@ |
| 80 | |
| 81 | if [ ${ARCH} = "auto" ] ; then |
| 82 | ARCH=`uname` |
| 83 | fi |
| 84 | |
| 85 | |
| 86 | # |
| 87 | # Error checking |
| 88 | # |
| 89 | if [ "x${LIBNAME}" = "x" ] ; then |
| 90 | echo "mklib: Error: no library name specified" |
| 91 | exit 1 |
| 92 | fi |
| 93 | if [ "x${OBJECTS}" = "x" ] ; then |
| 94 | echo "mklib: Error: no object files specified" |
| 95 | exit 1 |
| 96 | fi |
| 97 | |
| 98 | |
| 99 | # |
| 100 | # Debugging info |
| 101 | # |
| 102 | if [ ] ; then |
| 103 | echo "-----------------" |
| 104 | echo ARCH is $ARCH |
| 105 | echo LIBNAME is $LIBNAME |
| 106 | echo MAJOR is $MAJOR |
| 107 | echo MINOR is $MINOR |
| 108 | echo PATCH is $PATCH |
| 109 | echo DEPS are $DEPS |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 110 | echo "EXPORTS in" $EXPORTS |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 111 | echo "-----------------" |
| 112 | fi |
| 113 | |
| 114 | |
| 115 | # |
| 116 | # OK, make the library now |
| 117 | # |
| 118 | case $ARCH in |
| 119 | |
Brian Paul | 12d6cae | 2004-01-10 22:12:21 +0000 | [diff] [blame] | 120 | 'Linux' | 'OpenBSD') |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 121 | # we assume gcc |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 122 | |
Brian Paul | c498742 | 2004-10-16 15:02:16 +0000 | [diff] [blame] | 123 | # Set default compilers if env vars not set |
| 124 | if [ "x$CXX" = "x" ] ; then |
| 125 | CXX=g++ |
| 126 | fi |
| 127 | if [ "x$CC" = "x" ] ; then |
| 128 | CC=gcc |
| 129 | fi |
| 130 | |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 131 | if [ $NOPREFIX = 1 ] ; then |
| 132 | # No "lib" or ".so" part |
| 133 | echo "mklib: Making" $ARCH "shared library: " ${LIBNAME} |
| 134 | #OPTS="-shared -Wl,-soname,${LIBNAME}" # soname??? |
| 135 | OPTS="-shared" |
| 136 | if [ $CPLUSPLUS = 1 ] ; then |
Ian Romanick | 9eecb03 | 2004-06-25 22:51:39 +0000 | [diff] [blame] | 137 | LINK=$CXX |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 138 | else |
Ian Romanick | 9eecb03 | 2004-06-25 22:51:39 +0000 | [diff] [blame] | 139 | LINK=$CC |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 140 | fi |
| 141 | rm -f ${LIBNAME} |
| 142 | |
| 143 | # make lib |
| 144 | ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 145 | # finish up |
| 146 | FINAL_LIBS="${LIBNAME}" |
| 147 | elif [ $STATIC = 1 ] ; then |
| 148 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
Brian Paul | 5b9a9d4 | 2004-01-17 18:31:12 +0000 | [diff] [blame] | 149 | echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 150 | LINK="ar" |
Brian Paul | 6e450f2 | 2004-02-21 18:08:41 +0000 | [diff] [blame] | 151 | OPTS="-ru" |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 152 | # make lib |
| 153 | ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS} |
Brian Paul | 6e450f2 | 2004-02-21 18:08:41 +0000 | [diff] [blame] | 154 | ranlib ${LIBNAME}.a |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 155 | # finish up |
Brian Paul | 6e450f2 | 2004-02-21 18:08:41 +0000 | [diff] [blame] | 156 | FINAL_LIBS=${LIBNAME}.a |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 157 | else |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 158 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
Brian Paul | 5b9a9d4 | 2004-01-17 18:31:12 +0000 | [diff] [blame] | 159 | if [ $ARCH = 'Linux' ] ; then |
| 160 | OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}" |
| 161 | else |
| 162 | OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}" |
| 163 | fi |
Brian Paul | 158a251 | 2004-10-16 15:10:45 +0000 | [diff] [blame] | 164 | if [ $EXPORTS ] ; then |
| 165 | #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}" |
| 166 | # Make the 'exptmp' file for --version-script option |
| 167 | echo "VERSION_${MAJOR}.${MINOR} {" > exptmp |
| 168 | echo "global:" >> exptmp |
| 169 | sed 's/$/;/' ${EXPORTS} >> exptmp |
| 170 | echo "local:" >> exptmp |
| 171 | echo "*;" >> exptmp |
| 172 | echo "};" >> exptmp |
| 173 | OPTS="${OPTS} -Xlinker --version-script=exptmp" |
| 174 | # exptmp is removed below |
| 175 | fi |
Brian Paul | 3e19618 | 2005-03-03 01:38:13 +0000 | [diff] [blame] | 176 | |
| 177 | # Check if objects are 32-bit and we're running in 64-bit |
| 178 | # environment. If so, pass -m32 flag to linker. |
| 179 | set ${OBJECTS} |
| 180 | ABI32=`file $1 | grep 32-bit` |
| 181 | if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then |
| 182 | OPTS="-m32 ${OPTS}" |
| 183 | fi |
| 184 | |
Brian Paul | 6e450f2 | 2004-02-21 18:08:41 +0000 | [diff] [blame] | 185 | if [ x${PATCH} = "x" ] ; then |
| 186 | VERSION="${MAJOR}.${MINOR}" |
| 187 | else |
| 188 | VERSION="${MAJOR}.${MINOR}.${PATCH}" |
| 189 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 190 | |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 191 | echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 192 | |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 193 | if [ $CPLUSPLUS = 1 ] ; then |
Ian Romanick | 9eecb03 | 2004-06-25 22:51:39 +0000 | [diff] [blame] | 194 | LINK=$CXX |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 195 | else |
Ian Romanick | 9eecb03 | 2004-06-25 22:51:39 +0000 | [diff] [blame] | 196 | LINK=$CC |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 197 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 198 | |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 199 | # rm any old libs |
| 200 | rm -f ${LIBNAME}.so.${VERSION} |
| 201 | rm -f ${LIBNAME}.so.${MAJOR} |
| 202 | rm -f ${LIBNAME}.so |
| 203 | |
| 204 | # make lib |
| 205 | ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} |
| 206 | # make usual symlinks |
| 207 | ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} |
| 208 | ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so |
| 209 | # finish up |
| 210 | FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so" |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 211 | # rm -f exptmp |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 212 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 213 | ;; |
| 214 | |
| 215 | 'SunOS') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 216 | if [ $STATIC = 1 ] ; then |
| 217 | LIBNAME="lib${LIBNAME}.a" |
| 218 | echo "mklib: Making SunOS static library: " ${LIBNAME} |
| 219 | rm -f ${LIBNAME} |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 220 | ar -ruv ${LIBNAME} ${OBJECTS} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 221 | FINAL_LIBS=${LIBNAME} |
| 222 | else |
| 223 | LIBNAME="lib${LIBNAME}.so" |
| 224 | echo "mklib: Making SunOS shared library: " ${LIBNAME} |
| 225 | # XXX OPTS for gcc should be -shared, but that doesn't work. |
| 226 | # Using -G does work though. |
| 227 | if [ $CPLUSPLUS = 1 ] ; then |
| 228 | # determine linker and options for C++ code |
| 229 | if [ "x${CXX}" = "xg++" ] ; then |
| 230 | # use g++ |
| 231 | LINK="g++" |
| 232 | OPTS="-G" |
| 233 | elif [ "x${CXX}" = "xCC" ] ; then |
| 234 | # use Sun CC |
| 235 | LINK="CC" |
| 236 | OPTS="-G" |
| 237 | elif [ "x${CXX}" = "xc++" ] ; then |
| 238 | # use Sun c++ |
| 239 | LINK="c++" |
| 240 | OPTS="-G" |
| 241 | elif [ `which c++` ] ; then |
| 242 | # use Sun c++ |
| 243 | LINK="c++" |
| 244 | OPTS="-G" |
| 245 | elif [ `type g++` ] ; then |
| 246 | # use g++ |
| 247 | LINK="g++" |
| 248 | OPTS="-G" |
| 249 | else |
| 250 | echo "mklib: warning: can't find C++ comiler, trying CC." |
| 251 | LINK="CC" |
| 252 | OPTS="-G" |
| 253 | fi |
| 254 | elif [ "x${CC}" = "xgcc" ] ; then |
| 255 | # use gcc for linking |
| 256 | LINK="gcc" |
Brian Paul | 4b60344 | 2004-01-14 23:18:47 +0000 | [diff] [blame] | 257 | OPTS="-G" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 258 | else |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 259 | # use native Sun linker |
| 260 | LINK="ld" |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame] | 261 | OPTS="-G" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 262 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 263 | echo "mklib: linker is" ${LINK} ${OPTS} |
| 264 | rm -f ${LIBNAME}.${MAJOR} ${LIBNAME} |
| 265 | ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS} |
| 266 | ln -s ${LIBNAME}.${MAJOR} ${LIBNAME} |
| 267 | FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 268 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 269 | ;; |
| 270 | |
| 271 | 'FreeBSD') |
Brian Paul | dd74e36 | 2004-04-08 22:26:22 +0000 | [diff] [blame] | 272 | if [ $NOPREFIX = 1 ] ; then |
| 273 | # No "lib" or ".so" part |
| 274 | echo "mklib: Making FreeBSD shared library: " ${LIBNAME} |
| 275 | rm -f ${LIBNAME} |
| 276 | ld -Bshareable -o ${LIBNAME} ${OBJECTS} |
| 277 | FINAL_LIBS=${LIBNAME} |
| 278 | elif [ $STATIC = 1 ] ; then |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 279 | STLIB="lib${LIBNAME}.a" |
| 280 | echo "mklib: Making FreeBSD static library: " ${STLIB} |
| 281 | rm -f ${STLIB} |
| 282 | ar cq ${STLIB} ${OBJECTS} |
| 283 | ranlib ${STLIB} |
| 284 | FINAL_LIBS=${STLIB} |
| 285 | else |
| 286 | SHLIB="lib${LIBNAME}.so.${MAJOR}.${MINOR}" |
| 287 | echo "mklib: Making FreeBSD shared library: " ${SHLIB} |
| 288 | rm -f ${SHLIB} |
| 289 | ld -Bshareable -o ${SHLIB} ${OBJECTS} |
| 290 | # XXX make lib${LIBNAME}.so.${MAJOR} symlink? |
| 291 | FINAL_LIBS=${SHLIB} |
| 292 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 293 | ;; |
| 294 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 295 | 'NetBSD') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 296 | if [ $STATIC = 1 ] ; then |
| 297 | LIBNAME="lib${LIBNAME}_pic.a" |
| 298 | echo "mklib: Making NetBSD PIC static library: " ${LIBNAME} |
| 299 | rm -f ${LIBNAME} |
| 300 | ar cq ${LIBNAME} ${OBJECTS} |
| 301 | ranlib ${LIBNAME} |
| 302 | FINAL_LIBS=${LIBNAME} |
| 303 | else |
| 304 | LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}" |
| 305 | echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME} |
| 306 | rm -f ${LIBNAME} |
| 307 | ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS} |
| 308 | FINAL_LIBS=${LIBNAME} |
| 309 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 310 | ;; |
| 311 | |
Brian Paul | f8c31fc | 2004-01-29 15:21:47 +0000 | [diff] [blame] | 312 | 'IRIX' | 'IRIX64') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 313 | if [ $STATIC = 1 ] ; then |
| 314 | LIBNAME="lib${LIBNAME}.a" |
| 315 | rm -f ${LIBNAME} |
| 316 | ar rc ${LIBNAME} ${OBJECTS} |
| 317 | FINAL_LIBS=${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 318 | else |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 319 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" |
| 320 | if [ $ARCHOPT = "64" ] ; then |
| 321 | # 64-bit ABI |
| 322 | OPTS="-64 -shared -all" |
| 323 | echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME} |
| 324 | elif [ $ARCHOPT = "o32" ] ; then |
| 325 | # old 32-bit ABI |
| 326 | OPTS="-32 -shared -all" |
| 327 | echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME} |
| 328 | else |
| 329 | # new 32-bit ABI |
| 330 | OPTS="-n32 -shared -all" |
| 331 | echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME} |
| 332 | fi |
| 333 | if [ $CPLUSPLUS = 1 ] ; then |
| 334 | LINK="CC" |
| 335 | else |
| 336 | LINK="ld" |
| 337 | fi |
| 338 | ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 339 | FINAL_LIBS=${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 340 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 341 | ;; |
| 342 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 343 | 'linux-cygwin') |
| 344 | LIBNAME="lib${LIBNAME}.a" |
| 345 | echo "mklib: Making linux-cygwin library: " ${LIBNAME} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 346 | rm -f ${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 347 | gnuwin32ar ruv ${LIBNAME} ${OBJECTS} |
| 348 | FINAL_LIBS=${LIBNAME} |
| 349 | ;; |
| 350 | |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 351 | 'HP-UX') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 352 | if [ $STATIC = 1 ] ; then |
| 353 | LIBNAME="lib${LIBNAME}.a" |
Brian Paul | 52fb07e | 2004-03-30 14:47:02 +0000 | [diff] [blame] | 354 | echo "mklib: Making HP-UX static library: " ${LIBNAME} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 355 | rm -f ${LIBNAME} |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 356 | ar -ruv ${LIBNAME} ${OBJECTS} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 357 | FINAL_LIBS=${LIBNAME} |
| 358 | else |
| 359 | RUNLIB="lib${LIBNAME}.${MAJOR}" |
| 360 | DEVLIB="lib${LIBNAME}.sl" |
Brian Paul | 52fb07e | 2004-03-30 14:47:02 +0000 | [diff] [blame] | 361 | echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 362 | ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS} |
| 363 | ln -s ${RUNLIB} ${DEVLIB} |
Brian Paul | ac0cfee | 2004-04-25 15:13:56 +0000 | [diff] [blame] | 364 | FINAL_LIBS="${RUNLIB} ${DEVLIB}" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 365 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 366 | ;; |
| 367 | |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 368 | 'AIX' | 'AIX64') |
| 369 | if [ $ARCH = "AIX64" ] ; then |
| 370 | X64="-X64" |
| 371 | fi |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 372 | |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 373 | if [ $STATIC = 1 ] ; then |
| 374 | LIBNAME="lib${LIBNAME}.a" |
| 375 | echo "mklib: Making AIX static library: " ${LIBNAME} |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 376 | ar -ruv ${X64} ${LIBNAME} ${OBJECTS} |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 377 | FINAL_LIBS=${LIBNAME} |
| 378 | else |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 379 | EXPFILE="lib${LIBNAME}.exp" |
| 380 | OFILE=shr.o #Want to be consistent with the IBM libGL.a |
| 381 | LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 382 | if [ $ARCH = "AIX64" ] ; then |
| 383 | OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry -q64" |
| 384 | else |
| 385 | OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry" |
| 386 | fi |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 387 | rm -f ${EXPFILE} ${OFILE} |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 388 | NM="/bin/nm -eC ${X64}" |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 389 | echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE} |
| 390 | ${NM} ${OBJECTS} | awk '{ |
| 391 | if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \ |
| 392 | && ( substr($1,1,1) != ".")) { |
| 393 | if (substr ($1, 1, 7) != "__sinit" && |
| 394 | substr ($1, 1, 7) != "__sterm") { |
| 395 | if (substr ($1, 1, 5) == "__tf1") |
| 396 | print (substr ($1, 7)) |
| 397 | else if (substr ($1, 1, 5) == "__tf9") |
| 398 | print (substr ($1, 15)) |
| 399 | else |
| 400 | print $1 |
| 401 | } |
| 402 | } |
| 403 | }' | sort -u >> ${EXPFILE} |
| 404 | cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS} |
Brian Paul | b17a1a1 | 2004-11-01 22:28:42 +0000 | [diff] [blame] | 405 | ar ${X64} -r ${LIBNAME} ${OFILE} |
Karl Schultz | a16bdb5 | 2004-10-01 13:33:26 +0000 | [diff] [blame] | 406 | FINAL_LIBS="${LIBNAME}" |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 407 | fi |
| 408 | ;; |
| 409 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 410 | 'OpenSTEP') |
| 411 | LIBNAME="lib${LIBNAME}.a" |
| 412 | echo "mklib: Making OpenSTEP static library: " ${LIBNAME} |
| 413 | libtool -static -o ${LIBNAME} - ${OBJECTS} |
| 414 | FINAL_LIBS=${LIBNAME} |
| 415 | ;; |
| 416 | |
| 417 | 'OSF1') |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 418 | if [ $STATIC = 1 ] ; then |
| 419 | LIBNAME="lib${LIBNAME}.a" |
| 420 | echo "mklib: Making OSF/1 static library: " ${LIBNAME} |
| 421 | rm -f ${LIBNAME} |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 422 | ar -ruv ${LIBNAME} ${OBJECTS} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 423 | FINAL_LIBS=${LIBNAME} |
| 424 | else |
| 425 | VERSION="${MAJOR}.${MINOR}" |
| 426 | LIBNAME="lib${LIBNAME}.so" |
| 427 | echo "mklib: Making OSF/1 shared library: " ${LIBNAME} |
Brian Paul | 0d5e6cc | 2004-11-29 17:23:12 +0000 | [diff] [blame] | 428 | if [ $CPLUSPLUS = 1 ] ; then |
| 429 | LINK=$CXX |
| 430 | else |
| 431 | LINK=$CC |
| 432 | fi |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 433 | rm -f ${LIBNAME}.${VERSION} |
Brian Paul | 0d5e6cc | 2004-11-29 17:23:12 +0000 | [diff] [blame] | 434 | ${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] | 435 | ln -sf ${LIBNAME}.${VERSION} ${LIBNAME} |
| 436 | FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}" |
| 437 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 438 | ;; |
| 439 | |
| 440 | 'Darwin') |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 441 | if [ $STATIC = 1 ] ; then |
| 442 | LIBNAME="lib${LIBNAME}.a" |
| 443 | echo "mklib: Making Darwin static library: " ${LIBNAME} |
| 444 | LINK="ar" |
| 445 | OPTS="-ruv" |
| 446 | ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS} |
| 447 | FINAL_LIBS=${LIBNAME} |
| 448 | else |
Brian Paul | ccda216 | 2005-06-30 02:33:25 +0000 | [diff] [blame] | 449 | LIBNAME="lib${LIBNAME}.dylib" |
Brian Paul | c50d77a | 2004-04-13 17:35:17 +0000 | [diff] [blame] | 450 | echo "mklib: Making Darwin shared library: " ${LIBNAME} |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 451 | FLAGS="-dynamiclib -multiply_defined suppress" |
Brian Paul | c05658d | 2004-03-25 21:18:32 +0000 | [diff] [blame] | 452 | if [ $CPLUSPLUS = 1 ] ; then |
| 453 | LINK="g++" |
| 454 | else |
| 455 | LINK="cc" |
| 456 | fi |
| 457 | ${LINK} ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
Brian Paul | aaba075 | 2004-03-23 23:25:47 +0000 | [diff] [blame] | 458 | FINAL_LIBS=${LIBNAME} |
Brian Paul | c193bd0 | 2004-03-18 15:41:59 +0000 | [diff] [blame] | 459 | fi |
| 460 | ;; |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 461 | |
| 462 | 'LynxOS') |
| 463 | LIBNAME="lib${LIBNAME}.a" |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 464 | echo "mklib: Making LynxOS static library: " ${LIBNAME} |
| 465 | rm -f ${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 466 | ar ru ${LIBNAME} ${OBJECTS} |
| 467 | FINAL_LIBS=${LIBNAME} |
| 468 | ;; |
| 469 | |
| 470 | 'BeOS') |
Philippe Houdoin | ef4dd5a | 2004-08-14 10:12:38 +0000 | [diff] [blame] | 471 | if [ $STATIC = 1 ] ; then |
| 472 | LIBNAME="lib${LIBNAME}.a" |
| 473 | echo "mklib: Making BeOS static library: " ${LIBNAME} |
| 474 | ar -cru "${LIBNAME}" ${OBJECTS} |
| 475 | else |
Brian Paul | b784b8f | 2004-08-14 14:30:36 +0000 | [diff] [blame] | 476 | LIBNAME="lib${LIBNAME}.so" |
| 477 | echo "mklib: Making BeOS shared library: " ${LIBNAME} |
| 478 | gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}" |
| 479 | mimeset -f "${LIBNAME}" |
| 480 | setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!" |
| 481 | fi |
| 482 | FINAL_LIBS=${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 483 | ;; |
| 484 | |
| 485 | 'QNX') |
| 486 | LIBNAME="lib${LIBNAME}.a" |
| 487 | echo "mklib: Making QNX library: " ${LIBNAME} |
| 488 | wlib ${LIBNAME} ${OBJECTS} |
| 489 | FINAL_LIBS=${LIBNAME} |
| 490 | ;; |
| 491 | |
Brian Paul | 65e2ab3 | 2003-10-27 18:13:37 +0000 | [diff] [blame] | 492 | 'MorphOS') |
| 493 | LIBNAME="lib${LIBNAME}.a" |
| 494 | echo "mklib: Making MorphOS library: " ${LIBNAME} |
| 495 | ppc-morphos-ar rc ${LIBNAME} ${OBJECTS} |
| 496 | FINAL_LIBS="${LIBNAME}" |
| 497 | ;; |
| 498 | |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 499 | 'icc') |
| 500 | # Intel C compiler |
| 501 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
| 502 | |
| 503 | if [ $STATIC = 1 ] ; then |
| 504 | echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a |
| 505 | LINK="ar" |
| 506 | OPTS="-ruv" |
| 507 | # make lib |
| 508 | ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS} |
| 509 | # finish up |
| 510 | FINAL_LIBS="${LIBNAME}.a" |
| 511 | else |
| 512 | OPTS="-shared" |
| 513 | VERSION="${MAJOR}.${MINOR}.${PATCH}" |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 514 | echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION} |
| 515 | |
| 516 | if [ $CPLUSPLUS = 1 ] ; then |
| 517 | LINK="icc" |
| 518 | else |
| 519 | LINK="icc" |
| 520 | fi |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 521 | # rm any old libs |
| 522 | rm -f ${LIBNAME}.so.${VERSION} |
| 523 | rm -f ${LIBNAME}.so.${MAJOR} |
| 524 | rm -f ${LIBNAME}.so |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 525 | # make lib |
| 526 | ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} |
| 527 | # make usual symlinks |
| 528 | ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} |
| 529 | ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so |
| 530 | # finish up |
| 531 | FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so" |
| 532 | fi |
| 533 | ;; |
| 534 | |
Brian Paul | 12d6cae | 2004-01-10 22:12:21 +0000 | [diff] [blame] | 535 | 'aix-gcc') |
| 536 | # AIX with gcc |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 537 | if [ $STATIC = 1 ] ; then |
| 538 | LIBNAME="lib${LIBNAME}.a" |
| 539 | echo "mklib: Making AIX GCC static library: " ${LIBNAME} |
| 540 | rm -f ${LIBNAME} |
| 541 | ar ru ${LIBNAME} ${OBJECTS} |
| 542 | FINAL_LIBS=${LIBNAME} |
| 543 | else |
| 544 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" |
| 545 | echo "mklib: Making AIX GCC shared library: " ${LIBNAME} |
| 546 | # remove old lib |
| 547 | rm -f ${LIBNAME} |
| 548 | # make the lib |
| 549 | gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 550 | # NOTE: the application linking with this library must specify |
| 551 | # the -Wl,-brtl flags to gcc |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 552 | FINAL_LIBS=${LIBNAME} |
| 553 | fi |
| 554 | ;; |
| 555 | |
| 556 | 'ultrix') |
| 557 | # XXX untested |
| 558 | if [ $STATIC = 0 ] ; then |
| 559 | echo "mklib: Warning shared libs not supported on Ultrix" |
| 560 | fi |
| 561 | LIBNAME="lib${LIBNAME}.a" |
| 562 | echo "mklib: Making static library for Ultrix: " ${LIBNAME} |
Brian Paul | 12d6cae | 2004-01-10 22:12:21 +0000 | [diff] [blame] | 563 | rm -f ${LIBNAME} |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 564 | ar ru ${LIBNAME} ${OBJECTS} |
| 565 | FINAL_LIBS="${LIBNAME}" |
Brian Paul | 12d6cae | 2004-01-10 22:12:21 +0000 | [diff] [blame] | 566 | ;; |
Brian Paul | b3b725b | 2003-12-15 16:14:55 +0000 | [diff] [blame] | 567 | |
Brian Paul | 580548d | 2004-04-22 16:16:42 +0000 | [diff] [blame] | 568 | CYGWIN*) |
| 569 | # GCC-based environment |
| 570 | CYGNAME="cyg${LIBNAME}" # prefix with "cyg" |
| 571 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
| 572 | |
| 573 | if [ $STATIC = 1 ] ; then |
| 574 | echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a |
| 575 | LINK="ar" |
| 576 | OPTS="-ru" |
| 577 | # make lib |
| 578 | ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS} |
| 579 | ranlib ${LIBNAME}.a |
| 580 | # finish up |
| 581 | FINAL_LIBS=${LIBNAME}.a |
| 582 | else |
| 583 | OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a" |
| 584 | echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll |
| 585 | |
| 586 | if [ $CPLUSPLUS = 1 ] ; then |
| 587 | LINK="g++" |
| 588 | else |
| 589 | LINK="gcc" |
| 590 | fi |
| 591 | |
| 592 | # rm any old libs |
| 593 | rm -f ${LIBNAME}-${MAJOR}.dll |
| 594 | rm -f ${LIBNAME}.dll.a |
| 595 | rm -f ${LIBNAME}.a |
| 596 | |
| 597 | # make lib |
| 598 | ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} |
| 599 | # make usual symlinks |
| 600 | ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a |
| 601 | # finish up |
| 602 | FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a" |
| 603 | # special case for installing in bin |
| 604 | FINAL_BINS="${CYGNAME}-${MAJOR}.dll" |
| 605 | fi |
| 606 | ;; |
| 607 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 608 | 'example') |
| 609 | # If you're adding support for a new architecture, you can |
| 610 | # start with this: |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 611 | if [ $STATIC = 1 ] ; then |
| 612 | LIBNAME="lib${LIBNAME}.a" |
| 613 | echo "mklib: Making static library for example arch: " ${LIBNAME} |
| 614 | rm -f ${LIBNAME} |
| 615 | ar rv ${LIBNAME} ${OBJECTS} |
| 616 | FINAL_LIBS="${LIBNAME}" |
| 617 | else |
| 618 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib" |
| 619 | echo "mklib: Making shared library for example arch: " ${LIBNAME} |
| 620 | ld -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 621 | FINAL_LIBS="${LIBNAME}" |
| 622 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 623 | ;; |
| 624 | |
| 625 | *) |
Brian Paul | 5396ab2 | 2004-02-12 14:48:52 +0000 | [diff] [blame] | 626 | echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH} |
| 627 | echo "mklib: Please add necessary commands to mklib script." |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 628 | ;; |
| 629 | esac |
| 630 | |
| 631 | |
| 632 | # |
| 633 | # Put library files into installation directory if specified. |
| 634 | # |
| 635 | if [ ${INSTALLDIR} != "." ] ; then |
| 636 | echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR} |
| 637 | mv ${FINAL_LIBS} ${INSTALLDIR}/ |
| 638 | fi |