ylwrap 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #! /bin/sh
  2. # ylwrap - wrapper for lex/yacc invocations.
  3. scriptversion=2009-04-28.21; # UTC
  4. # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
  5. # 2007, 2009 Free Software Foundation, Inc.
  6. #
  7. # Written by Tom Tromey <tromey@cygnus.com>.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. # As a special exception to the GNU General Public License, if you
  22. # distribute this file as part of a program that contains a
  23. # configuration script generated by Autoconf, you may include it under
  24. # the same distribution terms that you use for the rest of that program.
  25. # This file is maintained in Automake, please report
  26. # bugs to <bug-automake@gnu.org> or send patches to
  27. # <automake-patches@gnu.org>.
  28. case "$1" in
  29. '')
  30. echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
  31. exit 1
  32. ;;
  33. --basedir)
  34. basedir=$2
  35. shift 2
  36. ;;
  37. -h|--h*)
  38. cat <<\EOF
  39. Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
  40. Wrapper for lex/yacc invocations, renaming files as desired.
  41. INPUT is the input file
  42. OUTPUT is one file PROG generates
  43. DESIRED is the file we actually want instead of OUTPUT
  44. PROGRAM is program to run
  45. ARGS are passed to PROG
  46. Any number of OUTPUT,DESIRED pairs may be used.
  47. Report bugs to <bug-automake@gnu.org>.
  48. EOF
  49. exit $?
  50. ;;
  51. -v|--v*)
  52. echo "ylwrap $scriptversion"
  53. exit $?
  54. ;;
  55. esac
  56. # The input.
  57. input="$1"
  58. shift
  59. case "$input" in
  60. [\\/]* | ?:[\\/]*)
  61. # Absolute path; do nothing.
  62. ;;
  63. *)
  64. # Relative path. Make it absolute.
  65. input="`pwd`/$input"
  66. ;;
  67. esac
  68. pairlist=
  69. while test "$#" -ne 0; do
  70. if test "$1" = "--"; then
  71. shift
  72. break
  73. fi
  74. pairlist="$pairlist $1"
  75. shift
  76. done
  77. # The program to run.
  78. prog="$1"
  79. shift
  80. # Make any relative path in $prog absolute.
  81. case "$prog" in
  82. [\\/]* | ?:[\\/]*) ;;
  83. *[\\/]*) prog="`pwd`/$prog" ;;
  84. esac
  85. # FIXME: add hostname here for parallel makes that run commands on
  86. # other machines. But that might take us over the 14-char limit.
  87. dirname=ylwrap$$
  88. trap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
  89. mkdir $dirname || exit 1
  90. cd $dirname
  91. case $# in
  92. 0) "$prog" "$input" ;;
  93. *) "$prog" "$@" "$input" ;;
  94. esac
  95. ret=$?
  96. if test $ret -eq 0; then
  97. set X $pairlist
  98. shift
  99. first=yes
  100. # Since DOS filename conventions don't allow two dots,
  101. # the DOS version of Bison writes out y_tab.c instead of y.tab.c
  102. # and y_tab.h instead of y.tab.h. Test to see if this is the case.
  103. y_tab_nodot="no"
  104. if test -f y_tab.c || test -f y_tab.h; then
  105. y_tab_nodot="yes"
  106. fi
  107. # The directory holding the input.
  108. input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
  109. # Quote $INPUT_DIR so we can use it in a regexp.
  110. # FIXME: really we should care about more than `.' and `\'.
  111. input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
  112. while test "$#" -ne 0; do
  113. from="$1"
  114. # Handle y_tab.c and y_tab.h output by DOS
  115. if test $y_tab_nodot = "yes"; then
  116. if test $from = "y.tab.c"; then
  117. from="y_tab.c"
  118. else
  119. if test $from = "y.tab.h"; then
  120. from="y_tab.h"
  121. fi
  122. fi
  123. fi
  124. if test -f "$from"; then
  125. # If $2 is an absolute path name, then just use that,
  126. # otherwise prepend `../'.
  127. case "$2" in
  128. [\\/]* | ?:[\\/]*) target="$2";;
  129. *) target="../$2";;
  130. esac
  131. # We do not want to overwrite a header file if it hasn't
  132. # changed. This avoid useless recompilations. However the
  133. # parser itself (the first file) should always be updated,
  134. # because it is the destination of the .y.c rule in the
  135. # Makefile. Divert the output of all other files to a temporary
  136. # file so we can compare them to existing versions.
  137. if test $first = no; then
  138. realtarget="$target"
  139. target="tmp-`echo $target | sed s/.*[\\/]//g`"
  140. fi
  141. # Edit out `#line' or `#' directives.
  142. #
  143. # We don't want the resulting debug information to point at
  144. # an absolute srcdir; it is better for it to just mention the
  145. # .y file with no path.
  146. #
  147. # We want to use the real output file name, not yy.lex.c for
  148. # instance.
  149. #
  150. # We want the include guards to be adjusted too.
  151. FROM=`echo "$from" | sed \
  152. -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
  153. -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
  154. TARGET=`echo "$2" | sed \
  155. -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
  156. -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
  157. sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
  158. -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
  159. # Check whether header files must be updated.
  160. if test $first = no; then
  161. if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
  162. echo "$2" is unchanged
  163. rm -f "$target"
  164. else
  165. echo updating "$2"
  166. mv -f "$target" "$realtarget"
  167. fi
  168. fi
  169. else
  170. # A missing file is only an error for the first file. This
  171. # is a blatant hack to let us support using "yacc -d". If -d
  172. # is not specified, we don't want an error when the header
  173. # file is "missing".
  174. if test $first = yes; then
  175. ret=1
  176. fi
  177. fi
  178. shift
  179. shift
  180. first=no
  181. done
  182. else
  183. ret=$?
  184. fi
  185. # Remove the directory.
  186. cd ..
  187. rm -rf $dirname
  188. exit $ret
  189. # Local Variables:
  190. # mode: shell-script
  191. # sh-indentation: 2
  192. # eval: (add-hook 'write-file-hooks 'time-stamp)
  193. # time-stamp-start: "scriptversion="
  194. # time-stamp-format: "%:y-%02m-%02d.%02H"
  195. # time-stamp-time-zone: "UTC"
  196. # time-stamp-end: "; # UTC"
  197. # End: