Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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