Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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