Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

mklib 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 [ "x${CXX}" = "xCC" ] ; then
  127. LINK="CC"
  128. elif [ `which c++` ] ; then
  129. LINK="c++"
  130. elif [ `type 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. echo "mklib: linker is " ${LINK}
  144. rm -f ${LIBNAME}
  145. ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  146. FINAL_LIBS=${LIBNAME}
  147. ;;
  148. 'FreeBSD')
  149. SHLIB="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
  150. STLIB="lib${LIBNAME}.a"
  151. echo "mklib: Making FreeBSD shared library: " ${SHLIB}
  152. rm -f ${SHLIB} ${STLIB}
  153. ar cq ${STLIB} ${OBJECTS}
  154. ranlib ${STLIB}
  155. ld -Bshareable -o ${SHLIB} ${OBJECTS}
  156. # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
  157. FINAL_LIBS="${SHLIB} ${STLIB}"
  158. ;;
  159. 'OpenBSD')
  160. LIBNAME="lib${LIBNAME}"
  161. VERSION="${MAJOR}.${MINOR}"
  162. echo "Building OpenBSD PIC library: " ${LIBNAME}
  163. rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}
  164. ar cq ${LIBNAME}_pic.a ${OBJECTS}
  165. ranlib ${LIBNAME}_pic.a
  166. ld -x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a
  167. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so
  168. FINAL_LIBS="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION} ${LIBNAME}.so"
  169. ;;
  170. 'NetBSD')
  171. LIBNAME="lib${LIBNAME}"
  172. echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
  173. VERSION="${MAJOR}.${MINOR}"
  174. rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}
  175. ar cq ${LIBNAME}_pic.a ${OBJECTS}
  176. ranlib ${LIBNAME}_pic.a
  177. ld -x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a
  178. FINAL_LIBS="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}"
  179. ;;
  180. 'IRIX')
  181. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  182. if [ $ARCHOPTS = "64" ] ; then
  183. # 64-bit ABI
  184. OPTS="-64 -shared -all"
  185. echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
  186. elif [ $ARCHOPTS = "o32" ] ; then
  187. # old 32-bit ABI
  188. OPTS="-32 -shared -all"
  189. echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
  190. else
  191. # new 32-bit ABI
  192. OPTS="-n32 -shared -all"
  193. echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
  194. fi
  195. ld ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  196. FINAL_LIBS="${LIBNAME}"
  197. ;;
  198. 'IRIX64')
  199. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  200. echo "mklib: Making IRIX64 library: " ${LIBNAME}
  201. # 64-bit ABI
  202. OPTS="-64 -shared -all"
  203. ld ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  204. FINAL_LIBS="${LIBNAME}"
  205. ;;
  206. 'linux-cygwin')
  207. LIBNAME="lib${LIBNAME}.a"
  208. echo "mklib: Making linux-cygwin library: " ${LIBNAME}
  209. gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
  210. FINAL_LIBS=${LIBNAME}
  211. ;;
  212. 'HPUX')
  213. RUNLIB="lib${LIBNAME}.${MAJOR}"
  214. DEVLIB="lib${LIBNAME}.sl"
  215. echo "mklib: Making HPUX library: " ${RUNLIB} ${DEVLIB}
  216. ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
  217. ln -s ${RUNLIB} ${DEVLIB}
  218. FINAL_LIBS="{RUNLIB} ${DEVLIB}"
  219. ;;
  220. 'OpenSTEP')
  221. LIBNAME="lib${LIBNAME}.a"
  222. echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
  223. libtool -static -o ${LIBNAME} - ${OBJECTS}
  224. FINAL_LIBS=${LIBNAME}
  225. ;;
  226. 'OSF1')
  227. VERSION="${MAJOR}.${MINOR}"
  228. LIBNAME="lib${LIBNAME}.so"
  229. ARNAME="lib${LIBNAME}.a"
  230. echo "mklib: Making OSF/1 library: " ${LIBNAME}
  231. rm -f ${LIBNAME}.${VERSION}
  232. ld -o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
  233. ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
  234. # also make static lib
  235. rm -f ${ARNAME}
  236. ar clqz ${ARNAME} ${OBJECTS}
  237. FINAL_LIBS="${ARNAME} ${LIBNAME} ${LIBNAME}.${VERSION}"
  238. ;;
  239. 'Darwin')
  240. VERSION="${MAJOR}.${MINOR}.${TINY}"
  241. LIBNAME="lib${LIBNAME}.dylib"
  242. ARNAME="lib${LIBNAME}.dylib.a"
  243. echo "mklib: Making Darwin libraries: " ${LIBNAME} ${ARNAME}
  244. FLAGS="-dynamiclib -multiply_defined suppress"
  245. cc ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  246. # also make regular .a files,
  247. # provided by Danek Duvall (duvall@dhduvall.student.princeton.edu)
  248. ar ruv ${ARNAME} ${OBJECTS}
  249. ranlib ${ARNAME}
  250. FINAL_LIBS="${ARNAME} ${LIBNAME}"
  251. ;;
  252. 'LynxOS')
  253. LIBNAME="lib${LIBNAME}.a"
  254. echo "mklib: Making LynxOS library: " ${LIBNAME}
  255. ar ru ${LIBNAME} ${OBJECTS}
  256. FINAL_LIBS=${LIBNAME}
  257. ;;
  258. 'BeOS')
  259. LIBNAME="lib${LIBNAME}.so"
  260. echo "mklib: Making BeOS shared library: " ${LIBNAME}
  261. gcc -nostart -Xlinker -soname=${LIBNAME} -L/Be/develop/lib/x86 ${OBJECTS} -lbe -o ${LIBNAME}
  262. FINAL_LIBS=${LIBNAME}
  263. ;;
  264. 'QNX')
  265. LIBNAME="lib${LIBNAME}.a"
  266. echo "mklib: Making QNX library: " ${LIBNAME}
  267. wlib ${LIBNAME} ${OBJECTS}
  268. FINAL_LIBS=${LIBNAME}
  269. ;;
  270. 'example')
  271. # If you're adding support for a new architecture, you can
  272. # start with this:
  273. LIBNAME="lib${LIBNAME}.so" # prefix with "lib"
  274. echo "mklib: Making library for example arch: " ${LIBNAME}
  275. ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
  276. FINAL_LIBS="${LIBNAME}"
  277. ;;
  278. *)
  279. echo "mklib: WARNING: making library for unknown platform!"
  280. echo "mklib: WARNING: this may not work!"
  281. echo "mklib: WARNING: please update the bin/mklib script!"
  282. # XXX this is a total hack for Mesa - remove someday
  283. # fall-back to an old mklib.* script
  284. ${MAKELIB} "lib${LIBNAME}.a" ${MAJOR} ${MINOR} ${PATCH} ${OBJECTS}
  285. ;;
  286. esac
  287. #
  288. # Put library files into installation directory if specified.
  289. #
  290. if [ ${INSTALLDIR} != "." ] ; then
  291. echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
  292. mv ${FINAL_LIBS} ${INSTALLDIR}/
  293. fi