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

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