Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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