OSDN Git Service

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