OSDN Git Service

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