Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

mklib 28KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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. # Given a list of files, look for .a archives and unpack them.
  24. # Return the original list of files minus the .a files plus the unpacked files.
  25. expand_archives() {
  26. FILES=$@
  27. NEWFILES=""
  28. for FILE in $FILES ; do
  29. case $FILE in
  30. *.a)
  31. # extract the .o files from this .a archive
  32. MEMBERS=`ar t $FILE`
  33. ar x $FILE
  34. NEWFILES="$NEWFILES $MEMBERS"
  35. ;;
  36. *)
  37. # other file type, just add to list
  38. NEWFILES="$NEWFILES $FILE"
  39. ;;
  40. esac
  41. done
  42. echo $NEWFILES
  43. }
  44. # Given a list of files, look for .a archives and return a list of all objects
  45. # in the .a archives.
  46. contents_of_archives() {
  47. FILES=$@
  48. NEWFILES=""
  49. for FILE in $FILES ; do
  50. case $FILE in
  51. *.a)
  52. # get list of members in this .a archive
  53. MEMBERS=`ar t $FILE`
  54. NEWFILES="$NEWFILES $MEMBERS"
  55. ;;
  56. *)
  57. # skip other file types
  58. ;;
  59. esac
  60. done
  61. echo $NEWFILES
  62. }
  63. # Make static library with 'ar'
  64. # params:
  65. # options to ar
  66. # 1 or 0 to indicate if ranlib should be run
  67. # libname to make
  68. # list of object files
  69. # Return name of library we made
  70. # Example: "make_ar_static_lib -ru 1 libfoo.a foo.o bar.o"
  71. make_ar_static_lib() {
  72. OPTS=$1
  73. shift;
  74. RANLIB=$1
  75. shift;
  76. LIBNAME=$1
  77. shift;
  78. OBJECTS=$@
  79. # remove existing lib, if present
  80. rm -f ${LIBNAME}
  81. # make static lib
  82. ar ${OPTS} ${LIBNAME} ${OBJECTS}
  83. # run ranlib
  84. if [ ${RANLIB} = 1 ] ; then
  85. ranlib ${LIBNAME}
  86. fi
  87. echo ${LIBNAME}
  88. }
  89. # Print usage info.
  90. usage() {
  91. echo 'Usage: mklib [options] objects'
  92. echo 'Create a shared library from object files.'
  93. echo ' -o LIBRARY specifies the name of the resulting library, without'
  94. echo ' the leading "lib" or any suffix.'
  95. echo ' (eg: "-o GL" might result in "libGL.so" being made)'
  96. echo ' -major N specifies major version number (default is 1)'
  97. echo ' -minor N specifies minor version number (default is 0)'
  98. echo ' -patch N specifies patch version number (default is 0)'
  99. echo ' -lLIBRARY specifies a dependency on LIBRARY'
  100. echo ' -LDIR search in DIR for library dependencies at build time'
  101. echo ' -RDIR search in DIR for library dependencies at run time'
  102. echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
  103. echo ' Not observed on all systems at this time.'
  104. echo ' -ldflags OPT specify any additional linker flags in OPT'
  105. echo ' -cplusplus link with C++ runtime'
  106. echo ' -static make a static library (default is dynamic/shared)'
  107. echo ' -dlopen make a shared library suitable for dynamic loading'
  108. echo ' -install DIR put resulting library file(s) in DIR'
  109. echo ' -arch ARCH override using `uname` to determine host system'
  110. echo ' -archopt OPT specify an extra achitecture-specific option OPT'
  111. echo ' -altopts OPTS alternate options to override all others'
  112. echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
  113. echo ' -exports FILE only export the symbols listed in FILE'
  114. echo ' -id NAME Sets the id of the dylib (Darwin)'
  115. echo ' -h, --help display this information and exit'
  116. }
  117. #
  118. # Option defaults
  119. #
  120. LIBNAME=""
  121. MAJOR=1
  122. MINOR=0
  123. PATCH=""
  124. DEPS=""
  125. LINK=""
  126. LDFLAGS=""
  127. CPLUSPLUS=0
  128. STATIC=0
  129. DLOPEN=0
  130. INSTALLDIR="."
  131. ARCH="auto"
  132. ARCHOPT=""
  133. NOPREFIX=0
  134. EXPORTS=""
  135. ID=""
  136. #
  137. # Parse arguments
  138. #
  139. while true
  140. do
  141. case $1 in
  142. '-h' | '--help')
  143. usage
  144. exit 1
  145. ;;
  146. '-o')
  147. shift 1;
  148. LIBNAME=$1
  149. ;;
  150. '-major')
  151. shift 1;
  152. MAJOR=$1
  153. ;;
  154. '-minor')
  155. shift 1;
  156. MINOR=$1
  157. ;;
  158. '-patch')
  159. shift 1;
  160. PATCH=$1
  161. ;;
  162. '-linker')
  163. shift 1;
  164. LINK=$1
  165. ;;
  166. '-ldflags')
  167. shift 1;
  168. LDFLAGS=$1
  169. ;;
  170. -l*)
  171. DEPS="$DEPS $1"
  172. ;;
  173. -L*)
  174. DEPS="$DEPS $1"
  175. ;;
  176. -R*)
  177. DEPS="$DEPS $1"
  178. ;;
  179. -Wl*)
  180. DEPS="$DEPS $1"
  181. ;;
  182. -pthread)
  183. # this is a special case (see bugzilla 10876)
  184. DEPS="$DEPS $1"
  185. ;;
  186. '-pthread')
  187. DEPS="$DEPS -pthread"
  188. ;;
  189. '-cplusplus')
  190. CPLUSPLUS=1
  191. ;;
  192. '-static')
  193. STATIC=1
  194. ;;
  195. '-dlopen')
  196. DLOPEN=1
  197. ;;
  198. '-install')
  199. shift 1;
  200. INSTALLDIR=$1
  201. ;;
  202. '-arch')
  203. shift 1;
  204. ARCH=$1
  205. ;;
  206. '-archopt')
  207. shift 1;
  208. ARCHOPT=$1
  209. ;;
  210. '-altopts')
  211. shift 1;
  212. ALTOPTS=$1
  213. ;;
  214. '-noprefix')
  215. NOPREFIX=1
  216. ;;
  217. '-exports')
  218. shift 1;
  219. EXPORTS=$1
  220. ;;
  221. '-id')
  222. shift 1;
  223. ID=$1
  224. ;;
  225. -*)
  226. echo "mklib: Unknown option: " $1 ;
  227. exit 1
  228. ;;
  229. *)
  230. # This should be the first object file, stop parsing
  231. break
  232. esac
  233. shift 1
  234. done
  235. OBJECTS=$@
  236. if [ ${ARCH} = "auto" ] ; then
  237. ARCH=`uname`
  238. fi
  239. if [ $STATIC = 1 ]; then
  240. # filter out linker options inside object list
  241. NEWOBJECTS=""
  242. for OBJ in $OBJECTS ; do
  243. case $OBJ in
  244. -Wl,*)
  245. echo "mklib: warning: ignoring $OBJ for static library"
  246. ;;
  247. *)
  248. NEWOBJECTS="$NEWOBJECTS $OBJ"
  249. ;;
  250. esac
  251. done
  252. OBJECTS=$NEWOBJECTS
  253. fi
  254. #
  255. # Error checking
  256. #
  257. if [ "x${LIBNAME}" = "x" ] ; then
  258. echo "mklib: Error: no library name specified (-h for help)"
  259. exit 1
  260. fi
  261. if [ "x${OBJECTS}" = "x" ] ; then
  262. echo "mklib: Error: no object files specified (-h for help)"
  263. exit 1
  264. fi
  265. #
  266. # Debugging info
  267. #
  268. if [ ] ; then
  269. echo "-----------------"
  270. echo ARCH is $ARCH
  271. echo LIBNAME is $LIBNAME
  272. echo MAJOR is $MAJOR
  273. echo MINOR is $MINOR
  274. echo PATCH is $PATCH
  275. echo DEPS are $DEPS
  276. echo "EXPORTS in" $EXPORTS
  277. echo ID is $ID
  278. echo "-----------------"
  279. fi
  280. #
  281. # OK, make the library now
  282. #
  283. case $ARCH in
  284. 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*)
  285. # we assume gcc
  286. if [ "x$LINK" = "x" ] ; then
  287. # -linker was not specified so set default link command now
  288. if [ $CPLUSPLUS = 1 ] ; then
  289. LINK=g++
  290. else
  291. LINK=gcc
  292. fi
  293. fi
  294. if [ $NOPREFIX = 1 ] ; then
  295. # No "lib" or ".so" part
  296. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
  297. case $ARCH in 'Linux' | 'GNU' | GNU/*)
  298. OPTS="-Xlinker -Bsymbolic -shared"
  299. ;;
  300. *)
  301. OPTS="-shared"
  302. ;;
  303. esac
  304. # Check if objects are 32-bit and we're running in 64-bit
  305. # environment. If so, pass -m32 flag to linker.
  306. set ${OBJECTS}
  307. ABI32=`file $1 | grep 32-bit`
  308. if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
  309. OPTS="-m32 ${OPTS}"
  310. fi
  311. if [ "${ALTOPTS}" ] ; then
  312. OPTS=${ALTOPTS}
  313. fi
  314. rm -f ${LIBNAME}
  315. # make lib
  316. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  317. # finish up
  318. FINAL_LIBS="${LIBNAME}"
  319. elif [ $STATIC = 1 ] ; then
  320. # make a static .a library
  321. LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
  322. echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
  323. OPTS="-ru"
  324. if [ "${ALTOPTS}" ] ; then
  325. OPTS=${ALTOPTS}
  326. fi
  327. # expand .a into .o files
  328. NEW_OBJECTS=`expand_archives $OBJECTS`
  329. # make static lib
  330. FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
  331. # remove temporary extracted .o files
  332. rm -f `contents_of_archives $OBJECTS`
  333. else
  334. # make dynamic library
  335. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  336. case $ARCH in 'Linux' | 'GNU' | GNU/*)
  337. OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  338. ;;
  339. *)
  340. OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  341. ;;
  342. esac
  343. if [ $EXPORTS ] ; then
  344. #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
  345. # Make the 'exptmp' file for --version-script option
  346. echo "{" > exptmp
  347. echo "global:" >> exptmp
  348. sed 's/$/;/' ${EXPORTS} >> exptmp
  349. echo "local:" >> exptmp
  350. echo "*;" >> exptmp
  351. echo "};" >> exptmp
  352. OPTS="${OPTS} -Xlinker --version-script=exptmp"
  353. # exptmp is removed below
  354. fi
  355. # Check if objects are 32-bit and we're running in 64-bit
  356. # environment. If so, pass -m32 flag to linker.
  357. set ${OBJECTS}
  358. ABI32=`file $1 | grep 32-bit`
  359. if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
  360. OPTS="-m32 ${OPTS}"
  361. fi
  362. if [ "${ALTOPTS}" ] ; then
  363. OPTS=${ALTOPTS}
  364. fi
  365. if [ x${PATCH} = "x" ] ; then
  366. VERSION="${MAJOR}.${MINOR}"
  367. else
  368. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  369. fi
  370. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
  371. # rm any old libs
  372. rm -f ${LIBNAME}.so.${VERSION}
  373. rm -f ${LIBNAME}.so.${MAJOR}
  374. rm -f ${LIBNAME}.so
  375. # make lib
  376. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  377. # make usual symlinks
  378. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  379. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  380. # finish up
  381. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  382. # rm -f exptmp
  383. fi
  384. ;;
  385. 'SunOS')
  386. if [ $STATIC = 1 ] ; then
  387. LIBNAME="lib${LIBNAME}.a"
  388. echo "mklib: Making SunOS static library: " ${LIBNAME}
  389. FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
  390. else
  391. if [ $NOPREFIX = 0 ] ; then
  392. LIBNAME="lib${LIBNAME}.so"
  393. fi
  394. echo "mklib: Making SunOS shared library: " ${LIBNAME}
  395. if [ "x$LINK" = "x" ] ; then
  396. # -linker was not specified, choose default linker now
  397. if [ $CPLUSPLUS = 1 ] ; then
  398. # determine linker and options for C++ code
  399. if [ `which c++` ] ; then
  400. # use Sun c++
  401. LINK="c++"
  402. elif [ `type g++` ] ; then
  403. # use g++
  404. LINK="g++"
  405. else
  406. echo "mklib: warning: can't find C++ compiler, trying CC."
  407. LINK="CC"
  408. fi
  409. else
  410. # use native Sun linker for C code
  411. LINK="ld"
  412. fi
  413. fi
  414. # linker options
  415. if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
  416. # SunOS tools, -G to make shared libs
  417. OPTS="-G"
  418. else
  419. # gcc linker
  420. # Check if objects are 32-bit and we're running in 64-bit
  421. # environment. If so, pass -m32 flag to linker.
  422. set ${OBJECTS}
  423. ABI32=`file $1 | grep 32-bit`
  424. if [ "${ABI32}" ] ; then
  425. OPTS="-m32 -shared -Wl,-Bdynamic"
  426. else
  427. OPTS="-m64 -shared -Wl,-Bdynamic"
  428. fi
  429. fi
  430. # If using Sun C++ compiler, need to tell it not to add runpaths
  431. # that are specific to the build machine
  432. if [ ${LINK} = "CC" ] ; then
  433. OPTS="${OPTS} -norunpath"
  434. fi
  435. # Solaris linker requires explicitly listing the Standard C & C++
  436. # libraries in the link path when building shared objects
  437. if [ ${LINK} = "CC" ] ; then
  438. DEPS="${DEPS} -lCrun"
  439. fi
  440. DEPS="${DEPS} -lc"
  441. if [ $EXPORTS ] ; then
  442. # Make the 'mapfile.scope' linker mapfile
  443. echo "{" > mapfile.scope
  444. echo "global:" >> mapfile.scope
  445. sed 's/$/;/' ${EXPORTS} >> mapfile.scope
  446. echo "local:" >> mapfile.scope
  447. echo " *;" >> mapfile.scope
  448. echo "};" >> mapfile.scope
  449. OPTS="${OPTS} -Wl,-Mmapfile.scope"
  450. fi
  451. # Check if objects are SPARC v9
  452. # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
  453. set ${OBJECTS}
  454. if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
  455. SPARCV9=`file $1 | grep SPARCV9`
  456. if [ "${SPARCV9}" ] ; then
  457. OPTS="${OPTS} -xarch=v9"
  458. fi
  459. fi
  460. if [ "${ALTOPTS}" ] ; then
  461. OPTS=${ALTOPTS}
  462. fi
  463. # for debug:
  464. #echo "mklib: linker is" ${LINK} ${OPTS}
  465. if [ $NOPREFIX = 1 ] ; then
  466. rm -f ${LIBNAME}
  467. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  468. FINAL_LIBS="${LIBNAME}"
  469. else
  470. rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
  471. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
  472. ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
  473. FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
  474. fi
  475. fi
  476. ;;
  477. 'FreeBSD')
  478. # we assume gcc
  479. if [ "x$LINK" = "x" ] ; then
  480. # -linker was not specified so set default link command now
  481. if [ $CPLUSPLUS = 1 ] ; then
  482. LINK=g++
  483. else
  484. LINK=gcc
  485. fi
  486. fi
  487. if [ $NOPREFIX = 1 ] ; then
  488. # No "lib" or ".so" part
  489. echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
  490. OPTS="-shared"
  491. if [ "${ALTOPTS}" ] ; then
  492. OPTS=${ALTOPTS}
  493. fi
  494. rm -f ${LIBNAME}
  495. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  496. FINAL_LIBS=${LIBNAME}
  497. elif [ $STATIC = 1 ] ; then
  498. # make a static .a library
  499. STLIB="lib${LIBNAME}.a"
  500. echo "mklib: Making FreeBSD static library: " ${STLIB}
  501. # expand .a into .o files
  502. NEW_OBJECTS=`expand_archives $OBJECTS`
  503. FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
  504. # remove temporary extracted .o files
  505. rm -f `contents_of_archives $OBJECTS`
  506. else
  507. # make dynamic library
  508. SHLIB="lib${LIBNAME}.so.${MAJOR}"
  509. OPTS="-shared -Wl,-soname,${SHLIB}"
  510. if [ "${ALTOPTS}" ] ; then
  511. OPTS=${ALTOPTS}
  512. fi
  513. echo "mklib: Making FreeBSD shared library: " ${SHLIB}
  514. rm -f ${SHLIB}
  515. ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
  516. ln -sf ${SHLIB} "lib${LIBNAME}.so"
  517. FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
  518. fi
  519. ;;
  520. 'NetBSD')
  521. if [ $STATIC = 1 ] ; then
  522. LIBNAME="lib${LIBNAME}_pic.a"
  523. echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
  524. FINAL_LIBS=`make_ar_static_lib cq 1 ${LIBNAME} ${OBJECTS}`
  525. else
  526. LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
  527. echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
  528. rm -f ${LIBNAME}
  529. ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
  530. FINAL_LIBS=${LIBNAME}
  531. fi
  532. ;;
  533. 'IRIX' | 'IRIX64')
  534. if [ $STATIC = 1 ] ; then
  535. LIBNAME="lib${LIBNAME}.a"
  536. FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
  537. else
  538. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  539. # examine first object to determine ABI
  540. set ${OBJECTS}
  541. ABI_O32=`file $1 | grep 'ELF 32-bit'`
  542. ABI_N32=`file $1 | grep 'ELF N32'`
  543. ABI_N64=`file $1 | grep 'ELF 64-bit'`
  544. if [ "${ABI_O32}" ] ; then
  545. OPTS="-32 -shared -all"
  546. ABI="o32-bit"
  547. elif [ "${ABI_N32}" ] ; then
  548. OPTS="-n32 -shared -all"
  549. ABI="n32-bit"
  550. elif [ "${ABI_N64}" ] ; then
  551. OPTS="-64 -shared -all"
  552. ABI="64-bit"
  553. else
  554. echo "Error: Unexpected IRIX ABI!"
  555. exit 1
  556. fi
  557. if [ "${ALTOPTS}" ] ; then
  558. OPTS=${ALTOPTS}
  559. fi
  560. if [ $CPLUSPLUS = 1 ] ; then
  561. LINK="CC"
  562. else
  563. LINK="ld"
  564. fi
  565. echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
  566. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  567. FINAL_LIBS=${LIBNAME}
  568. fi
  569. ;;
  570. 'linux-cygwin')
  571. LIBNAME="lib${LIBNAME}.a"
  572. echo "mklib: Making linux-cygwin library: " ${LIBNAME}
  573. rm -f ${LIBNAME}
  574. gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
  575. FINAL_LIBS=${LIBNAME}
  576. ;;
  577. 'HP-UX')
  578. if [ $STATIC = 1 ] ; then
  579. LIBNAME="lib${LIBNAME}.a"
  580. echo "mklib: Making HP-UX static library: " ${LIBNAME}
  581. FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
  582. else
  583. # HP uses a .2 for their current GL/GLU libraries
  584. if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
  585. MAJOR=2
  586. fi
  587. RUNLIB="lib${LIBNAME}.${MAJOR}"
  588. DEVLIB="lib${LIBNAME}.sl"
  589. echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
  590. ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
  591. ln -s ${RUNLIB} ${DEVLIB}
  592. FINAL_LIBS="${RUNLIB} ${DEVLIB}"
  593. fi
  594. ;;
  595. 'AIX' )
  596. # examine first object to determine ABI
  597. set ${OBJECTS}
  598. ABI_64=`file $1 | grep '64-bit'`
  599. if [ "${ABI_64}" ] ; then
  600. X64="-X64"
  601. Q64="-q64"
  602. OFILE=shr_64.o
  603. else
  604. OFILE=shr.o #Want to be consistent with the IBM libGL.a
  605. fi
  606. if [ $STATIC = 1 ] ; then
  607. LIBNAME="lib${LIBNAME}.a"
  608. echo "mklib: Making AIX static library: " ${LIBNAME}
  609. FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
  610. else
  611. EXPFILE="lib${LIBNAME}.exp"
  612. LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
  613. OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
  614. rm -f ${EXPFILE} ${OFILE}
  615. NM="/bin/nm -eC ${X64}"
  616. echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
  617. ${NM} ${OBJECTS} | awk '{
  618. if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
  619. && ( substr($1,1,1) != ".")) {
  620. if (substr ($1, 1, 7) != "__sinit" &&
  621. substr ($1, 1, 7) != "__sterm") {
  622. if (substr ($1, 1, 5) == "__tf1")
  623. print (substr ($1, 7))
  624. else if (substr ($1, 1, 5) == "__tf9")
  625. print (substr ($1, 15))
  626. else
  627. print $1
  628. }
  629. }
  630. }' | sort -u >> ${EXPFILE}
  631. if [ "${ALTOPTS}" ] ; then
  632. OPTS=${ALTOPTS}
  633. fi
  634. # On AIX a shared library is linked differently when
  635. # you want to dlopen the file
  636. if [ $DLOPEN = "1" ] ; then
  637. cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  638. else
  639. cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
  640. ar ${X64} -r ${LIBNAME} ${OFILE}
  641. fi
  642. FINAL_LIBS="${LIBNAME}"
  643. fi
  644. ;;
  645. 'OpenSTEP')
  646. LIBNAME="lib${LIBNAME}.a"
  647. echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
  648. libtool -static -o ${LIBNAME} - ${OBJECTS}
  649. FINAL_LIBS=${LIBNAME}
  650. ;;
  651. 'OSF1')
  652. if [ $STATIC = 1 ] ; then
  653. LIBNAME="lib${LIBNAME}.a"
  654. echo "mklib: Making OSF/1 static library: " ${LIBNAME}
  655. FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
  656. else
  657. VERSION="${MAJOR}.${MINOR}"
  658. LIBNAME="lib${LIBNAME}.so"
  659. echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
  660. if [ "x$LINK" = "x" ] ; then
  661. if [ $CPLUSPLUS = 1 ] ; then
  662. LINK=cxx
  663. else
  664. LINK=cc
  665. fi
  666. fi
  667. rm -f ${LIBNAME}.${VERSION}
  668. ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
  669. ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
  670. FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
  671. fi
  672. ;;
  673. 'Darwin')
  674. if [ $STATIC = 1 ] ; then
  675. LIBNAME="lib${LIBNAME}.a"
  676. echo "mklib: Making Darwin static library: " ${LIBNAME}
  677. LINK="ar"
  678. OPTS="-ruvs"
  679. if [ "${ALTOPTS}" ] ; then
  680. OPTS=${ALTOPTS}
  681. fi
  682. ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
  683. FINAL_LIBS=${LIBNAME}
  684. else
  685. # On Darwin a .bundle is used for a library that you want to dlopen
  686. if [ $DLOPEN = "1" ] ; then
  687. LIBSUFFIX="bundle"
  688. OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
  689. else
  690. LIBSUFFIX="dylib"
  691. if [ -z "$ID" ] ; then
  692. ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
  693. fi
  694. OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
  695. fi
  696. if [ ${EXPORTS} ] ; then
  697. if [ -f ${EXPORTS}".darwin" ] ; then
  698. EXPORTS=$EXPORTS".darwin"
  699. fi
  700. OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
  701. fi
  702. LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
  703. LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
  704. LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
  705. # examine first object to determine ABI
  706. set ${OBJECTS}
  707. ABIS=`lipo -info $1 | sed s/.*://`
  708. for ABI in $ABIS; do
  709. OPTS="${OPTS} -arch ${ABI}"
  710. done
  711. if [ "${ALTOPTS}" ] ; then
  712. OPTS=${ALTOPTS}
  713. fi
  714. # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
  715. # to OPTS here?
  716. # determine linker
  717. if [ $CPLUSPLUS = 1 ] ; then
  718. LINK="g++"
  719. else
  720. LINK="cc"
  721. fi
  722. echo "mklib: Making Darwin shared library: " ${LIBNAME}
  723. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  724. ln -s ${LIBNAME} ${LINKNAME}
  725. ln -s ${LIBNAME} ${LINKNAME2}
  726. FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
  727. fi
  728. ;;
  729. 'LynxOS')
  730. LIBNAME="lib${LIBNAME}.a"
  731. echo "mklib: Making LynxOS static library: " ${LIBNAME}
  732. FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
  733. ;;
  734. 'BeOS')
  735. if [ $STATIC = 1 ] ; then
  736. LIBNAME="lib${LIBNAME}.a"
  737. echo "mklib: Making BeOS static library: " ${LIBNAME}
  738. FINAL_LIBS=`make_ar_static_lib -cru 0 ${LIBNAME} ${OBJECTS}`
  739. else
  740. LIBNAME="lib${LIBNAME}.so"
  741. echo "mklib: Making BeOS shared library: " ${LIBNAME}
  742. gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
  743. mimeset -f "${LIBNAME}"
  744. # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
  745. setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
  746. fi
  747. FINAL_LIBS=${LIBNAME}
  748. ;;
  749. 'QNX')
  750. LIBNAME="lib${LIBNAME}.a"
  751. echo "mklib: Making QNX library: " ${LIBNAME}
  752. wlib ${LIBNAME} ${OBJECTS}
  753. FINAL_LIBS=${LIBNAME}
  754. ;;
  755. 'MorphOS')
  756. LIBNAME="lib${LIBNAME}.a"
  757. echo "mklib: Making MorphOS library: " ${LIBNAME}
  758. ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
  759. FINAL_LIBS="${LIBNAME}"
  760. ;;
  761. 'icc' | 'icc-istatic')
  762. # Intel C compiler
  763. # This should get merged into the Linux code, above, since this isn't
  764. # really a different architecture.
  765. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  766. if [ $STATIC = 1 ] ; then
  767. echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
  768. LINK="ar"
  769. OPTS="-ruv"
  770. if [ "${ALTOPTS}" ] ; then
  771. OPTS=${ALTOPTS}
  772. fi
  773. # make lib
  774. ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
  775. # finish up
  776. FINAL_LIBS="${LIBNAME}.a"
  777. else
  778. if [ $ARCH = icc-istatic ] ; then
  779. OPTS="-shared -i-static -cxxlib-icc"
  780. else
  781. OPTS="-shared"
  782. fi
  783. if [ "${ALTOPTS}" ] ; then
  784. OPTS=${ALTOPTS}
  785. fi
  786. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  787. echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
  788. if [ $CPLUSPLUS = 1 ] ; then
  789. LINK="icpc"
  790. else
  791. LINK="icc"
  792. fi
  793. # rm any old libs
  794. rm -f ${LIBNAME}.so.${VERSION}
  795. rm -f ${LIBNAME}.so.${MAJOR}
  796. rm -f ${LIBNAME}.so
  797. # make lib
  798. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  799. # make usual symlinks
  800. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  801. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  802. # finish up
  803. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  804. fi
  805. ;;
  806. 'aix-gcc')
  807. # AIX with gcc
  808. if [ $STATIC = 1 ] ; then
  809. LIBNAME="lib${LIBNAME}.a"
  810. echo "mklib: Making AIX GCC static library: " ${LIBNAME}
  811. FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
  812. else
  813. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  814. echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
  815. # remove old lib
  816. rm -f ${LIBNAME}
  817. # make the lib
  818. gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
  819. # NOTE: the application linking with this library must specify
  820. # the -Wl,-brtl flags to gcc
  821. FINAL_LIBS=${LIBNAME}
  822. fi
  823. ;;
  824. 'ultrix')
  825. # XXX untested
  826. if [ $STATIC = 0 ] ; then
  827. echo "mklib: Warning shared libs not supported on Ultrix"
  828. fi
  829. LIBNAME="lib${LIBNAME}.a"
  830. echo "mklib: Making static library for Ultrix: " ${LIBNAME}
  831. FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
  832. ;;
  833. CYGWIN*)
  834. # GCC-based environment
  835. if [ $NOPREFIX = 1 ] ; then
  836. # No "lib" or ".so" part
  837. echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
  838. OPTS="-shared -Wl,--enable-auto-image-base"
  839. if [ "${ALTOPTS}" ] ; then
  840. OPTS=${ALTOPTS}
  841. fi
  842. rm -f ${LIBNAME}
  843. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  844. FINAL_LIBS=${LIBNAME}
  845. else
  846. CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
  847. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  848. if [ $STATIC = 1 ] ; then
  849. LIBNAME=${LIBNAME}.a
  850. echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
  851. OPTS="-ru"
  852. if [ "${ALTOPTS}" ] ; then
  853. OPTS=${ALTOPTS}
  854. fi
  855. FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${OBJECTS}`
  856. else
  857. OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
  858. if [ "${ALTOPTS}" ] ; then
  859. OPTS=${ALTOPTS}
  860. fi
  861. echo "mklib: Making" $ARCH "shared library: " ${CYGNAME}-${MAJOR}.dll
  862. if [ $CPLUSPLUS = 1 ] ; then
  863. LINK="g++"
  864. else
  865. LINK="gcc"
  866. fi
  867. # rm any old libs
  868. rm -f ${CYGNAME}-${MAJOR}.dll
  869. rm -f ${LIBNAME}-${MAJOR}.dll.a
  870. rm -f ${LIBNAME}.dll.a
  871. rm -f ${LIBNAME}.a
  872. # make lib
  873. ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
  874. # make usual symlinks
  875. ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
  876. # finish up
  877. FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
  878. # special case for installing in bin
  879. FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
  880. fi
  881. fi
  882. ;;
  883. 'example')
  884. # If you're adding support for a new architecture, you can
  885. # start with this:
  886. if [ $STATIC = 1 ] ; then
  887. LIBNAME="lib${LIBNAME}.a"
  888. echo "mklib: Making static library for example arch: " ${LIBNAME}
  889. FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
  890. else
  891. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  892. echo "mklib: Making shared library for example arch: " ${LIBNAME}
  893. ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
  894. FINAL_LIBS="${LIBNAME}"
  895. fi
  896. ;;
  897. *)
  898. echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
  899. echo "mklib: Please add necessary commands to mklib script."
  900. ;;
  901. esac
  902. #
  903. # Put library files into installation directory if specified.
  904. #
  905. if [ ${INSTALLDIR} != "." ] ; then
  906. echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
  907. test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
  908. mv ${FINAL_LIBS} ${INSTALLDIR}/
  909. fi