OSDN Git Service

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