Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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. # make lib
  244. ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
  245. ranlib ${LIBNAME}
  246. # finish up
  247. FINAL_LIBS=${LIBNAME}
  248. else
  249. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  250. case $ARCH in 'Linux' | 'GNU' | GNU/*)
  251. OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  252. ;;
  253. *)
  254. OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  255. ;;
  256. esac
  257. if [ $EXPORTS ] ; then
  258. #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
  259. # Make the 'exptmp' file for --version-script option
  260. echo "{" > exptmp
  261. echo "global:" >> exptmp
  262. sed 's/$/;/' ${EXPORTS} >> exptmp
  263. echo "local:" >> exptmp
  264. echo "*;" >> exptmp
  265. echo "};" >> exptmp
  266. OPTS="${OPTS} -Xlinker --version-script=exptmp"
  267. # exptmp is removed below
  268. fi
  269. # Check if objects are 32-bit and we're running in 64-bit
  270. # environment. If so, pass -m32 flag to linker.
  271. set ${OBJECTS}
  272. ABI32=`file $1 | grep 32-bit`
  273. if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
  274. OPTS="-m32 ${OPTS}"
  275. fi
  276. if [ "${ALTOPTS}" ] ; then
  277. OPTS=${ALTOPTS}
  278. fi
  279. if [ x${PATCH} = "x" ] ; then
  280. VERSION="${MAJOR}.${MINOR}"
  281. else
  282. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  283. fi
  284. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
  285. # rm any old libs
  286. rm -f ${LIBNAME}.so.${VERSION}
  287. rm -f ${LIBNAME}.so.${MAJOR}
  288. rm -f ${LIBNAME}.so
  289. # make lib
  290. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  291. # make usual symlinks
  292. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  293. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  294. # finish up
  295. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  296. # rm -f exptmp
  297. fi
  298. ;;
  299. 'SunOS')
  300. if [ $STATIC = 1 ] ; then
  301. LIBNAME="lib${LIBNAME}.a"
  302. echo "mklib: Making SunOS static library: " ${LIBNAME}
  303. rm -f ${LIBNAME}
  304. ar -ruv ${LIBNAME} ${OBJECTS}
  305. FINAL_LIBS=${LIBNAME}
  306. else
  307. if [ $NOPREFIX = 0 ] ; then
  308. LIBNAME="lib${LIBNAME}.so"
  309. fi
  310. echo "mklib: Making SunOS shared library: " ${LIBNAME}
  311. if [ "x$LINK" = "x" ] ; then
  312. # -linker was not specified, choose default linker now
  313. if [ $CPLUSPLUS = 1 ] ; then
  314. # determine linker and options for C++ code
  315. if [ `which c++` ] ; then
  316. # use Sun c++
  317. LINK="c++"
  318. elif [ `type g++` ] ; then
  319. # use g++
  320. LINK="g++"
  321. else
  322. echo "mklib: warning: can't find C++ compiler, trying CC."
  323. LINK="CC"
  324. fi
  325. else
  326. # use native Sun linker for C code
  327. LINK="ld"
  328. fi
  329. fi
  330. # linker options
  331. if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
  332. # SunOS tools, -G to make shared libs
  333. OPTS="-G"
  334. else
  335. # gcc linker
  336. # Check if objects are 32-bit and we're running in 64-bit
  337. # environment. If so, pass -m32 flag to linker.
  338. set ${OBJECTS}
  339. ABI32=`file $1 | grep 32-bit`
  340. if [ "${ABI32}" ] ; then
  341. OPTS="-m32 -shared -Wl,-Bdynamic"
  342. else
  343. OPTS="-m64 -shared -Wl,-Bdynamic"
  344. fi
  345. fi
  346. # Check if objects are SPARC v9
  347. # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
  348. set ${OBJECTS}
  349. if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
  350. SPARCV9=`file $1 | grep SPARCV9`
  351. if [ "${SPARCV9}" ] ; then
  352. OPTS="${OPTS} -xarch=v9"
  353. fi
  354. fi
  355. if [ "${ALTOPTS}" ] ; then
  356. OPTS=${ALTOPTS}
  357. fi
  358. # for debug:
  359. #echo "mklib: linker is" ${LINK} ${OPTS}
  360. if [ $NOPREFIX = 1 ] ; then
  361. rm -f ${LIBNAME}
  362. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  363. else
  364. rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
  365. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
  366. ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
  367. fi
  368. FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
  369. fi
  370. ;;
  371. 'FreeBSD')
  372. # we assume gcc
  373. if [ "x$LINK" = "x" ] ; then
  374. # -linker was not specified so set default link command now
  375. if [ $CPLUSPLUS = 1 ] ; then
  376. LINK=g++
  377. else
  378. LINK=gcc
  379. fi
  380. fi
  381. if [ $NOPREFIX = 1 ] ; then
  382. # No "lib" or ".so" part
  383. echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
  384. OPTS="-shared"
  385. if [ "${ALTOPTS}" ] ; then
  386. OPTS=${ALTOPTS}
  387. fi
  388. rm -f ${LIBNAME}
  389. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  390. FINAL_LIBS=${LIBNAME}
  391. elif [ $STATIC = 1 ] ; then
  392. STLIB="lib${LIBNAME}.a"
  393. echo "mklib: Making FreeBSD static library: " ${STLIB}
  394. rm -f ${STLIB}
  395. ar cq ${STLIB} ${OBJECTS}
  396. ranlib ${STLIB}
  397. FINAL_LIBS=${STLIB}
  398. else
  399. SHLIB="lib${LIBNAME}.so.${MAJOR}"
  400. OPTS="-shared -Wl,-soname,${SHLIB}"
  401. if [ "${ALTOPTS}" ] ; then
  402. OPTS=${ALTOPTS}
  403. fi
  404. echo "mklib: Making FreeBSD shared library: " ${SHLIB}
  405. rm -f ${SHLIB}
  406. ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
  407. ln -sf ${SHLIB} "lib${LIBNAME}.so"
  408. FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
  409. fi
  410. ;;
  411. 'NetBSD')
  412. if [ $STATIC = 1 ] ; then
  413. LIBNAME="lib${LIBNAME}_pic.a"
  414. echo "mklib: Making NetBSD PIC static library: " ${LIBNAME}
  415. rm -f ${LIBNAME}
  416. ar cq ${LIBNAME} ${OBJECTS}
  417. ranlib ${LIBNAME}
  418. FINAL_LIBS=${LIBNAME}
  419. else
  420. LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}"
  421. echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME}
  422. rm -f ${LIBNAME}
  423. ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS}
  424. FINAL_LIBS=${LIBNAME}
  425. fi
  426. ;;
  427. 'IRIX' | 'IRIX64')
  428. if [ $STATIC = 1 ] ; then
  429. LIBNAME="lib${LIBNAME}.a"
  430. rm -f ${LIBNAME}
  431. ar rc ${LIBNAME} ${OBJECTS}
  432. FINAL_LIBS=${LIBNAME}
  433. else
  434. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  435. # examine first object to determine ABI
  436. set ${OBJECTS}
  437. ABI_O32=`file $1 | grep 'ELF 32-bit'`
  438. ABI_N32=`file $1 | grep 'ELF N32'`
  439. ABI_N64=`file $1 | grep 'ELF 64-bit'`
  440. if [ "${ABI_O32}" ] ; then
  441. OPTS="-32 -shared -all"
  442. ABI="o32-bit"
  443. elif [ "${ABI_N32}" ] ; then
  444. OPTS="-n32 -shared -all"
  445. ABI="n32-bit"
  446. elif [ "${ABI_N64}" ] ; then
  447. OPTS="-64 -shared -all"
  448. ABI="64-bit"
  449. else
  450. echo "Error: Unexpected IRIX ABI!"
  451. exit 1
  452. fi
  453. if [ "${ALTOPTS}" ] ; then
  454. OPTS=${ALTOPTS}
  455. fi
  456. if [ $CPLUSPLUS = 1 ] ; then
  457. LINK="CC"
  458. else
  459. LINK="ld"
  460. fi
  461. echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
  462. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  463. FINAL_LIBS=${LIBNAME}
  464. fi
  465. ;;
  466. 'linux-cygwin')
  467. LIBNAME="lib${LIBNAME}.a"
  468. echo "mklib: Making linux-cygwin library: " ${LIBNAME}
  469. rm -f ${LIBNAME}
  470. gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
  471. FINAL_LIBS=${LIBNAME}
  472. ;;
  473. 'HP-UX')
  474. if [ $STATIC = 1 ] ; then
  475. LIBNAME="lib${LIBNAME}.a"
  476. echo "mklib: Making HP-UX static library: " ${LIBNAME}
  477. rm -f ${LIBNAME}
  478. ar -ruv ${LIBNAME} ${OBJECTS}
  479. FINAL_LIBS=${LIBNAME}
  480. else
  481. # HP uses a .2 for their current GL/GLU libraries
  482. if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
  483. MAJOR=2
  484. fi
  485. RUNLIB="lib${LIBNAME}.${MAJOR}"
  486. DEVLIB="lib${LIBNAME}.sl"
  487. echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
  488. ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
  489. ln -s ${RUNLIB} ${DEVLIB}
  490. FINAL_LIBS="${RUNLIB} ${DEVLIB}"
  491. fi
  492. ;;
  493. 'AIX' )
  494. # examine first object to determine ABI
  495. set ${OBJECTS}
  496. ABI_64=`file $1 | grep '64-bit'`
  497. if [ "${ABI_64}" ] ; then
  498. X64="-X64"
  499. Q64="-q64"
  500. OFILE=shr_64.o
  501. else
  502. OFILE=shr.o #Want to be consistent with the IBM libGL.a
  503. fi
  504. if [ $STATIC = 1 ] ; then
  505. LIBNAME="lib${LIBNAME}.a"
  506. echo "mklib: Making AIX static library: " ${LIBNAME}
  507. ar -ruv ${X64} ${LIBNAME} ${OBJECTS}
  508. FINAL_LIBS=${LIBNAME}
  509. else
  510. EXPFILE="lib${LIBNAME}.exp"
  511. LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
  512. OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
  513. rm -f ${EXPFILE} ${OFILE}
  514. NM="/bin/nm -eC ${X64}"
  515. echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
  516. ${NM} ${OBJECTS} | awk '{
  517. if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
  518. && ( substr($1,1,1) != ".")) {
  519. if (substr ($1, 1, 7) != "__sinit" &&
  520. substr ($1, 1, 7) != "__sterm") {
  521. if (substr ($1, 1, 5) == "__tf1")
  522. print (substr ($1, 7))
  523. else if (substr ($1, 1, 5) == "__tf9")
  524. print (substr ($1, 15))
  525. else
  526. print $1
  527. }
  528. }
  529. }' | sort -u >> ${EXPFILE}
  530. if [ "${ALTOPTS}" ] ; then
  531. OPTS=${ALTOPTS}
  532. fi
  533. # On AIX a shared library is linked differently when
  534. # you want to dlopen the file
  535. if [ $DLOPEN = "1" ] ; then
  536. cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  537. else
  538. cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
  539. ar ${X64} -r ${LIBNAME} ${OFILE}
  540. fi
  541. FINAL_LIBS="${LIBNAME}"
  542. fi
  543. ;;
  544. 'OpenSTEP')
  545. LIBNAME="lib${LIBNAME}.a"
  546. echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
  547. libtool -static -o ${LIBNAME} - ${OBJECTS}
  548. FINAL_LIBS=${LIBNAME}
  549. ;;
  550. 'OSF1')
  551. if [ $STATIC = 1 ] ; then
  552. LIBNAME="lib${LIBNAME}.a"
  553. echo "mklib: Making OSF/1 static library: " ${LIBNAME}
  554. rm -f ${LIBNAME}
  555. ar -ruv ${LIBNAME} ${OBJECTS}
  556. FINAL_LIBS=${LIBNAME}
  557. else
  558. VERSION="${MAJOR}.${MINOR}"
  559. LIBNAME="lib${LIBNAME}.so"
  560. echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
  561. if [ "x$LINK" = "x" ] ; then
  562. if [ $CPLUSPLUS = 1 ] ; then
  563. LINK=cxx
  564. else
  565. LINK=cc
  566. fi
  567. fi
  568. rm -f ${LIBNAME}.${VERSION}
  569. ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
  570. ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
  571. FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
  572. fi
  573. ;;
  574. 'Darwin')
  575. if [ $STATIC = 1 ] ; then
  576. LIBNAME="lib${LIBNAME}.a"
  577. echo "mklib: Making Darwin static library: " ${LIBNAME}
  578. LINK="ar"
  579. OPTS="-ruvs"
  580. if [ "${ALTOPTS}" ] ; then
  581. OPTS=${ALTOPTS}
  582. fi
  583. ${LINK} ${OPTS} ${LIBNAME} ${OBJECTS}
  584. FINAL_LIBS=${LIBNAME}
  585. else
  586. # On Darwin a .bundle is used for a library that you want to dlopen
  587. if [ $DLOPEN = "1" ] ; then
  588. LIBSUFFIX="bundle"
  589. OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
  590. else
  591. LIBSUFFIX="dylib"
  592. if [ -z "$ID" ] ; then
  593. ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
  594. fi
  595. OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
  596. fi
  597. if [ ${EXPORTS} ] ; then
  598. if [ -f ${EXPORTS}".darwin" ] ; then
  599. EXPORTS=$EXPORTS".darwin"
  600. fi
  601. OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
  602. fi
  603. LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
  604. LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}"
  605. LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}"
  606. # examine first object to determine ABI
  607. set ${OBJECTS}
  608. ABI_PPC=`file $1 | grep ' ppc'`
  609. ABI_I386=`file $1 | grep ' i386'`
  610. ABI_PPC64=`file $1 | grep ' ppc64'`
  611. ABI_X86_64=`file $1 | grep ' x86_64'`
  612. if [ "${ABI_PPC}" ] ; then
  613. OPTS="${OPTS} -arch ppc"
  614. fi
  615. if [ "${ABI_I386}" ] ; then
  616. OPTS="${OPTS} -arch i386"
  617. fi
  618. if [ "${ABI_PPC64}" ] ; then
  619. OPTS="${OPTS} -arch ppc64"
  620. fi
  621. if [ "${ABI_X86_64}" ] ; then
  622. OPTS="${OPTS} -arch x86_64"
  623. fi
  624. if [ "${ALTOPTS}" ] ; then
  625. OPTS=${ALTOPTS}
  626. fi
  627. # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk
  628. # to OPTS here?
  629. # determine linker
  630. if [ $CPLUSPLUS = 1 ] ; then
  631. LINK="g++"
  632. else
  633. LINK="cc"
  634. fi
  635. echo "mklib: Making Darwin shared library: " ${LIBNAME}
  636. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  637. ln -s ${LIBNAME} ${LINKNAME}
  638. ln -s ${LIBNAME} ${LINKNAME2}
  639. FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}"
  640. fi
  641. ;;
  642. 'LynxOS')
  643. LIBNAME="lib${LIBNAME}.a"
  644. echo "mklib: Making LynxOS static library: " ${LIBNAME}
  645. rm -f ${LIBNAME}
  646. ar ru ${LIBNAME} ${OBJECTS}
  647. FINAL_LIBS=${LIBNAME}
  648. ;;
  649. 'BeOS')
  650. if [ $STATIC = 1 ] ; then
  651. LIBNAME="lib${LIBNAME}.a"
  652. echo "mklib: Making BeOS static library: " ${LIBNAME}
  653. ar -cru "${LIBNAME}" ${OBJECTS}
  654. else
  655. LIBNAME="lib${LIBNAME}.so"
  656. echo "mklib: Making BeOS shared library: " ${LIBNAME}
  657. gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}"
  658. mimeset -f "${LIBNAME}"
  659. # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific.
  660. setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!"
  661. fi
  662. FINAL_LIBS=${LIBNAME}
  663. ;;
  664. 'QNX')
  665. LIBNAME="lib${LIBNAME}.a"
  666. echo "mklib: Making QNX library: " ${LIBNAME}
  667. wlib ${LIBNAME} ${OBJECTS}
  668. FINAL_LIBS=${LIBNAME}
  669. ;;
  670. 'MorphOS')
  671. LIBNAME="lib${LIBNAME}.a"
  672. echo "mklib: Making MorphOS library: " ${LIBNAME}
  673. ppc-morphos-ar rc ${LIBNAME} ${OBJECTS}
  674. FINAL_LIBS="${LIBNAME}"
  675. ;;
  676. 'icc' | 'icc-istatic')
  677. # Intel C compiler
  678. # This should get merged into the Linux code, above, since this isn't
  679. # really a different architecture.
  680. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  681. if [ $STATIC = 1 ] ; then
  682. echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a
  683. LINK="ar"
  684. OPTS="-ruv"
  685. if [ "${ALTOPTS}" ] ; then
  686. OPTS=${ALTOPTS}
  687. fi
  688. # make lib
  689. ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
  690. # finish up
  691. FINAL_LIBS="${LIBNAME}.a"
  692. else
  693. if [ $ARCH = icc-istatic ] ; then
  694. OPTS="-shared -i-static -cxxlib-icc"
  695. else
  696. OPTS="-shared"
  697. fi
  698. if [ "${ALTOPTS}" ] ; then
  699. OPTS=${ALTOPTS}
  700. fi
  701. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  702. echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION}
  703. if [ $CPLUSPLUS = 1 ] ; then
  704. LINK="icpc"
  705. else
  706. LINK="icc"
  707. fi
  708. # rm any old libs
  709. rm -f ${LIBNAME}.so.${VERSION}
  710. rm -f ${LIBNAME}.so.${MAJOR}
  711. rm -f ${LIBNAME}.so
  712. # make lib
  713. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  714. # make usual symlinks
  715. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  716. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  717. # finish up
  718. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  719. fi
  720. ;;
  721. 'aix-gcc')
  722. # AIX with gcc
  723. if [ $STATIC = 1 ] ; then
  724. LIBNAME="lib${LIBNAME}.a"
  725. echo "mklib: Making AIX GCC static library: " ${LIBNAME}
  726. rm -f ${LIBNAME}
  727. ar ru ${LIBNAME} ${OBJECTS}
  728. FINAL_LIBS=${LIBNAME}
  729. else
  730. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  731. echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
  732. # remove old lib
  733. rm -f ${LIBNAME}
  734. # make the lib
  735. gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
  736. # NOTE: the application linking with this library must specify
  737. # the -Wl,-brtl flags to gcc
  738. FINAL_LIBS=${LIBNAME}
  739. fi
  740. ;;
  741. 'ultrix')
  742. # XXX untested
  743. if [ $STATIC = 0 ] ; then
  744. echo "mklib: Warning shared libs not supported on Ultrix"
  745. fi
  746. LIBNAME="lib${LIBNAME}.a"
  747. echo "mklib: Making static library for Ultrix: " ${LIBNAME}
  748. rm -f ${LIBNAME}
  749. ar ru ${LIBNAME} ${OBJECTS}
  750. FINAL_LIBS="${LIBNAME}"
  751. ;;
  752. CYGWIN*)
  753. # GCC-based environment
  754. CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
  755. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  756. if [ $STATIC = 1 ] ; then
  757. echo "mklib: Making" $ARCH "static library: " ${LIBNAME}.a
  758. LINK="ar"
  759. OPTS="-ru"
  760. if [ "${ALTOPTS}" ] ; then
  761. OPTS=${ALTOPTS}
  762. fi
  763. # make lib
  764. ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS}
  765. ranlib ${LIBNAME}.a
  766. # finish up
  767. FINAL_LIBS=${LIBNAME}.a
  768. else
  769. OPTS="-shared -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
  770. if [ "${ALTOPTS}" ] ; then
  771. OPTS=${ALTOPTS}
  772. fi
  773. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}-${MAJOR}.dll
  774. if [ $CPLUSPLUS = 1 ] ; then
  775. LINK="g++"
  776. else
  777. LINK="gcc"
  778. fi
  779. # rm any old libs
  780. rm -f ${LIBNAME}-${MAJOR}.dll
  781. rm -f ${LIBNAME}.dll.a
  782. rm -f ${LIBNAME}.a
  783. # make lib
  784. ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS}
  785. # make usual symlinks
  786. ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
  787. # finish up
  788. FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
  789. # special case for installing in bin
  790. FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
  791. fi
  792. ;;
  793. 'example')
  794. # If you're adding support for a new architecture, you can
  795. # start with this:
  796. if [ $STATIC = 1 ] ; then
  797. LIBNAME="lib${LIBNAME}.a"
  798. echo "mklib: Making static library for example arch: " ${LIBNAME}
  799. rm -f ${LIBNAME}
  800. ar rv ${LIBNAME} ${OBJECTS}
  801. FINAL_LIBS="${LIBNAME}"
  802. else
  803. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  804. echo "mklib: Making shared library for example arch: " ${LIBNAME}
  805. ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
  806. FINAL_LIBS="${LIBNAME}"
  807. fi
  808. ;;
  809. *)
  810. echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
  811. echo "mklib: Please add necessary commands to mklib script."
  812. ;;
  813. esac
  814. #
  815. # Put library files into installation directory if specified.
  816. #
  817. if [ ${INSTALLDIR} != "." ] ; then
  818. echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
  819. mv ${FINAL_LIBS} ${INSTALLDIR}/
  820. fi