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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. #!/bin/sh
  2. # Make a shared library.
  3. # Basically do a switch/case depending on the OS and make a shared (or static)
  4. # library 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 file(s) 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=""
  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' | 'OpenBSD')
  98. # GCC-based environment
  99. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  100. if [ $STATIC = 1 ] ; then
  101. echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
  102. LINK="ar"
  103. OPTS="-ru"
  104. # make lib
  105. ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
  106. ranlib ${LIBNAME}.a
  107. # finish up
  108. FINAL_LIBS=${LIBNAME}.a
  109. else
  110. if [ $ARCH = 'Linux' ] ; then
  111. OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  112. else
  113. OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  114. fi
  115. if [ x${PATCH} = "x" ] ; then
  116. VERSION="${MAJOR}.${MINOR}"
  117. else
  118. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  119. fi
  120. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
  121. if [ $CPLUSPLUS = 1 ] ; then
  122. LINK="g++"
  123. else
  124. LINK="gcc"
  125. fi
  126. # rm any old libs
  127. rm -f ${LIBNAME}.so.${VERSION}
  128. rm -f ${LIBNAME}.so.${MAJOR}
  129. rm -f ${LIBNAME}.so
  130. # make lib
  131. ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  132. # make usual symlinks
  133. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  134. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  135. # finish up
  136. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  137. fi
  138. ;;
  139. 'SunOS')
  140. if [ $STATIC = 1 ] ; then
  141. LIBNAME="lib${LIBNAME}.a"
  142. echo "mklib: Making SunOS static library: " ${LIBNAME}
  143. rm -f ${LIBNAME}
  144. ar ru ${LIBNAME} ${OBJECTS}
  145. FINAL_LIBS=${LIBNAME}
  146. else
  147. LIBNAME="lib${LIBNAME}.so"
  148. echo "mklib: Making SunOS shared library: " ${LIBNAME}
  149. # XXX OPTS for gcc should be -shared, but that doesn't work.
  150. # Using -G does work though.
  151. if [ $CPLUSPLUS = 1 ] ; then
  152. # determine linker and options for C++ code
  153. if [ "x${CXX}" = "xg++" ] ; then
  154. # use g++
  155. LINK="g++"
  156. OPTS="-G"
  157. elif [ "x${CXX}" = "xCC" ] ; then
  158. # use Sun CC
  159. LINK="CC"
  160. OPTS="-G"
  161. elif [ "x${CXX}" = "xc++" ] ; then
  162. # use Sun c++
  163. LINK="c++"
  164. OPTS="-G"
  165. elif [ `which c++` ] ; then
  166. # use Sun c++
  167. LINK="c++"
  168. OPTS="-G"
  169. elif [ `type g++` ] ; then
  170. # use g++
  171. LINK="g++"
  172. OPTS="-G"
  173. else
  174. echo "mklib: warning: can't find C++ comiler, trying CC."
  175. LINK="CC"
  176. OPTS="-G"
  177. fi
  178. elif [ "x${CC}" = "xgcc" ] ; then
  179. # use gcc for linking
  180. LINK="gcc"
  181. OPTS="-G"
  182. else
  183. # use native Sun linker
  184. LINK="ld"
  185. OPTS="-G"
  186. fi
  187. echo "mklib: linker is" ${LINK} ${OPTS}
  188. rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
  189. ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
  190. ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
  191. FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
  192. fi
  193. ;;
  194. 'FreeBSD')
  195. if [ $STATIC = 1 ] ; then
  196. STLIB="lib${LIBNAME}.a"
  197. echo "mklib: Making FreeBSD static library: " ${STLIB}
  198. rm -f ${STLIB}
  199. ar cq ${STLIB} ${OBJECTS}
  200. ranlib ${STLIB}
  201. FINAL_LIBS=${STLIB}
  202. else
  203. SHLIB="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
  204. echo "mklib: Making FreeBSD shared library: " ${SHLIB}
  205. rm -f ${SHLIB}
  206. ld -Bshareable -o ${SHLIB} ${OBJECTS}
  207. # XXX make lib${LIBNAME}.so.${MAJOR} symlink?
  208. FINAL_LIBS=${SHLIB}
  209. fi
  210. ;;
  211. 'NetBSD')
  212. if [ $STATIC = 1 ] ; then
  213. LIBNAME="lib${LIBNAME}_pic.a"
  214. echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
  215. rm -f ${LIBNAME}
  216. ar cq ${LIBNAME} ${OBJECTS}
  217. ranlib ${LIBNAME}
  218. FINAL_LIBS=${LIBNAME}
  219. else
  220. LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
  221. echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
  222. rm -f ${LIBNAME}
  223. ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
  224. FINAL_LIBS=${LIBNAME}
  225. fi
  226. ;;
  227. 'IRIX' | 'IRIX64')
  228. if [ $STATIC = 1 ] ; then
  229. LIBNAME="lib${LIBNAME}.a"
  230. rm -f ${LIBNAME}
  231. ar rc ${LIBNAME} ${OBJECTS}
  232. FINAL_LIBS=${LIBNAME}
  233. else
  234. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  235. if [ $ARCHOPT = "64" ] ; then
  236. # 64-bit ABI
  237. OPTS="-64 -shared -all"
  238. echo "mklib: Making IRIX 64-bit shared library: " ${LIBNAME}
  239. elif [ $ARCHOPT = "o32" ] ; then
  240. # old 32-bit ABI
  241. OPTS="-32 -shared -all"
  242. echo "mklib: Making IRIX o32-bit shared library: " ${LIBNAME}
  243. else
  244. # new 32-bit ABI
  245. OPTS="-n32 -shared -all"
  246. echo "mklib: Making IRIX n32-bit shared library: " ${LIBNAME}
  247. fi
  248. if [ $CPLUSPLUS = 1 ] ; then
  249. LINK="CC"
  250. else
  251. LINK="ld"
  252. fi
  253. ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  254. FINAL_LIBS=${LIBNAME}
  255. fi
  256. ;;
  257. 'linux-cygwin')
  258. LIBNAME="lib${LIBNAME}.a"
  259. echo "mklib: Making linux-cygwin library: " ${LIBNAME}
  260. rm -f ${LIBNAME}
  261. gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
  262. FINAL_LIBS=${LIBNAME}
  263. ;;
  264. 'HPUX')
  265. if [ $STATIC = 1 ] ; then
  266. LIBNAME="lib${LIBNAME}.a"
  267. echo "mklib: Making HPUX static library: " ${LIBNAME}
  268. rm -f ${LIBNAME}
  269. ar ru ${LIBNAME} ${OBJECTS}
  270. FINAL_LIBS=${LIBNAME}
  271. else
  272. RUNLIB="lib${LIBNAME}.${MAJOR}"
  273. DEVLIB="lib${LIBNAME}.sl"
  274. echo "mklib: Making HPUX stared library: " ${RUNLIB} ${DEVLIB}
  275. ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
  276. ln -s ${RUNLIB} ${DEVLIB}
  277. FINAL_LIBS="{RUNLIB} ${DEVLIB}"
  278. fi
  279. ;;
  280. 'OpenSTEP')
  281. LIBNAME="lib${LIBNAME}.a"
  282. echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
  283. libtool -static -o ${LIBNAME} - ${OBJECTS}
  284. FINAL_LIBS=${LIBNAME}
  285. ;;
  286. 'OSF1')
  287. if [ $STATIC = 1 ] ; then
  288. LIBNAME="lib${LIBNAME}.a"
  289. echo "mklib: Making OSF/1 static library: " ${LIBNAME}
  290. rm -f ${LIBNAME}
  291. ar clqz ${LIBNAME} ${OBJECTS}
  292. FINAL_LIBS=${LIBNAME}
  293. else
  294. VERSION="${MAJOR}.${MINOR}"
  295. LIBNAME="lib${LIBNAME}.so"
  296. echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
  297. rm -f ${LIBNAME}.${VERSION}
  298. ld -o ${LIBNAME}.${VERSION} -shared -no_archive -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
  299. ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
  300. FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
  301. fi
  302. ;;
  303. 'Darwin')
  304. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  305. ARNAME="lib${LIBNAME}.dylib.a"
  306. LIBNAME="lib${LIBNAME}.dylib"
  307. echo "mklib: Making Darwin libraries: " ${LIBNAME} ${ARNAME}
  308. FLAGS="-dynamiclib -multiply_defined suppress"
  309. cc ${FLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  310. # also make regular .a files,
  311. # provided by Danek Duvall (duvall@dhduvall.student.princeton.edu)
  312. rm -f ${ARNAME}
  313. ar ruv ${ARNAME} ${OBJECTS}
  314. ranlib ${ARNAME}
  315. FINAL_LIBS="${ARNAME} ${LIBNAME}"
  316. ;;
  317. 'LynxOS')
  318. LIBNAME="lib${LIBNAME}.a"
  319. echo "mklib: Making LynxOS static library: " ${LIBNAME}
  320. rm -f ${LIBNAME}
  321. ar ru ${LIBNAME} ${OBJECTS}
  322. FINAL_LIBS=${LIBNAME}
  323. ;;
  324. 'BeOS')
  325. LIBNAME="lib${LIBNAME}.so"
  326. echo "mklib: Making BeOS shared library: " ${LIBNAME}
  327. gcc -nostart -Xlinker -soname=${LIBNAME} -L/Be/develop/lib/x86 ${OBJECTS} -lbe -o ${LIBNAME}
  328. FINAL_LIBS=${LIBNAME}
  329. ;;
  330. 'QNX')
  331. LIBNAME="lib${LIBNAME}.a"
  332. echo "mklib: Making QNX library: " ${LIBNAME}
  333. wlib ${LIBNAME} ${OBJECTS}
  334. FINAL_LIBS=${LIBNAME}
  335. ;;
  336. 'MorphOS')
  337. LIBNAME="lib${LIBNAME}.a"
  338. echo "mklib: Making MorphOS library: " ${LIBNAME}
  339. ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
  340. FINAL_LIBS="${LIBNAME}"
  341. ;;
  342. 'icc')
  343. # Intel C compiler
  344. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  345. if [ $STATIC = 1 ] ; then
  346. echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
  347. LINK="ar"
  348. OPTS="-ruv"
  349. # make lib
  350. ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
  351. # finish up
  352. FINAL_LIBS="${LIBNAME}.a"
  353. else
  354. OPTS="-shared"
  355. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  356. echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
  357. if [ $CPLUSPLUS = 1 ] ; then
  358. LINK="icc"
  359. else
  360. LINK="icc"
  361. fi
  362. # rm any old libs
  363. rm -f ${LIBNAME}.so.${VERSION}
  364. rm -f ${LIBNAME}.so.${MAJOR}
  365. rm -f ${LIBNAME}.so
  366. # make lib
  367. ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  368. # make usual symlinks
  369. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  370. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  371. # finish up
  372. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  373. fi
  374. ;;
  375. 'aix-gcc')
  376. # AIX with gcc
  377. if [ $STATIC = 1 ] ; then
  378. LIBNAME="lib${LIBNAME}.a"
  379. echo "mklib: Making AIX GCC static library: " ${LIBNAME}
  380. rm -f ${LIBNAME}
  381. ar ru ${LIBNAME} ${OBJECTS}
  382. FINAL_LIBS=${LIBNAME}
  383. else
  384. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  385. echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
  386. # remove old lib
  387. rm -f ${LIBNAME}
  388. # make the lib
  389. gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
  390. # NOTE: the application linking with this library must specify
  391. # the -Wl,-brtl flags to gcc
  392. FINAL_LIBS=${LIBNAME}
  393. fi
  394. ;;
  395. 'ultrix')
  396. # XXX untested
  397. if [ $STATIC = 0 ] ; then
  398. echo "mklib: Warning shared libs not supported on Ultrix"
  399. fi
  400. LIBNAME="lib${LIBNAME}.a"
  401. echo "mklib: Making static library for Ultrix: " ${LIBNAME}
  402. rm -f ${LIBNAME}
  403. ar ru ${LIBNAME} ${OBJECTS}
  404. FINAL_LIBS="${LIBNAME}"
  405. ;;
  406. 'example')
  407. # If you're adding support for a new architecture, you can
  408. # start with this:
  409. if [ $STATIC = 1 ] ; then
  410. LIBNAME="lib${LIBNAME}.a"
  411. echo "mklib: Making static library for example arch: " ${LIBNAME}
  412. rm -f ${LIBNAME}
  413. ar rv ${LIBNAME} ${OBJECTS}
  414. FINAL_LIBS="${LIBNAME}"
  415. else
  416. LIBNAME="lib${LIBNAME}.so" # prefix with "lib"
  417. echo "mklib: Making shared library for example arch: " ${LIBNAME}
  418. ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
  419. FINAL_LIBS="${LIBNAME}"
  420. fi
  421. ;;
  422. *)
  423. echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
  424. echo "mklib: Please add necessary commands to mklib script."
  425. ;;
  426. esac
  427. #
  428. # Put library files into installation directory if specified.
  429. #
  430. if [ ${INSTALLDIR} != "." ] ; then
  431. echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
  432. mv ${FINAL_LIBS} ${INSTALLDIR}/
  433. fi