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

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