Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

mklib 24KB

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