Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mklib 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. if [ $STATIC = 1 ] ; then
  99. echo "mklib: Making Linux static library: " ${LIBNAME}.a
  100. LINK="ar"
  101. OPTS="-ruv"
  102. # make lib
  103. ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
  104. # finish up
  105. FINAL_LIBS="${LIBNAME}.a"
  106. else
  107. OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  108. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  109. echo "mklib: Making Linux shared library: " ${LIBNAME}.so.${VERSION}
  110. if [ $CPLUSPLUS = 1 ] ; then
  111. LINK="g++"
  112. else
  113. LINK="gcc"
  114. fi
  115. # rm any old libs
  116. rm -f ${LIBNAME}.so.${VERSION}
  117. rm -f ${LIBNAME}.so.${MAJOR}
  118. rm -f ${LIBNAME}.so
  119. # make lib
  120. ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  121. # make usual symlinks
  122. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  123. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  124. # finish up
  125. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  126. fi
  127. ;;
  128. 'SunOS')
  129. LIBNAME="lib${LIBNAME}.so"
  130. echo "mklib: Making SunOS shared library: " ${LIBNAME}
  131. OPTS="-G"
  132. if [ $CPLUSPLUS = 1 ] ; then
  133. # link for C++
  134. if [ "x${CXX}" = "xg++" ] ; then
  135. LINK="g++"
  136. elif [ "x${CXX}" = "xCC" ] ; then
  137. LINK="CC"
  138. elif [ `which c++` ] ; then
  139. LINK="c++"
  140. elif [ `type g++` ] ; then
  141. LINK="g++"
  142. else
  143. echo "mklib: warning: can't find C++ comiler, trying CC."
  144. LINK="CC"
  145. fi
  146. elif [ "x${CC}" = "xgcc" ] ; then
  147. # use gcc for linking
  148. LINK="gcc"
  149. else
  150. # use native Sun linker
  151. LINK="ld"
  152. fi
  153. echo "mklib: linker is " ${LINK}
  154. rm -f ${LIBNAME}
  155. ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  156. FINAL_LIBS=${LIBNAME}
  157. ;;
  158. 'FreeBSD')
  159. SHLIB="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
  160. STLIB="lib${LIBNAME}.a"
  161. echo "mklib: Making FreeBSD shared library: " ${SHLIB}
  162. rm -f ${SHLIB} ${STLIB}
  163. ar cq ${STLIB} ${OBJECTS}
  164. ranlib ${STLIB}
  165. ld -Bshareable -o ${SHLIB} ${OBJECTS}
  166. # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
  167. FINAL_LIBS="${SHLIB} ${STLIB}"
  168. ;;
  169. 'OpenBSD')
  170. LIBNAME="lib${LIBNAME}"
  171. VERSION="${MAJOR}.${MINOR}"
  172. echo "Building OpenBSD PIC library: " ${LIBNAME}
  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. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so
  178. FINAL_LIBS="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION} ${LIBNAME}.so"
  179. ;;
  180. 'NetBSD')
  181. LIBNAME="lib${LIBNAME}"
  182. echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
  183. VERSION="${MAJOR}.${MINOR}"
  184. rm -f ${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}
  185. ar cq ${LIBNAME}_pic.a ${OBJECTS}
  186. ranlib ${LIBNAME}_pic.a
  187. ld -x -Bshareable -Bforcearchive -o ${LIBNAME}.so.${VERSION} ${LIBNAME}_pic.a
  188. FINAL_LIBS="${LIBNAME}_pic.a ${LIBNAME}.so.${VERSION}"
  189. ;;
  190. 'IRIX')
  191. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  192. if [ $ARCHOPTS = "64" ] ; then
  193. # 64-bit ABI
  194. OPTS="-64 -shared -all"
  195. echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
  196. elif [ $ARCHOPTS = "o32" ] ; then
  197. # old 32-bit ABI
  198. OPTS="-32 -shared -all"
  199. echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
  200. else
  201. # new 32-bit ABI
  202. OPTS="-n32 -shared -all"
  203. echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
  204. fi
  205. ld ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  206. FINAL_LIBS="${LIBNAME}"
  207. ;;
  208. 'IRIX64')
  209. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  210. echo "mklib: Making IRIX64 library: " ${LIBNAME}
  211. # 64-bit ABI
  212. OPTS="-64 -shared -all"
  213. ld ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  214. FINAL_LIBS="${LIBNAME}"
  215. ;;
  216. 'linux-cygwin')
  217. LIBNAME="lib${LIBNAME}.a"
  218. echo "mklib: Making linux-cygwin library: " ${LIBNAME}
  219. gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
  220. FINAL_LIBS=${LIBNAME}
  221. ;;
  222. 'HPUX')
  223. RUNLIB="lib${LIBNAME}.${MAJOR}"
  224. DEVLIB="lib${LIBNAME}.sl"
  225. echo "mklib: Making HPUX library: " ${RUNLIB} ${DEVLIB}
  226. ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
  227. ln -s ${RUNLIB} ${DEVLIB}
  228. FINAL_LIBS="{RUNLIB} ${DEVLIB}"
  229. ;;
  230. 'OpenSTEP')
  231. LIBNAME="lib${LIBNAME}.a"
  232. echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
  233. libtool -static -o ${LIBNAME} - ${OBJECTS}
  234. FINAL_LIBS=${LIBNAME}
  235. ;;
  236. 'OSF1')
  237. VERSION="${MAJOR}.${MINOR}"
  238. LIBNAME="lib${LIBNAME}.so"
  239. ARNAME="lib${LIBNAME}.a"
  240. echo "mklib: Making OSF/1 library: " ${LIBNAME}
  241. rm -f ${LIBNAME}.${VERSION}
  242. ld -o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
  243. ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
  244. # also make static lib
  245. rm -f ${ARNAME}
  246. ar clqz ${ARNAME} ${OBJECTS}
  247. FINAL_LIBS="${ARNAME} ${LIBNAME} ${LIBNAME}.${VERSION}"
  248. ;;
  249. 'Darwin')
  250. VERSION="${MAJOR}.${MINOR}.${TINY}"
  251. LIBNAME="lib${LIBNAME}.dylib"
  252. ARNAME="lib${LIBNAME}.dylib.a"
  253. echo "mklib: Making Darwin libraries: " ${LIBNAME} ${ARNAME}
  254. FLAGS="-dynamiclib -multiply_defined suppress"
  255. cc ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  256. # also make regular .a files,
  257. # provided by Danek Duvall (duvall@dhduvall.student.princeton.edu)
  258. ar ruv ${ARNAME} ${OBJECTS}
  259. ranlib ${ARNAME}
  260. FINAL_LIBS="${ARNAME} ${LIBNAME}"
  261. ;;
  262. 'LynxOS')
  263. LIBNAME="lib${LIBNAME}.a"
  264. echo "mklib: Making LynxOS library: " ${LIBNAME}
  265. ar ru ${LIBNAME} ${OBJECTS}
  266. FINAL_LIBS=${LIBNAME}
  267. ;;
  268. 'BeOS')
  269. LIBNAME="lib${LIBNAME}.so"
  270. echo "mklib: Making BeOS shared library: " ${LIBNAME}
  271. gcc -nostart -Xlinker -soname=${LIBNAME} -L/Be/develop/lib/x86 ${OBJECTS} -lbe -o ${LIBNAME}
  272. FINAL_LIBS=${LIBNAME}
  273. ;;
  274. 'QNX')
  275. LIBNAME="lib${LIBNAME}.a"
  276. echo "mklib: Making QNX library: " ${LIBNAME}
  277. wlib ${LIBNAME} ${OBJECTS}
  278. FINAL_LIBS=${LIBNAME}
  279. ;;
  280. 'MorphOS')
  281. LIBNAME="lib${LIBNAME}.a"
  282. echo "mklib: Making MorphOS library: " ${LIBNAME}
  283. ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
  284. FINAL_LIBS="${LIBNAME}"
  285. ;;
  286. 'example')
  287. # If you're adding support for a new architecture, you can
  288. # start with this:
  289. LIBNAME="lib${LIBNAME}.so" # prefix with "lib"
  290. echo "mklib: Making library for example arch: " ${LIBNAME}
  291. ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
  292. FINAL_LIBS="${LIBNAME}"
  293. ;;
  294. *)
  295. echo "mklib: WARNING: making library for unknown platform!"
  296. echo "mklib: WARNING: this may not work!"
  297. echo "mklib: WARNING: please update the bin/mklib script!"
  298. # XXX this is a total hack for Mesa - remove someday
  299. # fall-back to an old mklib.* script
  300. ${MAKELIB} "lib${LIBNAME}.a" ${MAJOR} ${MINOR} ${PATCH} ${OBJECTS}
  301. FINAL_LIBS="${LIBNAME}"
  302. ;;
  303. esac
  304. #
  305. # Put library files into installation directory if specified.
  306. #
  307. if [ ${INSTALLDIR} != "." ] ; then
  308. echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
  309. mv ${FINAL_LIBS} ${INSTALLDIR}/
  310. fi