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