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