OSDN Git Service

(stdio.h): BSDI 2.0 changed the spelling of _VA_LIST_ to
[pf3gnuchains/gcc-fork.git] / gcc / fixincludes
1 #! /bin/sh
2 # Install modified versions of certain ANSI-incompatible system header files
3 # which are fixed to work correctly with ANSI C
4 # and placed in a directory that GNU C will search.
5
6 # See README-fixinc for more information.
7
8 # Directory containing the original header files.
9 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
10 INPUT=${2-${INPUT-/usr/include}}
11
12 # Directory in which to store the results.
13 LIB=${1?"fixincludes: output directory not specified"}
14
15 # Define PWDCMD as a command to use to get the working dir
16 # in the form that we want.
17 PWDCMD=pwd
18 case "`pwd`" in
19 //*)
20         # On an Apollo, discard everything before `/usr'.
21         PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
22         ;;
23 esac
24
25 # Original directory.
26 ORIGDIR=`${PWDCMD}`
27
28 # Make sure it exists.
29 if [ ! -d $LIB ]; then
30   mkdir $LIB || exit 1
31 fi
32
33 # Make LIB absolute only if needed to avoid problems with the amd.
34 case $LIB in
35 /*)
36         ;;
37 *)
38         cd $LIB; LIB=`${PWDCMD}`
39         ;;
40 esac
41
42 # Fail if no arg to specify a directory for the output.
43 if [ x$1 = x ]
44 then echo fixincludes: no output directory specified
45 exit 1
46 fi
47
48 echo Building fixed headers in ${LIB}
49
50 # Determine whether this system has symbolic links.
51 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
52   rm -f $LIB/ShouldNotExist
53   LINKS=true
54 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
55   rm -f /tmp/ShouldNotExist
56   LINKS=true
57 else
58   LINKS=false
59 fi
60
61 echo Finding directories and links to directories
62 cd ${INPUT}
63 # Find all directories and all symlinks that point to directories.
64 # Put the list in $files.
65 # Each time we find a symlink, add it to newdirs
66 # so that we do another find within the dir the link points to.
67 # Note that $files may have duplicates in it;
68 # later parts of this file are supposed to ignore them.
69 dirs="."
70 levels=2
71 while [ -n "$dirs" ] && [ $levels -gt 0 ]
72 do
73     levels=`expr $levels - 1`
74     newdirs=
75     for d in $dirs
76     do
77         echo " Searching $INPUT/$d"
78         if [ "$d" != . ]
79         then
80             d=$d/.
81         fi
82
83         # Find all directories under $d, relative to $d, excluding $d itself.
84         files="$files `find $d -type d -print | \
85                        sed -e '/\/\.$/d' -e '/^\.$/d'`"
86         # Find all links to directories.
87         # Using `-exec test -d' in find fails on some systems,
88         # and trying to run test via sh fails on others,
89         # so this is the simplest alternative left.
90         # First find all the links, then test each one.
91         theselinks=
92         $LINKS && \
93           theselinks=`find $d -type l -print`
94         for d1 in $theselinks --dummy--
95         do
96             # If the link points to a directory,
97             # add that dir to $newdirs
98             if [ -d $d1 ]
99             then
100                 files="$files $d1"
101                 if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
102                 then
103                     newdirs="$newdirs $d1"
104                 fi
105             fi
106         done
107     done
108
109     dirs="$newdirs"
110 done
111
112 dirs=
113 echo "All directories (including links to directories):"
114 echo $files
115
116 for file in $files; do
117   rm -rf $LIB/$file
118   if [ ! -d $LIB/$file ]
119   then mkdir $LIB/$file
120   fi
121 done
122 mkdir $LIB/root
123
124 # treetops gets an alternating list
125 # of old directories to copy
126 # and the new directories to copy to.
127 treetops="${INPUT} ${LIB}"
128
129 if $LINKS; then
130   echo 'Making symbolic directory links'
131   for file in $files; do
132     dest=`ls -ld $file | sed -n 's/.*-> //p'`
133     if [ "$dest" ]; then    
134       cwd=`${PWDCMD}`
135       # In case $dest is relative, get to $file's dir first.
136       cd ${INPUT}
137       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
138       # Check that the target directory exists.
139       # Redirections changed to avoid bug in sh on Ultrix.
140       (cd $dest) > /dev/null 2>&1
141       if [ $? = 0 ]; then
142         cd $dest
143         # X gets the dir that the link actually leads to.
144         x=`${PWDCMD}`
145         # Canonicalize ${INPUT} now to minimize the time an
146         # automounter has to change the result of ${PWDCMD}.
147         cinput=`cd ${INPUT}; ${PWDCMD}`
148         # If a link points to ., make a similar link to .
149         if [ $x = ${cinput} ]; then
150           echo $file '->' . ': Making link'
151           rm -fr ${LIB}/$file > /dev/null 2>&1
152           ln -s . ${LIB}/$file > /dev/null 2>&1
153         # If link leads back into ${INPUT},
154         # make a similar link here.
155         elif expr $x : "${cinput}/.*" > /dev/null; then
156           # Y gets the actual target dir name, relative to ${INPUT}.
157           y=`echo $x | sed -n "s&${cinput}/&&p"`
158           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
159           dots=`echo "$file" |
160             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
161           echo $file '->' $dots$y ': Making link'
162           rm -fr ${LIB}/$file > /dev/null 2>&1
163           ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
164         else
165           # If the link is to a dir $target outside ${INPUT},
166           # repoint the link at ${INPUT}/root$target
167           # and process $target into ${INPUT}/root$target
168           # treat this directory as if it actually contained the files.
169           echo $file '->' root$x ': Making link'
170           if [ -d $LIB/root$x ]
171           then true
172           else
173             dirname=root$x/
174             dirmade=.
175             cd $LIB
176             while [ x$dirname != x ]; do
177               component=`echo $dirname | sed -e 's|/.*$||'`
178               mkdir $component >/dev/null 2>&1
179               cd $component
180               dirmade=$dirmade/$component
181               dirname=`echo $dirname | sed -e 's|[^/]*/||'`
182             done
183           fi
184           # Duplicate directory structure created in ${LIB}/$file in new
185           # root area.
186           for file2 in $files; do
187             case $file2 in
188               $file/./*)
189                 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
190                 echo "Duplicating ${file}'s ${dupdir}"
191                 if [ -d ${dupdir} ]
192                 then true
193                 else
194                   mkdir ${dupdir}
195                 fi
196                 ;;
197               *)
198                 ;;
199             esac
200           done
201           # Get the path from ${LIB} to $file, accounting for symlinks.
202           parent=`echo "$file" | sed -e 's@/[^/]*$@@'`
203           libabs=`cd ${LIB}; ${PWDCMD}`
204           file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"`
205           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
206           dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'`
207           rm -fr ${LIB}/$file > /dev/null 2>&1
208           ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
209           treetops="$treetops $x ${LIB}/root$x"
210         fi
211       fi
212       cd $cwd
213     fi
214   done
215 fi
216
217 required=
218 set x $treetops
219 shift
220 while [ $# != 0 ]; do
221   # $1 is an old directory to copy, and $2 is the new directory to copy to.
222   cd ${INPUT}
223   cd $1
224 # The same dir can appear more than once in treetops.
225 # There's no need to scan it more than once.
226   if [ -f $2/DONE ]
227   then
228     files=
229   else
230     touch $2/DONE
231     echo Fixing directory $1 into $2
232 # Check .h files which are symlinks as well as those which are files.
233 # A link to a header file will not be processed by anything but this.
234     if $LINKS; then
235       files=`find . -name '*.h' \( -type f -o -type l \) -print`
236     else
237       files=`find . -name '*.h' -type f -print`
238     fi
239     echo Checking header files
240   fi
241 # Note that BSD43_* are used on recent MIPS systems.
242   for file in $files; do
243 # This call to egrep is essential, since checking a file with egrep
244 # is much faster than actually trying to fix it.
245 # It is also essential that most files *not* match!
246 # Thus, matching every #endif is unacceptable.
247 # But the argument to egrep must be kept small, or many versions of egrep
248 # won't be able to handle it.
249 #
250 # We use the pattern [!-.0-~] instead of [^/    ] to match a noncomment
251 # following #else or #endif because some buggy egreps think [^/] matches
252 # newline, and they thus think `#else ' matches `#e[ndiflse]*[  ]+[^/   ]'.
253 #
254 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
255 # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
256 # in this pattern lacks `d' and `l'; this means we don't worry about
257 # identifiers starting with `d' or `l'.  This is OK, since none of the
258 # identifiers below start with `d' or `l'.  It also greatly improves
259 # performance, since many files contain lines of the form `#if ... defined ...'
260 # or `#if lint'.
261     if egrep '//|[      _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[     ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-zA-Z][a-zA-Z0-9]' $file >/dev/null; then
262       if [ -r $file ]; then
263         cp $file $2/$file >/dev/null 2>&1       \
264         || echo "Can't copy $file"
265         chmod +w $2/$file
266         chmod a+r $2/$file
267         # Here is how the sed commands in braces work.
268         # (It doesn't work to put the comments inside the sed commands.)
269                 # Surround each word with spaces, to simplify matching below.
270                 # ANSIfy each pre-ANSI machine-dependent symbol
271                 # by surrounding it with __ __.
272                 # Remove the spaces that we inserted around each word.
273         sed -e '
274                                    :loop
275           /\\$/                 N
276           /\\$/                 b loop
277           s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
278           s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
279           s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
280           s%^\([        ]*#[    ]*endif\)[      ]*\*[^/].*%\1%
281           s%^\([        ]*#[    ]*endif\)[      ]*[^/*  ].*%\1%
282           /\/\/[^*]/                    s|//\(.*\)$|/*\1*/|
283           /[    ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[  ]*(\)\(.\),/\1'\''\2'\'',/
284           /[    ]BSD43__IO[A-Z]*[       ]*(/    s/(\(.\),/('\''\1'\'',/
285           /#define._IO/                 s/'\''\([cgxtf]\)'\''/\1/g
286           /#define.BSD43__IO/           s/'\''\([cgx]\)'\''/\1/g
287           /[^A-Z0-9_]CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
288           /[^A-Z0-9]_CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
289           /#define[     ]*[     ]CTRL/          s/'\''\([cgx]\)'\''/\1/g
290           /#define[     ]*[     ]_CTRL/         s/'\''\([cgx]\)'\''/\1/g
291           /#define.BSD43_CTRL/          s/'\''\([cgx]\)'\''/\1/g
292           /#[el]*if/{
293                 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
294
295                 s/ bsd4\([0-9]\) / __bsd4\1__ /g
296                 s/ _*host_mips / __host_mips__ /g
297                 s/ _*i386 / __i386__ /g
298                 s/ M32 / __M32__ /g
299                 s/ is68k / __is68k__ /g
300                 s/ m68k / __m68k__ /g
301                 s/ mc680\([0-9]\)0 / __mc680\10__ /g
302                 s/ m88k / __m88k__ /g
303                 s/ _*mips / __mips__ /g
304                 s/ news\([0-9]*\) / __news\1__ /g
305                 s/ ns32000 / __ns32000__ /g
306                 s/ pdp11 / __pdp11__ /g
307                 s/ pyr / __pyr__ /g
308                 s/ sony_news / __sony_news__ /g
309                 s/ sparc / __sparc__ /g
310                 s/ sun\([a-z0-9]*\) / __sun\1__ /g
311                 s/ tower\([_0-9]*\) / __tower\1__ /g
312                 s/ u370 / __u370__ /g
313                 s/ u3b\([0-9]*\) / __u3b\1__ /g
314                 s/ unix / __unix__ /g
315                 s/ vax / __vax__ /g
316                 s/ _*MIPSE\([LB]\) / __MIPSE\1__ /g
317                 s/ _*R\([34]\)000 / __R\1000__ /g
318                 s/ _*SYSTYPE_\([A-Z0-9]*\) / __SYSTYPE_\1__ /g
319
320                 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
321           }
322           /^#define.NULL[       ]/      i\
323                 #undef NULL
324         ' $2/$file > $2/$file.
325         mv $2/$file. $2/$file
326         if cmp $file $2/$file >/dev/null 2>&1 \
327             || egrep 'This file is part of the GNU C Library' $2/$file >/dev/null 2>&1; then
328            rm $2/$file
329         else
330            echo Fixed $file
331            # Find any include directives that use "file".
332            for include in `egrep '^[    ]*#[    ]*include[      ]*"[^/]' $2/$file | sed -e 's/^[        ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
333               dir=`echo $file | sed -e s'|/[^/]*$||'`
334               required="$required $1 $dir/$include $2/$dir/$include"
335            done
336         fi
337       fi
338     fi
339   done
340   shift; shift
341 done
342
343 cd ${INPUT}
344
345 # Install the proper definition of the three standard types in header files
346 # that they come from.
347 for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
348   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
349     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
350     chmod +w ${LIB}/$file 2>/dev/null
351     chmod a+r ${LIB}/$file 2>/dev/null
352   fi
353
354   if [ -r ${LIB}/$file ]; then
355     echo Fixing size_t, ptrdiff_t and wchar_t in $file
356     sed \
357       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]size_t/i\
358 #ifndef __SIZE_TYPE__\
359 #define __SIZE_TYPE__ long unsigned int\
360 #endif
361 ' \
362       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]size_t/typedef __SIZE_TYPE__ size_t/' \
363       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/i\
364 #ifndef __PTRDIFF_TYPE__\
365 #define __PTRDIFF_TYPE__ long int\
366 #endif
367 ' \
368       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
369       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]wchar_t/i\
370 #ifndef __WCHAR_TYPE__\
371 #define __WCHAR_TYPE__ int\
372 #endif
373 ' \
374       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
375       ${LIB}/$file > ${LIB}/${file}.sed
376     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
377     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
378       rm ${LIB}/$file
379     else
380       # Find any include directives that use "file".
381       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
382         dir=`echo $file | sed -e s'|/[^/]*$||'`
383         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
384       done
385     fi
386   fi
387 done
388
389 # Fix one other error in this file: a mismatched quote not inside a C comment.
390 file=sundev/vuid_event.h
391 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
392   mkdir ${LIB}/sundev 2>/dev/null
393   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
394   chmod +w ${LIB}/$file 2>/dev/null
395   chmod a+r ${LIB}/$file 2>/dev/null
396 fi
397
398 if [ -r ${LIB}/$file ]; then
399   echo Fixing $file comment
400   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
401   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
402   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
403     rm ${LIB}/$file
404   else
405     # Find any include directives that use "file".
406     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
407       dir=`echo $file | sed -e s'|/[^/]*$||'`
408       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
409     done
410   fi
411 fi
412
413 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
414 file=sunwindow/win_cursor.h
415 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
416 #  mkdir ${LIB}/sunwindow 2>/dev/null
417   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
418   chmod +w ${LIB}/$file 2>/dev/null
419 fi
420 if [ -r ${LIB}/$file ]; then
421   echo Fixing $file
422   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
423   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
424   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
425     rm ${LIB}/$file
426   else
427     # Find any include directives that use "file".
428     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
429       dir=`echo $file | sed -e s'|/[^/]*$||'`
430       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
431     done
432   fi
433 fi
434 file=sunwindow/win_lock.h
435 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
436 #  mkdir ${LIB}/sunwindow 2>/dev/null
437   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
438   chmod +w ${LIB}/$file 2>/dev/null
439 fi
440 if [ -r ${LIB}/$file ]; then
441   echo Fixing $file
442   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
443   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
444   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
445     rm ${LIB}/$file
446   else
447     # Find any include directives that use "file".
448     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
449       dir=`echo $file | sed -e s'|/[^/]*$||'`
450       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
451     done
452   fi
453 fi
454
455 # Fix this Sun file to avoid interfering with stddef.h.
456 file=sys/stdtypes.h
457 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
458   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
459   chmod +w ${LIB}/$file 2>/dev/null
460   chmod a+r ${LIB}/$file 2>/dev/null
461 fi
462
463 if [ -r ${LIB}/$file ]; then
464   echo Fixing $file
465 sed -e '/[       ]size_t.*;/i\
466 #ifndef _GCC_SIZE_T\
467 #define _GCC_SIZE_T
468 ' \
469     -e '/[       ]size_t.*;/a\
470 #endif
471 ' \
472     -e '/[       ]ptrdiff_t.*;/i\
473 #ifndef _GCC_PTRDIFF_T\
474 #define _GCC_PTRDIFF_T
475 ' \
476     -e '/[       ]ptrdiff_t.*;/a\
477 #endif
478 ' \
479     -e '/[       ]wchar_t.*;/i\
480 #ifndef _GCC_WCHAR_T\
481 #define _GCC_WCHAR_T
482 ' \
483     -e '/[       ]wchar_t.*;/a\
484 #endif
485 ' ${LIB}/$file > ${LIB}/${file}.sed
486   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
487   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
488     rm ${LIB}/$file
489   else
490     # Find any include directives that use "file".
491     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
492       dir=`echo $file | sed -e s'|/[^/]*$||'`
493       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
494     done
495   fi
496 fi
497
498 # Fix this ARM/RISCiX file to avoid interfering with the use of __wchar_t
499 # in cc1plus.
500 file=stdlib.h
501 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
502   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
503   chmod +w ${LIB}/$file 2>/dev/null
504   chmod a+r ${LIB}/$file 2>/dev/null
505 fi
506
507 if [ -r ${LIB}/$file ]; then
508   echo Fixing $file
509   sed -e "s/\(#[        ]*ifndef[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
510       -e "s/\(#[        ]*define[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
511      ${LIB}/$file > ${LIB}/${file}.sed
512   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
513   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
514     rm ${LIB}/$file
515   else
516     # Find any include directives that use "file".
517     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
518       dir=`echo $file | sed -e s'|/[^/]*$||'`
519       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
520     done
521   fi
522 fi
523
524 # Fix this ARM/RISCiX file where ___type is a Compiler hint that is specific to
525 # the Norcroft compiler.
526 file=X11/Intrinsic.h
527 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
528   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
529   chmod +w ${LIB}/$file 2>/dev/null
530   chmod a+r ${LIB}/$file 2>/dev/null
531 fi
532
533 if [ -r ${LIB}/$file ]; then
534   echo Fixing $file
535   sed -e "s/___type p_type/p_type/" \
536      ${LIB}/$file > ${LIB}/${file}.sed
537   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
538   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
539     rm ${LIB}/$file
540   else
541     # Find any include directives that use "file".
542     for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
543       dir=`echo $file | sed -e s'|/[^/]*$||'`
544       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
545     done
546   fi
547 fi
548
549 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
550 # match ssize_t present in AIX for the ps/2, or typedefs which use (but do not
551 # set) size_t.
552 file=sys/types.h
553 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
554   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
555   chmod +w ${LIB}/$file 2>/dev/null
556   chmod a+r ${LIB}/$file 2>/dev/null
557 fi
558
559 if [ -r ${LIB}/$file ]; then
560   echo Fixing $file
561 sed -e '/typedef[       ][      ]*[A-Za-z_][    A-Za-z_]*[      ]size_t/i\
562 #ifndef _GCC_SIZE_T\
563 #define _GCC_SIZE_T
564 ' \
565     -e '/typedef[       ][      ]*[A-Za-z_][    A-Za-z_]*[      ]size_t/a\
566 #endif
567 ' ${LIB}/$file > ${LIB}/${file}.sed
568   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
569   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
570     rm ${LIB}/$file
571   else
572     # Find any include directives that use "file".
573     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
574       dir=`echo $file | sed -e s'|/[^/]*$||'`
575       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
576     done
577   fi
578 fi
579
580 # Fix HP's use of ../machine/inline.h to refer to
581 # /usr/include/machine/inline.h
582 file=sys/spinlock.h
583 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
584   cp $file ${LIB}/$file
585 fi
586 if [ -r ${LIB}/$file ] ; then
587   echo Fixing $file
588   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
589     -e 's,"../machine/psl.h",<machine/psl.h>,' \
590   ${LIB}/$file > ${LIB}/${file}.sed
591   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
592   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
593     rm ${LIB}/$file
594   else
595     # Find any include directives that use "file".
596     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
597       dir=`echo $file | sed -e s'|/[^/]*$||'`
598       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
599     done
600   fi
601 fi
602
603 # Fix an error in this file: the #if says _cplusplus, not the double
604 # underscore __cplusplus that it should be
605 file=tinfo.h
606 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
607   mkdir ${LIB}/rpcsvc 2>/dev/null
608   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
609   chmod +w ${LIB}/$file 2>/dev/null
610   chmod a+r ${LIB}/$file 2>/dev/null
611 fi
612
613 if [ -r ${LIB}/$file ]; then
614   echo Fixing $file, __cplusplus macro
615   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
616   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
617   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
618     rm ${LIB}/$file
619   else
620     # Find any include directives that use "file".
621     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
622       dir=`echo $file | sed -e s'|/[^/]*$||'`
623       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
624     done
625   fi
626 fi
627
628 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
629 # structure definition.
630 file=rpcsvc/rstat.h
631 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
632   mkdir ${LIB}/rpcsvc 2>/dev/null
633   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
634   chmod +w ${LIB}/$file 2>/dev/null
635   chmod a+r ${LIB}/$file 2>/dev/null
636 fi
637
638 if [ -r ${LIB}/$file ]; then
639   echo Fixing $file, definition of statsswtch
640   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
641   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
642   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
643     rm ${LIB}/$file
644   else
645     # Find any include directives that use "file".
646     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
647       dir=`echo $file | sed -e s'|/[^/]*$||'`
648       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
649     done
650   fi
651 fi
652
653 # Fix an error in this file: a missing semi-colon at the end of the nodeent
654 # structure definition.
655 file=netdnet/dnetdb.h
656 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
657   mkdir ${LIB}/netdnet 2>/dev/null
658   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
659   chmod +w ${LIB}/$file 2>/dev/null
660   chmod a+r ${LIB}/$file 2>/dev/null
661 fi
662
663 if [ -r ${LIB}/$file ]; then
664   echo Fixing $file, definition of nodeent
665   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
666   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
667   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
668     rm ${LIB}/$file
669   else
670     # Find any include directives that use "file".
671     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
672       dir=`echo $file | sed -e s'|/[^/]*$||'`
673       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
674     done
675   fi
676 fi
677
678 # Check for bad #ifdef line (in Ultrix 4.1)
679 file=sys/file.h
680 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
681   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
682   chmod +w ${LIB}/$file 2>/dev/null
683   chmod a+r ${LIB}/$file 2>/dev/null
684 fi
685
686 if [ -r ${LIB}/$file ]; then
687   echo Fixing $file, bad \#ifdef line
688   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
689   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
690   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
691     rm ${LIB}/$file
692   else
693     # Find any include directives that use "file".
694     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
695       dir=`echo $file | sed -e s'|/[^/]*$||'`
696       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
697     done
698   fi
699 fi
700
701 # Check for superfluous `static' (in Ultrix 4.2)
702 # On Ultrix 4.3, includes of other files (r3_cpu.h,r4_cpu.h) is broken.
703 file=machine/cpu.h
704 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
705   mkdir ${LIB}/machine 2>/dev/null
706   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
707   chmod +w ${LIB}/$file 2>/dev/null
708   chmod a+r ${LIB}/$file 2>/dev/null
709 fi
710
711 if [ -r ${LIB}/$file ]; then
712   echo Fixing $file, superfluous static and broken includes of other files.
713   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' \
714       -e 's/^#include "r3_cpu\.h"$/#include <machine\/r3_cpu\.h>/' \
715       -e 's/^#include "r4_cpu\.h"$/#include <machine\/r4_cpu\.h>/' \
716       ${LIB}/$file > ${LIB}/${file}.sed
717   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
718   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
719     rm ${LIB}/$file
720   else
721     # Find any include directives that use "file".
722     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
723       dir=`echo $file | sed -e s'|/[^/]*$||'`
724       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
725     done
726 # This file has an alternative name, mips/cpu.h.  Fix that name, too.
727     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
728       mkdir ${LIB}/mips 2>&-
729 # Don't remove the file first, they may be the same file!
730       ln ${LIB}/$file ${LIB}/mips/cpu.h > /dev/null 2>&1
731     fi
732   fi
733 fi
734
735 # Incorrect sprintf declaration in X11/Xmu.h
736 file=X11/Xmu.h
737 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
738   mkdir ${LIB}/X11 2>/dev/null
739   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
740   chmod +w ${LIB}/$file 2>/dev/null
741   chmod a+r ${LIB}/$file 2>/dev/null
742 fi
743
744 if [ -r ${LIB}/$file ]; then
745   echo Fixing $file sprintf declaration
746   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
747 extern char *   sprintf();\
748 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
749   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
750   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
751     rm ${LIB}/$file
752   else
753     # Find any include directives that use "file".
754     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
755       dir=`echo $file | sed -e s'|/[^/]*$||'`
756       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
757     done
758   fi
759 fi
760
761 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
762 # (It's not clear whether the right file name is this or X11/Xmu.h.)
763 file=X11/Xmu/Xmu.h
764 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
765   mkdir ${LIB}/X11/Xmu 2>/dev/null
766   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
767   chmod +w ${LIB}/$file 2>/dev/null
768   chmod a+r ${LIB}/$file 2>/dev/null
769 fi
770
771 if [ -r ${LIB}/$file ]; then
772   echo Fixing $file sprintf declaration
773   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
774 extern char *   sprintf();\
775 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
776   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
777   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
778     rm ${LIB}/$file
779   else
780     # Find any include directives that use "file".
781     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
782       dir=`echo $file | sed -e s'|/[^/]*$||'`
783       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
784     done
785   fi
786 fi
787
788 # Check for missing ';' in struct
789 file=netinet/ip.h
790 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
791   mkdir ${LIB}/netinet 2>/dev/null
792   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
793   chmod +w ${LIB}/$file 2>/dev/null
794   chmod a+r ${LIB}/$file 2>/dev/null
795 fi
796
797 if [ -r ${LIB}/$file ]; then
798   echo Fixing $file
799   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
800   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
801   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
802     rm -f ${LIB}/$file
803   else
804     # Find any include directives that use "file".
805     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
806       dir=`echo $file | sed -e s'|/[^/]*$||'`
807       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
808     done
809   fi
810 fi
811
812 # Fix the CAT macro in SunOS memvar.h.
813 file=pixrect/memvar.h
814 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
815   mkdir ${LIB}/pixrect 2>/dev/null
816   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
817   chmod +w ${LIB}/$file 2>/dev/null
818   chmod a+r ${LIB}/$file 2>/dev/null
819 fi
820
821 if [ -r ${LIB}/$file ]; then
822   echo Fixing $file
823   sed -e '/^#define.CAT(a,b)/ i\
824 #ifdef __STDC__ \
825 #define CAT(a,b) a##b\
826 #else
827 /^#define.CAT(a,b)/ a\
828 #endif
829 ' ${LIB}/$file > ${LIB}/${file}.sed
830   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
831   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
832     rm -f ${LIB}/$file
833   else
834     # Find any include directives that use "file".
835     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
836       dir=`echo $file | sed -e s'|/[^/]*$||'`
837       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
838     done
839   fi
840 fi
841
842 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
843 file=rpcsvc/rusers.h
844 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
845   mkdir ${LIB}/rpcsvc 2>/dev/null
846   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
847   chmod +w ${LIB}/$file 2>/dev/null
848   chmod a+r ${LIB}/$file 2>/dev/null
849 fi
850
851 if [ -r ${LIB}/$file ]; then
852   echo Fixing $file
853   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
854   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
855   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
856     rm -f ${LIB}/$file
857   else
858     # Find any include directives that use "file".
859     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
860       dir=`echo $file | sed -e s'|/[^/]*$||'`
861       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
862     done
863   fi
864 fi
865
866 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
867 # Also wrap protection around size_t for m88k-sysv3 systems.
868 file=stdlib.h
869 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
870   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
871   chmod +w ${LIB}/$file 2>/dev/null
872   chmod a+r ${LIB}/$file 2>/dev/null
873 fi
874
875 if [ -r ${LIB}/$file ]; then
876   echo Fixing $file
877   sed -e 's/int abort/void      abort/g' \
878   -e 's/int     free/void       free/g' \
879   -e 's/char \* calloc/void \*  calloc/g' \
880   -e 's/char \* malloc/void \*  malloc/g' \
881   -e 's/char \* realloc/void \* realloc/g' \
882   -e 's/int     exit/void       exit/g' \
883   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/i\
884 #ifndef _GCC_SIZE_T\
885 #define _GCC_SIZE_T
886 ' \
887   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/a\
888 #endif
889 ' \
890       ${LIB}/$file > ${LIB}/${file}.sed
891   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
892   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
893     rm -f ${LIB}/$file
894   else
895     # Find any include directives that use "file".
896     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
897       dir=`echo $file | sed -e s'|/[^/]*$||'`
898       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
899     done
900   fi
901 fi
902
903 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
904 file=malloc.h
905 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
906   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
907   chmod +w ${LIB}/$file 2>/dev/null
908   chmod a+r ${LIB}/$file 2>/dev/null
909 fi
910
911 if [ -r ${LIB}/$file ]; then
912   echo Fixing $file
913   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
914   -e 's/int[    ][      ]*free/void     free/g' \
915   ${LIB}/$file > ${LIB}/${file}.sed
916   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
917   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
918     rm -f ${LIB}/$file
919   else
920     # Find any include directives that use "file".
921     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
922       dir=`echo $file | sed -e s'|/[^/]*$||'`
923       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
924     done
925   fi
926 fi
927
928 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
929 file=hsfs/hsfs_spec.h
930 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
931   mkdir ${LIB}/hsfs 2>/dev/null
932   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
933   chmod +w ${LIB}/$file 2>/dev/null
934   chmod a+r ${LIB}/$file 2>/dev/null
935 fi
936
937 if [ -r ${LIB}/$file ]; then
938   echo Fixing $file
939   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
940     ${LIB}/$file > ${LIB}/${file}.
941   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
942   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
943     rm -f ${LIB}/$file
944   else
945     # Find any include directives that use "file".
946     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
947       dir=`echo $file | sed -e s'|/[^/]*$||'`
948       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
949     done
950   fi
951 fi
952
953 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
954 file=hsfs/hsnode.h
955 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
956   mkdir ${LIB}/hsfs 2>/dev/null
957   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
958   chmod +w ${LIB}/$file 2>/dev/null
959   chmod a+r ${LIB}/$file 2>/dev/null
960 fi
961
962 if [ -r ${LIB}/$file ]; then
963   echo Fixing $file
964   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
965     ${LIB}/$file > ${LIB}/${file}.sed
966   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
967   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
968     rm -f ${LIB}/$file
969   else
970     # Find any include directives that use "file".
971     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
972       dir=`echo $file | sed -e s'|/[^/]*$||'`
973       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
974     done
975   fi
976 fi
977
978 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
979 file=hsfs/iso_spec.h
980 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
981   mkdir ${LIB}/hsfs 2>/dev/null
982   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
983   chmod +w ${LIB}/$file 2>/dev/null
984   chmod a+r ${LIB}/$file 2>/dev/null
985 fi
986
987 if [ -r ${LIB}/$file ]; then
988   echo Fixing $file
989   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
990     ${LIB}/$file > ${LIB}/${file}.sed
991   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
992   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
993     rm -f ${LIB}/$file
994   else
995     # Find any include directives that use "file".
996     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
997       dir=`echo $file | sed -e s'|/[^/]*$||'`
998       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
999     done
1000   fi
1001 fi
1002
1003 # Incorrect #include in Sony News-OS 3.2.
1004 file=machine/machparam.h
1005 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1006   mkdir ${LIB}/machine 2>/dev/null
1007   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1008   chmod +w ${LIB}/$file 2>/dev/null
1009   chmod a+r ${LIB}/$file 2>/dev/null
1010 fi
1011
1012 if [ -r ${LIB}/$file ]; then
1013   echo Fixing $file, incorrect \#include
1014   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
1015     ${LIB}/$file > ${LIB}/${file}.
1016   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
1017   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1018     rm -f ${LIB}/$file
1019   else
1020     # Find any include directives that use "file".
1021     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1022       dir=`echo $file | sed -e s'|/[^/]*$||'`
1023       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1024     done
1025   fi
1026 fi
1027
1028 # Multiline comment after typedef on IRIX 4.0.1.
1029 file=sys/types.h
1030 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1031   mkdir ${LIB}/sys 2>/dev/null
1032   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1033   chmod +w ${LIB}/$file 2>/dev/null
1034   chmod a+r ${LIB}/$file 2>/dev/null
1035 fi
1036
1037 if [ -r ${LIB}/$file ]; then
1038   echo Fixing $file, comment in the middle of \#ifdef
1039   sed -e 's@type of the result@type of the result */@' \
1040     -e 's@of the sizeof@/* of the sizeof@' \
1041     ${LIB}/$file > ${LIB}/${file}.sed
1042   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1043   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1044     rm -f ${LIB}/$file
1045   else
1046     # Find any include directives that use "file".
1047     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1048       dir=`echo $file | sed -e s'|/[^/]*$||'`
1049       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1050     done
1051   fi
1052 fi
1053
1054 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
1055 # header file, which embeds // comments inside multi-line /* */
1056 # comments.  If this looks like the IRIX header file, we refix it by
1057 # just throwing away the // comments.
1058 file=fam.h
1059 if [ -r ${LIB}/$file ]; then
1060   if egrep indigo.esd ${LIB}/$file > /dev/null; then
1061     echo Fixing $file, overeager sed script
1062     rm ${LIB}/$file
1063     sed -e 's|//.*$||g' $file > ${LIB}/$file
1064     chmod +w ${LIB}/$file 2>/dev/null
1065     chmod a+r ${LIB}/$file 2>/dev/null
1066   fi
1067 fi
1068
1069 # Some IRIX header files contains the string "//"
1070 for file in elf_abi.h elf.h; do
1071   if [ -r ${LIB}/$file ]; then
1072     echo Fixing $file, overeager sed script
1073     sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
1074     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1075     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1076       rm -f ${LIB}/$file
1077   else
1078     # Find any include directives that use "file".
1079     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1080       dir=`echo $file | sed -e s'|/[^/]*$||'`
1081       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1082     done
1083     fi
1084   fi
1085 done
1086
1087 # IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr in prototype without
1088 # previous definition.
1089 file=rpc/auth.h
1090 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1091   mkdir ${LIB}/rpc 2>/dev/null
1092   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1093   chmod +w ${LIB}/$file 2>/dev/null
1094   chmod a+r ${LIB}/$file 2>/dev/null
1095 fi
1096
1097 if [ -r ${LIB}/$file ]; then
1098   echo Fixing $file, undefined type
1099   sed -e '/authdes_create.*struct sockaddr/i\
1100 struct sockaddr;
1101 ' \
1102     ${LIB}/$file > ${LIB}/$file.sed
1103   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1104   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1105     rm -f ${LIB}/$file
1106   else
1107     # Find any include directives that use "file".
1108     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1109       dir=`echo $file | sed -e s'|/[^/]*$||'`
1110       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1111     done
1112   fi
1113 fi
1114
1115 # IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s in prototype without previous
1116 # definition.
1117 file=rpc/xdr.h
1118 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1119   mkdir ${LIB}/rpc 2>/dev/null
1120   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1121   chmod +w ${LIB}/$file 2>/dev/null
1122   chmod a+r ${LIB}/$file 2>/dev/null
1123 fi
1124
1125 if [ -r ${LIB}/$file ]; then
1126   echo Fixing $file, undefined type
1127   sed -e '/xdrstdio_create.*struct __file_s/i\
1128 struct __file_s;
1129 ' \
1130     ${LIB}/$file > ${LIB}/$file.sed
1131   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1132   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1133     rm -f ${LIB}/$file
1134   else
1135     # Find any include directives that use "file".
1136     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1137       dir=`echo $file | sed -e s'|/[^/]*$||'`
1138       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1139     done
1140   fi
1141 fi
1142
1143 # Same problem with a file from SunOS 4.1.3 : a header file containing
1144 # the string "//" embedded in "/**/"
1145 file=sbusdev/audiovar.h
1146 if [ -r ${LIB}/$file ]; then
1147   echo Fixing $file, overeager sed script
1148   rm ${LIB}/$file
1149   sed -e 's|//.*$||g' $file > ${LIB}/$file
1150   chmod +w ${LIB}/$file 2>/dev/null
1151   chmod a+r ${LIB}/$file 2>/dev/null
1152 fi
1153
1154 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
1155 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
1156 # many other systems have similar text but correct versions of the file.
1157 # To ensure only Sun's is fixed, we grep for a likely unique string.
1158 file=memory.h
1159 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
1160   if [ ! -r ${LIB}/$file ]; then
1161     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1162     chmod +w ${LIB}/$file 2>/dev/null
1163     chmod a+r ${LIB}/$file 2>/dev/null
1164   fi
1165   if [ -r ${LIB}/$file ]; then
1166     echo Replacing $file
1167     cat > ${LIB}/$file << EOF
1168 /* This file was generated by fixincludes */
1169 #ifndef __memory_h__
1170 #define __memory_h__
1171
1172 #ifdef __STDC__
1173 extern void *memccpy();
1174 extern void *memchr();
1175 extern void *memcpy();
1176 extern void *memset();
1177 #else
1178 extern char *memccpy();
1179 extern char *memchr();
1180 extern char *memcpy();
1181 extern char *memset();
1182 #endif /* __STDC__ */
1183
1184 extern int memcmp();
1185
1186 #endif /* __memory_h__ */
1187 EOF
1188   fi
1189 fi
1190
1191 # parameters not const on DECstation Ultrix V4.0 and OSF/1.
1192 file=stdio.h
1193 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1194   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1195   chmod +w ${LIB}/$file 2>/dev/null
1196   chmod a+r ${LIB}/$file 2>/dev/null
1197 fi
1198
1199 if [ -r ${LIB}/$file ]; then
1200   echo Fixing $file, non-const arg
1201   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
1202       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
1203       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
1204       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
1205       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
1206       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
1207       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
1208       -e 's@popen(char \*, char \*);@popen(const char *, const char *);@' \
1209       -e 's@tempnam(char\*,char\*);@tempnam(const char*,const char*);@' \
1210     ${LIB}/$file > ${LIB}/${file}.sed
1211   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1212   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1213     rm -f ${LIB}/$file
1214   else
1215     # Find any include directives that use "file".
1216     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1217       dir=`echo $file | sed -e s'|/[^/]*$||'`
1218       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1219     done
1220   fi
1221 fi
1222
1223 # parameters conflict with C++ new on rs/6000 
1224 for file in stdio.h unistd.h ; do
1225   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1226     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1227     chmod +w ${LIB}/$file 2>/dev/null
1228   fi
1229
1230   if [ -r ${LIB}/$file ]; then
1231     echo Fixing $file, parameter name conflicts
1232     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
1233       ${LIB}/$file > ${LIB}/${file}.sed
1234     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1235     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1236       rm -f ${LIB}/$file
1237     else
1238       # Find any include directives that use "file".
1239       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1240         dir=`echo $file | sed -e s'|/[^/]*$||'`
1241         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1242       done
1243     fi
1244   fi
1245 done
1246
1247 # function class(double x) conflicts with C++ keyword on rs/6000 
1248 file=math.h
1249 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1250   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1251   chmod +w ${LIB}/$file 2>/dev/null
1252   chmod a+r ${LIB}/$file 2>/dev/null
1253 fi
1254
1255 if [ -r ${LIB}/$file ]; then
1256   if grep 'class[(]' ${LIB}/$file >/dev/null; then
1257     echo Fixing $file
1258     sed -e '/class[(]/i\
1259 #ifndef __cplusplus
1260 ' \
1261         -e '/class[(]/a\
1262 #endif
1263 ' ${LIB}/$file > ${LIB}/${file}.sed
1264     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1265     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1266       rm ${LIB}/$file
1267     else
1268       # Find any include directives that use "file".
1269       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1270         dir=`echo $file | sed -e s'|/[^/]*$||'`
1271         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1272       done
1273     fi
1274   fi
1275 fi
1276
1277 # Wrong fchmod prototype on RS/6000.
1278 file=sys/stat.h
1279 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1280   mkdir ${LIB}/sys 2>/dev/null
1281   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1282   chmod +w ${LIB}/$file 2>/dev/null
1283   chmod a+r ${LIB}/$file 2>/dev/null
1284 fi
1285
1286 if [ -r ${LIB}/$file ]; then
1287   echo Fixing $file, fchmod prototype
1288   sed -e 's/fchmod(char \*/fchmod(int/' \
1289     ${LIB}/$file > ${LIB}/$file.sed
1290   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1291   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1292     rm -f ${LIB}/$file
1293   else
1294     # Find any include directives that use "file".
1295     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1296       dir=`echo $file | sed -e s'|/[^/]*$||'`
1297       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1298     done
1299   fi
1300 fi
1301
1302 # There are several name conflicts with C++ reserved words in X11
1303 # header files.  These are fixed in some versions, so don't do the
1304 # fixes if we find __cplusplus in the file.  These were found on the
1305 # RS/6000.
1306
1307 # class in X11/ShellP.h
1308 file=X11/ShellP.h
1309 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1310   mkdir ${LIB}/sys 2>/dev/null
1311   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1312   chmod +w ${LIB}/$file 2>/dev/null
1313   chmod a+r ${LIB}/$file 2>/dev/null
1314 fi
1315
1316 if [ -r ${LIB}/$file ]; then
1317   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1318     true;
1319   else
1320     echo Fixing $file, field class
1321     sed -e '/char [*]class;/i\
1322 #ifdef __cplusplus\
1323         char *c_class;\
1324 #else
1325 ' \
1326         -e '/char [*]class;/a\
1327 #endif
1328 ' ${LIB}/$file > ${LIB}/${file}.sed
1329     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1330   fi
1331   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1332     rm -f ${LIB}/$file
1333   else
1334     # Find any include directives that use "file".
1335     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1336       dir=`echo $file | sed -e s'|/[^/]*$||'`
1337       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1338     done
1339   fi
1340 fi
1341 # new in Xm/Traversal.h
1342 file=Xm/Traversal.h
1343 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1344   mkdir ${LIB}/sys 2>/dev/null
1345   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1346   chmod +w ${LIB}/$file 2>/dev/null
1347   chmod a+r ${LIB}/$file 2>/dev/null
1348 fi
1349
1350 if [ -r ${LIB}/$file ]; then
1351   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1352     true;
1353   else
1354     echo Fixing $file, uses of new
1355     sed -e '/Widget     old, new;/i\
1356 #ifdef __cplusplus\
1357         Widget  old, c_new;\
1358 #else
1359 ' \
1360         -e '/Widget     old, new;/a\
1361 #endif
1362 ' \
1363         -e 's/Widget new,/Widget c_new,/g' ${LIB}/$file > ${LIB}/${file}.sed
1364     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1365   fi
1366   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1367     rm -f ${LIB}/$file
1368   else
1369     # Find any include directives that use "file".
1370     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1371       dir=`echo $file | sed -e s'|/[^/]*$||'`
1372       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1373     done
1374   fi
1375 fi
1376 # class in Xm/BaseClassI.h
1377 file=Xm/BaseClassI.h
1378 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1379   mkdir ${LIB}/sys 2>/dev/null
1380   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1381   chmod +w ${LIB}/$file 2>/dev/null
1382   chmod a+r ${LIB}/$file 2>/dev/null
1383 fi
1384
1385 if [ -r ${LIB}/$file ]; then
1386   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1387     true;
1388   else
1389     echo Fixing $file, prototype parameter name
1390     sed -e 's/ class[)]/ c_class)/g' ${LIB}/$file > ${LIB}/${file}.sed
1391     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1392   fi
1393   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1394     rm -f ${LIB}/$file
1395   else
1396     # Find any include directives that use "file".
1397     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1398       dir=`echo $file | sed -e s'|/[^/]*$||'`
1399       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1400     done
1401   fi
1402 fi
1403
1404 # NeXT 3.2 adds const prefix to some math functions. These conflict
1405 # with the built-in functions.
1406 file=ansi/math.h
1407 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1408   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1409   chmod +w ${LIB}/$file 2>/dev/null
1410 fi
1411 if [ -r ${LIB}/$file ]; then
1412   echo Fixing $file
1413   sed -e '/^extern.*double.*__const__.*cos(/s/__const__//' \
1414       -e '/^extern.*double.*__const__.*sin(/s/__const__//' ${LIB}/$file > ${LIB}/${file}.sed
1415   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1416   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1417     rm -f ${LIB}/$file
1418   else
1419     # Find any include directives that use "file".
1420     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1421       dir=`echo $file | sed -e s'|/[^/]*$||'`
1422       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1423     done
1424   fi
1425 fi
1426
1427 # NeXT 3.2 uses the word "template" as a parameter for some 
1428 # functions. GCC reports an invalid use of a reserved key word
1429 # with the built-in functions. NeXT 3.2 includes the keyword
1430 # volatile in the prototype for abort(). This conflicts with
1431 # the built-in definition.
1432 file=bsd/libc.h
1433 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1434   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1435   chmod +w ${LIB}/$file 2>/dev/null
1436 fi
1437 if [ -r ${LIB}/$file ]; then
1438   echo Fixing $file
1439   sed -e '/\(.*template\)/s/template//' \
1440       -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
1441   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1442   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1443     rm -f ${LIB}/$file
1444   else
1445     # Find any include directives that use "file".
1446     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1447       dir=`echo $file | sed -e s'|/[^/]*$||'`
1448       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1449     done
1450   fi
1451 fi
1452
1453 # NeXT 3.2 includes the keyword volatile in the abort() and 
1454 # exit() function prototypes. That conflicts with the 
1455 # built-in functions.
1456 file=ansi/stdlib.h
1457 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1458   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1459   chmod +w ${LIB}/$file 2>/dev/null
1460 fi
1461 if [ -r ${LIB}/$file ]; then
1462   echo Fixing $file
1463   sed -e '/extern.*volatile.*void.*exit/s/volatile//' \
1464       -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
1465   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1466   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1467     rm -f ${LIB}/$file
1468   else
1469     # Find any include directives that use "file".
1470     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1471       dir=`echo $file | sed -e s'|/[^/]*$||'`
1472       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1473     done
1474   fi
1475 fi
1476
1477 # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1478 # Note that version 3 of the NeXT system has wait.h in a different directory,
1479 # so that this code won't do anything.  But wait.h in version 3 has a
1480 # conditional, so it doesn't need this fix.  So everything is okay.
1481 file=sys/wait.h
1482 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1483   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1484   chmod +w ${LIB}/$file 2>/dev/null
1485 fi
1486
1487 if [ -r ${LIB}/$file ] \
1488   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
1489   echo Fixing $file, bad wait formal
1490   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
1491   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1492   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1493     rm -f ${LIB}/$file
1494   else
1495     # Find any include directives that use "file".
1496     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1497       dir=`echo $file | sed -e s'|/[^/]*$||'`
1498       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1499     done
1500   fi
1501 fi
1502
1503 # Don't use or define the name va_list in stdio.h.
1504 # This is for ANSI and also to interoperate properly with gcc's varargs.h.
1505 file=stdio.h
1506 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1507   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1508   chmod +w ${LIB}/$file 2>/dev/null
1509   chmod a+r ${LIB}/$file 2>/dev/null
1510 fi
1511
1512 if [ -r ${LIB}/$file ]; then
1513   echo Fixing $file, use of va_list
1514   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1515   if egrep "__need___va_list" ${LIB}/$file >/dev/null 2>&1; then
1516     touch ${LIB}/${file}.sed
1517   else
1518     (echo "#define __need___va_list"
1519      echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1520   fi
1521   # Use __gnuc_va_list in arg types in place of va_list.
1522   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1523   # trailing parentheses and semicolon save all other systems from this.
1524   # Define __va_list__ (something harmless and unused) instead of va_list.
1525   # Don't claim to have defined va_list.
1526   sed -e 's@ va_list @ __gnuc_va_list @' \
1527       -e 's@ va_list)@ __gnuc_va_list)@' \
1528       -e 's@ _BSD_VA_LIST_));@ __gnuc_va_list));@' \
1529       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1530       -e 's@ va_list@ __va_list__@' \
1531       -e 's@\*va_list@*__va_list__@' \
1532       -e 's@ __va_list)@ __gnuc_va_list)@' \
1533       -e 's@GNUC_VA_LIST@GNUC_Va_LIST@' \
1534       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1535       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1536       -e 's@_Va_LIST@_VA_LIST@' \
1537     ${LIB}/$file >> ${LIB}/${file}.sed
1538   
1539   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1540   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1541     rm -f ${LIB}/$file
1542   else
1543     # Find any include directives that use "file".
1544     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1545       dir=`echo $file | sed -e s'|/[^/]*$||'`
1546       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1547     done
1548   fi
1549 fi
1550
1551 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1552 file=ansi_compat.h
1553 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1554   if grep -s ULTRIX $file; then
1555     echo "/* This file intentionally left blank.  */" > $LIB/$file
1556   fi
1557 fi
1558
1559 # parameter to atof not const on DECstation Ultrix V4.0 and NEWS-OS 4.2R.
1560 # also get rid of bogus inline definitions in HP-UX 8.0
1561 file=math.h
1562 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1563   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1564   chmod +w ${LIB}/$file 2>/dev/null
1565   chmod a+r ${LIB}/$file 2>/dev/null
1566 fi
1567
1568 if [ -r ${LIB}/$file ]; then
1569   echo Fixing $file, non-const arg
1570   sed -e 's@atof(\([    ]*char[         ]*\*[^)]*\))@atof(const \1)@' \
1571       -e 's@inline int abs(int [a-z][a-z]*) {.*}@@' \
1572       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
1573       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
1574       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
1575     ${LIB}/$file > ${LIB}/${file}.sed
1576   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1577   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1578     rm -f ${LIB}/$file
1579   else
1580     # Find any include directives that use "file".
1581     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1582       dir=`echo $file | sed -e s'|/[^/]*$||'`
1583       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1584     done
1585   fi
1586 fi
1587
1588 # Avoid nested comments on Ultrix 4.3.
1589 file=rpc/svc.h
1590 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1591   mkdir ${LIB}/rpc 2>/dev/null
1592   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1593   chmod +w ${LIB}/$file 2>/dev/null
1594   chmod a+r ${LIB}/$file 2>/dev/null
1595 fi
1596
1597 if [ -r ${LIB}/$file ]; then
1598   echo Fixing $file, nested comment
1599   sed -e 's@^\( \*      int protocol;  \)/\*@\1*/ /*@' \
1600     ${LIB}/$file > ${LIB}/$file.sed
1601   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1602   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1603     rm -f ${LIB}/$file
1604   else
1605     # Find any include directives that use "file".
1606     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1607       dir=`echo $file | sed -e s'|/[^/]*$||'`
1608       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1609     done
1610   fi
1611 fi
1612
1613 # This file in RISC/os uses /**/ to concatenate two tokens.
1614 file=bsd43/bsd43_.h
1615 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1616   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1617   chmod +w ${LIB}/$file 2>/dev/null
1618   chmod a+r ${LIB}/$file 2>/dev/null
1619 fi
1620 if [ -r ${LIB}/$file ]; then
1621   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
1622   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1623   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1624     rm -f ${LIB}/$file
1625   else
1626     # Find any include directives that use "file".
1627     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1628       dir=`echo $file | sed -e s'|/[^/]*$||'`
1629       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1630     done
1631   fi
1632 fi
1633
1634 file=rpc/rpc.h
1635 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1636   mkdir ${LIB}/rpc 2>/dev/null
1637   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1638   chmod +w ${LIB}/$file 2>/dev/null
1639   chmod a+r ${LIB}/$file 2>/dev/null
1640 fi
1641
1642 if [ -r ${LIB}/$file ]; then
1643   echo Fixing $file, nested comment
1644   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
1645     ${LIB}/$file > ${LIB}/$file.sed
1646   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1647   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1648     rm -f ${LIB}/$file
1649   else
1650     # Find any include directives that use "file".
1651     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1652       dir=`echo $file | sed -e s'|/[^/]*$||'`
1653       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1654     done
1655   fi
1656 fi
1657
1658 # In limits.h, put #ifndefs around things that are supposed to be defined
1659 # in float.h to avoid redefinition errors if float.h is included first.
1660 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1661 # multi line comments and the inserted #endif winds up inside the
1662 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1663 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1664 # are there, and we do not add them ourselves.
1665 for file in limits.h sys/limits.h; do
1666   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1667     mkdir ${LIB}/sys 2>/dev/null
1668     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1669     chmod +w ${LIB}/$file 2>/dev/null
1670     chmod a+r ${LIB}/$file 2>/dev/null
1671   fi
1672
1673   if [ -r ${LIB}/$file ]; then
1674     if egrep 'ifndef[   ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1675       true
1676     else
1677       echo Fixing $file
1678       sed -e '/[        ]FLT_MIN[       ]/i\
1679 #ifndef FLT_MIN
1680 '\
1681           -e '/[        ]FLT_MIN[       ]/a\
1682 #endif
1683 '\
1684           -e '/[        ]FLT_MAX[       ]/i\
1685 #ifndef FLT_MAX
1686 '\
1687           -e '/[        ]FLT_MAX[       ]/a\
1688 #endif
1689 '\
1690           -e '/[        ]FLT_DIG[       ]/i\
1691 #ifndef FLT_DIG
1692 '\
1693           -e '/[        ]FLT_DIG[       ]/a\
1694 #endif
1695 '\
1696           -e '/[        ]DBL_MIN[       ]/i\
1697 #ifndef DBL_MIN
1698 '\
1699           -e '/[        ]DBL_MIN[       ]/a\
1700 #endif
1701 '\
1702           -e '/[        ]DBL_MAX[       ]/i\
1703 #ifndef DBL_MAX
1704 '\
1705           -e '/[        ]DBL_MAX[       ]/a\
1706 #endif
1707 '\
1708           -e '/[        ]DBL_DIG[       ]/i\
1709 #ifndef DBL_DIG
1710 '\
1711           -e '/[        ]DBL_DIG[       ]/a\
1712 #endif
1713 '\
1714         ${LIB}/$file > ${LIB}/${file}.sed
1715       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1716     fi
1717     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1718       echo Deleting ${LIB}/$file\; no fixes were needed.
1719       rm -f ${LIB}/$file
1720     else
1721       # Find any include directives that use "file".
1722       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1723         dir=`echo $file | sed -e s'|/[^/]*$||'`
1724         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1725       done
1726     fi
1727   fi
1728 done
1729
1730 # In math.h, put #ifndefs around things that might be defined in a gcc
1731 # specific math-*.h file.
1732 file=math.h
1733 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1734   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1735   chmod +w ${LIB}/$file 2>/dev/null
1736   chmod a+r ${LIB}/$file 2>/dev/null
1737 fi
1738
1739 if [ -r ${LIB}/$file ]; then
1740   echo Fixing $file
1741   sed -e '/define[      ]HUGE_VAL[      ]/i\
1742 #ifndef HUGE_VAL
1743 '\
1744       -e '/define[      ]HUGE_VAL[      ]/a\
1745 #endif
1746 '\
1747     ${LIB}/$file > ${LIB}/${file}.sed
1748   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1749
1750   # In addition, copy the definition of DBL_MAX from float.h
1751   # if math.h requires one.  The Lynx math.h requires it.
1752   if egrep '#define[    ]*HUGE_VAL[     ]+DBL_MAX' $file >/dev/null 2>&1; then
1753     if egrep '#define[  ]+DBL_MAX[      ]+' $file >/dev/null 2>&1; then
1754       true;
1755     else
1756       dbl_max_def=`egrep 'define[       ]+DBL_MAX[      ]+.*' float.h 2>/dev/null`
1757       if [ "$dbl_max_def" != "" ]; then
1758         dbl_max_def=`echo $dbl_max_def | sed 's/.*define[       ]*DBL_MAX[      ]*//'`
1759         sed -e "/define[        ]HUGE_VAL[      ]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
1760           ${LIB}/$file > ${LIB}/${file}.sed
1761         rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1762       fi
1763     fi
1764   fi
1765
1766   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1767     echo Deleting ${LIB}/$file\; no fixes were needed.
1768     rm -f ${LIB}/$file
1769   else
1770     # Find any include directives that use "file".
1771     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1772       dir=`echo $file | sed -e s'|/[^/]*$||'`
1773       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1774     done
1775   fi
1776 fi
1777
1778 # Remove erroneous parentheses in sym.h on Alpha OSF/1.
1779 file=sym.h
1780 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1781   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1782   chmod +w ${LIB}/$file 2>/dev/null
1783   chmod a+r ${LIB}/$file 2>/dev/null
1784 fi
1785
1786 if [ -r ${LIB}/$file ]; then
1787   echo Fixing $file
1788   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
1789     ${LIB}/$file > ${LIB}/${file}.sed
1790   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1791   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1792     rm -f ${LIB}/$file
1793   else
1794     # Find any include directives that use "file".
1795     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1796       dir=`echo $file | sed -e s'|/[^/]*$||'`
1797       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1798     done
1799   fi
1800 fi
1801
1802 # Correct the return type for strlen in string.h on Lynx.
1803 # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
1804 # Add missing const for strdup on OSF/1 V3.0.
1805 file=string.h
1806 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1807   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1808   chmod +w ${LIB}/$file 2>/dev/null
1809   chmod a+r ${LIB}/$file 2>/dev/null
1810 fi
1811
1812 if [ -r ${LIB}/$file ]; then
1813   echo Fixing $file
1814   sed -e 's/extern[     ]*int[  ]*strlen();/extern unsigned int strlen();/' \
1815       -e 's/extern[     ]*int[  ]*ffs[  ]*(long);/extern int ffs(int);/' \
1816       -e 's/strdup(char \*s1);/strdup(const char *s1);/' \
1817     ${LIB}/$file > ${LIB}/${file}.sed
1818   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1819   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1820     rm -f ${LIB}/$file
1821   else
1822     # Find any include directives that use "file".
1823     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1824       dir=`echo $file | sed -e s'|/[^/]*$||'`
1825       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1826     done
1827   fi
1828 fi
1829
1830 # Correct the return type for strlen in strings.h in SunOS 4.
1831 file=strings.h
1832 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1833   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1834   chmod +w ${LIB}/$file 2>/dev/null
1835   chmod a+r ${LIB}/$file 2>/dev/null
1836 fi
1837
1838 if [ -r ${LIB}/$file ]; then
1839   echo Fixing $file
1840   sed -e 's/int[        ]*strlen();/__SIZE_TYPE__ strlen();/' \
1841     ${LIB}/$file > ${LIB}/${file}.sed
1842   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1843   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1844     rm -f ${LIB}/$file
1845   else
1846     # Find any include directives that use "file".
1847     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1848       dir=`echo $file | sed -e s'|/[^/]*$||'`
1849       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1850     done
1851   fi
1852 fi
1853
1854 # Delete the '#define void int' line from curses.h on Lynx
1855 file=curses.h
1856 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1857   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1858   chmod +w ${LIB}/$file 2>/dev/null
1859   chmod a+r ${LIB}/$file 2>/dev/null
1860 fi
1861
1862 if [ -r ${LIB}/$file ]; then
1863   echo Fixing $file
1864   sed -e '/#[   ]*define[       ][      ]*void[         ]int/d' \
1865      ${LIB}/$file > ${LIB}/${file}.sed
1866   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1867   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1868     rm -f ${LIB}/$file
1869   else
1870     # Find any include directives that use "file".
1871     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1872       dir=`echo $file | sed -e s'|/[^/]*$||'`
1873       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1874     done
1875   fi
1876 fi
1877
1878 # Fix `typedef struct term;' on hppa1.1-hp-hpux9.
1879 file=curses.h
1880 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1881   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1882   chmod +w ${LIB}/$file 2>/dev/null
1883   chmod a+r ${LIB}/$file 2>/dev/null
1884 fi
1885
1886 if [ -r ${LIB}/$file ]; then
1887   echo Fixing $file
1888   sed -e 's/^[  ]*typedef[      ][      ]*\(struct[     ][      ]*term[         ]*;[    ]*\)$/\1/' \
1889      ${LIB}/$file > ${LIB}/${file}.sed
1890   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1891   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1892     rm -f ${LIB}/$file
1893   else
1894     # Find any include directives that use "file".
1895     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1896       dir=`echo $file | sed -e s'|/[^/]*$||'`
1897       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1898     done
1899   fi
1900 fi
1901
1902 # For C++, avoid any typedef or macro definition of bool, and use the
1903 # built in type instead.
1904 for files in curses.h; do
1905   if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then
1906     if [ ! -r ${LIB}/$file ]; then
1907       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1908       chmod +w ${LIB}/$file 2>/dev/null
1909       chmod a+r ${LIB}/$file 2>/dev/null
1910     fi
1911
1912     echo Fixing $file
1913     sed -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/i\
1914 #ifndef __cplusplus'\
1915         -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/a\
1916 #endif'\
1917         -e '/^typedef[  ][      ]*char[         ][      ]*bool[         ]*;[    ]*$/i\
1918 #ifndef __cplusplus'\
1919         -e '/^typedef[  ][      ]*char[         ][      ]*bool[         ]*;[    ]*$/a\
1920 #endif'\
1921         ${LIB}/$file > ${LIB}/${file}.sed
1922     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1923     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1924       rm -f ${LIB}/$file
1925     else
1926       # Find any include directives that use "file".
1927       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1928         dir=`echo $file | sed -e s'|/[^/]*$||'`
1929         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1930       done
1931     fi
1932   fi
1933 done
1934
1935 # Fix incorrect S_IF* definitions on m88k-sysv3.
1936 file=sys/stat.h
1937 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1938   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1939   chmod +w ${LIB}/$file 2>/dev/null
1940   chmod a+r ${LIB}/$file 2>/dev/null
1941 fi
1942
1943 if [ -r ${LIB}/$file ]; then
1944   echo Fixing $file
1945   sed -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(S_IF[A-Z][A-Z][A-Z][A-Z]*\)[        ]*)/\1 (((m)\&S_IFMT)==\2)/' \
1946       -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(0[0-9]*\)[  ]*)/\1 (((m)\&S_IFMT)==\2)/' \
1947     ${LIB}/$file > ${LIB}/${file}.sed
1948   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1949   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1950     rm -f ${LIB}/$file
1951   else
1952     # Find any include directives that use "file".
1953     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1954       dir=`echo $file | sed -e s'|/[^/]*$||'`
1955       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1956     done
1957   fi
1958 fi
1959
1960 # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
1961 for file in stdio.h stdlib.h; do
1962   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1963     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1964     chmod +w ${LIB}/$file 2>/dev/null
1965     chmod a+r ${LIB}/$file 2>/dev/null
1966   fi
1967
1968   if [ -r ${LIB}/$file ]; then
1969     echo Fixing $file, getopt declaration
1970     sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
1971       ${LIB}/$file > ${LIB}/${file}.sed
1972     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1973     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1974       rm -f ${LIB}/$file
1975     else
1976       # Find any include directives that use "file".
1977       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1978         dir=`echo $file | sed -e s'|/[^/]*$||'`
1979         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1980       done
1981     fi
1982   fi
1983 done
1984
1985 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1986 # need to fix some additional files.  This is the same test for ISC that
1987 # Autoconf uses.
1988 if test -d /etc/conf/kconfig.d \
1989     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1990   echo "Fixing ISC __STDC__ goof in several files..."
1991   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1992     echo $name
1993     if test -r ${LIB}/$name; then
1994       file=${LIB}/$name
1995     else
1996       file=${INPUT}/$name
1997     fi
1998     # On Interactive 2.2, certain traditional Unix definitions
1999     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
2000     # defined, not just if _POSIX_SOURCE is defined.  This makes it
2001     # impossible to compile any nontrivial program except with -posix.
2002     sed \
2003 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
2004             < $file > ${LIB}/$name.
2005     mv ${LIB}/$name. ${LIB}/$name
2006   done
2007   
2008   echo "Fixing ISC fmod declaration"
2009   # This one's already been fixed for other things.
2010   file=${LIB}/math.h
2011   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
2012   mv $file. $file
2013   
2014   echo "Fixing nested comments in ISC <sys/limits.h>"
2015   file=sys/limits.h
2016   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
2017   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
2018 fi
2019
2020 # These files in Sun OS 4.x use /**/ to concatenate tokens.
2021 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
2022         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
2023         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
2024 do
2025   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2026     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2027     chmod +w ${LIB}/$file 2>/dev/null
2028     chmod a+r ${LIB}/$file 2>/dev/null
2029   fi
2030
2031   if [ -r ${LIB}/$file ]; then
2032     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
2033     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2034     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2035       rm -f ${LIB}/$file
2036     else
2037       # Find any include directives that use "file".
2038       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2039         dir=`echo $file | sed -e s'|/[^/]*$||'`
2040         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2041       done
2042     fi
2043   fi
2044 done
2045
2046 # These files in ARM/RISCiX use /**/ to concatenate tokens.
2047 for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
2048         dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
2049 do
2050   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2051     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2052     chmod +w ${LIB}/$file 2>/dev/null
2053     chmod a+r ${LIB}/$file 2>/dev/null
2054   fi
2055
2056   if [ -r ${LIB}/$file ]; then
2057     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
2058     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2059     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2060       rm -f ${LIB}/$file
2061   else
2062     # Find any include directives that use "file".
2063     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2064       dir=`echo $file | sed -e s'|/[^/]*$||'`
2065       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2066     done
2067     fi
2068   fi
2069 done
2070
2071 # math.h on SunOS 4 puts the declaration of matherr before the definition
2072 # of struct exception, so the prototype (added by fixproto) causes havoc.
2073 file=math.h
2074 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2075   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2076   chmod +w ${LIB}/$file 2>/dev/null
2077   chmod a+r ${LIB}/$file 2>/dev/null
2078 fi
2079
2080 if [ -r ${LIB}/$file ]; then
2081   echo Fixing $file, matherr declaration
2082   sed -e '/^struct exception/,$b' \
2083       -e '/matherr/i\
2084 struct exception;
2085 '\
2086     ${LIB}/$file > ${LIB}/${file}.sed
2087   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2088   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2089     rm -f ${LIB}/$file
2090   else
2091     # Find any include directives that use "file".
2092     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2093       dir=`echo $file | sed -e s'|/[^/]*$||'`
2094       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2095     done
2096   fi
2097 fi
2098
2099 # assert.h on HP/UX is not C++ ready, even though NO_IMPLICIT_EXTERN_C
2100 # is defined on HP/UX.
2101 file=assert.h
2102 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2103   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2104   chmod +w ${LIB}/$file 2>/dev/null
2105   chmod a+r ${LIB}/$file 2>/dev/null
2106 fi
2107
2108 if [ -r ${LIB}/$file ]; then
2109   if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
2110      || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
2111     true
2112   else
2113     echo Fixing $file
2114     echo '#ifdef __cplusplus
2115 extern "C" {
2116 #endif' > ${LIB}/${file}.sed
2117     cat ${LIB}/${file} >> ${LIB}/${file}.sed
2118     echo '#ifdef __cplusplus
2119 }
2120 #endif' >> ${LIB}/${file}.sed 
2121     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2122     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2123       rm -f ${LIB}/$file
2124     else
2125       # Find any include directives that use "file".
2126       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2127         dir=`echo $file | sed -e s'|/[^/]*$||'`
2128         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2129       done
2130     fi
2131   fi
2132 fi
2133
2134 # check for broken assert.h that needs stdio.h or stdlib.h
2135 file=assert.h
2136 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2137   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2138   chmod +w ${LIB}/$file 2>/dev/null
2139   chmod a+r ${LIB}/$file 2>/dev/null
2140 fi
2141
2142 if [ -r ${LIB}/$file ]; then
2143   if grep 'stderr' ${LIB}/$file >/dev/null 2>/dev/null; then
2144     if grep 'include.*stdio.h' ${LIB}/$file >/dev/null 2>/dev/null; then
2145       true
2146     else
2147       echo "Fixing $file (needs stdio.h)"
2148       echo '#ifdef __cplusplus
2149 #include <stdio.h>
2150 #endif' >>${LIB}/$file
2151     fi
2152   fi
2153   if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
2154      grep 'abort *(' ${LIB}/$file >/dev/null 2>/dev/null; then
2155     if grep 'include.*stdlib.h' ${LIB}/$file >/dev/null 2>/dev/null; then
2156       true
2157     else
2158       echo "Fixing $file (needs stdlib.h)"
2159       echo '#ifdef __cplusplus
2160 #include <stdlib.h>
2161 #endif' >>${LIB}/$file
2162     fi
2163   fi
2164   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2165     rm -f ${LIB}/$file
2166   else
2167     # Find any include directives that use "file".
2168     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2169       dir=`echo $file | sed -e s'|/[^/]*$||'`
2170       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2171     done
2172   fi
2173 fi
2174
2175 # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
2176 file=unistd.h
2177 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2178   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2179   chmod +w ${LIB}/$file 2>/dev/null
2180   chmod a+r ${LIB}/$file 2>/dev/null
2181 fi
2182
2183 if [ -r ${LIB}/$file ]; then
2184   echo Fixing $file, sbrk declaration
2185   sed -e 's/char\([     ]*\*[    ]*sbrk[        ]*(\)/void\1/' \
2186     ${LIB}/$file > ${LIB}/${file}.sed
2187   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2188   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2189     rm -f ${LIB}/$file
2190   else
2191     # Find any include directives that use "file".
2192     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2193       dir=`echo $file | sed -e s'|/[^/]*$||'`
2194       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2195     done
2196   fi
2197 fi
2198
2199 # This file on SunOS 4 has a very large macro.  When the sed loop
2200 # tries pull it in, it overflows the pattern space size of the SunOS
2201 # sed (GNU sed does not have this problem).  Since the file does not
2202 # require fixing, we remove it from the fixed directory.
2203 file=sundev/ipi_error.h
2204 if [ -r ${LIB}/$file ]; then
2205   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
2206   rm -f ${LIB}/$file
2207 fi
2208
2209 # Put cpp wrappers around these include files to avoid redeclaration
2210 # errors during multiple inclusion on m88k-tektronix-sysv3.
2211 for file in time.h sys/time.h ; do
2212   if egrep '#ifndef' $file >/dev/null 2>&1; then
2213     true
2214   else
2215     if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2216       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2217       chmod +w ${LIB}/$file 2>/dev/null
2218     fi
2219     if [ -r ${LIB}/$file ]; then
2220       echo Fixing $file, to protect against multiple inclusion.
2221       cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
2222       (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
2223       echo "#define __GCC_GOT_${cpp_wrapper}_"
2224       cat ${LIB}/${file}
2225       echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
2226       rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
2227     fi
2228   fi
2229 done
2230
2231 # Fix fcntl prototype in fcntl.h on LynxOS.
2232 file=fcntl.h
2233 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2234   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2235   chmod +w ${LIB}/$file 2>/dev/null
2236   chmod a+r ${LIB}/$file 2>/dev/null
2237 fi
2238
2239 if [ -r ${LIB}/$file ]; then
2240   echo Fixing $file, fcntl declaration
2241   sed -e 's/\(fcntl.*(int, int, \)int)/\1...)/' \
2242     ${LIB}/$file > ${LIB}/${file}.sed
2243   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2244   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2245     rm -f ${LIB}/$file
2246   else
2247     # Find any include directives that use "file".
2248     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2249       dir=`echo $file | sed -e s'|/[^/]*$||'`
2250       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2251     done
2252   fi
2253 fi
2254
2255 # Fix definitions of macros used by va-i960.h in VxWorks header file.
2256 file=arch/i960/archI960.h
2257 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2258   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2259   chmod +w ${LIB}/$file 2>/dev/null
2260   chmod a+r ${LIB}/$file 2>/dev/null
2261 fi
2262
2263 if [ -r ${LIB}/$file ]; then
2264   echo Fixing $file
2265   sed -e 's/__vsiz/__vxvsiz/' -e 's/__vali/__vxvali/' \
2266       -e s'/__vpad/__vxvpad/' -e 's/__alignof__/__vxalignof__/' \
2267     ${LIB}/$file > ${LIB}/${file}.sed
2268   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2269   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2270     rm -f ${LIB}/$file
2271   else
2272     # Find any include directives that use "file".
2273     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2274       dir=`echo $file | sed -e s'|/[^/]*$||'`
2275       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2276     done
2277   fi
2278 fi
2279
2280 # Make VxWorks header which is almost gcc ready fully gcc ready.
2281 file=types/vxTypesBase.h
2282 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2283   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2284   chmod +w ${LIB}/$file 2>/dev/null
2285   chmod a+r ${LIB}/$file 2>/dev/null
2286 fi
2287
2288 if [ -r ${LIB}/$file ]; then
2289   echo Fixing $file
2290   sed -e 's/#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__/#if 1/' \
2291       -e '/[    ]size_t/i\
2292 #ifndef _GCC_SIZE_T\
2293 #define _GCC_SIZE_T
2294 ' \
2295       -e '/[    ]size_t/a\
2296 #endif
2297 ' \
2298       -e '/[    ]ptrdiff_t/i\
2299 #ifndef _GCC_PTRDIFF_T\
2300 #define _GCC_PTRDIFF_T
2301 ' \
2302       -e '/[    ]ptrdiff_t/a\
2303 #endif
2304 ' \
2305       -e '/[    ]wchar_t/i\
2306 #ifndef _GCC_WCHAR_T\
2307 #define _GCC_WCHAR_T
2308 ' \
2309       -e '/[    ]wchar_t/a\
2310 #endif
2311 ' \
2312     ${LIB}/$file > ${LIB}/${file}.sed
2313   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2314   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2315     rm -f ${LIB}/$file
2316   else
2317     # Find any include directives that use "file".
2318     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2319       dir=`echo $file | sed -e s'|/[^/]*$||'`
2320       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2321     done
2322   fi
2323 fi
2324
2325 # Fix VxWorks <sys/stat.h> to not require including <vxWorks.h>.
2326 file=sys/stat.h
2327 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2328   mkdir ${LIB}/sys 2>/dev/null
2329   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2330   chmod +w ${LIB}/$file 2>/dev/null
2331   chmod a+r ${LIB}/$file 2>/dev/null
2332 fi
2333
2334 if [ -r ${LIB}/$file ]; then
2335   if egrep '#include' ${LIB}/$file >/dev/null 2>&1; then
2336     :
2337   else
2338     if egrep 'ULONG' ${LIB}/$file >/dev/null 2>&1 \
2339        && [ -r types/vxTypesOld.h ]; then
2340       echo Fixing $file
2341       sed -e '/#define[         ][      ]*__INCstath/a\
2342 #include <types/vxTypesOld.h>
2343 ' \
2344     ${LIB}/$file > ${LIB}/${file}.sed
2345       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2346     fi
2347   fi
2348   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2349     rm -f ${LIB}/$file
2350   else
2351     # Find any include directives that use "file".
2352     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2353       dir=`echo $file | sed -e s'|/[^/]*$||'`
2354       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2355     done
2356   fi
2357 fi
2358
2359 # Fix VxWorks <time.h> to not require including <vxTypes.h>.
2360 file=time.h
2361 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2362   mkdir ${LIB}/sys 2>/dev/null
2363   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2364   chmod +w ${LIB}/$file 2>/dev/null
2365   chmod a+r ${LIB}/$file 2>/dev/null
2366 fi
2367
2368 if [ -r ${LIB}/$file ]; then
2369   if egrep 'uint_t[     ][      ]*_clocks_per_sec' ${LIB}/$file >/dev/null 2>&1; then
2370     echo Fixing $file
2371     sed -e 's/uint_t/unsigned int/' ${LIB}/$file > ${LIB}/${file}.sed
2372     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2373   fi
2374   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2375     rm -f ${LIB}/$file
2376   else
2377     # Find any include directives that use "file".
2378     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2379       dir=`echo $file | sed -e s'|/[^/]*$||'`
2380       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2381     done
2382   fi
2383 fi
2384     
2385
2386 # This loop does not appear to do anything, because it uses file
2387 # rather than $file when setting target.  It also appears to be
2388 # unnecessary, since the main loop processes symbolic links.
2389 #if $LINKS; then
2390 #  echo 'Making internal symbolic non-directory links'
2391 #  cd ${INPUT}
2392 #  files=`find . -type l -print`
2393 #  for file in $files; do
2394 #    dest=`ls -ld $file | sed -n 's/.*-> //p'`
2395 #    if expr "$dest" : '[^/].*' > /dev/null; then    
2396 #      target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
2397 #      if [ -f $target ]; then
2398 #        ln -s $dest ${LIB}/$file >/dev/null 2>&1
2399 #      fi
2400 #    fi
2401 #  done
2402 #fi
2403
2404 # Make sure that any include files referenced using double quotes
2405 # exist in the fixed directory.  This comes last since otherwise
2406 # we might end up deleting some of these files "because they don't
2407 # need any change."
2408 set x $required
2409 shift
2410 while [ $# != 0 ]; do
2411   newreq=
2412   while [ $# != 0 ]; do
2413     # $1 is the directory to copy from, $2 is the unfixed file,
2414     # $3 is the fixed file name.
2415     cd ${INPUT}
2416     cd $1
2417     if [ -r $2 ] && [ ! -r $3 ]; then
2418       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
2419       chmod +w $3 2>/dev/null
2420       chmod a+r $3 2>/dev/null
2421       echo Copied $2
2422       for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' $3 | sed -e 's/^[      ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2423         dir=`echo $2 | sed -e s'|/[^/]*$||'`
2424         dir2=`echo $3 | sed -e s'|/[^/]*$||'`
2425         newreq="$newreq $1 $dir/$include $dir2/$include"
2426       done
2427     fi
2428     shift; shift; shift
2429   done
2430   set x $newreq
2431   shift
2432 done
2433
2434 echo 'Cleaning up DONE files.'
2435 cd $LIB
2436 find . -name DONE -exec rm -f '{}' ';'
2437
2438 echo 'Removing unneeded directories:'
2439 cd $LIB
2440 files=`find . -type d -print | sort -r`
2441 for file in $files; do
2442   rmdir $LIB/$file > /dev/null 2>&1
2443 done
2444
2445 exit 0