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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. #!/bin/sh
  2. # Make a shared library.
  3. # This script should be useful for projects other than Mesa.
  4. # Improvements/fixes are welcome.
  5. # Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a
  8. # copy of this software and associated documentation files (the "Software"),
  9. # to deal in the Software without restriction, including without limitation
  10. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. # and/or sell copies of the Software, and to permit persons to whom the
  12. # Software is furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included
  15. # in all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. # BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  21. # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. #
  24. # Option defaults
  25. #
  26. LIBNAME=""
  27. MAJOR=1
  28. MINOR=0
  29. PATCH=""
  30. DEPS=""
  31. LINK=""
  32. CPLUSPLUS=0
  33. STATIC=0
  34. DLOPEN=0
  35. INSTALLDIR="."
  36. ARCH="auto"
  37. ARCHOPT=""
  38. NOPREFIX=0
  39. EXPORTS=""
  40. #
  41. # Parse arguments
  42. #
  43. while true
  44. do
  45. case $1 in
  46. '-h' | '--help')
  47. echo 'Usage: mklib [options] objects'
  48. echo 'Create a shared library from object files.'
  49. echo ' -o LIBRARY specifies the name of the resulting library, without'
  50. echo ' the leading "lib" or any suffix.'
  51. echo ' (eg: "-o GL" might result in "libGL.so" being made)'
  52. echo ' -major N specifies major version number (default is 1)'
  53. echo ' -minor N specifies minor version number (default is 0)'
  54. echo ' -patch N specifies patch version number (default is 0)'
  55. echo ' -lLIBRARY specifies a dependency on LIBRARY'
  56. echo ' -LDIR search in DIR for library dependencies'
  57. echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
  58. echo ' Not observed on all systems at this time.'
  59. echo ' -cplusplus link with C++ runtime'
  60. echo ' -static make a static library (default is dynamic/shared)'
  61. echo ' -dlopen make a shared library suitable for dynamic loading'
  62. echo ' -install DIR put resulting library file(s) in DIR'
  63. echo ' -arch ARCH override using `uname` to determine host system'
  64. echo ' -archopt OPT specify an extra achitecture-specific option OPT'
  65. echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
  66. echo ' -exports FILE only export the symbols listed in FILE'
  67. echo ' -h, --help display this information and exit'
  68. exit 1
  69. ;;
  70. '-o')
  71. shift 1;
  72. LIBNAME=$1
  73. ;;
  74. '-major')
  75. shift 1;
  76. MAJOR=$1
  77. ;;
  78. '-minor')
  79. shift 1;
  80. MINOR=$1
  81. ;;
  82. '-patch')
  83. shift 1;
  84. PATCH=$1
  85. ;;
  86. '-linker')
  87. shift 1;
  88. LINK=$1
  89. ;;
  90. -l*)
  91. DEPS="$DEPS $1"
  92. ;;
  93. -L*)
  94. DEPS="$DEPS $1"
  95. ;;
  96. '-cplusplus')
  97. CPLUSPLUS=1
  98. ;;
  99. '-static')
  100. STATIC=1
  101. ;;
  102. '-dlopen')
  103. DLOPEN=1
  104. ;;
  105. '-install')
  106. shift 1;
  107. INSTALLDIR=$1
  108. ;;
  109. '-arch')
  110. shift 1;
  111. ARCH=$1
  112. ;;
  113. '-archopt')
  114. shift 1;
  115. ARCHOPT=$1
  116. ;;
  117. '-noprefix')
  118. NOPREFIX=1
  119. ;;
  120. '-exports')
  121. shift 1;
  122. EXPORTS=$1
  123. ;;
  124. -*)
  125. echo "mklib: Unknown option: " $1 ;
  126. exit 1
  127. ;;
  128. *)
  129. # This should be the first object file, stop parsing
  130. break
  131. esac
  132. shift 1
  133. done
  134. OBJECTS=$@
  135. if [ ${ARCH} = "auto" ] ; then
  136. ARCH=`uname`
  137. fi
  138. #
  139. # Error checking
  140. #
  141. if [ "x${LIBNAME}" = "x" ] ; then
  142. echo "mklib: Error: no library name specified"
  143. exit 1
  144. fi
  145. if [ "x${OBJECTS}" = "x" ] ; then
  146. echo "mklib: Error: no object files specified"
  147. exit 1
  148. fi
  149. #
  150. # Debugging info
  151. #
  152. if [ ] ; then
  153. echo "-----------------"
  154. echo ARCH is $ARCH
  155. echo LIBNAME is $LIBNAME
  156. echo MAJOR is $MAJOR
  157. echo MINOR is $MINOR
  158. echo PATCH is $PATCH
  159. echo DEPS are $DEPS
  160. echo "EXPORTS in" $EXPORTS
  161. echo "-----------------"
  162. fi
  163. #
  164. # OK, make the library now
  165. #
  166. case $ARCH in
  167. 'Linux' | 'OpenBSD' | 'GNU' | GNU/*)
  168. # we assume gcc
  169. if [ "x$LINK" = "x" ] ; then
  170. # -linker was not specified so set default link command now
  171. if [ $CPLUSPLUS = 1 ] ; then
  172. LINK=g++
  173. else
  174. LINK=gcc
  175. fi
  176. fi
  177. if [ $NOPREFIX = 1 ] ; then
  178. # No "lib" or ".so" part
  179. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
  180. #OPTS="-shared -Wl,-soname,${LIBNAME}" # soname???
  181. OPTS="-shared"
  182. # Check if objects are 32-bit and we're running in 64-bit
  183. # environment. If so, pass -m32 flag to linker.
  184. set ${OBJECTS}
  185. ABI32=`file $1 | grep 32-bit`
  186. if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
  187. OPTS="-m32 ${OPTS}"
  188. fi
  189. rm -f ${LIBNAME}
  190. # make lib
  191. ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  192. # finish up
  193. FINAL_LIBS="${LIBNAME}"
  194. elif [ $STATIC = 1 ] ; then
  195. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  196. echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
  197. LINK="ar"
  198. OPTS="-ru"
  199. # make lib
  200. ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
  201. ranlib ${LIBNAME}.a
  202. # finish up
  203. FINAL_LIBS=${LIBNAME}.a
  204. else
  205. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  206. case $ARCH in 'Linux' | 'GNU' | GNU/*)
  207. OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  208. ;;
  209. *)
  210. OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  211. ;;
  212. esac
  213. if [ $EXPORTS ] ; then
  214. #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
  215. # Make the 'exptmp' file for --version-script option
  216. echo "VERSION_${MAJOR}.${MINOR} {" > exptmp
  217. echo "global:" >> exptmp
  218. sed 's/$/;/' ${EXPORTS} >> exptmp
  219. echo "local:" >> exptmp
  220. echo "*;" >> exptmp
  221. echo "};" >> exptmp
  222. OPTS="${OPTS} -Xlinker --version-script=exptmp"
  223. # exptmp is removed below
  224. fi
  225. # Check if objects are 32-bit and we're running in 64-bit
  226. # environment. If so, pass -m32 flag to linker.
  227. set ${OBJECTS}
  228. ABI32=`file $1 | grep 32-bit`
  229. if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
  230. OPTS="-m32 ${OPTS}"
  231. fi
  232. if [ x${PATCH} = "x" ] ; then
  233. VERSION="${MAJOR}.${MINOR}"
  234. else
  235. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  236. fi
  237. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
  238. # rm any old libs
  239. rm -f ${LIBNAME}.so.${VERSION}
  240. rm -f ${LIBNAME}.so.${MAJOR}
  241. rm -f ${LIBNAME}.so
  242. # make lib
  243. ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  244. # make usual symlinks
  245. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  246. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  247. # finish up
  248. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  249. # rm -f exptmp
  250. fi
  251. ;;
  252. 'SunOS')
  253. if [ $STATIC = 1 ] ; then
  254. LIBNAME="lib${LIBNAME}.a"
  255. echo "mklib: Making SunOS static library: " ${LIBNAME}
  256. rm -f ${LIBNAME}
  257. ar -ruv ${LIBNAME} ${OBJECTS}
  258. FINAL_LIBS=${LIBNAME}
  259. else
  260. LIBNAME="lib${LIBNAME}.so"
  261. echo "mklib: Making SunOS shared library: " ${LIBNAME}
  262. if [ "x$LINK" = "x" ] ; then
  263. # -linker was not specified, choose default linker now
  264. if [ $CPLUSPLUS = 1 ] ; then
  265. # determine linker and options for C++ code
  266. if [ `which c++` ] ; then
  267. # use Sun c++
  268. LINK="c++"
  269. elif [ `type g++` ] ; then
  270. # use g++
  271. LINK="g++"
  272. else
  273. echo "mklib: warning: can't find C++ comiler, trying CC."
  274. LINK="CC"
  275. fi
  276. else
  277. # use native Sun linker for C code
  278. LINK="ld"
  279. fi
  280. fi
  281. # linker options
  282. if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
  283. # SunOS tools, -G to make shared libs
  284. OPTS="-G"
  285. else
  286. # gcc linker
  287. # Check if objects are 32-bit and we're running in 64-bit
  288. # environment. If so, pass -m32 flag to linker.
  289. set ${OBJECTS}
  290. ABI32=`file $1 | grep 32-bit`
  291. if [ "${ABI32}" ] ; then
  292. OPTS="-m32 -shared -Wl,-Bdynamic"
  293. else
  294. OPTS="-m64 -shared -Wl,-Bdynamic"
  295. fi
  296. fi
  297. # Check if objects are SPARC v9
  298. # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
  299. set ${OBJECTS}
  300. SPARCV9=`file $1 | grep SPARCV9`
  301. if [ "${SPARCV9}" ] ; then
  302. OPTS="${OPTS} -xarch=v9"
  303. fi
  304. # for debug:
  305. #echo "mklib: linker is" ${LINK} ${OPTS}
  306. rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
  307. ${LINK} ${OPTS} -o ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
  308. ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
  309. FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
  310. fi
  311. ;;
  312. 'FreeBSD')
  313. # we assume gcc
  314. if [ "x$LINK" = "x" ] ; then
  315. # -linker was not specified so set default link command now
  316. if [ $CPLUSPLUS = 1 ] ; then
  317. LINK=g++
  318. else
  319. LINK=gcc
  320. fi
  321. fi
  322. if [ $NOPREFIX = 1 ] ; then
  323. # No "lib" or ".so" part
  324. echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
  325. OPTS="-shared"
  326. rm -f ${LIBNAME}
  327. ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  328. FINAL_LIBS=${LIBNAME}
  329. elif [ $STATIC = 1 ] ; then
  330. STLIB="lib${LIBNAME}.a"
  331. echo "mklib: Making FreeBSD static library: " ${STLIB}
  332. rm -f ${STLIB}
  333. ar cq ${STLIB} ${OBJECTS}
  334. ranlib ${STLIB}
  335. FINAL_LIBS=${STLIB}
  336. else
  337. SHLIB="lib${LIBNAME}.so.${MAJOR}"
  338. OPTS="-shared -Wl,-soname,${SHLIB}"
  339. echo "mklib: Making FreeBSD shared library: " ${SHLIB}
  340. rm -f ${SHLIB}
  341. ${LINK} ${OPTS} -o ${SHLIB} ${OBJECTS} ${DEPS}
  342. ln -sf ${SHLIB} "lib${LIBNAME}.so"
  343. FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
  344. fi
  345. ;;
  346. 'NetBSD')
  347. if [ $STATIC = 1 ] ; then
  348. LIBNAME="lib${LIBNAME}_pic.a"
  349. echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
  350. rm -f ${LIBNAME}
  351. ar cq ${LIBNAME} ${OBJECTS}
  352. ranlib ${LIBNAME}
  353. FINAL_LIBS=${LIBNAME}
  354. else
  355. LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
  356. echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
  357. rm -f ${LIBNAME}
  358. ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
  359. FINAL_LIBS=${LIBNAME}
  360. fi
  361. ;;
  362. 'IRIX' | 'IRIX64')
  363. if [ $STATIC = 1 ] ; then
  364. LIBNAME="lib${LIBNAME}.a"
  365. rm -f ${LIBNAME}
  366. ar rc ${LIBNAME} ${OBJECTS}
  367. FINAL_LIBS=${LIBNAME}
  368. else
  369. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  370. # examine first object to determine ABI
  371. set ${OBJECTS}
  372. ABI_O32=`file $1 | grep 'ELF 32-bit'`
  373. ABI_N32=`file $1 | grep 'ELF N32'`
  374. ABI_N64=`file $1 | grep 'ELF 64-bit'`
  375. if [ "${ABI_O32}" ] ; then
  376. OPTS="-32 -shared -all"
  377. ABI="o32-bit"
  378. elif [ "${ABI_N32}" ] ; then
  379. OPTS="-n32 -shared -all"
  380. ABI="n32-bit"
  381. elif [ "${ABI_N64}" ] ; then
  382. OPTS="-64 -shared -all"
  383. ABI="64-bit"
  384. else
  385. echo "Error: Unexpected IRIX ABI!"
  386. exit 1
  387. fi
  388. if [ $CPLUSPLUS = 1 ] ; then
  389. LINK="CC"
  390. else
  391. LINK="ld"
  392. fi
  393. echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
  394. ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  395. FINAL_LIBS=${LIBNAME}
  396. fi
  397. ;;
  398. 'linux-cygwin')
  399. LIBNAME="lib${LIBNAME}.a"
  400. echo "mklib: Making linux-cygwin library: " ${LIBNAME}
  401. rm -f ${LIBNAME}
  402. gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
  403. FINAL_LIBS=${LIBNAME}
  404. ;;
  405. 'HP-UX')
  406. if [ $STATIC = 1 ] ; then
  407. LIBNAME="lib${LIBNAME}.a"
  408. echo "mklib: Making HP-UX static library: " ${LIBNAME}
  409. rm -f ${LIBNAME}
  410. ar -ruv ${LIBNAME} ${OBJECTS}
  411. FINAL_LIBS=${LIBNAME}
  412. else
  413. # HP uses a .2 for their current GL/GLU libraries
  414. if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
  415. MAJOR=2
  416. fi
  417. RUNLIB="lib${LIBNAME}.${MAJOR}"
  418. DEVLIB="lib${LIBNAME}.sl"
  419. echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
  420. ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
  421. ln -s ${RUNLIB} ${DEVLIB}
  422. FINAL_LIBS="${RUNLIB} ${DEVLIB}"
  423. fi
  424. ;;
  425. 'AIX' )
  426. # examine first object to determine ABI
  427. set ${OBJECTS}
  428. ABI_64=`file $1 | grep '64-bit'`
  429. if [ "${ABI_64}" ] ; then
  430. X64="-X64"
  431. Q64="-q64"
  432. OFILE=shr_64.o
  433. else
  434. OFILE=shr.o #Want to be consistent with the IBM libGL.a
  435. fi
  436. if [ $STATIC = 1 ] ; then
  437. LIBNAME="lib${LIBNAME}.a"
  438. echo "mklib: Making AIX static library: " ${LIBNAME}
  439. ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
  440. FINAL_LIBS=${LIBNAME}
  441. else
  442. EXPFILE="lib${LIBNAME}.exp"
  443. LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
  444. OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
  445. rm -f ${EXPFILE} ${OFILE}
  446. NM="/bin/nm -eC ${X64}"
  447. echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
  448. ${NM} ${OBJECTS} | awk '{
  449. if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
  450. && ( substr($1,1,1) != ".")) {
  451. if (substr ($1, 1, 7) != "__sinit" &&
  452. substr ($1, 1, 7) != "__sterm") {
  453. if (substr ($1, 1, 5) == "__tf1")
  454. print (substr ($1, 7))
  455. else if (substr ($1, 1, 5) == "__tf9")
  456. print (substr ($1, 15))
  457. else
  458. print $1
  459. }
  460. }
  461. }' | sort -u >> ${EXPFILE}
  462. # On AIX a shared library is linked differently when
  463. # you want to dlopen the file
  464. if [ $DLOPEN = "1" ] ; then
  465. cc -G ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  466. else
  467. cc ${OPTS} -o ${OFILE} ${OBJECTS} ${DEPS}
  468. ar ${X64} -r ${LIBNAME} ${OFILE}
  469. fi
  470. FINAL_LIBS="${LIBNAME}"
  471. fi
  472. ;;
  473. 'OpenSTEP')
  474. LIBNAME="lib${LIBNAME}.a"
  475. echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
  476. libtool -static -o ${LIBNAME} - ${OBJECTS}
  477. FINAL_LIBS=${LIBNAME}
  478. ;;
  479. 'OSF1')
  480. if [ $STATIC = 1 ] ; then
  481. LIBNAME="lib${LIBNAME}.a"
  482. echo "mklib: Making OSF/1 static library: " ${LIBNAME}
  483. rm -f ${LIBNAME}
  484. ar -ruv ${LIBNAME} ${OBJECTS}
  485. FINAL_LIBS=${LIBNAME}
  486. else
  487. VERSION="${MAJOR}.${MINOR}"
  488. LIBNAME="lib${LIBNAME}.so"
  489. echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
  490. if [ "x$LINK" = "x" ] ; then
  491. if [ $CPLUSPLUS = 1 ] ; then
  492. LINK=cxx
  493. else
  494. LINK=cc
  495. fi
  496. fi
  497. rm -f ${LIBNAME}.${VERSION}
  498. ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
  499. ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
  500. FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
  501. fi
  502. ;;
  503. 'Darwin')
  504. if [ $STATIC = 1 ] ; then
  505. LIBNAME="lib${LIBNAME}.a"
  506. echo "mklib: Making Darwin static library: " ${LIBNAME}
  507. LINK="ar"
  508. OPTS="-ruvs"
  509. ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
  510. FINAL_LIBS=${LIBNAME}
  511. else
  512. # On Darwin a .bundle is used for a library that you want to dlopen
  513. if [ $DLOPEN = "1" ] ; then
  514. LIBSUFFIX="bundle"
  515. OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
  516. else
  517. LIBSUFFIX="dylib"
  518. OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
  519. fi
  520. LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
  521. LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
  522. # examine first object to determine ABI
  523. set ${OBJECTS}
  524. ABI_PPC=`file $1 | grep 'object ppc'`
  525. ABI_I386=`file $1 | grep 'object i386'`
  526. if [ "${ABI_PPC}" ] ; then
  527. OPTS="${OPTS} -arch ppc"
  528. fi
  529. if [ "${ABI_I386}" ] ; then
  530. OPTS="${OPTS} -arch i386"
  531. fi
  532. # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
  533. # to OPTS here?
  534. # determine linker
  535. if [ $CPLUSPLUS = 1 ] ; then
  536. LINK="g++"
  537. else
  538. LINK="cc"
  539. fi
  540. echo "mklib: Making Darwin shared library: " ${LIBNAME}
  541. ${LINK} ${OPTS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  542. ln -s ${LIBNAME} ${LINKNAME}
  543. FINAL_LIBS="${LIBNAME} ${LINKNAME}"
  544. fi
  545. ;;
  546. 'LynxOS')
  547. LIBNAME="lib${LIBNAME}.a"
  548. echo "mklib: Making LynxOS static library: " ${LIBNAME}
  549. rm -f ${LIBNAME}
  550. ar ru ${LIBNAME} ${OBJECTS}
  551. FINAL_LIBS=${LIBNAME}
  552. ;;
  553. 'BeOS')
  554. if [ $STATIC = 1 ] ; then
  555. LIBNAME="lib${LIBNAME}.a"
  556. echo "mklib: Making BeOS static library: " ${LIBNAME}
  557. ar -cru "${LIBNAME}" ${OBJECTS}
  558. else
  559. LIBNAME="lib${LIBNAME}.so"
  560. echo "mklib: Making BeOS shared library: " ${LIBNAME}
  561. gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
  562. mimeset -f "${LIBNAME}"
  563. # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
  564. setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
  565. fi
  566. FINAL_LIBS=${LIBNAME}
  567. ;;
  568. 'QNX')
  569. LIBNAME="lib${LIBNAME}.a"
  570. echo "mklib: Making QNX library: " ${LIBNAME}
  571. wlib ${LIBNAME} ${OBJECTS}
  572. FINAL_LIBS=${LIBNAME}
  573. ;;
  574. 'MorphOS')
  575. LIBNAME="lib${LIBNAME}.a"
  576. echo "mklib: Making MorphOS library: " ${LIBNAME}
  577. ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
  578. FINAL_LIBS="${LIBNAME}"
  579. ;;
  580. 'icc' | 'icc-istatic')
  581. # Intel C compiler
  582. # This should get merged into the Linux code, above, since this isn't
  583. # really a different architecture.
  584. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  585. if [ $STATIC = 1 ] ; then
  586. echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
  587. LINK="ar"
  588. OPTS="-ruv"
  589. # make lib
  590. ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
  591. # finish up
  592. FINAL_LIBS="${LIBNAME}.a"
  593. else
  594. if [ $ARCH = icc-istatic ] ; then
  595. OPTS="-shared -i-static -cxxlib-icc"
  596. else
  597. OPTS="-shared"
  598. fi
  599. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  600. echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
  601. if [ $CPLUSPLUS = 1 ] ; then
  602. LINK="icpc"
  603. else
  604. LINK="icc"
  605. fi
  606. # rm any old libs
  607. rm -f ${LIBNAME}.so.${VERSION}
  608. rm -f ${LIBNAME}.so.${MAJOR}
  609. rm -f ${LIBNAME}.so
  610. # make lib
  611. ${LINK} ${OPTS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  612. # make usual symlinks
  613. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  614. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  615. # finish up
  616. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  617. fi
  618. ;;
  619. 'aix-gcc')
  620. # AIX with gcc
  621. if [ $STATIC = 1 ] ; then
  622. LIBNAME="lib${LIBNAME}.a"
  623. echo "mklib: Making AIX GCC static library: " ${LIBNAME}
  624. rm -f ${LIBNAME}
  625. ar ru ${LIBNAME} ${OBJECTS}
  626. FINAL_LIBS=${LIBNAME}
  627. else
  628. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  629. echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
  630. # remove old lib
  631. rm -f ${LIBNAME}
  632. # make the lib
  633. gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
  634. # NOTE: the application linking with this library must specify
  635. # the -Wl,-brtl flags to gcc
  636. FINAL_LIBS=${LIBNAME}
  637. fi
  638. ;;
  639. 'ultrix')
  640. # XXX untested
  641. if [ $STATIC = 0 ] ; then
  642. echo "mklib: Warning shared libs not supported on Ultrix"
  643. fi
  644. LIBNAME="lib${LIBNAME}.a"
  645. echo "mklib: Making static library for Ultrix: " ${LIBNAME}
  646. rm -f ${LIBNAME}
  647. ar ru ${LIBNAME} ${OBJECTS}
  648. FINAL_LIBS="${LIBNAME}"
  649. ;;
  650. CYGWIN*)
  651. # GCC-based environment
  652. CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
  653. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  654. if [ $STATIC = 1 ] ; then
  655. echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
  656. LINK="ar"
  657. OPTS="-ru"
  658. # make lib
  659. ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
  660. ranlib ${LIBNAME}.a
  661. # finish up
  662. FINAL_LIBS=${LIBNAME}.a
  663. else
  664. OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
  665. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
  666. if [ $CPLUSPLUS = 1 ] ; then
  667. LINK="g++"
  668. else
  669. LINK="gcc"
  670. fi
  671. # rm any old libs
  672. rm -f ${LIBNAME}-${MAJOR}.dll
  673. rm -f ${LIBNAME}.dll.a
  674. rm -f ${LIBNAME}.a
  675. # make lib
  676. ${LINK} ${OPTS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
  677. # make usual symlinks
  678. ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
  679. # finish up
  680. FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
  681. # special case for installing in bin
  682. FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
  683. fi
  684. ;;
  685. 'example')
  686. # If you're adding support for a new architecture, you can
  687. # start with this:
  688. if [ $STATIC = 1 ] ; then
  689. LIBNAME="lib${LIBNAME}.a"
  690. echo "mklib: Making static library for example arch: " ${LIBNAME}
  691. rm -f ${LIBNAME}
  692. ar rv ${LIBNAME} ${OBJECTS}
  693. FINAL_LIBS="${LIBNAME}"
  694. else
  695. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  696. echo "mklib: Making shared library for example arch: " ${LIBNAME}
  697. ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
  698. FINAL_LIBS="${LIBNAME}"
  699. fi
  700. ;;
  701. *)
  702. echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
  703. echo "mklib: Please add necessary commands to mklib script."
  704. ;;
  705. esac
  706. #
  707. # Put library files into installation directory if specified.
  708. #
  709. if [ ${INSTALLDIR} != "." ] ; then
  710. echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
  711. mv ${FINAL_LIBS} ${INSTALLDIR}/
  712. fi