The generated files
[platform/upstream/gcc.git] / gcc / fixinc / hackshell.tpl
1 [= autogen template include =]
2 [=
3 # $Id: hackshell.tpl,v 1.2 1998/12/16 21:19:08 law Exp $
4 #
5 #  This file contanes the shell template replacement for the
6 #  fixincl program.  It is the repetitive guts of the fixincludes logic.
7 #
8 =]
9   if $LINKS; then
10     files=`find . -name '*.h' \( -type f -o -type l \) -print`
11   else
12     files=`find . -name '*.h' -type f -print`
13   fi
14   echo Checking header files
15   for file in $files; do
16
17     if ( test ! -r $file -o \
18     -n "`fgrep 'This file is part of the GNU C Library' $file`" )
19     then continue ; fi
20
21     fixlist=""
22 [=
23 #
24 #  FOR  every fix description,
25 #  DO:  emit the shell text to apply the fix to the current file
26 #
27 # =][=
28
29 _FOR fix "\n\n" =]
30     #
31     # Fix [=_eval _index 1 + #%3d _printf=]:  [=hackname _Cap=]
32     #[=
33     _IF files _exist=]
34     case "$file" in [=_FOR files " | \\\n\t"=]./[=files=][=/files=] )[=
35     _ENDIF=][=
36
37     _IF mach _exist=]
38     case "$target_canonical" in [=
39         _FOR mach " | \\\n\t" =][=
40             mach =][=
41         /mach =] )[=
42         _IF mach_unmatched _exist =] : ;;
43     * )[=
44         _ENDIF =][=
45
46     _ENDIF=][=
47
48     #  There are three conditional tests:  select, bypass and test.
49        They may appear as often as desired.  They must all pass for
50        the fix to be applied.  "select" and "bypass" are egrep expressions
51        that must each appear (or not appear) in the target file.
52        "test" is an arbitrary test program expression that must yield
53        true or false.  It is enclosed in parenthesis to avoid
54        precedence problems.  The output looks like this:
55
56        if ( test -n "`egrep 'find-expr' $file`" -a
57                  -z "`egrep 'not-find'  $file`" -a
58                  '(' <some-test-expression> ')'
59           ) > /dev/null 2>&1 ; then
60
61     #  =][=
62
63     _IF select _exist =]
64     if ( test [=
65         _FOR select " -a \\\n              "
66               =]-n [=select _shrstr "#`egrep %s $file`"
67                             _printf _shstr =][=
68         /select=][=
69
70         _IF bypass _exist =][=
71             _FOR bypass=] -a \
72               -z [=bypass _shrstr "#`egrep %s $file`"
73                             _printf _shstr =][=
74             /bypass=][=
75         _ENDIF=][=
76
77         _IF test _exist=][=
78             _FOR test=] -a \
79               '(' [=test=] ')'[=
80             /test=][=
81         _ENDIF=]
82        ) > /dev/null 2>&1 ; then[=
83
84
85     _ELIF test _exist =]
86     if ( test [=
87         _FOR test " -a \\\n              "
88               =]'(' [=test=] ')'[=
89         /test=][=
90
91         _IF bypass _exist=][=
92             _FOR bypass=] -a \
93               -z [=bypass _shrstr "#`egrep %s $file`"
94                             _printf _shstr=][=
95             /bypass=][=
96         _ENDIF=]
97        ) > /dev/null 2>&1 ; then[=
98
99
100     _ELIF bypass _exist =]
101     if ( test [=_FOR bypass " -a \\\n              "
102               =]-z [=bypass _shrstr "#`egrep %s $file`"
103                             _printf _shstr=][=/bypass=]
104        ) > /dev/null 2>&1 ; then[=
105
106       _ENDIF=]
107     fixlist="${fixlist}
108       [=hackname=]"
109     if [ ! -r ${DESTDIR}/$file ]
110     then infile=$file
111     else infile=${DESTDIR}/$file ; fi [=
112
113     _IF sed _exist=][=
114         _IF shell _exist =][=
115           _ERROR hackname _get
116           "fixincludes Error:  %s fix has multiple fixups" _printf=][=
117         _ENDIF=]
118
119     sed [=
120         _FOR sed =]-e [=sed _shrstr=] \
121         [=
122         /sed=]  < $infile > ${DESTDIR}/$file.[=
123
124
125     _ELIF shell _exist =]
126     ( [=shell=] ) < $infile > ${DESTDIR}/$file.
127
128     #  Shell scripts have the potential of removing the output
129     #  We interpret that to mean the file is not to be altered
130     #
131     if test ! -f ${DESTDIR}/$file.
132     then continue ; fi [=
133
134
135     _ELSE=][=
136         _ERROR hackname _get "ERROR:  %s has no fixup" _printf=][=
137
138     _ENDIF=]
139     
140     mv -f ${DESTDIR}/$file. ${DESTDIR}/$file[=
141
142     #  Close off any opened "if" or "case" statements in reverse order
143
144     # =][=
145
146     _IF select _exist test _exist | bypass _exist | =]
147     fi # end of selection 'if'[=
148     _ENDIF =][=
149
150     _IF mach _exist=]
151     ;; # case end for machine type test
152     esac[=
153     _ENDIF =][=
154
155     _IF files _exist=]
156     ;; # case end for file name test
157     esac[=
158     _ENDIF =][=
159
160 /fix =][=
161 #
162 #  DONE with every fix for the current file
163 #
164 #=]
165     #  IF the output has been removed OR it is unchanged,
166     #  THEN ensure the output is gone
167     #  ELSE look for local directory include syntax
168     #
169     if ( test ! -f ${DESTDIR}/$file || \
170          cmp $file ${DESTDIR}/$file ) > /dev/null 2>&1
171     then
172       rm -f ${DESTDIR}/$file
173     else
174       echo "Fixed $file:${fixlist}"
175
176       # Find any include directives that use "file".
177       #
178       for include in `
179          egrep '^[      ]*#[    ]*include[      ]*"[^/]' ${DESTDIR}/$file |
180      sed -e 's/^[       ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`
181       do
182     dir=`echo $file | sed -e s'|/[^/]*$||'`
183     required="$required ${SRCDIR} $dir/$include ${DESTDIR}/$dir/$include"
184       done
185     fi
186   done # for file in $files