mergelib.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. XCOMM!/bin/sh
  2. XCOMM
  3. XCOMM $XConsortium: mergelib.cpp,v 1.3 91/08/22 11:08:08 rws Exp $
  4. XCOMM
  5. XCOMM Copyright 1989 Massachusetts Institute of Technology
  6. XCOMM
  7. XCOMM Permission to use, copy, modify, distribute, and sell this software and its
  8. XCOMM documentation for any purpose is hereby granted without fee, provided that
  9. XCOMM the above copyright notice appear in all copies and that both that
  10. XCOMM copyright notice and this permission notice appear in supporting
  11. XCOMM documentation, and that the name of M.I.T. not be used in advertising or
  12. XCOMM publicity pertaining to distribution of the software without specific,
  13. XCOMM written prior permission. M.I.T. makes no representations about the
  14. XCOMM suitability of this software for any purpose. It is provided "as is"
  15. XCOMM without express or implied warranty.
  16. XCOMM
  17. XCOMM M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  18. XCOMM IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  19. XCOMM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  20. XCOMM WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  21. XCOMM OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  22. XCOMM CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  23. XCOMM
  24. XCOMM Author: Jim Fulton, MIT X Consortium
  25. XCOMM
  26. XCOMM mergelib - merge one library into another; this is commonly used by X
  27. XCOMM to add the extension library into the base Xlib.
  28. XCOMM
  29. usage="usage: $0 to-library from-library [object-filename-prefix]"
  30. objprefix=_
  31. case $# in
  32. 2) ;;
  33. 3) objprefix=$3 ;;
  34. *) echo "$usage" 1>&2; exit 1 ;;
  35. esac
  36. tolib=$1
  37. fromlib=$2
  38. if [ ! -f $fromlib ]; then
  39. echo "$0: no such from-library $fromlib" 1>&2
  40. exit 1
  41. fi
  42. if [ ! -f $tolib ]; then
  43. echo "$0: no such to-library $tolib" 1>&2
  44. exit 1
  45. fi
  46. XCOMM
  47. XCOMM Create a temp directory, and figure out how to reference the
  48. XCOMM object files from it (i.e. relative vs. absolute path names).
  49. XCOMM
  50. tmpdir=tmp.$$
  51. origdir=..
  52. mkdir $tmpdir
  53. if [ ! -d $tmpdir ]; then
  54. echo "$0: unable to create temporary directory $tmpdir" 1>&2
  55. exit 1
  56. fi
  57. case "$fromlib" in
  58. /?*) upfrom= ;;
  59. *) upfrom=../ ;;
  60. esac
  61. case "$tolib" in
  62. /?*) upto= ;;
  63. *) upto=../ ;;
  64. esac
  65. XCOMM
  66. XCOMM In the temp directory, extract all of the object files and prefix
  67. XCOMM them with some symbol to avoid name clashes with the base library.
  68. XCOMM
  69. cd $tmpdir
  70. ar x ${upfrom}$fromlib
  71. for i in *.o; do
  72. mv $i ${objprefix}$i
  73. done
  74. XCOMM
  75. XCOMM Merge in the object modules, ranlib (if appropriate) and cleanup
  76. XCOMM
  77. ARCMD ${upto}$tolib *.o
  78. RANLIB ${upto}$tolib
  79. cd $origdir
  80. rm -rf $tmpdir