OSDN Git Service

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