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

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