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

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