OSDN Git Service

Fix HP/UX <sys/file.h> for g++ -pedantic-errors.
[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 file=malloc.h
936 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
937   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
938   chmod +w ${LIB}/$file 2>/dev/null
939   chmod a+r ${LIB}/$file 2>/dev/null
940 fi
941
942 if [ -r ${LIB}/$file ]; then
943   echo Fixing $file
944   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
945   -e 's/int[    ][      ]*free/void     free/g' \
946   ${LIB}/$file > ${LIB}/${file}.sed
947   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
948   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
949     rm -f ${LIB}/$file
950   else
951     # Find any include directives that use "file".
952     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
953       dir=`echo $file | sed -e s'|/[^/]*$||'`
954       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
955     done
956   fi
957 fi
958
959 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
960 file=hsfs/hsfs_spec.h
961 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
962   mkdir ${LIB}/hsfs 2>/dev/null
963   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
964   chmod +w ${LIB}/$file 2>/dev/null
965   chmod a+r ${LIB}/$file 2>/dev/null
966 fi
967
968 if [ -r ${LIB}/$file ]; then
969   echo Fixing $file
970   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
971     ${LIB}/$file > ${LIB}/${file}.
972   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
973   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
974     rm -f ${LIB}/$file
975   else
976     # Find any include directives that use "file".
977     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
978       dir=`echo $file | sed -e s'|/[^/]*$||'`
979       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
980     done
981   fi
982 fi
983
984 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
985 file=hsfs/hsnode.h
986 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
987   mkdir ${LIB}/hsfs 2>/dev/null
988   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
989   chmod +w ${LIB}/$file 2>/dev/null
990   chmod a+r ${LIB}/$file 2>/dev/null
991 fi
992
993 if [ -r ${LIB}/$file ]; then
994   echo Fixing $file
995   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
996     ${LIB}/$file > ${LIB}/${file}.sed
997   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
998   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
999     rm -f ${LIB}/$file
1000   else
1001     # Find any include directives that use "file".
1002     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1003       dir=`echo $file | sed -e s'|/[^/]*$||'`
1004       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1005     done
1006   fi
1007 fi
1008
1009 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
1010 file=hsfs/iso_spec.h
1011 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1012   mkdir ${LIB}/hsfs 2>/dev/null
1013   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1014   chmod +w ${LIB}/$file 2>/dev/null
1015   chmod a+r ${LIB}/$file 2>/dev/null
1016 fi
1017
1018 if [ -r ${LIB}/$file ]; then
1019   echo Fixing $file
1020   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
1021     ${LIB}/$file > ${LIB}/${file}.sed
1022   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1023   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1024     rm -f ${LIB}/$file
1025   else
1026     # Find any include directives that use "file".
1027     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1028       dir=`echo $file | sed -e s'|/[^/]*$||'`
1029       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1030     done
1031   fi
1032 fi
1033
1034 # Incorrect #include in Sony News-OS 3.2.
1035 file=machine/machparam.h
1036 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1037   mkdir ${LIB}/machine 2>/dev/null
1038   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1039   chmod +w ${LIB}/$file 2>/dev/null
1040   chmod a+r ${LIB}/$file 2>/dev/null
1041 fi
1042
1043 if [ -r ${LIB}/$file ]; then
1044   echo Fixing $file, incorrect \#include
1045   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
1046     ${LIB}/$file > ${LIB}/${file}.
1047   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
1048   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1049     rm -f ${LIB}/$file
1050   else
1051     # Find any include directives that use "file".
1052     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1053       dir=`echo $file | sed -e s'|/[^/]*$||'`
1054       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1055     done
1056   fi
1057 fi
1058
1059 # Multiline comment after typedef on IRIX 4.0.1.
1060 file=sys/types.h
1061 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1062   mkdir ${LIB}/sys 2>/dev/null
1063   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1064   chmod +w ${LIB}/$file 2>/dev/null
1065   chmod a+r ${LIB}/$file 2>/dev/null
1066 fi
1067
1068 if [ -r ${LIB}/$file ]; then
1069   echo Fixing $file, comment in the middle of \#ifdef
1070   sed -e 's@type of the result@type of the result */@' \
1071     -e 's@of the sizeof@/* of the sizeof@' \
1072     ${LIB}/$file > ${LIB}/${file}.sed
1073   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1074   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1075     rm -f ${LIB}/$file
1076   else
1077     # Find any include directives that use "file".
1078     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1079       dir=`echo $file | sed -e s'|/[^/]*$||'`
1080       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1081     done
1082   fi
1083 fi
1084
1085 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
1086 # header file, which embeds // comments inside multi-line /* */
1087 # comments.  If this looks like the IRIX header file, we refix it by
1088 # just throwing away the // comments.
1089 file=fam.h
1090 if [ -r ${LIB}/$file ]; then
1091   if egrep indigo.esd ${LIB}/$file > /dev/null; then
1092     echo Fixing $file, overeager sed script
1093     rm ${LIB}/$file
1094     sed -e 's|//.*$||g' $file > ${LIB}/$file
1095     chmod +w ${LIB}/$file 2>/dev/null
1096     chmod a+r ${LIB}/$file 2>/dev/null
1097   fi
1098 fi
1099
1100 # There is a similar problem with the VxWorks drv/netif/if_med.h file.
1101 file=drv/netif/if_med.h
1102 if [ -r ${LIB}/$file ]; then
1103   if egrep 'Wind River' ${LIB}/$file > /dev/null; then
1104     echo Fixing $file, overeager sed script
1105     rm ${LIB}/$file
1106     sed -e 's|//.*$||g' $file > ${LIB}/$file
1107     chmod +w ${LIB}/$file 2>/dev/null
1108     chmod a+r ${LIB}/$file 2>/dev/null
1109   fi
1110 fi
1111
1112 # Some IRIX header files contains the string "//"
1113 for file in elf_abi.h elf.h; do
1114   if [ -r ${LIB}/$file ]; then
1115     echo Fixing $file, overeager sed script
1116     sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
1117     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1118     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1119       rm -f ${LIB}/$file
1120   else
1121     # Find any include directives that use "file".
1122     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1123       dir=`echo $file | sed -e s'|/[^/]*$||'`
1124       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1125     done
1126     fi
1127   fi
1128 done
1129
1130 # IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr in prototype without
1131 # previous definition.
1132 file=rpc/auth.h
1133 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1134   mkdir ${LIB}/rpc 2>/dev/null
1135   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1136   chmod +w ${LIB}/$file 2>/dev/null
1137   chmod a+r ${LIB}/$file 2>/dev/null
1138 fi
1139
1140 if [ -r ${LIB}/$file ]; then
1141   echo Fixing $file, undefined type
1142   sed -e '/authdes_create.*struct sockaddr/i\
1143 struct sockaddr;
1144 ' \
1145     ${LIB}/$file > ${LIB}/$file.sed
1146   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1147   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1148     rm -f ${LIB}/$file
1149   else
1150     # Find any include directives that use "file".
1151     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1152       dir=`echo $file | sed -e s'|/[^/]*$||'`
1153       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1154     done
1155   fi
1156 fi
1157
1158 # IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s in prototype without previous
1159 # definition.
1160 file=rpc/xdr.h
1161 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1162   mkdir ${LIB}/rpc 2>/dev/null
1163   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1164   chmod +w ${LIB}/$file 2>/dev/null
1165   chmod a+r ${LIB}/$file 2>/dev/null
1166 fi
1167
1168 if [ -r ${LIB}/$file ]; then
1169   echo Fixing $file, undefined type
1170   sed -e '/xdrstdio_create.*struct __file_s/i\
1171 struct __file_s;
1172 ' \
1173     ${LIB}/$file > ${LIB}/$file.sed
1174   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1175   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1176     rm -f ${LIB}/$file
1177   else
1178     # Find any include directives that use "file".
1179     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1180       dir=`echo $file | sed -e s'|/[^/]*$||'`
1181       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1182     done
1183   fi
1184 fi
1185
1186 # Same problem with a file from SunOS 4.1.3 : a header file containing
1187 # the string "//" embedded in "/**/"
1188 file=sbusdev/audiovar.h
1189 if [ -r ${LIB}/$file ]; then
1190   echo Fixing $file, overeager sed script
1191   rm ${LIB}/$file
1192   sed -e 's|//.*$||g' $file > ${LIB}/$file
1193   chmod +w ${LIB}/$file 2>/dev/null
1194   chmod a+r ${LIB}/$file 2>/dev/null
1195 fi
1196
1197 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
1198 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
1199 # many other systems have similar text but correct versions of the file.
1200 # To ensure only Sun's is fixed, we grep for a likely unique string.
1201 file=memory.h
1202 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
1203   if [ ! -r ${LIB}/$file ]; then
1204     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1205     chmod +w ${LIB}/$file 2>/dev/null
1206     chmod a+r ${LIB}/$file 2>/dev/null
1207   fi
1208   if [ -r ${LIB}/$file ]; then
1209     echo Replacing $file
1210     cat > ${LIB}/$file << EOF
1211 /* This file was generated by fixincludes */
1212 #ifndef __memory_h__
1213 #define __memory_h__
1214
1215 #ifdef __STDC__
1216 extern void *memccpy();
1217 extern void *memchr();
1218 extern void *memcpy();
1219 extern void *memset();
1220 #else
1221 extern char *memccpy();
1222 extern char *memchr();
1223 extern char *memcpy();
1224 extern char *memset();
1225 #endif /* __STDC__ */
1226
1227 extern int memcmp();
1228
1229 #endif /* __memory_h__ */
1230 EOF
1231   fi
1232 fi
1233
1234 # parameters not const on DECstation Ultrix V4.0 and OSF/1.
1235 file=stdio.h
1236 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1237   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1238   chmod +w ${LIB}/$file 2>/dev/null
1239   chmod a+r ${LIB}/$file 2>/dev/null
1240 fi
1241
1242 if [ -r ${LIB}/$file ]; then
1243   echo Fixing $file, non-const arg
1244   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
1245       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
1246       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
1247       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
1248       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
1249       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
1250       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
1251       -e 's@popen(char \*, char \*);@popen(const char *, const char *);@' \
1252       -e 's@tempnam(char\*,char\*);@tempnam(const char*,const char*);@' \
1253     ${LIB}/$file > ${LIB}/${file}.sed
1254   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1255   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1256     rm -f ${LIB}/$file
1257   else
1258     # Find any include directives that use "file".
1259     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1260       dir=`echo $file | sed -e s'|/[^/]*$||'`
1261       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1262     done
1263   fi
1264 fi
1265
1266 # parameters conflict with C++ new on rs/6000 
1267 for file in stdio.h unistd.h ; do
1268   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1269     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1270     chmod +w ${LIB}/$file 2>/dev/null
1271   fi
1272
1273   if [ -r ${LIB}/$file ]; then
1274     echo Fixing $file, parameter name conflicts
1275     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
1276       ${LIB}/$file > ${LIB}/${file}.sed
1277     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1278     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1279       rm -f ${LIB}/$file
1280     else
1281       # Find any include directives that use "file".
1282       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1283         dir=`echo $file | sed -e s'|/[^/]*$||'`
1284         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1285       done
1286     fi
1287   fi
1288 done
1289
1290 # function class(double x) conflicts with C++ keyword on rs/6000 
1291 file=math.h
1292 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1293   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1294   chmod +w ${LIB}/$file 2>/dev/null
1295   chmod a+r ${LIB}/$file 2>/dev/null
1296 fi
1297
1298 if [ -r ${LIB}/$file ]; then
1299   if grep 'class[(]' ${LIB}/$file >/dev/null; then
1300     echo Fixing $file
1301     sed -e '/class[(]/i\
1302 #ifndef __cplusplus
1303 ' \
1304         -e '/class[(]/a\
1305 #endif
1306 ' ${LIB}/$file > ${LIB}/${file}.sed
1307     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1308     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1309       rm ${LIB}/$file
1310     else
1311       # Find any include directives that use "file".
1312       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1313         dir=`echo $file | sed -e s'|/[^/]*$||'`
1314         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1315       done
1316     fi
1317   fi
1318 fi
1319
1320 # Wrong fchmod prototype on RS/6000.
1321 file=sys/stat.h
1322 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1323   mkdir ${LIB}/sys 2>/dev/null
1324   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1325   chmod +w ${LIB}/$file 2>/dev/null
1326   chmod a+r ${LIB}/$file 2>/dev/null
1327 fi
1328
1329 if [ -r ${LIB}/$file ]; then
1330   echo Fixing $file, fchmod prototype
1331   sed -e 's/fchmod(char \*/fchmod(int/' \
1332     ${LIB}/$file > ${LIB}/$file.sed
1333   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1334   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1335     rm -f ${LIB}/$file
1336   else
1337     # Find any include directives that use "file".
1338     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1339       dir=`echo $file | sed -e s'|/[^/]*$||'`
1340       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1341     done
1342   fi
1343 fi
1344
1345 # There are several name conflicts with C++ reserved words in X11
1346 # header files.  These are fixed in some versions, so don't do the
1347 # fixes if we find __cplusplus in the file.  These were found on the
1348 # RS/6000.
1349
1350 # class in X11/ShellP.h
1351 file=X11/ShellP.h
1352 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1353   mkdir ${LIB}/sys 2>/dev/null
1354   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1355   chmod +w ${LIB}/$file 2>/dev/null
1356   chmod a+r ${LIB}/$file 2>/dev/null
1357 fi
1358
1359 if [ -r ${LIB}/$file ]; then
1360   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1361     true;
1362   else
1363     echo Fixing $file, field class
1364     sed -e '/char [*]class;/i\
1365 #ifdef __cplusplus\
1366         char *c_class;\
1367 #else
1368 ' \
1369         -e '/char [*]class;/a\
1370 #endif
1371 ' ${LIB}/$file > ${LIB}/${file}.sed
1372     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1373   fi
1374   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1375     rm -f ${LIB}/$file
1376   else
1377     # Find any include directives that use "file".
1378     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1379       dir=`echo $file | sed -e s'|/[^/]*$||'`
1380       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1381     done
1382   fi
1383 fi
1384 # new in Xm/Traversal.h
1385 file=Xm/Traversal.h
1386 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1387   mkdir ${LIB}/sys 2>/dev/null
1388   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1389   chmod +w ${LIB}/$file 2>/dev/null
1390   chmod a+r ${LIB}/$file 2>/dev/null
1391 fi
1392
1393 if [ -r ${LIB}/$file ]; then
1394   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1395     true;
1396   else
1397     echo Fixing $file, uses of new
1398     sed -e '/Widget     old, new;/i\
1399 #ifdef __cplusplus\
1400         Widget  old, c_new;\
1401 #else
1402 ' \
1403         -e '/Widget     old, new;/a\
1404 #endif
1405 ' \
1406         -e 's/Widget new,/Widget c_new,/g' ${LIB}/$file > ${LIB}/${file}.sed
1407     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1408   fi
1409   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1410     rm -f ${LIB}/$file
1411   else
1412     # Find any include directives that use "file".
1413     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1414       dir=`echo $file | sed -e s'|/[^/]*$||'`
1415       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1416     done
1417   fi
1418 fi
1419 # class in Xm/BaseClassI.h
1420 file=Xm/BaseClassI.h
1421 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1422   mkdir ${LIB}/sys 2>/dev/null
1423   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1424   chmod +w ${LIB}/$file 2>/dev/null
1425   chmod a+r ${LIB}/$file 2>/dev/null
1426 fi
1427
1428 if [ -r ${LIB}/$file ]; then
1429   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1430     true;
1431   else
1432     echo Fixing $file, prototype parameter name
1433     sed -e 's/ class[)]/ c_class)/g' ${LIB}/$file > ${LIB}/${file}.sed
1434     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1435   fi
1436   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1437     rm -f ${LIB}/$file
1438   else
1439     # Find any include directives that use "file".
1440     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1441       dir=`echo $file | sed -e s'|/[^/]*$||'`
1442       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1443     done
1444   fi
1445 fi
1446
1447 # NeXT 3.2 adds const prefix to some math functions. These conflict
1448 # with the built-in functions.
1449 file=ansi/math.h
1450 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1451   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1452   chmod +w ${LIB}/$file 2>/dev/null
1453 fi
1454 if [ -r ${LIB}/$file ]; then
1455   echo Fixing $file
1456   sed -e '/^extern.*double.*__const__.*cos(/s/__const__//' \
1457       -e '/^extern.*double.*__const__.*sin(/s/__const__//' ${LIB}/$file > ${LIB}/${file}.sed
1458   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1459   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1460     rm -f ${LIB}/$file
1461   else
1462     # Find any include directives that use "file".
1463     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1464       dir=`echo $file | sed -e s'|/[^/]*$||'`
1465       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1466     done
1467   fi
1468 fi
1469
1470 # NeXT 3.2 uses the word "template" as a parameter for some 
1471 # functions. GCC reports an invalid use of a reserved key word
1472 # with the built-in functions. NeXT 3.2 includes the keyword
1473 # volatile in the prototype for abort(). This conflicts with
1474 # the built-in definition.
1475 file=bsd/libc.h
1476 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1477   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1478   chmod +w ${LIB}/$file 2>/dev/null
1479 fi
1480 if [ -r ${LIB}/$file ]; then
1481   echo Fixing $file
1482   sed -e '/\(.*template\)/s/template//' \
1483       -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
1484   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1485   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1486     rm -f ${LIB}/$file
1487   else
1488     # Find any include directives that use "file".
1489     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1490       dir=`echo $file | sed -e s'|/[^/]*$||'`
1491       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1492     done
1493   fi
1494 fi
1495
1496 # NeXT 3.2 includes the keyword volatile in the abort() and 
1497 # exit() function prototypes. That conflicts with the 
1498 # built-in functions.
1499 file=ansi/stdlib.h
1500 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1501   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1502   chmod +w ${LIB}/$file 2>/dev/null
1503 fi
1504 if [ -r ${LIB}/$file ]; then
1505   echo Fixing $file
1506   sed -e '/extern.*volatile.*void.*exit/s/volatile//' \
1507       -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
1508   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1509   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1510     rm -f ${LIB}/$file
1511   else
1512     # Find any include directives that use "file".
1513     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1514       dir=`echo $file | sed -e s'|/[^/]*$||'`
1515       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1516     done
1517   fi
1518 fi
1519
1520 # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1521 # Note that version 3 of the NeXT system has wait.h in a different directory,
1522 # so that this code won't do anything.  But wait.h in version 3 has a
1523 # conditional, so it doesn't need this fix.  So everything is okay.
1524 file=sys/wait.h
1525 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1526   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1527   chmod +w ${LIB}/$file 2>/dev/null
1528 fi
1529
1530 if [ -r ${LIB}/$file ] \
1531   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
1532   echo Fixing $file, bad wait formal
1533   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
1534   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1535   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1536     rm -f ${LIB}/$file
1537   else
1538     # Find any include directives that use "file".
1539     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1540       dir=`echo $file | sed -e s'|/[^/]*$||'`
1541       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1542     done
1543   fi
1544 fi
1545
1546 # Don't use or define the name va_list in stdio.h.
1547 # This is for ANSI and also to interoperate properly with gcc's varargs.h.
1548 file=stdio.h
1549 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1550   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1551   chmod +w ${LIB}/$file 2>/dev/null
1552   chmod a+r ${LIB}/$file 2>/dev/null
1553 fi
1554
1555 if [ -r ${LIB}/$file ]; then
1556   echo Fixing $file, use of va_list
1557   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1558   if egrep "__need___va_list" ${LIB}/$file >/dev/null 2>&1; then
1559     touch ${LIB}/${file}.sed
1560   else
1561     (echo "#define __need___va_list"
1562      echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1563   fi
1564   # Use __gnuc_va_list in arg types in place of va_list.
1565   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1566   # trailing parentheses and semicolon save all other systems from this.
1567   # Define __va_list__ (something harmless and unused) instead of va_list.
1568   # Don't claim to have defined va_list.
1569   sed -e 's@ va_list @ __gnuc_va_list @' \
1570       -e 's@ va_list)@ __gnuc_va_list)@' \
1571       -e 's@ _BSD_VA_LIST_));@ __gnuc_va_list));@' \
1572       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1573       -e 's@ va_list@ __va_list__@' \
1574       -e 's@\*va_list@*__va_list__@' \
1575       -e 's@ __va_list)@ __gnuc_va_list)@' \
1576       -e 's@GNUC_VA_LIST@GNUC_Va_LIST@' \
1577       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1578       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1579       -e 's@_Va_LIST@_VA_LIST@' \
1580     ${LIB}/$file >> ${LIB}/${file}.sed
1581   
1582   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1583   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1584     rm -f ${LIB}/$file
1585   else
1586     # Find any include directives that use "file".
1587     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1588       dir=`echo $file | sed -e s'|/[^/]*$||'`
1589       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1590     done
1591   fi
1592 fi
1593
1594 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1595 file=ansi_compat.h
1596 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1597   if grep -s ULTRIX $file; then
1598     echo "/* This file intentionally left blank.  */" > $LIB/$file
1599   fi
1600 fi
1601
1602 # parameter to atof not const on DECstation Ultrix V4.0 and NEWS-OS 4.2R.
1603 # also get rid of bogus inline definitions in HP-UX 8.0
1604 file=math.h
1605 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1606   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1607   chmod +w ${LIB}/$file 2>/dev/null
1608   chmod a+r ${LIB}/$file 2>/dev/null
1609 fi
1610
1611 if [ -r ${LIB}/$file ]; then
1612   echo Fixing $file, non-const arg
1613   sed -e 's@atof(\([    ]*char[         ]*\*[^)]*\))@atof(const \1)@' \
1614       -e 's@inline int abs(int [a-z][a-z]*) {.*}@extern "C" int abs(int);@' \
1615       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
1616       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
1617       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
1618     ${LIB}/$file > ${LIB}/${file}.sed
1619   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1620   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1621     rm -f ${LIB}/$file
1622   else
1623     # Find any include directives that use "file".
1624     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1625       dir=`echo $file | sed -e s'|/[^/]*$||'`
1626       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1627     done
1628   fi
1629 fi
1630
1631 # fix bogus recursive stdlib.h in NEWS-OS 4.0C
1632 file=stdlib.h
1633 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1634   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1635   chmod +w ${LIB}/$file 2>/dev/null
1636   chmod a+r ${LIB}/$file 2>/dev/null
1637 fi
1638
1639 if [ -r ${LIB}/$file ]; then
1640   echo Fixing $file, recursive inclusion
1641   sed -e '/^#include <stdlib.h>/i\
1642 #if 0
1643 ' \
1644       -e '/^#include <stdlib.h>/a\
1645 #endif
1646 ' \
1647     ${LIB}/$file > ${LIB}/${file}.sed
1648   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1649   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1650     rm -f ${LIB}/$file
1651   else
1652     # Find any include directives that use "file".
1653     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1654       dir=`echo $file | sed -e s'|/[^/]*$||'`
1655       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1656     done
1657   fi
1658 fi
1659
1660 # Avoid nested comments on Ultrix 4.3.
1661 file=rpc/svc.h
1662 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1663   mkdir ${LIB}/rpc 2>/dev/null
1664   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1665   chmod +w ${LIB}/$file 2>/dev/null
1666   chmod a+r ${LIB}/$file 2>/dev/null
1667 fi
1668
1669 if [ -r ${LIB}/$file ]; then
1670   echo Fixing $file, nested comment
1671   sed -e 's@^\( \*      int protocol;  \)/\*@\1*/ /*@' \
1672     ${LIB}/$file > ${LIB}/$file.sed
1673   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1674   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1675     rm -f ${LIB}/$file
1676   else
1677     # Find any include directives that use "file".
1678     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1679       dir=`echo $file | sed -e s'|/[^/]*$||'`
1680       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1681     done
1682   fi
1683 fi
1684
1685 # This file in RISC/os uses /**/ to concatenate two tokens.
1686 file=bsd43/bsd43_.h
1687 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1688   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1689   chmod +w ${LIB}/$file 2>/dev/null
1690   chmod a+r ${LIB}/$file 2>/dev/null
1691 fi
1692 if [ -r ${LIB}/$file ]; then
1693   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
1694   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1695   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1696     rm -f ${LIB}/$file
1697   else
1698     # Find any include directives that use "file".
1699     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1700       dir=`echo $file | sed -e s'|/[^/]*$||'`
1701       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1702     done
1703   fi
1704 fi
1705
1706 file=rpc/rpc.h
1707 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1708   mkdir ${LIB}/rpc 2>/dev/null
1709   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1710   chmod +w ${LIB}/$file 2>/dev/null
1711   chmod a+r ${LIB}/$file 2>/dev/null
1712 fi
1713
1714 if [ -r ${LIB}/$file ]; then
1715   echo Fixing $file, nested comment
1716   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
1717     ${LIB}/$file > ${LIB}/$file.sed
1718   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1719   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1720     rm -f ${LIB}/$file
1721   else
1722     # Find any include directives that use "file".
1723     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1724       dir=`echo $file | sed -e s'|/[^/]*$||'`
1725       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1726     done
1727   fi
1728 fi
1729
1730 # In limits.h, put #ifndefs around things that are supposed to be defined
1731 # in float.h to avoid redefinition errors if float.h is included first.
1732 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1733 # multi line comments and the inserted #endif winds up inside the
1734 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1735 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1736 # are there, and we do not add them ourselves.
1737 for file in limits.h sys/limits.h; do
1738   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1739     mkdir ${LIB}/sys 2>/dev/null
1740     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1741     chmod +w ${LIB}/$file 2>/dev/null
1742     chmod a+r ${LIB}/$file 2>/dev/null
1743   fi
1744
1745   if [ -r ${LIB}/$file ]; then
1746     if egrep 'ifndef[   ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1747       true
1748     else
1749       echo Fixing $file
1750       sed -e '/[        ]FLT_MIN[       ]/i\
1751 #ifndef FLT_MIN
1752 '\
1753           -e '/[        ]FLT_MIN[       ]/a\
1754 #endif
1755 '\
1756           -e '/[        ]FLT_MAX[       ]/i\
1757 #ifndef FLT_MAX
1758 '\
1759           -e '/[        ]FLT_MAX[       ]/a\
1760 #endif
1761 '\
1762           -e '/[        ]FLT_DIG[       ]/i\
1763 #ifndef FLT_DIG
1764 '\
1765           -e '/[        ]FLT_DIG[       ]/a\
1766 #endif
1767 '\
1768           -e '/[        ]DBL_MIN[       ]/i\
1769 #ifndef DBL_MIN
1770 '\
1771           -e '/[        ]DBL_MIN[       ]/a\
1772 #endif
1773 '\
1774           -e '/[        ]DBL_MAX[       ]/i\
1775 #ifndef DBL_MAX
1776 '\
1777           -e '/[        ]DBL_MAX[       ]/a\
1778 #endif
1779 '\
1780           -e '/[        ]DBL_DIG[       ]/i\
1781 #ifndef DBL_DIG
1782 '\
1783           -e '/[        ]DBL_DIG[       ]/a\
1784 #endif
1785 '\
1786         ${LIB}/$file > ${LIB}/${file}.sed
1787       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1788     fi
1789     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1790       echo Deleting ${LIB}/$file\; no fixes were needed.
1791       rm -f ${LIB}/$file
1792     else
1793       # Find any include directives that use "file".
1794       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1795         dir=`echo $file | sed -e s'|/[^/]*$||'`
1796         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1797       done
1798     fi
1799   fi
1800 done
1801
1802 # In math.h, put #ifndefs around things that might be defined in a gcc
1803 # specific math-*.h file.
1804 file=math.h
1805 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1806   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1807   chmod +w ${LIB}/$file 2>/dev/null
1808   chmod a+r ${LIB}/$file 2>/dev/null
1809 fi
1810
1811 if [ -r ${LIB}/$file ]; then
1812   echo Fixing $file
1813   sed -e '/define[      ]HUGE_VAL[      ]/i\
1814 #ifndef HUGE_VAL
1815 '\
1816       -e '/define[      ]HUGE_VAL[      ]/a\
1817 #endif
1818 '\
1819     ${LIB}/$file > ${LIB}/${file}.sed
1820   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1821
1822   # In addition, copy the definition of DBL_MAX from float.h
1823   # if math.h requires one.  The Lynx math.h requires it.
1824   if egrep '#define[    ]*HUGE_VAL[     ]+DBL_MAX' $file >/dev/null 2>&1; then
1825     if egrep '#define[  ]+DBL_MAX[      ]+' $file >/dev/null 2>&1; then
1826       true;
1827     else
1828       dbl_max_def=`egrep 'define[       ]+DBL_MAX[      ]+.*' float.h 2>/dev/null`
1829       if [ "$dbl_max_def" != "" ]; then
1830         dbl_max_def=`echo $dbl_max_def | sed 's/.*define[       ]*DBL_MAX[      ]*//'`
1831         sed -e "/define[        ]HUGE_VAL[      ]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
1832           ${LIB}/$file > ${LIB}/${file}.sed
1833         rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1834       fi
1835     fi
1836   fi
1837
1838   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1839     echo Deleting ${LIB}/$file\; no fixes were needed.
1840     rm -f ${LIB}/$file
1841   else
1842     # Find any include directives that use "file".
1843     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1844       dir=`echo $file | sed -e s'|/[^/]*$||'`
1845       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1846     done
1847   fi
1848 fi
1849
1850 # Remove erroneous parentheses in sym.h on Alpha OSF/1.
1851 file=sym.h
1852 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1853   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1854   chmod +w ${LIB}/$file 2>/dev/null
1855   chmod a+r ${LIB}/$file 2>/dev/null
1856 fi
1857
1858 if [ -r ${LIB}/$file ]; then
1859   echo Fixing $file
1860   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
1861     ${LIB}/$file > ${LIB}/${file}.sed
1862   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1863   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1864     rm -f ${LIB}/$file
1865   else
1866     # Find any include directives that use "file".
1867     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1868       dir=`echo $file | sed -e s'|/[^/]*$||'`
1869       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1870     done
1871   fi
1872 fi
1873
1874 # Fix return value of mem{ccpy,chr,cpy,set} and str{len,spn,cspn}
1875 # in string.h on sysV68
1876 # Correct the return type for strlen in string.h on Lynx.
1877 # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
1878 # Add missing const for strdup on OSF/1 V3.0.
1879 file=string.h
1880 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1881   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1882   chmod +w ${LIB}/$file 2>/dev/null
1883   chmod a+r ${LIB}/$file 2>/dev/null
1884 fi
1885
1886 if [ -r ${LIB}/$file ]; then
1887   echo Fixing $file, mem{ccpy,chr,cpy,set} and str{len,spn,cspn} return value
1888   sed -e 's/extern[     ]*int[  ]*strlen();/extern unsigned int strlen();/' \
1889       -e 's/extern[     ]*int[  ]*ffs[  ]*(long);/extern int ffs(int);/' \
1890       -e 's/strdup(char \*s1);/strdup(const char *s1);/' \
1891       -e '/^extern char$/N' \
1892       -e 's/^extern char\(\n    \*memccpy(),\)$/extern void\1/'\
1893       -e '/^    strncmp(),$/N'\
1894       -e 's/^\( strncmp()\),\n\(        strlen(),\)$/\1;\
1895 extern unsigned int\
1896 \2/'\
1897     ${LIB}/$file > ${LIB}/${file}.sed
1898   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1899   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1900     rm -f ${LIB}/$file
1901   else
1902     # Find any include directives that use "file".
1903     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1904       dir=`echo $file | sed -e s'|/[^/]*$||'`
1905       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1906     done
1907   fi
1908 fi
1909
1910 # Correct the return type for strlen in strings.h in SunOS 4.
1911 file=strings.h
1912 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1913   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1914   chmod +w ${LIB}/$file 2>/dev/null
1915   chmod a+r ${LIB}/$file 2>/dev/null
1916 fi
1917
1918 if [ -r ${LIB}/$file ]; then
1919   echo Fixing $file
1920   sed -e 's/int[        ]*strlen();/__SIZE_TYPE__ strlen();/' \
1921     ${LIB}/$file > ${LIB}/${file}.sed
1922   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1923   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1924     rm -f ${LIB}/$file
1925   else
1926     # Find any include directives that use "file".
1927     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1928       dir=`echo $file | sed -e s'|/[^/]*$||'`
1929       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1930     done
1931   fi
1932 fi
1933
1934 # Delete the '#define void int' line from curses.h on Lynx
1935 file=curses.h
1936 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1937   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1938   chmod +w ${LIB}/$file 2>/dev/null
1939   chmod a+r ${LIB}/$file 2>/dev/null
1940 fi
1941
1942 if [ -r ${LIB}/$file ]; then
1943   echo Fixing $file
1944   sed -e '/#[   ]*define[       ][      ]*void[         ]int/d' \
1945      ${LIB}/$file > ${LIB}/${file}.sed
1946   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1947   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1948     rm -f ${LIB}/$file
1949   else
1950     # Find any include directives that use "file".
1951     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1952       dir=`echo $file | sed -e s'|/[^/]*$||'`
1953       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1954     done
1955   fi
1956 fi
1957
1958 # Fix `typedef struct term;' on hppa1.1-hp-hpux9.
1959 file=curses.h
1960 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1961   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1962   chmod +w ${LIB}/$file 2>/dev/null
1963   chmod a+r ${LIB}/$file 2>/dev/null
1964 fi
1965
1966 if [ -r ${LIB}/$file ]; then
1967   echo Fixing $file
1968   sed -e 's/^[  ]*typedef[      ][      ]*\(struct[     ][      ]*term[         ]*;[    ]*\)$/\1/' \
1969      ${LIB}/$file > ${LIB}/${file}.sed
1970   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1971   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1972     rm -f ${LIB}/$file
1973   else
1974     # Find any include directives that use "file".
1975     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1976       dir=`echo $file | sed -e s'|/[^/]*$||'`
1977       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1978     done
1979   fi
1980 fi
1981
1982 # For C++, avoid any typedef or macro definition of bool, and use the
1983 # built in type instead.
1984 for files in curses.h; do
1985   if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then
1986     if [ ! -r ${LIB}/$file ]; then
1987       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1988       chmod +w ${LIB}/$file 2>/dev/null
1989       chmod a+r ${LIB}/$file 2>/dev/null
1990     fi
1991
1992     echo Fixing $file
1993     sed -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/i\
1994 #ifndef __cplusplus'\
1995         -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/a\
1996 #endif'\
1997         -e '/^typedef[  ][      ]*char[         ][      ]*bool[         ]*;/i\
1998 #ifndef __cplusplus'\
1999         -e '/^typedef[  ][      ]*char[         ][      ]*bool[         ]*;/a\
2000 #endif'\
2001         ${LIB}/$file > ${LIB}/${file}.sed
2002     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2003     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2004       rm -f ${LIB}/$file
2005     else
2006       # Find any include directives that use "file".
2007       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2008         dir=`echo $file | sed -e s'|/[^/]*$||'`
2009         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2010       done
2011     fi
2012   fi
2013 done
2014
2015 # Fix incorrect S_IF* definitions on m88k-sysv3.
2016 file=sys/stat.h
2017 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2018   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2019   chmod +w ${LIB}/$file 2>/dev/null
2020   chmod a+r ${LIB}/$file 2>/dev/null
2021 fi
2022
2023 if [ -r ${LIB}/$file ]; then
2024   echo Fixing $file
2025   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)/' \
2026       -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(0[0-9]*\)[  ]*)/\1 (((m)\&S_IFMT)==\2)/' \
2027     ${LIB}/$file > ${LIB}/${file}.sed
2028   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2029   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2030     rm -f ${LIB}/$file
2031   else
2032     # Find any include directives that use "file".
2033     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2034       dir=`echo $file | sed -e s'|/[^/]*$||'`
2035       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2036     done
2037   fi
2038 fi
2039
2040 # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
2041 for file in stdio.h stdlib.h; do
2042   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2043     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2044     chmod +w ${LIB}/$file 2>/dev/null
2045     chmod a+r ${LIB}/$file 2>/dev/null
2046   fi
2047
2048   if [ -r ${LIB}/$file ]; then
2049     echo Fixing $file, getopt declaration
2050     sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
2051       ${LIB}/$file > ${LIB}/${file}.sed
2052     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2053     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2054       rm -f ${LIB}/$file
2055     else
2056       # Find any include directives that use "file".
2057       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2058         dir=`echo $file | sed -e s'|/[^/]*$||'`
2059         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2060       done
2061     fi
2062   fi
2063 done
2064
2065 # Determine if we're on Interactive Unix 2.2 or later, in which case we
2066 # need to fix some additional files.  This is the same test for ISC that
2067 # Autoconf uses.
2068 if test -d /etc/conf/kconfig.d \
2069     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
2070   echo "Fixing ISC __STDC__ goof in several files..."
2071   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
2072     echo $name
2073     if test -r ${LIB}/$name; then
2074       file=${LIB}/$name
2075     else
2076       file=${INPUT}/$name
2077     fi
2078     # On Interactive 2.2, certain traditional Unix definitions
2079     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
2080     # defined, not just if _POSIX_SOURCE is defined.  This makes it
2081     # impossible to compile any nontrivial program except with -posix.
2082     sed \
2083 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
2084             < $file > ${LIB}/$name.
2085     mv ${LIB}/$name. ${LIB}/$name
2086   done
2087   
2088   echo "Fixing ISC fmod declaration"
2089   # This one's already been fixed for other things.
2090   file=${LIB}/math.h
2091   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
2092   mv $file. $file
2093   
2094   echo "Fixing nested comments in ISC <sys/limits.h>"
2095   file=sys/limits.h
2096   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
2097   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
2098 fi
2099
2100 # These files in Sun OS 4.x use /**/ to concatenate tokens.
2101 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
2102         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
2103         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
2104 do
2105   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2106     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2107     chmod +w ${LIB}/$file 2>/dev/null
2108     chmod a+r ${LIB}/$file 2>/dev/null
2109   fi
2110
2111   if [ -r ${LIB}/$file ]; then
2112     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
2113     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2114     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2115       rm -f ${LIB}/$file
2116     else
2117       # Find any include directives that use "file".
2118       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2119         dir=`echo $file | sed -e s'|/[^/]*$||'`
2120         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2121       done
2122     fi
2123   fi
2124 done
2125
2126 # These files in ARM/RISCiX use /**/ to concatenate tokens.
2127 for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
2128         dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
2129 do
2130   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2131     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2132     chmod +w ${LIB}/$file 2>/dev/null
2133     chmod a+r ${LIB}/$file 2>/dev/null
2134   fi
2135
2136   if [ -r ${LIB}/$file ]; then
2137     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
2138     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2139     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2140       rm -f ${LIB}/$file
2141   else
2142     # Find any include directives that use "file".
2143     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2144       dir=`echo $file | sed -e s'|/[^/]*$||'`
2145       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2146     done
2147     fi
2148   fi
2149 done
2150
2151 # math.h on SunOS 4 puts the declaration of matherr before the definition
2152 # of struct exception, so the prototype (added by fixproto) causes havoc.
2153 file=math.h
2154 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2155   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2156   chmod +w ${LIB}/$file 2>/dev/null
2157   chmod a+r ${LIB}/$file 2>/dev/null
2158 fi
2159
2160 if [ -r ${LIB}/$file ]; then
2161   echo Fixing $file, matherr declaration
2162   sed -e '/^struct exception/,$b' \
2163       -e '/matherr/i\
2164 struct exception;
2165 '\
2166     ${LIB}/$file > ${LIB}/${file}.sed
2167   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2168   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2169     rm -f ${LIB}/$file
2170   else
2171     # Find any include directives that use "file".
2172     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2173       dir=`echo $file | sed -e s'|/[^/]*$||'`
2174       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2175     done
2176   fi
2177 fi
2178
2179 # assert.h on HP/UX is not C++ ready, even though NO_IMPLICIT_EXTERN_C
2180 # is defined on HP/UX.
2181 file=assert.h
2182 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2183   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2184   chmod +w ${LIB}/$file 2>/dev/null
2185   chmod a+r ${LIB}/$file 2>/dev/null
2186 fi
2187
2188 if [ -r ${LIB}/$file ]; then
2189   if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
2190      || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
2191     true
2192   else
2193     echo Fixing $file
2194     echo '#ifdef __cplusplus
2195 extern "C" {
2196 #endif' > ${LIB}/${file}.sed
2197     cat ${LIB}/${file} >> ${LIB}/${file}.sed
2198     echo '#ifdef __cplusplus
2199 }
2200 #endif' >> ${LIB}/${file}.sed 
2201     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2202     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2203       rm -f ${LIB}/$file
2204     else
2205       # Find any include directives that use "file".
2206       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2207         dir=`echo $file | sed -e s'|/[^/]*$||'`
2208         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2209       done
2210     fi
2211   fi
2212 fi
2213
2214 # check for broken assert.h that needs stdio.h or stdlib.h
2215 file=assert.h
2216 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2217   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2218   chmod +w ${LIB}/$file 2>/dev/null
2219   chmod a+r ${LIB}/$file 2>/dev/null
2220 fi
2221
2222 if [ -r ${LIB}/$file ]; then
2223   if grep 'stderr' ${LIB}/$file >/dev/null 2>/dev/null; then
2224     if grep 'include.*stdio.h' ${LIB}/$file >/dev/null 2>/dev/null; then
2225       true
2226     else
2227       echo "Fixing $file (needs stdio.h)"
2228       echo '#ifdef __cplusplus
2229 #include <stdio.h>
2230 #endif' >>${LIB}/$file
2231     fi
2232   fi
2233   if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
2234      grep 'abort *(' ${LIB}/$file >/dev/null 2>/dev/null; then
2235     if grep 'include.*stdlib.h' ${LIB}/$file >/dev/null 2>/dev/null; then
2236       true
2237     else
2238       echo "Fixing $file (needs stdlib.h)"
2239       echo '#ifdef __cplusplus
2240 #include <stdlib.h>
2241 #endif' >>${LIB}/$file
2242     fi
2243   fi
2244   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2245     rm -f ${LIB}/$file
2246   else
2247     # Find any include directives that use "file".
2248     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2249       dir=`echo $file | sed -e s'|/[^/]*$||'`
2250       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2251     done
2252   fi
2253 fi
2254
2255 # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
2256 file=unistd.h
2257 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2258   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2259   chmod +w ${LIB}/$file 2>/dev/null
2260   chmod a+r ${LIB}/$file 2>/dev/null
2261 fi
2262
2263 if [ -r ${LIB}/$file ]; then
2264   echo Fixing $file, sbrk declaration
2265   sed -e 's/char\([     ]*\*[    ]*sbrk[        ]*(\)/void\1/' \
2266     ${LIB}/$file > ${LIB}/${file}.sed
2267   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2268   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2269     rm -f ${LIB}/$file
2270   else
2271     # Find any include directives that use "file".
2272     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2273       dir=`echo $file | sed -e s'|/[^/]*$||'`
2274       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2275     done
2276   fi
2277 fi
2278
2279 # This file on SunOS 4 has a very large macro.  When the sed loop
2280 # tries pull it in, it overflows the pattern space size of the SunOS
2281 # sed (GNU sed does not have this problem).  Since the file does not
2282 # require fixing, we remove it from the fixed directory.
2283 file=sundev/ipi_error.h
2284 if [ -r ${LIB}/$file ]; then
2285   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
2286   rm -f ${LIB}/$file
2287 fi
2288
2289 # Put cpp wrappers around these include files to avoid redeclaration
2290 # errors during multiple inclusion on m88k-tektronix-sysv3.
2291 for file in time.h sys/time.h ; do
2292   if egrep '#ifndef' $file >/dev/null 2>&1; then
2293     true
2294   else
2295     if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2296       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2297       chmod +w ${LIB}/$file 2>/dev/null
2298     fi
2299     if [ -r ${LIB}/$file ]; then
2300       echo Fixing $file, to protect against multiple inclusion.
2301       cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
2302       (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
2303       echo "#define __GCC_GOT_${cpp_wrapper}_"
2304       cat ${LIB}/${file}
2305       echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
2306       rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
2307     fi
2308   fi
2309 done
2310
2311 # Fix fcntl prototype in fcntl.h on LynxOS.
2312 file=fcntl.h
2313 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2314   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2315   chmod +w ${LIB}/$file 2>/dev/null
2316   chmod a+r ${LIB}/$file 2>/dev/null
2317 fi
2318
2319 if [ -r ${LIB}/$file ]; then
2320   echo Fixing $file, fcntl declaration
2321   sed -e 's/\(fcntl.*(int, int, \)int)/\1...)/' \
2322     ${LIB}/$file > ${LIB}/${file}.sed
2323   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2324   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2325     rm -f ${LIB}/$file
2326   else
2327     # Find any include directives that use "file".
2328     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2329       dir=`echo $file | sed -e s'|/[^/]*$||'`
2330       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2331     done
2332   fi
2333 fi
2334
2335 # Fix definitions of macros used by va-i960.h in VxWorks header file.
2336 file=arch/i960/archI960.h
2337 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2338   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2339   chmod +w ${LIB}/$file 2>/dev/null
2340   chmod a+r ${LIB}/$file 2>/dev/null
2341 fi
2342
2343 if [ -r ${LIB}/$file ]; then
2344   echo Fixing $file
2345   sed -e 's/__vsiz/__vxvsiz/' -e 's/__vali/__vxvali/' \
2346       -e s'/__vpad/__vxvpad/' -e 's/__alignof__/__vxalignof__/' \
2347     ${LIB}/$file > ${LIB}/${file}.sed
2348   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2349   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2350     rm -f ${LIB}/$file
2351   else
2352     # Find any include directives that use "file".
2353     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2354       dir=`echo $file | sed -e s'|/[^/]*$||'`
2355       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2356     done
2357   fi
2358 fi
2359
2360 # Make VxWorks header which is almost gcc ready fully gcc ready.
2361 file=types/vxTypesBase.h
2362 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2363   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2364   chmod +w ${LIB}/$file 2>/dev/null
2365   chmod a+r ${LIB}/$file 2>/dev/null
2366 fi
2367
2368 if [ -r ${LIB}/$file ]; then
2369   echo Fixing $file
2370   sed -e 's/#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__/#if 1/' \
2371       -e '/[    ]size_t/i\
2372 #ifndef _GCC_SIZE_T\
2373 #define _GCC_SIZE_T
2374 ' \
2375       -e '/[    ]size_t/a\
2376 #endif
2377 ' \
2378       -e '/[    ]ptrdiff_t/i\
2379 #ifndef _GCC_PTRDIFF_T\
2380 #define _GCC_PTRDIFF_T
2381 ' \
2382       -e '/[    ]ptrdiff_t/a\
2383 #endif
2384 ' \
2385       -e '/[    ]wchar_t/i\
2386 #ifndef _GCC_WCHAR_T\
2387 #define _GCC_WCHAR_T
2388 ' \
2389       -e '/[    ]wchar_t/a\
2390 #endif
2391 ' \
2392     ${LIB}/$file > ${LIB}/${file}.sed
2393   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2394   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2395     rm -f ${LIB}/$file
2396   else
2397     # Find any include directives that use "file".
2398     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2399       dir=`echo $file | sed -e s'|/[^/]*$||'`
2400       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2401     done
2402   fi
2403 fi
2404
2405 # Fix VxWorks <sys/stat.h> to not require including <vxWorks.h>.
2406 file=sys/stat.h
2407 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2408   mkdir ${LIB}/sys 2>/dev/null
2409   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2410   chmod +w ${LIB}/$file 2>/dev/null
2411   chmod a+r ${LIB}/$file 2>/dev/null
2412 fi
2413
2414 if [ -r ${LIB}/$file ]; then
2415   if egrep '#include' ${LIB}/$file >/dev/null 2>&1; then
2416     :
2417   else
2418     if egrep 'ULONG' ${LIB}/$file >/dev/null 2>&1 \
2419        && [ -r types/vxTypesOld.h ]; then
2420       echo Fixing $file
2421       sed -e '/#define[         ][      ]*__INCstath/a\
2422 #include <types/vxTypesOld.h>
2423 ' \
2424     ${LIB}/$file > ${LIB}/${file}.sed
2425       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2426     fi
2427   fi
2428   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2429     rm -f ${LIB}/$file
2430   else
2431     # Find any include directives that use "file".
2432     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2433       dir=`echo $file | sed -e s'|/[^/]*$||'`
2434       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2435     done
2436   fi
2437 fi
2438
2439 # Fix VxWorks <time.h> to not require including <vxTypes.h>.
2440 file=time.h
2441 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2442   mkdir ${LIB}/sys 2>/dev/null
2443   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2444   chmod +w ${LIB}/$file 2>/dev/null
2445   chmod a+r ${LIB}/$file 2>/dev/null
2446 fi
2447
2448 if [ -r ${LIB}/$file ]; then
2449   if egrep 'uint_t[     ][      ]*_clocks_per_sec' ${LIB}/$file >/dev/null 2>&1; then
2450     echo Fixing $file
2451     sed -e 's/uint_t/unsigned int/' ${LIB}/$file > ${LIB}/${file}.sed
2452     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2453   fi
2454   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2455     rm -f ${LIB}/$file
2456   else
2457     # Find any include directives that use "file".
2458     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2459       dir=`echo $file | sed -e s'|/[^/]*$||'`
2460       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2461     done
2462   fi
2463 fi
2464     
2465
2466 # This loop does not appear to do anything, because it uses file
2467 # rather than $file when setting target.  It also appears to be
2468 # unnecessary, since the main loop processes symbolic links.
2469 #if $LINKS; then
2470 #  echo 'Making internal symbolic non-directory links'
2471 #  cd ${INPUT}
2472 #  files=`find . -type l -print`
2473 #  for file in $files; do
2474 #    dest=`ls -ld $file | sed -n 's/.*-> //p'`
2475 #    if expr "$dest" : '[^/].*' > /dev/null; then    
2476 #      target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
2477 #      if [ -f $target ]; then
2478 #        ln -s $dest ${LIB}/$file >/dev/null 2>&1
2479 #      fi
2480 #    fi
2481 #  done
2482 #fi
2483
2484 # Make sure that any include files referenced using double quotes
2485 # exist in the fixed directory.  This comes last since otherwise
2486 # we might end up deleting some of these files "because they don't
2487 # need any change."
2488 set x $required
2489 shift
2490 while [ $# != 0 ]; do
2491   newreq=
2492   while [ $# != 0 ]; do
2493     # $1 is the directory to copy from, $2 is the unfixed file,
2494     # $3 is the fixed file name.
2495     cd ${INPUT}
2496     cd $1
2497     if [ -r $2 ] && [ ! -r $3 ]; then
2498       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
2499       chmod +w $3 2>/dev/null
2500       chmod a+r $3 2>/dev/null
2501       echo Copied $2
2502       for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' $3 | sed -e 's/^[      ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2503         dir=`echo $2 | sed -e s'|/[^/]*$||'`
2504         dir2=`echo $3 | sed -e s'|/[^/]*$||'`
2505         newreq="$newreq $1 $dir/$include $dir2/$include"
2506       done
2507     fi
2508     shift; shift; shift
2509   done
2510   set x $newreq
2511   shift
2512 done
2513
2514 echo 'Cleaning up DONE files.'
2515 cd $LIB
2516 find . -name DONE -exec rm -f '{}' ';'
2517
2518 echo 'Removing unneeded directories:'
2519 cd $LIB
2520 files=`find . -type d -print | sort -r`
2521 for file in $files; do
2522   rmdir $LIB/$file > /dev/null 2>&1
2523 done
2524
2525 exit 0