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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  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. # Clear CDPATH as the 'cd' command will echo stuff
  24. # to stdout if it is set
  25. unset CDPATH
  26. # Given a list of files, look for .a archives and unpack them.
  27. # Return the original list of files minus the .a files plus the unpacked files.
  28. # first param: name of a temp directory (to be deleted when finished)
  29. # remaining params: list of .o and .a files
  30. expand_archives() {
  31. DIR=$1
  32. shift
  33. FILES=$@
  34. NEWFILES=""
  35. ORIG_DIR=`pwd`
  36. mkdir -p "$DIR"
  37. cd "$DIR"
  38. for FILE in $FILES ; do
  39. case $FILE in
  40. *.a)
  41. # extract the .o files from this .a archive
  42. case $FILE in
  43. /*) ;;
  44. *) FILE="$ORIG_DIR/$FILE" ;;
  45. esac
  46. MEMBERS=`ar t $FILE`
  47. ar x $FILE
  48. for MEMBER in $MEMBERS ; do
  49. NEWFILES="$NEWFILES $DIR/$MEMBER"
  50. done
  51. ;;
  52. *)
  53. # other file type, just add to list
  54. NEWFILES="$NEWFILES $FILE"
  55. ;;
  56. esac
  57. done
  58. cd "$ORIG_DIR"
  59. echo $NEWFILES
  60. }
  61. # Make static library with 'ar'
  62. # params:
  63. # options to ar
  64. # 1 or 0 to indicate if ranlib should be run
  65. # libname to make
  66. # list of object files
  67. # Return name of library we made
  68. # Example: "make_ar_static_lib -ru 1 libfoo.a foo.o bar.o"
  69. make_ar_static_lib() {
  70. OPTS=$1
  71. shift;
  72. RANLIB=$1
  73. shift;
  74. LIBNAME=$1
  75. shift;
  76. OBJECTS=$@
  77. # remove existing lib, if present
  78. rm -f ${LIBNAME}
  79. # make static lib
  80. ar ${OPTS} ${LIBNAME} ${OBJECTS}
  81. # run ranlib
  82. if [ ${RANLIB} = 1 ] ; then
  83. ranlib ${LIBNAME}
  84. fi
  85. echo ${LIBNAME}
  86. }
  87. # Print usage info.
  88. usage() {
  89. echo 'Usage: mklib [options] objects'
  90. echo 'Create a shared library from object files.'
  91. echo ' -o LIBRARY specifies the name of the resulting library, without'
  92. echo ' the leading "lib" or any suffix.'
  93. echo ' (eg: "-o GL" might result in "libGL.so" being made)'
  94. echo ' -major N specifies major version number (default is 1)'
  95. echo ' -minor N specifies minor version number (default is 0)'
  96. echo ' -patch N specifies patch version number (default is 0)'
  97. echo ' -lLIBRARY specifies a dependency on LIBRARY'
  98. echo ' -LDIR search in DIR for library dependencies at build time'
  99. echo ' -RDIR search in DIR for library dependencies at run time'
  100. echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)'
  101. echo ' Not observed on all systems at this time.'
  102. echo ' -ldflags OPT specify any additional linker flags in OPT'
  103. echo ' -cplusplus link with C++ runtime'
  104. echo ' -static make a static library (default is dynamic/shared)'
  105. echo ' -dlopen make a shared library suitable for dynamic loading'
  106. echo ' -install DIR put resulting library file(s) in DIR'
  107. echo ' -arch ARCH override using `uname` to determine host system'
  108. echo ' -archopt OPT specify an extra achitecture-specific option OPT'
  109. echo ' -altopts OPTS alternate options to override all others'
  110. echo " -noprefix don't prefix library name with 'lib' nor add any suffix"
  111. echo ' -exports FILE only export the symbols listed in FILE'
  112. echo ' -id NAME Sets the id of the dylib (Darwin)'
  113. echo ' -h, --help display this information and exit'
  114. }
  115. #
  116. # Option defaults
  117. #
  118. LIBNAME=""
  119. MAJOR=1
  120. MINOR=0
  121. PATCH=""
  122. DEPS=""
  123. LINK=""
  124. LDFLAGS=""
  125. CPLUSPLUS=0
  126. STATIC=0
  127. DLOPEN=0
  128. INSTALLDIR="."
  129. ARCH="auto"
  130. ARCHOPT=""
  131. NOPREFIX=0
  132. EXPORTS=""
  133. ID=""
  134. #
  135. # Parse arguments
  136. #
  137. while true
  138. do
  139. case $1 in
  140. '-h' | '--help')
  141. usage
  142. exit 1
  143. ;;
  144. '-o')
  145. shift 1;
  146. LIBNAME=$1
  147. ;;
  148. '-major')
  149. shift 1;
  150. MAJOR=$1
  151. ;;
  152. '-minor')
  153. shift 1;
  154. MINOR=$1
  155. ;;
  156. '-patch')
  157. shift 1;
  158. PATCH=$1
  159. ;;
  160. '-linker')
  161. shift 1;
  162. LINK=$1
  163. ;;
  164. '-ldflags')
  165. shift 1;
  166. LDFLAGS=$1
  167. ;;
  168. -l*)
  169. DEPS="$DEPS $1"
  170. ;;
  171. -L*)
  172. DEPS="$DEPS $1"
  173. ;;
  174. -R*)
  175. DEPS="$DEPS $1"
  176. ;;
  177. -Wl*)
  178. DEPS="$DEPS $1"
  179. ;;
  180. -pthread)
  181. # this is a special case (see bugzilla 10876)
  182. DEPS="$DEPS $1"
  183. ;;
  184. '-pthread')
  185. DEPS="$DEPS -pthread"
  186. ;;
  187. '-cplusplus')
  188. CPLUSPLUS=1
  189. ;;
  190. '-static')
  191. STATIC=1
  192. ;;
  193. '-dlopen')
  194. DLOPEN=1
  195. ;;
  196. '-install')
  197. shift 1;
  198. INSTALLDIR=$1
  199. ;;
  200. '-arch')
  201. shift 1;
  202. ARCH=$1
  203. ;;
  204. '-archopt')
  205. shift 1;
  206. ARCHOPT=$1
  207. ;;
  208. '-altopts')
  209. shift 1;
  210. ALTOPTS=$1
  211. ;;
  212. '-noprefix')
  213. NOPREFIX=1
  214. ;;
  215. '-exports')
  216. shift 1;
  217. EXPORTS=$1
  218. ;;
  219. '-id')
  220. shift 1;
  221. ID=$1
  222. ;;
  223. -*)
  224. echo "mklib: Unknown option: " $1 ;
  225. exit 1
  226. ;;
  227. *)
  228. # This should be the first object file, stop parsing
  229. break
  230. esac
  231. shift 1
  232. done
  233. OBJECTS=$@
  234. if [ ${ARCH} = "auto" ] ; then
  235. ARCH=`uname`
  236. fi
  237. if [ $STATIC = 1 ]; then
  238. # filter out linker options inside object list
  239. NEWOBJECTS=""
  240. for OBJ in $OBJECTS ; do
  241. case $OBJ in
  242. -Wl,*)
  243. echo "mklib: warning: ignoring $OBJ for static library"
  244. ;;
  245. *)
  246. NEWOBJECTS="$NEWOBJECTS $OBJ"
  247. ;;
  248. esac
  249. done
  250. OBJECTS=$NEWOBJECTS
  251. fi
  252. #
  253. # Error checking
  254. #
  255. if [ "x${LIBNAME}" = "x" ] ; then
  256. echo "mklib: Error: no library name specified (-h for help)"
  257. exit 1
  258. fi
  259. if [ "x${OBJECTS}" = "x" ] ; then
  260. echo "mklib: Error: no object files specified (-h for help)"
  261. exit 1
  262. fi
  263. #
  264. # Debugging info
  265. #
  266. if [ ] ; then
  267. echo "-----------------"
  268. echo ARCH is $ARCH
  269. echo LIBNAME is $LIBNAME
  270. echo MAJOR is $MAJOR
  271. echo MINOR is $MINOR
  272. echo PATCH is $PATCH
  273. echo DEPS are $DEPS
  274. echo "EXPORTS in" $EXPORTS
  275. echo ID is $ID
  276. echo "-----------------"
  277. fi
  278. #
  279. # OK, make the library now
  280. #
  281. case $ARCH in
  282. 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/* | 'NetBSD')
  283. # we assume gcc
  284. if [ "x$LINK" = "x" ] ; then
  285. # -linker was not specified so set default link command now
  286. if [ $CPLUSPLUS = 1 ] ; then
  287. LINK=g++
  288. else
  289. LINK=gcc
  290. fi
  291. fi
  292. if [ $NOPREFIX = 1 ] ; then
  293. # No "lib" or ".so" part
  294. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}
  295. case $ARCH in 'Linux' | 'GNU' | GNU/*)
  296. OPTS="-Xlinker -Bsymbolic -shared"
  297. ;;
  298. *)
  299. OPTS="-shared"
  300. ;;
  301. esac
  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}" -a `uname -m` = "x86_64" ] ; then
  307. OPTS="-m32 ${OPTS}"
  308. fi
  309. if [ "${ALTOPTS}" ] ; then
  310. OPTS=${ALTOPTS}
  311. fi
  312. rm -f ${LIBNAME}
  313. # make lib
  314. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  315. # finish up
  316. FINAL_LIBS="${LIBNAME}"
  317. elif [ $STATIC = 1 ] ; then
  318. # make a static .a library
  319. LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a"
  320. echo "mklib: Making" $ARCH "static library: " ${LIBNAME}
  321. OPTS="-ru"
  322. if [ "${ALTOPTS}" ] ; then
  323. OPTS=${ALTOPTS}
  324. fi
  325. # expand .a into .o files
  326. NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
  327. # make static lib
  328. FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
  329. # remove temporary extracted .o files
  330. rm -rf ${LIBNAME}.obj
  331. else
  332. # make dynamic library
  333. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  334. case $ARCH in 'Linux' | 'GNU' | GNU/*)
  335. OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  336. ;;
  337. *)
  338. OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}"
  339. ;;
  340. esac
  341. if [ $EXPORTS ] ; then
  342. #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}"
  343. # Make the 'exptmp' file for --version-script option
  344. echo "{" > exptmp
  345. echo "global:" >> exptmp
  346. sed 's/$/;/' ${EXPORTS} >> exptmp
  347. echo "local:" >> exptmp
  348. echo "*;" >> exptmp
  349. echo "};" >> exptmp
  350. OPTS="${OPTS} -Xlinker --version-script=exptmp"
  351. # exptmp is removed below
  352. fi
  353. # Check if objects are 32-bit and we're running in 64-bit
  354. # environment. If so, pass -m32 flag to linker.
  355. set ${OBJECTS}
  356. ABI32=`file $1 | grep 32-bit`
  357. if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then
  358. OPTS="-m32 ${OPTS}"
  359. fi
  360. if [ "${ALTOPTS}" ] ; then
  361. OPTS=${ALTOPTS}
  362. fi
  363. if [ x${PATCH} = "x" ] ; then
  364. VERSION="${MAJOR}.${MINOR}"
  365. else
  366. VERSION="${MAJOR}.${MINOR}.${PATCH}"
  367. fi
  368. echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION}
  369. # rm any old libs
  370. rm -f ${LIBNAME}.so.${VERSION}
  371. rm -f ${LIBNAME}.so.${MAJOR}
  372. rm -f ${LIBNAME}.so
  373. # make lib
  374. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS}
  375. # make usual symlinks
  376. ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR}
  377. ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so
  378. # finish up
  379. FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so"
  380. # rm -f exptmp
  381. fi
  382. ;;
  383. 'SunOS')
  384. if [ $STATIC = 1 ] ; then
  385. LIBNAME="lib${LIBNAME}.a"
  386. echo "mklib: Making SunOS static library: " ${LIBNAME}
  387. FINAL_LIBS=`make_ar_static_lib -ruc 0 ${LIBNAME} ${OBJECTS}`
  388. else
  389. if [ $NOPREFIX = 0 ] ; then
  390. LIBNAME="lib${LIBNAME}.so"
  391. fi
  392. echo "mklib: Making SunOS shared library: " ${LIBNAME}
  393. if [ "x$LINK" = "x" ] ; then
  394. # -linker was not specified, choose default linker now
  395. if [ $CPLUSPLUS = 1 ] ; then
  396. # determine linker and options for C++ code
  397. if [ `which c++` ] ; then
  398. # use Sun c++
  399. LINK="c++"
  400. elif [ `type g++` ] ; then
  401. # use g++
  402. LINK="g++"
  403. else
  404. echo "mklib: warning: can't find C++ compiler, trying CC."
  405. LINK="CC"
  406. fi
  407. else
  408. # use native Sun linker for C code
  409. LINK="ld"
  410. fi
  411. fi
  412. # linker options
  413. if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
  414. # SunOS tools, -G to make shared libs
  415. OPTS="-G"
  416. else
  417. # gcc linker
  418. # Check if objects are 32-bit and we're running in 64-bit
  419. # environment. If so, pass -m32 flag to linker.
  420. set ${OBJECTS}
  421. ABI32=`file $1 | grep 32-bit`
  422. if [ "${ABI32}" ] ; then
  423. OPTS="-m32 -shared -Wl,-Bdynamic"
  424. else
  425. OPTS="-m64 -shared -Wl,-Bdynamic"
  426. fi
  427. fi
  428. # If using Sun C++ compiler, need to tell it not to add runpaths
  429. # that are specific to the build machine
  430. if [ ${LINK} = "CC" ] ; then
  431. OPTS="${OPTS} -norunpath"
  432. fi
  433. # Solaris linker requires explicitly listing the Standard C & C++
  434. # libraries in the link path when building shared objects
  435. if [ ${LINK} = "CC" ] ; then
  436. DEPS="${DEPS} -lCrun"
  437. fi
  438. DEPS="${DEPS} -lc"
  439. if [ $EXPORTS ] ; then
  440. # Make the 'mapfile.scope' linker mapfile
  441. echo "{" > mapfile.scope
  442. echo "global:" >> mapfile.scope
  443. sed 's/$/;/' ${EXPORTS} >> mapfile.scope
  444. echo "local:" >> mapfile.scope
  445. echo " *;" >> mapfile.scope
  446. echo "};" >> mapfile.scope
  447. OPTS="${OPTS} -Wl,-Mmapfile.scope"
  448. fi
  449. # Check if objects are 64-bit
  450. # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1
  451. set ${OBJECTS}
  452. if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then
  453. ABI64=`file $1 | grep "ELF 64-bit"`
  454. if [ "${ABI64}" ] ; then
  455. case `uname -p` in
  456. sparc) OPTS="${OPTS} -xarch=v9" ;;
  457. i386) OPTS="${OPTS} -xarch=amd64" ;;
  458. esac
  459. fi
  460. fi
  461. if [ "${ALTOPTS}" ] ; then
  462. OPTS=${ALTOPTS}
  463. fi
  464. # for debug:
  465. #echo "mklib: linker is" ${LINK} ${OPTS}
  466. if [ $NOPREFIX = 1 ] ; then
  467. rm -f ${LIBNAME}
  468. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  469. FINAL_LIBS="${LIBNAME}"
  470. else
  471. rm -f ${LIBNAME}.${MAJOR} ${LIBNAME}
  472. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS}
  473. ln -s ${LIBNAME}.${MAJOR} ${LIBNAME}
  474. FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}"
  475. fi
  476. fi
  477. ;;
  478. 'FreeBSD')
  479. # we assume gcc
  480. if [ "x$LINK" = "x" ] ; then
  481. # -linker was not specified so set default link command now
  482. if [ $CPLUSPLUS = 1 ] ; then
  483. LINK=g++
  484. else
  485. LINK=gcc
  486. fi
  487. fi
  488. if [ $NOPREFIX = 1 ] ; then
  489. # No "lib" or ".so" part
  490. echo "mklib: Making FreeBSD shared library: " ${LIBNAME}
  491. OPTS="-shared"
  492. if [ "${ALTOPTS}" ] ; then
  493. OPTS=${ALTOPTS}
  494. fi
  495. rm -f ${LIBNAME}
  496. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  497. FINAL_LIBS=${LIBNAME}
  498. elif [ $STATIC = 1 ] ; then
  499. # make a static .a library
  500. STLIB="lib${LIBNAME}.a"
  501. echo "mklib: Making FreeBSD static library: " ${STLIB}
  502. # expand .a into .o files
  503. NEW_OBJECTS=`expand_archives ${STLIB}.obj $OBJECTS`
  504. FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}`
  505. # remove temporary extracted .o files
  506. rm -rf ${STLIB}.obj
  507. else
  508. # make dynamic library
  509. SHLIB="lib${LIBNAME}.so.${MAJOR}"
  510. OPTS="-shared -Wl,-soname,${SHLIB}"
  511. if [ "${ALTOPTS}" ] ; then
  512. OPTS=${ALTOPTS}
  513. fi
  514. echo "mklib: Making FreeBSD shared library: " ${SHLIB}
  515. rm -f ${SHLIB}
  516. ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS}
  517. ln -sf ${SHLIB} "lib${LIBNAME}.so"
  518. FINAL_LIBS="${SHLIB} lib${LIBNAME}.so"
  519. fi
  520. ;;
  521. 'IRIX' | 'IRIX64')
  522. if [ $STATIC = 1 ] ; then
  523. LIBNAME="lib${LIBNAME}.a"
  524. FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}`
  525. else
  526. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  527. # examine first object to determine ABI
  528. set ${OBJECTS}
  529. ABI_O32=`file $1 | grep 'ELF 32-bit'`
  530. ABI_N32=`file $1 | grep 'ELF N32'`
  531. ABI_N64=`file $1 | grep 'ELF 64-bit'`
  532. if [ "${ABI_O32}" ] ; then
  533. OPTS="-32 -shared -all"
  534. ABI="o32-bit"
  535. elif [ "${ABI_N32}" ] ; then
  536. OPTS="-n32 -shared -all"
  537. ABI="n32-bit"
  538. elif [ "${ABI_N64}" ] ; then
  539. OPTS="-64 -shared -all"
  540. ABI="64-bit"
  541. else
  542. echo "Error: Unexpected IRIX ABI!"
  543. exit 1
  544. fi
  545. if [ "${ALTOPTS}" ] ; then
  546. OPTS=${ALTOPTS}
  547. fi
  548. if [ $CPLUSPLUS = 1 ] ; then
  549. LINK="CC"
  550. else
  551. LINK="ld"
  552. fi
  553. echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME}
  554. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  555. FINAL_LIBS=${LIBNAME}
  556. fi
  557. ;;
  558. 'linux-cygwin')
  559. LIBNAME="lib${LIBNAME}.a"
  560. echo "mklib: Making linux-cygwin library: " ${LIBNAME}
  561. rm -f ${LIBNAME}
  562. gnuwin32ar ruv ${LIBNAME} ${OBJECTS}
  563. FINAL_LIBS=${LIBNAME}
  564. ;;
  565. 'HP-UX')
  566. if [ $STATIC = 1 ] ; then
  567. LIBNAME="lib${LIBNAME}.a"
  568. echo "mklib: Making HP-UX static library: " ${LIBNAME}
  569. FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
  570. else
  571. # HP uses a .2 for their current GL/GLU libraries
  572. if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then
  573. MAJOR=2
  574. fi
  575. RUNLIB="lib${LIBNAME}.${MAJOR}"
  576. DEVLIB="lib${LIBNAME}.sl"
  577. echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB}
  578. ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS}
  579. ln -s ${RUNLIB} ${DEVLIB}
  580. FINAL_LIBS="${RUNLIB} ${DEVLIB}"
  581. fi
  582. ;;
  583. 'AIX' )
  584. # examine first object to determine ABI
  585. set ${OBJECTS}
  586. ABI_64=`file $1 | grep '64-bit'`
  587. if [ "${ABI_64}" ] ; then
  588. X64="-X64"
  589. Q64="-q64"
  590. OFILE=shr_64.o
  591. else
  592. OFILE=shr.o #Want to be consistent with the IBM libGL.a
  593. fi
  594. if [ $STATIC = 1 ] ; then
  595. LIBNAME="lib${LIBNAME}.a"
  596. echo "mklib: Making AIX static library: " ${LIBNAME}
  597. FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
  598. else
  599. EXPFILE="lib${LIBNAME}.exp"
  600. LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries
  601. OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}"
  602. rm -f ${EXPFILE} ${OFILE}
  603. NM="/bin/nm -eC ${X64}"
  604. echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE}
  605. ${NM} ${OBJECTS} | awk '{
  606. if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \
  607. && ( substr($1,1,1) != ".")) {
  608. if (substr ($1, 1, 7) != "__sinit" &&
  609. substr ($1, 1, 7) != "__sterm") {
  610. if (substr ($1, 1, 5) == "__tf1")
  611. print (substr ($1, 7))
  612. else if (substr ($1, 1, 5) == "__tf9")
  613. print (substr ($1, 15))
  614. else
  615. print $1
  616. }
  617. }
  618. }' | sort -u >> ${EXPFILE}
  619. if [ "${ALTOPTS}" ] ; then
  620. OPTS=${ALTOPTS}
  621. fi
  622. # On AIX a shared library is linked differently when
  623. # you want to dlopen the file
  624. if [ $DLOPEN = "1" ] ; then
  625. cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  626. else
  627. cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS}
  628. ar ${X64} -r ${LIBNAME} ${OFILE}
  629. fi
  630. FINAL_LIBS="${LIBNAME}"
  631. fi
  632. ;;
  633. 'OpenSTEP')
  634. LIBNAME="lib${LIBNAME}.a"
  635. echo "mklib: Making OpenSTEP static library: " ${LIBNAME}
  636. libtool -static -o ${LIBNAME} - ${OBJECTS}
  637. FINAL_LIBS=${LIBNAME}
  638. ;;
  639. 'OSF1')
  640. if [ $STATIC = 1 ] ; then
  641. LIBNAME="lib${LIBNAME}.a"
  642. echo "mklib: Making OSF/1 static library: " ${LIBNAME}
  643. FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}`
  644. else
  645. VERSION="${MAJOR}.${MINOR}"
  646. LIBNAME="lib${LIBNAME}.so"
  647. echo "mklib: Making OSF/1 shared library: " ${LIBNAME}
  648. if [ "x$LINK" = "x" ] ; then
  649. if [ $CPLUSPLUS = 1 ] ; then
  650. LINK=cxx
  651. else
  652. LINK=cc
  653. fi
  654. fi
  655. rm -f ${LIBNAME}.${VERSION}
  656. ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS}
  657. ln -sf ${LIBNAME}.${VERSION} ${LIBNAME}
  658. FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}"
  659. fi
  660. ;;
  661. 'Darwin')
  662. if [ $STATIC = 1 ] ; then
  663. LIBNAME="lib${LIBNAME}.a"
  664. echo "mklib: Making Darwin static library: " ${LIBNAME}
  665. OPTS="-ruvs"
  666. if [ "${ALTOPTS}" ] ; then
  667. OPTS=${ALTOPTS}
  668. fi
  669. # expand .a into .o files
  670. NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
  671. # make static lib
  672. FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
  673. # remove temporary extracted .o files
  674. rm -rf ${LIBNAME}.obj
  675. FINAL_LIBS=${LIBNAME}
  676. else
  677. # On Darwin a .bundle is used for a library that you want to dlopen
  678. if [ $DLOPEN = "1" ] ; then
  679. LIBSUFFIX="bundle"
  680. OPTS="${ARCHOPT} -bundle -multiply_defined suppress"
  681. else
  682. LIBSUFFIX="dylib"
  683. if [ -z "$ID" ] ; then
  684. ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
  685. fi
  686. OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}"
  687. fi
  688. if [ ${EXPORTS} ] ; then
  689. if [ -f ${EXPORTS}".darwin" ] ; then
  690. EXPORTS=$EXPORTS".darwin"
  691. fi
  692. OPTS="${OPTS} -exported_symbols_list ${EXPORTS}"
  693. fi
  694. LINKNAME="lib${LIBNAME}.${LIBSUFFIX}"
  695. LIBNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}"
  696. # examine first object to determine ABI
  697. set ${OBJECTS}
  698. ABIS=`lipo -info $1 | sed s/.*://`
  699. for ABI in $ABIS; do
  700. OPTS="${OPTS} -arch ${ABI}"
  701. done
  702. if [ "${ALTOPTS}" ] ; then
  703. OPTS=${ALTOPTS}
  704. fi
  705. # determine linker
  706. if [ $CPLUSPLUS = 1 ] ; then
  707. LINK="g++"
  708. else
  709. LINK="cc"
  710. fi
  711. echo "mklib: Making Darwin shared library: " ${LIBNAME}
  712. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS}
  713. ln -s ${LIBNAME} ${LINKNAME}
  714. FINAL_LIBS="${LIBNAME} ${LINKNAME}"
  715. fi
  716. ;;
  717. 'LynxOS')
  718. LIBNAME="lib${LIBNAME}.a"
  719. echo "mklib: Making LynxOS static library: " ${LIBNAME}
  720. FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}`
  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. FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
  785. else
  786. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  787. echo "mklib: Making AIX GCC shared library: " ${LIBNAME}
  788. # remove old lib
  789. rm -f ${LIBNAME}
  790. # make the lib
  791. gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME}
  792. # NOTE: the application linking with this library must specify
  793. # the -Wl,-brtl flags to gcc
  794. FINAL_LIBS=${LIBNAME}
  795. fi
  796. ;;
  797. 'ultrix')
  798. # XXX untested
  799. if [ $STATIC = 0 ] ; then
  800. echo "mklib: Warning shared libs not supported on Ultrix"
  801. fi
  802. LIBNAME="lib${LIBNAME}.a"
  803. echo "mklib: Making static library for Ultrix: " ${LIBNAME}
  804. FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}`
  805. ;;
  806. CYGWIN*)
  807. # GCC-based environment
  808. if [ "x$LINK" = "x" ] ; then
  809. # -linker was not specified so set default link command now
  810. if [ $CPLUSPLUS = 1 ] ; then
  811. LINK=g++
  812. else
  813. LINK=gcc
  814. fi
  815. fi
  816. if [ $NOPREFIX = 1 ] ; then
  817. # No "lib" or ".so" part
  818. echo "mklib: Making CYGWIN shared library: " ${LIBNAME}
  819. OPTS="-shared -Wl,--enable-auto-image-base"
  820. if [ "${ALTOPTS}" ] ; then
  821. OPTS=${ALTOPTS}
  822. fi
  823. rm -f ${LIBNAME}
  824. ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} || exit $?
  825. FINAL_LIBS=${LIBNAME}
  826. else
  827. CYGNAME="cyg${LIBNAME}" # prefix with "cyg"
  828. LIBNAME="lib${LIBNAME}" # prefix with "lib"
  829. if [ $STATIC = 1 ] ; then
  830. LIBNAME=${LIBNAME}.a
  831. echo "mklib: Making CYGWIN static library: " ${LIBNAME}
  832. OPTS="-ru"
  833. if [ "${ALTOPTS}" ] ; then
  834. OPTS=${ALTOPTS}
  835. fi
  836. # expand .a into .o files
  837. NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS`
  838. FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}`
  839. # remove temporary extracted .o files
  840. rm -rf ${LIBNAME}.obj
  841. else
  842. OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a"
  843. if [ "${ALTOPTS}" ] ; then
  844. OPTS=${ALTOPTS}
  845. fi
  846. echo "mklib: Making CYGWIN shared library: " ${CYGNAME}-${MAJOR}.dll
  847. # rm any old libs
  848. rm -f ${CYGNAME}-${MAJOR}.dll
  849. rm -f ${LIBNAME}-${MAJOR}.dll.a
  850. rm -f ${LIBNAME}.dll.a
  851. rm -f ${LIBNAME}.a
  852. # make lib
  853. ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} || exit $?
  854. # make usual symlinks
  855. ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a
  856. # finish up
  857. FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a"
  858. # special case for installing in bin
  859. FINAL_BINS="${CYGNAME}-${MAJOR}.dll"
  860. fi
  861. fi
  862. ;;
  863. 'example')
  864. # If you're adding support for a new architecture, you can
  865. # start with this:
  866. if [ $STATIC = 1 ] ; then
  867. LIBNAME="lib${LIBNAME}.a"
  868. echo "mklib: Making static library for example arch: " ${LIBNAME}
  869. FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}`
  870. else
  871. LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so"
  872. echo "mklib: Making shared library for example arch: " ${LIBNAME}
  873. ld -o ${LIBNAME} ${OBJECTS} ${DEPS}
  874. FINAL_LIBS="${LIBNAME}"
  875. fi
  876. ;;
  877. *)
  878. echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH}
  879. echo "mklib: Please add necessary commands to mklib script."
  880. ;;
  881. esac
  882. #
  883. # Put library files into installation directory if specified.
  884. #
  885. if [ ${INSTALLDIR} != "." ] ; then
  886. echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR}
  887. test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR}
  888. mv ${FINAL_LIBS} ${INSTALLDIR}/
  889. if [ "x${FINAL_BINS}" != "x" ] ; then
  890. echo "mklib: Installing" ${FINAL_BINS} "in" ${INSTALLDIR}
  891. mv ${FINAL_BINS} ${INSTALLDIR}/
  892. fi
  893. fi