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

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