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 11KB

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