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