Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | #! /bin/sh |
2 | # ylwrap - wrapper for lex/yacc invocations. | |
6048df60 | 3 | # Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
252b5132 RH |
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 | ||
6048df60 DD |
20 | # Usage: |
21 | # ylwrap PROGRAM INPUT [OUTPUT DESIRED]... -- [ARGS]... | |
22 | # * PROGRAM is program to run. | |
23 | # * INPUT is the input file | |
24 | # * OUTPUT is file PROG generates | |
25 | # * DESIRED is file we actually want | |
26 | # * ARGS are passed to PROG | |
27 | # Any number of OUTPUT,DESIRED pairs may be used. | |
252b5132 | 28 | |
6048df60 DD |
29 | # The program to run. |
30 | prog="$1" | |
31 | shift | |
32 | # Make any relative path in $prog absolute. | |
33 | case "$prog" in | |
34 | /* | [A-Za-z]:\\*) ;; | |
35 | */*) prog="`pwd`/$prog" ;; | |
252b5132 RH |
36 | esac |
37 | ||
38 | # The input. | |
39 | input="$1" | |
40 | shift | |
41 | case "$input" in | |
6048df60 | 42 | /* | [A-Za-z]:\\*) |
252b5132 RH |
43 | # Absolute path; do nothing. |
44 | ;; | |
6048df60 DD |
45 | *) |
46 | # Relative path. Make it absolute. Why? Because otherwise any | |
47 | # debugging info in the generated file will point to the wrong | |
48 | # place. This is really gross. | |
252b5132 RH |
49 | input="`pwd`/$input" |
50 | ;; | |
51 | esac | |
52 | ||
6048df60 DD |
53 | # We don't want to use the absolute path if the input in the current |
54 | # directory like when making a tar ball. | |
55 | input_base=`echo $input | sed -e 's|.*/||'` | |
56 | if test -f $input_base && cmp $input_base $input >/dev/null 2>&1; then | |
57 | input=$input_base | |
58 | fi | |
59 | ||
252b5132 RH |
60 | pairlist= |
61 | while test "$#" -ne 0; do | |
6048df60 DD |
62 | if test "$1" = "--"; then |
63 | shift | |
64 | break | |
65 | fi | |
66 | pairlist="$pairlist $1" | |
67 | shift | |
252b5132 RH |
68 | done |
69 | ||
70 | # FIXME: add hostname here for parallel makes that run commands on | |
71 | # other machines. But that might take us over the 14-char limit. | |
72 | dirname=ylwrap$$ | |
73 | trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 | |
74 | mkdir $dirname || exit 1 | |
75 | ||
76 | cd $dirname | |
6048df60 DD |
77 | case "$input" in |
78 | /* | [A-Za-z]:\\*) | |
79 | # Absolute path; do nothing. | |
80 | ;; | |
81 | *) | |
82 | # Make a symbolic link, hard link or hardcopy. | |
83 | ln -s ../"$input" . > /dev/null 2>&1 || ln ../"$input" . > /dev/null 2>&1 || cp ../"$input" . | |
84 | ;; | |
252b5132 | 85 | esac |
6048df60 DD |
86 | $prog ${1+"$@"} "$input" |
87 | status=$? | |
88 | ||
89 | if test $status -eq 0; then | |
90 | set X $pairlist | |
91 | shift | |
92 | first=yes | |
93 | while test "$#" -ne 0; do | |
94 | if test -f "$1"; then | |
95 | # If $2 is an absolute path name, then just use that, | |
96 | # otherwise prepend `../'. | |
97 | case "$2" in | |
98 | /* | [A-Za-z]:\\*) target="$2";; | |
99 | *) target="../$2";; | |
100 | esac | |
101 | mv "$1" "$target" || status=$? | |
252b5132 | 102 | else |
6048df60 DD |
103 | # A missing file is only an error for the first file. This |
104 | # is a blatant hack to let us support using "yacc -d". If -d | |
105 | # is not specified, we don't want an error when the header | |
106 | # file is "missing". | |
107 | if test $first = yes; then | |
108 | status=1 | |
109 | fi | |
252b5132 | 110 | fi |
6048df60 DD |
111 | shift |
112 | shift | |
113 | first=no | |
114 | done | |
252b5132 | 115 | else |
6048df60 | 116 | status=$? |
252b5132 RH |
117 | fi |
118 | ||
119 | # Remove the directory. | |
120 | cd .. | |
121 | rm -rf $dirname | |
122 | ||
6048df60 | 123 | exit $status |