Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Make a shared library. |
| 4 | # Basically do a switch/case depending on the OS and make a shared |
| 5 | # lib conforming to that OS. |
| 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) |
| 20 | # -install DIR move resulting library files to DIR |
| 21 | # -arch ARCH override using `uname` to determine architecture |
| 22 | # -archopt OPT specify an extra achitecture-specific option OPT |
| 23 | # |
| 24 | # The library name should just be "GL" or "GLU", etc. The 'lib' prefix |
| 25 | # will be added here if needed, as well as the ".so" or ".a" suffix, etc. |
| 26 | # |
| 27 | # objects should be: foo.o bar.o etc.o |
| 28 | # |
| 29 | # Environment variables recognized: |
| 30 | # CC C compiler command |
| 31 | # CXX C++ compiler command |
| 32 | # |
| 33 | |
| 34 | |
| 35 | # |
| 36 | # Option defaults |
| 37 | # |
| 38 | LIBNAME="" |
| 39 | MAJOR=1 |
| 40 | MINOR=0 |
| 41 | PATCH=0 |
| 42 | DEPS="" |
| 43 | CPLUSPLUS=0 |
| 44 | STATIC=0 |
| 45 | INSTALLDIR="." |
| 46 | ARCH="auto" |
| 47 | ARCHOPT="" |
| 48 | |
| 49 | |
| 50 | # |
| 51 | # Parse arguments |
| 52 | # |
| 53 | while true |
| 54 | do |
| 55 | case $1 in |
| 56 | '-o') shift 1; LIBNAME=$1;; |
| 57 | '-major') shift 1; MAJOR=$1;; |
| 58 | '-minor') shift 1; MINOR=$1;; |
| 59 | '-patch') shift 1; PATCH=$1;; |
| 60 | -l*) DEPS="$DEPS $1";; |
| 61 | -L*) DEPS="$DEPS $1";; |
| 62 | '-cplusplus') CPLUSPLUS=1;; |
| 63 | '-static') STATIC=1;; |
| 64 | '-install') shift 1; INSTALLDIR=$1;; |
| 65 | '-arch') shift 1; ARCH=$1;; |
| 66 | '-archopt') shift 1; ARCHOPT=$1;; |
| 67 | -*) echo "mklib: Unknown option: " $1 ; exit 1;; |
| 68 | *) break |
| 69 | esac |
| 70 | shift 1 |
| 71 | done |
| 72 | OBJECTS=$@ |
| 73 | |
| 74 | if [ ${ARCH} = "auto" ] ; then |
| 75 | ARCH=`uname` |
| 76 | fi |
| 77 | |
| 78 | |
| 79 | # |
| 80 | # Error checking |
| 81 | # |
| 82 | if [ "x${LIBNAME}" = "x" ] ; then |
| 83 | echo "mklib: Error: no library name specified" |
| 84 | exit 1 |
| 85 | fi |
| 86 | if [ "x${OBJECTS}" = "x" ] ; then |
| 87 | echo "mklib: Error: no object files specified" |
| 88 | exit 1 |
| 89 | fi |
| 90 | |
| 91 | |
| 92 | # |
| 93 | # Debugging info |
| 94 | # |
| 95 | if [ ] ; then |
| 96 | echo "-----------------" |
| 97 | echo ARCH is $ARCH |
| 98 | echo LIBNAME is $LIBNAME |
| 99 | echo MAJOR is $MAJOR |
| 100 | echo MINOR is $MINOR |
| 101 | echo PATCH is $PATCH |
| 102 | echo DEPS are $DEPS |
| 103 | echo "-----------------" |
| 104 | fi |
| 105 | |
| 106 | |
| 107 | # |
| 108 | # OK, make the library now |
| 109 | # |
| 110 | case $ARCH in |
| 111 | |
| 112 | 'Linux') |
| 113 | LIBNAME="lib${LIBNAME}" # prefix with "lib" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 114 | |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 115 | if [ $STATIC = 1 ] ; then |
| 116 | echo "mklib: Making Linux static library: " ${LIBNAME}.a |
| 117 | LINK="ar" |
| 118 | OPTS="-ruv" |
| 119 | # make lib |
| 120 | ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS} |
| 121 | # finish up |
| 122 | FINAL_LIBS="${LIBNAME}.a" |
| 123 | else |
| 124 | OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}" |
| 125 | VERSION="${MAJOR}.${MINOR}.${PATCH}" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 126 | |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 127 | echo "mklib: Making Linux shared library: " ${LIBNAME}.so.${VERSION} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 128 | |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 129 | if [ $CPLUSPLUS = 1 ] ; then |
| 130 | LINK="g++" |
| 131 | else |
| 132 | LINK="gcc" |
| 133 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 134 | |
Brian Paul | 1c4b711 | 2003-10-10 17:58:38 +0000 | [diff] [blame] | 135 | # rm any old libs |
| 136 | rm -f ${LIBNAME}.so.${VERSION} |
| 137 | rm -f ${LIBNAME}.so.${MAJOR} |
| 138 | rm -f ${LIBNAME}.so |
| 139 | |
| 140 | # make lib |
| 141 | ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} |
| 142 | # make usual symlinks |
| 143 | ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} |
| 144 | ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so |
| 145 | # finish up |
| 146 | FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so" |
| 147 | fi |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 148 | ;; |
| 149 | |
| 150 | 'SunOS') |
| 151 | LIBNAME="lib${LIBNAME}.so" |
| 152 | echo "mklib: Making SunOS shared library: " ${LIBNAME} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 153 | if [ $CPLUSPLUS = 1 ] ; then |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 154 | # determine linker and options for C++ code |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 155 | if [ "x${CXX}" = "xg++" ] ; then |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 156 | # use g++ |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 157 | LINK="g++" |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 158 | OPTS="-shared" |
Brian Paul | 1761087 | 2003-09-08 14:59:11 +0000 | [diff] [blame] | 159 | elif [ "x${CXX}" = "xCC" ] ; then |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 160 | # use Sun CC |
Brian Paul | 1761087 | 2003-09-08 14:59:11 +0000 | [diff] [blame] | 161 | LINK="CC" |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 162 | OPTS="-G" |
| 163 | elif [ "x${CXX}" = "xc++" ] ; then |
| 164 | # use Sun c++ |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 165 | LINK="c++" |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 166 | OPTS="-G" |
| 167 | elif [ `which c++` ] ; then |
| 168 | # use Sun c++ |
| 169 | LINK="c++" |
| 170 | OPTS="-G" |
Brian Paul | 1761087 | 2003-09-08 14:59:11 +0000 | [diff] [blame] | 171 | elif [ `type g++` ] ; then |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 172 | # use g++ |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 173 | LINK="g++" |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 174 | OPTS="-shared" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 175 | else |
| 176 | echo "mklib: warning: can't find C++ comiler, trying CC." |
| 177 | LINK="CC" |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 178 | OPTS="-G" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 179 | fi |
| 180 | elif [ "x${CC}" = "xgcc" ] ; then |
| 181 | # use gcc for linking |
| 182 | LINK="gcc" |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 183 | OPTS="-shared" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 184 | else |
| 185 | # use native Sun linker |
| 186 | LINK="ld" |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 187 | OPTS="-G" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 188 | fi |
Brian Paul | 1a644b3 | 2003-12-06 17:57:12 +0000 | [diff] [blame^] | 189 | echo "mklib: linker is" ${LINK} ${OPTS} |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 190 | rm -f ${LIBNAME} |
| 191 | ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 192 | FINAL_LIBS=${LIBNAME} |
| 193 | ;; |
| 194 | |
| 195 | 'FreeBSD') |
| 196 | SHLIB="lib${LIBNAME}.so.${MAJOR}.${MINOR}" |
| 197 | STLIB="lib${LIBNAME}.a" |
| 198 | echo "mklib: Making FreeBSD shared library: " ${SHLIB} |
| 199 | rm -f ${SHLIB} ${STLIB} |
| 200 | ar cq ${STLIB} ${OBJECTS} |
| 201 | ranlib ${STLIB} |
| 202 | ld -Bshareable -o ${SHLIB} ${OBJECTS} |
| 203 | # XXX make lib${LIBNAME}.so.${MAJOR} symlink? |
| 204 | FINAL_LIBS="${SHLIB} ${STLIB}" |
| 205 | ;; |
| 206 | |
| 207 | 'OpenBSD') |
| 208 | LIBNAME="lib${LIBNAME}" |
| 209 | VERSION="${MAJOR}.${MINOR}" |
| 210 | echo "Building OpenBSD PIC library: " ${LIBNAME} |
| 211 | rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION} |
| 212 | ar cq ${LIBNAME}_pic.a ${OBJECTS} |
| 213 | ranlib ${LIBNAME}_pic.a |
| 214 | ld -x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a |
| 215 | ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so |
| 216 | FINAL_LIBS="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION} ${LIBNAME}.so" |
| 217 | ;; |
| 218 | |
| 219 | 'NetBSD') |
| 220 | LIBNAME="lib${LIBNAME}" |
| 221 | echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME} |
| 222 | VERSION="${MAJOR}.${MINOR}" |
| 223 | rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION} |
| 224 | ar cq ${LIBNAME}_pic.a ${OBJECTS} |
| 225 | ranlib ${LIBNAME}_pic.a |
| 226 | ld -x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a |
| 227 | FINAL_LIBS="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}" |
| 228 | ;; |
| 229 | |
| 230 | 'IRIX') |
| 231 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" |
| 232 | if [ $ARCHOPTS = "64" ] ; then |
| 233 | # 64-bit ABI |
| 234 | OPTS="-64 -shared -all" |
| 235 | echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME} |
| 236 | elif [ $ARCHOPTS = "o32" ] ; then |
| 237 | # old 32-bit ABI |
| 238 | OPTS="-32 -shared -all" |
| 239 | echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME} |
| 240 | else |
| 241 | # new 32-bit ABI |
| 242 | OPTS="-n32 -shared -all" |
| 243 | echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME} |
| 244 | fi |
| 245 | ld ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 246 | FINAL_LIBS="${LIBNAME}" |
| 247 | ;; |
| 248 | |
| 249 | 'IRIX64') |
| 250 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" |
| 251 | echo "mklib: Making IRIX64 library: " ${LIBNAME} |
| 252 | # 64-bit ABI |
| 253 | OPTS="-64 -shared -all" |
| 254 | ld ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 255 | FINAL_LIBS="${LIBNAME}" |
| 256 | ;; |
| 257 | |
| 258 | 'linux-cygwin') |
| 259 | LIBNAME="lib${LIBNAME}.a" |
| 260 | echo "mklib: Making linux-cygwin library: " ${LIBNAME} |
| 261 | gnuwin32ar ruv ${LIBNAME} ${OBJECTS} |
| 262 | FINAL_LIBS=${LIBNAME} |
| 263 | ;; |
| 264 | |
| 265 | 'HPUX') |
| 266 | RUNLIB="lib${LIBNAME}.${MAJOR}" |
| 267 | DEVLIB="lib${LIBNAME}.sl" |
| 268 | echo "mklib: Making HPUX library: " ${RUNLIB} ${DEVLIB} |
| 269 | ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS} |
| 270 | ln -s ${RUNLIB} ${DEVLIB} |
| 271 | FINAL_LIBS="{RUNLIB} ${DEVLIB}" |
| 272 | ;; |
| 273 | |
| 274 | 'OpenSTEP') |
| 275 | LIBNAME="lib${LIBNAME}.a" |
| 276 | echo "mklib: Making OpenSTEP static library: " ${LIBNAME} |
| 277 | libtool -static -o ${LIBNAME} - ${OBJECTS} |
| 278 | FINAL_LIBS=${LIBNAME} |
| 279 | ;; |
| 280 | |
| 281 | 'OSF1') |
| 282 | VERSION="${MAJOR}.${MINOR}" |
| 283 | LIBNAME="lib${LIBNAME}.so" |
| 284 | ARNAME="lib${LIBNAME}.a" |
| 285 | echo "mklib: Making OSF/1 library: " ${LIBNAME} |
| 286 | rm -f ${LIBNAME}.${VERSION} |
| 287 | ld -o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS} |
| 288 | ln -sf ${LIBNAME}.${VERSION} ${LIBNAME} |
| 289 | |
| 290 | # also make static lib |
| 291 | rm -f ${ARNAME} |
| 292 | ar clqz ${ARNAME} ${OBJECTS} |
| 293 | FINAL_LIBS="${ARNAME} ${LIBNAME} ${LIBNAME}.${VERSION}" |
| 294 | ;; |
| 295 | |
| 296 | 'Darwin') |
| 297 | VERSION="${MAJOR}.${MINOR}.${TINY}" |
| 298 | LIBNAME="lib${LIBNAME}.dylib" |
| 299 | ARNAME="lib${LIBNAME}.dylib.a" |
| 300 | echo "mklib: Making Darwin libraries: " ${LIBNAME} ${ARNAME} |
| 301 | FLAGS="-dynamiclib -multiply_defined suppress" |
| 302 | cc ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 303 | # also make regular .a files, |
| 304 | # provided by Danek Duvall (duvall@dhduvall.student.princeton.edu) |
| 305 | ar ruv ${ARNAME} ${OBJECTS} |
| 306 | ranlib ${ARNAME} |
| 307 | FINAL_LIBS="${ARNAME} ${LIBNAME}" |
| 308 | ;; |
| 309 | |
| 310 | 'LynxOS') |
| 311 | LIBNAME="lib${LIBNAME}.a" |
| 312 | echo "mklib: Making LynxOS library: " ${LIBNAME} |
| 313 | ar ru ${LIBNAME} ${OBJECTS} |
| 314 | FINAL_LIBS=${LIBNAME} |
| 315 | ;; |
| 316 | |
| 317 | 'BeOS') |
| 318 | LIBNAME="lib${LIBNAME}.so" |
| 319 | echo "mklib: Making BeOS shared library: " ${LIBNAME} |
| 320 | gcc -nostart -Xlinker -soname=${LIBNAME} -L/Be/develop/lib/x86 ${OBJECTS} -lbe -o ${LIBNAME} |
| 321 | FINAL_LIBS=${LIBNAME} |
| 322 | ;; |
| 323 | |
| 324 | 'QNX') |
| 325 | LIBNAME="lib${LIBNAME}.a" |
| 326 | echo "mklib: Making QNX library: " ${LIBNAME} |
| 327 | wlib ${LIBNAME} ${OBJECTS} |
| 328 | FINAL_LIBS=${LIBNAME} |
| 329 | ;; |
| 330 | |
Brian Paul | 65e2ab3 | 2003-10-27 18:13:37 +0000 | [diff] [blame] | 331 | 'MorphOS') |
| 332 | LIBNAME="lib${LIBNAME}.a" |
| 333 | echo "mklib: Making MorphOS library: " ${LIBNAME} |
| 334 | ppc-morphos-ar rc ${LIBNAME} ${OBJECTS} |
| 335 | FINAL_LIBS="${LIBNAME}" |
| 336 | ;; |
| 337 | |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 338 | 'example') |
| 339 | # If you're adding support for a new architecture, you can |
| 340 | # start with this: |
| 341 | LIBNAME="lib${LIBNAME}.so" # prefix with "lib" |
| 342 | echo "mklib: Making library for example arch: " ${LIBNAME} |
| 343 | ld -o ${LIBNAME} ${OBJECTS} ${DEPS} |
| 344 | FINAL_LIBS="${LIBNAME}" |
| 345 | ;; |
| 346 | |
| 347 | *) |
| 348 | echo "mklib: WARNING: making library for unknown platform!" |
| 349 | echo "mklib: WARNING: this may not work!" |
| 350 | echo "mklib: WARNING: please update the bin/mklib script!" |
| 351 | # XXX this is a total hack for Mesa - remove someday |
| 352 | # fall-back to an old mklib.* script |
Brian Paul | f023391 | 2003-11-03 21:59:36 +0000 | [diff] [blame] | 353 | LIBNAME="lib${LIBNAME}.a" |
Brian Paul | e96a121 | 2003-10-27 20:04:43 +0000 | [diff] [blame] | 354 | ${TOP}/${MAKELIB} "lib${LIBNAME}.a" ${MAJOR} ${MINOR} ${PATCH} ${OBJECTS} |
Brian Paul | 65e2ab3 | 2003-10-27 18:13:37 +0000 | [diff] [blame] | 355 | FINAL_LIBS="${LIBNAME}" |
Brian Paul | 8c20c7b | 2003-06-01 16:21:45 +0000 | [diff] [blame] | 356 | ;; |
| 357 | esac |
| 358 | |
| 359 | |
| 360 | # |
| 361 | # Put library files into installation directory if specified. |
| 362 | # |
| 363 | if [ ${INSTALLDIR} != "." ] ; then |
| 364 | echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR} |
| 365 | mv ${FINAL_LIBS} ${INSTALLDIR}/ |
| 366 | fi |