OSDN Git Service

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