ylwrap 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #! /bin/sh
  2. # ylwrap - wrapper for lex/yacc invocations.
  3. # Copyright (C) 1996, 1997 Free Software Foundation, Inc.
  4. # Written by Tom Tromey <tromey@cygnus.com>.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. # Usage:
  20. # ylwrap PROGRAM INPUT [OUTPUT DESIRED]... -- [ARGS]...
  21. # * PROGRAM is program to run.
  22. # * INPUT is the input file
  23. # * OUTPUT is file PROG generates
  24. # * DESIRED is file we actually want
  25. # * ARGS are passed to PROG
  26. # Any number of OUTPUT,DESIRED pairs may be used.
  27. # The program to run.
  28. prog="$1"
  29. shift
  30. # Make any relative path in $prog absolute.
  31. case "$prog" in
  32. /* | [A-Za-z]:\\*) ;;
  33. */*) prog="`pwd`/$prog" ;;
  34. esac
  35. # The input.
  36. input="$1"
  37. shift
  38. case "$input" in
  39. /* | [A-Za-z]:\\*)
  40. # Absolute path; do nothing.
  41. ;;
  42. *)
  43. # Relative path. Make it absolute. Why? Because otherwise any
  44. # debugging info in the generated file will point to the wrong
  45. # place. This is really gross.
  46. input="`pwd`/$input"
  47. ;;
  48. esac
  49. # We don't want to use the absolute path if the input in the current
  50. # directory like when making a tar ball.
  51. input_base=`echo $input | sed -e 's|.*/||'`
  52. if test -f $input_base && cmp $input_base $input >/dev/null 2>&1; then
  53. input=$input_base
  54. fi
  55. pairlist=
  56. while test "$#" -ne 0; do
  57. if test "$1" = "--"; then
  58. shift
  59. break
  60. fi
  61. pairlist="$pairlist $1"
  62. shift
  63. done
  64. # FIXME: add hostname here for parallel makes that run commands on
  65. # other machines. But that might take us over the 14-char limit.
  66. dirname=ylwrap$$
  67. trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
  68. mkdir $dirname || exit 1
  69. cd $dirname
  70. case "$input" in
  71. /* | [A-Za-z]:\\*)
  72. # Absolute path; do nothing.
  73. ;;
  74. *)
  75. # Make a symbolic link, hard link or hardcopy.
  76. ln -s ../"$input" . > /dev/null 2>&1 || ln ../"$input" . > /dev/null 2>&1 || cp ../"$input" .
  77. ;;
  78. esac
  79. $prog ${1+"$@"} "$input"
  80. status=$?
  81. if test $status -eq 0; then
  82. set X $pairlist
  83. shift
  84. first=yes
  85. while test "$#" -ne 0; do
  86. if test -f "$1"; then
  87. # If $2 is an absolute path name, then just use that,
  88. # otherwise prepend `../'.
  89. case "$2" in
  90. /* | [A-Za-z]:\\*) target="$2";;
  91. *) target="../$2";;
  92. esac
  93. mv "$1" "$target" || status=$?
  94. else
  95. # A missing file is only an error for the first file. This
  96. # is a blatant hack to let us support using "yacc -d". If -d
  97. # is not specified, we don't want an error when the header
  98. # file is "missing".
  99. if test $first = yes; then
  100. status=1
  101. fi
  102. fi
  103. shift
  104. shift
  105. first=no
  106. done
  107. else
  108. status=$?
  109. fi
  110. # Remove the directory.
  111. cd ..
  112. rm -rf $dirname
  113. exit $status