OSDN Git Service

Fix X11/Intrinsic.h on RISCiX; add files to REQUIRED as needed
[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.
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     ${LIB}/$file > ${LIB}/${file}.sed
1209   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1210   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1211     rm -f ${LIB}/$file
1212   else
1213     # Find any include directives that use "file".
1214     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1215       dir=`echo $file | sed -e s'|/[^/]*$||'`
1216       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1217     done
1218   fi
1219 fi
1220
1221 # parameters conflict with C++ new on rs/6000 
1222 for file in stdio.h unistd.h ; do
1223   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1224     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1225     chmod +w ${LIB}/$file 2>/dev/null
1226   fi
1227
1228   if [ -r ${LIB}/$file ]; then
1229     echo Fixing $file, parameter name conflicts
1230     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
1231       ${LIB}/$file > ${LIB}/${file}.sed
1232     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1233     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1234       rm -f ${LIB}/$file
1235     else
1236       # Find any include directives that use "file".
1237       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1238         dir=`echo $file | sed -e s'|/[^/]*$||'`
1239         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1240       done
1241     fi
1242   fi
1243 done
1244
1245 # function class(double x) conflicts with C++ keyword on rs/6000 
1246 file=math.h
1247 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1248   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1249   chmod +w ${LIB}/$file 2>/dev/null
1250   chmod a+r ${LIB}/$file 2>/dev/null
1251 fi
1252
1253 if [ -r ${LIB}/$file ]; then
1254   if grep 'class[(]' ${LIB}/$file >/dev/null; then
1255     echo Fixing $file
1256     sed -e '/class[(]/i\
1257 #ifndef __cplusplus
1258 ' \
1259         -e '/class[(]/a\
1260 #endif
1261 ' ${LIB}/$file > ${LIB}/${file}.sed
1262     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1263     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1264       rm ${LIB}/$file
1265     else
1266       # Find any include directives that use "file".
1267       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1268         dir=`echo $file | sed -e s'|/[^/]*$||'`
1269         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1270       done
1271     fi
1272   fi
1273 fi
1274
1275 # Wrong fchmod prototype on RS/6000.
1276 file=sys/stat.h
1277 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1278   mkdir ${LIB}/sys 2>/dev/null
1279   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1280   chmod +w ${LIB}/$file 2>/dev/null
1281   chmod a+r ${LIB}/$file 2>/dev/null
1282 fi
1283
1284 if [ -r ${LIB}/$file ]; then
1285   echo Fixing $file, fchmod prototype
1286   sed -e 's/fchmod(char \*/fchmod(int/' \
1287     ${LIB}/$file > ${LIB}/$file.sed
1288   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1289   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1290     rm -f ${LIB}/$file
1291   else
1292     # Find any include directives that use "file".
1293     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1294       dir=`echo $file | sed -e s'|/[^/]*$||'`
1295       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1296     done
1297   fi
1298 fi
1299
1300 # There are several name conflicts with C++ reserved words in X11
1301 # header files.  These are fixed in some versions, so don't do the
1302 # fixes if we find __cplusplus in the file.  These were found on the
1303 # RS/6000.
1304
1305 # class in X11/ShellP.h
1306 file=X11/ShellP.h
1307 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1308   mkdir ${LIB}/sys 2>/dev/null
1309   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1310   chmod +w ${LIB}/$file 2>/dev/null
1311   chmod a+r ${LIB}/$file 2>/dev/null
1312 fi
1313
1314 if [ -r ${LIB}/$file ]; then
1315   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1316     true;
1317   else
1318     echo Fixing $file, field class
1319     sed -e '/char [*]class;/i\
1320 #ifdef __cplusplus\
1321         char *c_class;\
1322 #else
1323 ' \
1324         -e '/char [*]class;/a\
1325 #endif
1326 ' ${LIB}/$file > ${LIB}/${file}.sed
1327     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1328   fi
1329   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1330     rm -f ${LIB}/$file
1331   else
1332     # Find any include directives that use "file".
1333     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1334       dir=`echo $file | sed -e s'|/[^/]*$||'`
1335       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1336     done
1337   fi
1338 fi
1339 # new in Xm/Traversal.h
1340 file=Xm/Traversal.h
1341 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1342   mkdir ${LIB}/sys 2>/dev/null
1343   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1344   chmod +w ${LIB}/$file 2>/dev/null
1345   chmod a+r ${LIB}/$file 2>/dev/null
1346 fi
1347
1348 if [ -r ${LIB}/$file ]; then
1349   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1350     true;
1351   else
1352     echo Fixing $file, uses of new
1353     sed -e '/Widget     old, new;/i\
1354 #ifdef __cplusplus\
1355         Widget  old, c_new;\
1356 #else
1357 ' \
1358         -e '/Widget     old, new;/a\
1359 #endif
1360 ' \
1361         -e 's/Widget new,/Widget c_new,/g' ${LIB}/$file > ${LIB}/${file}.sed
1362     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1363   fi
1364   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1365     rm -f ${LIB}/$file
1366   else
1367     # Find any include directives that use "file".
1368     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1369       dir=`echo $file | sed -e s'|/[^/]*$||'`
1370       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1371     done
1372   fi
1373 fi
1374 # class in Xm/BaseClassI.h
1375 file=Xm/BaseClassI.h
1376 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1377   mkdir ${LIB}/sys 2>/dev/null
1378   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1379   chmod +w ${LIB}/$file 2>/dev/null
1380   chmod a+r ${LIB}/$file 2>/dev/null
1381 fi
1382
1383 if [ -r ${LIB}/$file ]; then
1384   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1385     true;
1386   else
1387     echo Fixing $file, prototype parameter name
1388     sed -e 's/ class[)]/ c_class)/g' ${LIB}/$file > ${LIB}/${file}.sed
1389     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1390   fi
1391   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1392     rm -f ${LIB}/$file
1393   else
1394     # Find any include directives that use "file".
1395     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1396       dir=`echo $file | sed -e s'|/[^/]*$||'`
1397       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1398     done
1399   fi
1400 fi
1401
1402
1403 # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1404 # Note that version 3 of the NeXT system has wait.h in a different directory,
1405 # so that this code won't do anything.  But wait.h in version 3 has a
1406 # conditional, so it doesn't need this fix.  So everything is okay.
1407 file=sys/wait.h
1408 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1409   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1410   chmod +w ${LIB}/$file 2>/dev/null
1411 fi
1412
1413 if [ -r ${LIB}/$file ] \
1414   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
1415   echo Fixing $file, bad wait formal
1416   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
1417   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1418   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1419     rm -f ${LIB}/$file
1420   else
1421     # Find any include directives that use "file".
1422     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1423       dir=`echo $file | sed -e s'|/[^/]*$||'`
1424       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1425     done
1426   fi
1427 fi
1428
1429 # Don't use or define the name va_list in stdio.h.
1430 # This is for ANSI and also to interoperate properly with gcc's varargs.h.
1431 file=stdio.h
1432 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1433   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1434   chmod +w ${LIB}/$file 2>/dev/null
1435   chmod a+r ${LIB}/$file 2>/dev/null
1436 fi
1437
1438 if [ -r ${LIB}/$file ]; then
1439   echo Fixing $file, use of va_list
1440   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1441   if egrep "__need___va_list" ${LIB}/$file >/dev/null 2>&1; then
1442     touch ${LIB}/${file}.sed
1443   else
1444     (echo "#define __need___va_list"
1445      echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1446   fi
1447   # Use __gnuc_va_list in arg types in place of va_list.
1448   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1449   # trailing parentheses and semicolon save all other systems from this.
1450   # Define __va_list__ (something harmless and unused) instead of va_list.
1451   # Don't claim to have defined va_list.
1452   sed -e 's@ va_list @ __gnuc_va_list @' \
1453       -e 's@ va_list)@ __gnuc_va_list)@' \
1454       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1455       -e 's@ va_list@ __va_list__@' \
1456       -e 's@\*va_list@*__va_list__@' \
1457       -e 's@ __va_list)@ __gnuc_va_list)@' \
1458       -e 's@GNUC_VA_LIST@GNUC_Va_LIST@' \
1459       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1460       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1461       -e 's@_Va_LIST@_VA_LIST@' \
1462     ${LIB}/$file >> ${LIB}/${file}.sed
1463   
1464   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1465   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1466     rm -f ${LIB}/$file
1467   else
1468     # Find any include directives that use "file".
1469     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1470       dir=`echo $file | sed -e s'|/[^/]*$||'`
1471       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1472     done
1473   fi
1474 fi
1475
1476 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1477 file=ansi_compat.h
1478 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1479   if grep -s ULTRIX $file; then
1480     echo "/* This file intentionally left blank.  */" > $LIB/$file
1481   fi
1482 fi
1483
1484 # parameter to atof not const on DECstation Ultrix V4.0.
1485 # also get rid of bogus inline definitions in HP-UX 8.0
1486 file=math.h
1487 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1488   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1489   chmod +w ${LIB}/$file 2>/dev/null
1490   chmod a+r ${LIB}/$file 2>/dev/null
1491 fi
1492
1493 if [ -r ${LIB}/$file ]; then
1494   echo Fixing $file, non-const arg
1495   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
1496       -e 's@inline int abs(int [a-z][a-z]*) {.*}@@' \
1497       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
1498       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
1499       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
1500     ${LIB}/$file > ${LIB}/${file}.sed
1501   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1502   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1503     rm -f ${LIB}/$file
1504   else
1505     # Find any include directives that use "file".
1506     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1507       dir=`echo $file | sed -e s'|/[^/]*$||'`
1508       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1509     done
1510   fi
1511 fi
1512
1513 # Avoid nested comments on Ultrix 4.3.
1514 file=rpc/svc.h
1515 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1516   mkdir ${LIB}/rpc 2>/dev/null
1517   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1518   chmod +w ${LIB}/$file 2>/dev/null
1519   chmod a+r ${LIB}/$file 2>/dev/null
1520 fi
1521
1522 if [ -r ${LIB}/$file ]; then
1523   echo Fixing $file, nested comment
1524   sed -e 's@^\( \*      int protocol;  \)/\*@\1*/ /*@' \
1525     ${LIB}/$file > ${LIB}/$file.sed
1526   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1527   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1528     rm -f ${LIB}/$file
1529   else
1530     # Find any include directives that use "file".
1531     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1532       dir=`echo $file | sed -e s'|/[^/]*$||'`
1533       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1534     done
1535   fi
1536 fi
1537
1538 # This file in RISC/os uses /**/ to concatenate two tokens.
1539 file=bsd43/bsd43_.h
1540 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1541   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1542   chmod +w ${LIB}/$file 2>/dev/null
1543   chmod a+r ${LIB}/$file 2>/dev/null
1544 fi
1545 if [ -r ${LIB}/$file ]; then
1546   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
1547   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1548   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1549     rm -f ${LIB}/$file
1550   else
1551     # Find any include directives that use "file".
1552     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1553       dir=`echo $file | sed -e s'|/[^/]*$||'`
1554       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1555     done
1556   fi
1557 fi
1558
1559 file=rpc/rpc.h
1560 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1561   mkdir ${LIB}/rpc 2>/dev/null
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, nested comment
1569   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
1570     ${LIB}/$file > ${LIB}/$file.sed
1571   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1572   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1573     rm -f ${LIB}/$file
1574   else
1575     # Find any include directives that use "file".
1576     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1577       dir=`echo $file | sed -e s'|/[^/]*$||'`
1578       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1579     done
1580   fi
1581 fi
1582
1583 # In limits.h, put #ifndefs around things that are supposed to be defined
1584 # in float.h to avoid redefinition errors if float.h is included first.
1585 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1586 # multi line comments and the inserted #endif winds up inside the
1587 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1588 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1589 # are there, and we do not add them ourselves.
1590 for file in limits.h sys/limits.h; do
1591   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1592     mkdir ${LIB}/sys 2>/dev/null
1593     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1594     chmod +w ${LIB}/$file 2>/dev/null
1595     chmod a+r ${LIB}/$file 2>/dev/null
1596   fi
1597
1598   if [ -r ${LIB}/$file ]; then
1599     if egrep 'ifndef[   ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1600       true
1601     else
1602       echo Fixing $file
1603       sed -e '/[        ]FLT_MIN[       ]/i\
1604 #ifndef FLT_MIN
1605 '\
1606           -e '/[        ]FLT_MIN[       ]/a\
1607 #endif
1608 '\
1609           -e '/[        ]FLT_MAX[       ]/i\
1610 #ifndef FLT_MAX
1611 '\
1612           -e '/[        ]FLT_MAX[       ]/a\
1613 #endif
1614 '\
1615           -e '/[        ]FLT_DIG[       ]/i\
1616 #ifndef FLT_DIG
1617 '\
1618           -e '/[        ]FLT_DIG[       ]/a\
1619 #endif
1620 '\
1621           -e '/[        ]DBL_MIN[       ]/i\
1622 #ifndef DBL_MIN
1623 '\
1624           -e '/[        ]DBL_MIN[       ]/a\
1625 #endif
1626 '\
1627           -e '/[        ]DBL_MAX[       ]/i\
1628 #ifndef DBL_MAX
1629 '\
1630           -e '/[        ]DBL_MAX[       ]/a\
1631 #endif
1632 '\
1633           -e '/[        ]DBL_DIG[       ]/i\
1634 #ifndef DBL_DIG
1635 '\
1636           -e '/[        ]DBL_DIG[       ]/a\
1637 #endif
1638 '\
1639         ${LIB}/$file > ${LIB}/${file}.sed
1640       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1641     fi
1642     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1643       echo Deleting ${LIB}/$file\; no fixes were needed.
1644       rm -f ${LIB}/$file
1645     else
1646       # Find any include directives that use "file".
1647       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1648         dir=`echo $file | sed -e s'|/[^/]*$||'`
1649         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1650       done
1651     fi
1652   fi
1653 done
1654
1655 # In math.h, put #ifndefs around things that might be defined in a gcc
1656 # specific math-*.h file.
1657 file=math.h
1658 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1659   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1660   chmod +w ${LIB}/$file 2>/dev/null
1661   chmod a+r ${LIB}/$file 2>/dev/null
1662 fi
1663
1664 if [ -r ${LIB}/$file ]; then
1665   echo Fixing $file
1666   sed -e '/define[      ]HUGE_VAL[      ]/i\
1667 #ifndef HUGE_VAL
1668 '\
1669       -e '/define[      ]HUGE_VAL[      ]/a\
1670 #endif
1671 '\
1672     ${LIB}/$file > ${LIB}/${file}.sed
1673   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1674
1675   # In addition, copy the definition of DBL_MAX from float.h
1676   # if math.h requires one.  The Lynx math.h requires it.
1677   if egrep '#define[    ]*HUGE_VAL[     ]+DBL_MAX' $file >/dev/null 2>&1; then
1678     if egrep '#define[  ]+DBL_MAX[      ]+' $file >/dev/null 2>&1; then
1679       true;
1680     else
1681       dbl_max_def=`egrep 'define[       ]+DBL_MAX[      ]+.*' float.h 2>/dev/null`
1682       if [ "$dbl_max_def" != "" ]; then
1683         dbl_max_def=`echo $dbl_max_def | sed 's/.*define[       ]*DBL_MAX[      ]*//'`
1684         sed -e "/define[        ]HUGE_VAL[      ]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
1685           ${LIB}/$file > ${LIB}/${file}.sed
1686         rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1687       fi
1688     fi
1689   fi
1690
1691   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1692     echo Deleting ${LIB}/$file\; no fixes were needed.
1693     rm -f ${LIB}/$file
1694   else
1695     # Find any include directives that use "file".
1696     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1697       dir=`echo $file | sed -e s'|/[^/]*$||'`
1698       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1699     done
1700   fi
1701 fi
1702
1703 # Remove erroneous parentheses in sym.h on Alpha OSF/1.
1704 file=sym.h
1705 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1706   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1707   chmod +w ${LIB}/$file 2>/dev/null
1708   chmod a+r ${LIB}/$file 2>/dev/null
1709 fi
1710
1711 if [ -r ${LIB}/$file ]; then
1712   echo Fixing $file
1713   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
1714     ${LIB}/$file > ${LIB}/${file}.sed
1715   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1716   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1717     rm -f ${LIB}/$file
1718   else
1719     # Find any include directives that use "file".
1720     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1721       dir=`echo $file | sed -e s'|/[^/]*$||'`
1722       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1723     done
1724   fi
1725 fi
1726
1727 # Correct the return type for strlen in string.h on Lynx.
1728 # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
1729 file=string.h
1730 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1731   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1732   chmod +w ${LIB}/$file 2>/dev/null
1733   chmod a+r ${LIB}/$file 2>/dev/null
1734 fi
1735
1736 if [ -r ${LIB}/$file ]; then
1737   echo Fixing $file
1738   sed -e 's/extern[     ]*int[  ]*strlen();/extern unsigned int strlen();/' \
1739       -e 's/extern[     ]*int[  ]*ffs[  ]*(long);/extern int ffs(int);/' \
1740     ${LIB}/$file > ${LIB}/${file}.sed
1741   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1742   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1743     rm -f ${LIB}/$file
1744   else
1745     # Find any include directives that use "file".
1746     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1747       dir=`echo $file | sed -e s'|/[^/]*$||'`
1748       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1749     done
1750   fi
1751 fi
1752
1753 # Delete the '#define void int' line from curses.h on Lynx
1754 file=curses.h
1755 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1756   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1757   chmod +w ${LIB}/$file 2>/dev/null
1758   chmod a+r ${LIB}/$file 2>/dev/null
1759 fi
1760
1761 if [ -r ${LIB}/$file ]; then
1762   echo Fixing $file
1763   sed -e '/#[   ]*define[       ][      ]*void[         ]int/d' \
1764      ${LIB}/$file > ${LIB}/${file}.sed
1765   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1766   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
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 # For C++, avoid any typedef or macro definition of bool, and use the
1778 # built in type instead.
1779 for files in curses.h; do
1780   if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then
1781     if [ ! -r ${LIB}/$file ]; then
1782       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1783       chmod +w ${LIB}/$file 2>/dev/null
1784       chmod a+r ${LIB}/$file 2>/dev/null
1785     fi
1786
1787     echo Fixing $file
1788     sed -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/i\
1789 #ifndef __cplusplus'\
1790         -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/a\
1791 #endif'\
1792         -e '/^typedef[  ][      ]*char[         ][      ]*bool;[        ]*$/i\
1793 #ifndef __cplusplus'\
1794         -e '/^typedef[  ][      ]*char[         ][      ]*bool;[        ]*$/a\
1795 #endif'\
1796         ${LIB}/$file > ${LIB}/${file}.sed
1797     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1798     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1799       rm -f ${LIB}/$file
1800     else
1801       # Find any include directives that use "file".
1802       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1803         dir=`echo $file | sed -e s'|/[^/]*$||'`
1804         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1805       done
1806     fi
1807   fi
1808 done
1809
1810 # Fix incorrect S_IF* definitions on m88k-sysv3.
1811 file=sys/stat.h
1812 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1813   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1814   chmod +w ${LIB}/$file 2>/dev/null
1815   chmod a+r ${LIB}/$file 2>/dev/null
1816 fi
1817
1818 if [ -r ${LIB}/$file ]; then
1819   echo Fixing $file
1820   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)/' \
1821       -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(0[0-9]*\)[  ]*)/\1 (((m)\&S_IFMT)==\2)/' \
1822     ${LIB}/$file > ${LIB}/${file}.sed
1823   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1824   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1825     rm -f ${LIB}/$file
1826   else
1827     # Find any include directives that use "file".
1828     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1829       dir=`echo $file | sed -e s'|/[^/]*$||'`
1830       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1831     done
1832   fi
1833 fi
1834
1835 # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
1836 for file in stdio.h stdlib.h; do
1837   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1838     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1839     chmod +w ${LIB}/$file 2>/dev/null
1840     chmod a+r ${LIB}/$file 2>/dev/null
1841   fi
1842
1843   if [ -r ${LIB}/$file ]; then
1844     echo Fixing $file, getopt declaration
1845     sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
1846       ${LIB}/$file > ${LIB}/${file}.sed
1847     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1848     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1849       rm -f ${LIB}/$file
1850     else
1851       # Find any include directives that use "file".
1852       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1853         dir=`echo $file | sed -e s'|/[^/]*$||'`
1854         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1855       done
1856     fi
1857   fi
1858 done
1859
1860 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1861 # need to fix some additional files.  This is the same test for ISC that
1862 # Autoconf uses.
1863 if test -d /etc/conf/kconfig.d \
1864     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1865   echo "Fixing ISC __STDC__ goof in several files..."
1866   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1867     echo $name
1868     if test -r ${LIB}/$name; then
1869       file=${LIB}/$name
1870     else
1871       file=${INPUT}/$name
1872     fi
1873     # On Interactive 2.2, certain traditional Unix definitions
1874     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1875     # defined, not just if _POSIX_SOURCE is defined.  This makes it
1876     # impossible to compile any nontrivial program except with -posix.
1877     sed \
1878 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1879             < $file > ${LIB}/$name.
1880     mv ${LIB}/$name. ${LIB}/$name
1881   done
1882   
1883   echo "Fixing ISC fmod declaration"
1884   # This one's already been fixed for other things.
1885   file=${LIB}/math.h
1886   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1887   mv $file. $file
1888   
1889   echo "Fixing nested comments in ISC <sys/limits.h>"
1890   file=sys/limits.h
1891   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1892   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1893 fi
1894
1895 # These files in Sun OS 4.x use /**/ to concatenate tokens.
1896 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
1897         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
1898         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
1899 do
1900   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1901     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1902     chmod +w ${LIB}/$file 2>/dev/null
1903     chmod a+r ${LIB}/$file 2>/dev/null
1904   fi
1905
1906   if [ -r ${LIB}/$file ]; then
1907     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1908     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1909     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1910       rm -f ${LIB}/$file
1911     else
1912       # Find any include directives that use "file".
1913       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1914         dir=`echo $file | sed -e s'|/[^/]*$||'`
1915         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1916       done
1917     fi
1918   fi
1919 done
1920
1921 # These files in ARM/RISCiX use /**/ to concatenate tokens.
1922 for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
1923         dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
1924 do
1925   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1926     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1927     chmod +w ${LIB}/$file 2>/dev/null
1928     chmod a+r ${LIB}/$file 2>/dev/null
1929   fi
1930
1931   if [ -r ${LIB}/$file ]; then
1932     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1933     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1934     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1935       rm -f ${LIB}/$file
1936   else
1937     # Find any include directives that use "file".
1938     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1939       dir=`echo $file | sed -e s'|/[^/]*$||'`
1940       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1941     done
1942     fi
1943   fi
1944 done
1945
1946 # math.h on SunOS 4 puts the declaration of matherr before the definition
1947 # of struct exception, so the prototype (added by fixproto) causes havoc.
1948 file=math.h
1949 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1950   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1951   chmod +w ${LIB}/$file 2>/dev/null
1952   chmod a+r ${LIB}/$file 2>/dev/null
1953 fi
1954
1955 if [ -r ${LIB}/$file ]; then
1956   echo Fixing $file, matherr declaration
1957   sed -e '/^struct exception/,$b' \
1958       -e '/matherr/i\
1959 struct exception;
1960 '\
1961     ${LIB}/$file > ${LIB}/${file}.sed
1962   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1963   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1964     rm -f ${LIB}/$file
1965   else
1966     # Find any include directives that use "file".
1967     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1968       dir=`echo $file | sed -e s'|/[^/]*$||'`
1969       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1970     done
1971   fi
1972 fi
1973
1974 # assert.h on HP/UX is not C++ ready, even though NO_IMPLICIT_EXTERN_C
1975 # is defined on HP/UX.
1976 file=assert.h
1977 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1978   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1979   chmod +w ${LIB}/$file 2>/dev/null
1980   chmod a+r ${LIB}/$file 2>/dev/null
1981 fi
1982
1983 if [ -r ${LIB}/$file ]; then
1984   if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
1985      || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
1986     true
1987   else
1988     echo Fixing $file
1989     echo '#ifdef __cplusplus
1990 extern "C" {
1991 #endif' > ${LIB}/${file}.sed
1992     cat ${LIB}/${file} >> ${LIB}/${file}.sed
1993     echo '#ifdef __cplusplus
1994 }
1995 #endif' >> ${LIB}/${file}.sed 
1996     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1997     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1998       rm -f ${LIB}/$file
1999     else
2000       # Find any include directives that use "file".
2001       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2002         dir=`echo $file | sed -e s'|/[^/]*$||'`
2003         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2004       done
2005     fi
2006   fi
2007 fi
2008
2009 # check for broken assert.h that needs stdio.h or stdlib.h
2010 file=assert.h
2011 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2012   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2013   chmod +w ${LIB}/$file 2>/dev/null
2014   chmod a+r ${LIB}/$file 2>/dev/null
2015 fi
2016
2017 if [ -r ${LIB}/$file ]; then
2018   if grep 'stderr' ${LIB}/$file >/dev/null 2>/dev/null; then
2019     if grep 'include.*stdio.h' ${LIB}/$file >/dev/null 2>/dev/null; then
2020       true
2021     else
2022       echo "Fixing $file (needs stdio.h)"
2023       echo '#include <stdio.h>' >>${LIB}/$file
2024     fi
2025   fi
2026   if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
2027      grep 'abort *(' ${LIB}/$file >/dev/null 2>/dev/null; then
2028     if grep 'include.*stdlib.h' ${LIB}/$file >/dev/null 2>/dev/null; then
2029       true
2030     else
2031       echo "Fixing $file (needs stdlib.h)"
2032       echo '#include <stdlib.h>' >>${LIB}/$file
2033     fi
2034   fi
2035   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2036     rm -f ${LIB}/$file
2037   else
2038     # Find any include directives that use "file".
2039     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2040       dir=`echo $file | sed -e s'|/[^/]*$||'`
2041       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2042     done
2043   fi
2044 fi
2045
2046 # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
2047 file=unistd.h
2048 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2049   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2050   chmod +w ${LIB}/$file 2>/dev/null
2051   chmod a+r ${LIB}/$file 2>/dev/null
2052 fi
2053
2054 if [ -r ${LIB}/$file ]; then
2055   echo Fixing $file, sbrk declaration
2056   sed -e 's/char\([     ]*\*[    ]*sbrk[        ]*(\)/void\1/' \
2057     ${LIB}/$file > ${LIB}/${file}.sed
2058   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2059   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2060     rm -f ${LIB}/$file
2061   else
2062     # Find any include directives that use "file".
2063     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2064       dir=`echo $file | sed -e s'|/[^/]*$||'`
2065       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2066     done
2067   fi
2068 fi
2069
2070 # This file on SunOS 4 has a very large macro.  When the sed loop
2071 # tries pull it in, it overflows the pattern space size of the SunOS
2072 # sed (GNU sed does not have this problem).  Since the file does not
2073 # require fixing, we remove it from the fixed directory.
2074 file=sundev/ipi_error.h
2075 if [ -r ${LIB}/$file ]; then
2076   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
2077   rm -f ${LIB}/$file
2078 fi
2079
2080 # Put cpp wrappers around these include files to avoid redeclaration
2081 # errors during multiple inclusion on m88k-tektronix-sysv3.
2082 for file in time.h sys/time.h ; do
2083   if egrep '#ifndef' $file >/dev/null 2>&1; then
2084     true
2085   else
2086     if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2087       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2088       chmod +w ${LIB}/$file 2>/dev/null
2089     fi
2090     if [ -r ${LIB}/$file ]; then
2091       echo Fixing $file, to protect against multiple inclusion.
2092       cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
2093       (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
2094       echo "#define __GCC_GOT_${cpp_wrapper}_"
2095       cat ${LIB}/${file}
2096       echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
2097       rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
2098     fi
2099   fi
2100 done
2101
2102 # Fix fcntl prototype in fcntl.h on LynxOS.
2103 file=fcntl.h
2104 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2105   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2106   chmod +w ${LIB}/$file 2>/dev/null
2107   chmod a+r ${LIB}/$file 2>/dev/null
2108 fi
2109
2110 if [ -r ${LIB}/$file ]; then
2111   echo Fixing $file, fcntl declaration
2112   sed -e 's/\(fcntl.*(int, int, \)int)/\1...)/' \
2113     ${LIB}/$file > ${LIB}/${file}.sed
2114   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2115   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2116     rm -f ${LIB}/$file
2117   else
2118     # Find any include directives that use "file".
2119     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2120       dir=`echo $file | sed -e s'|/[^/]*$||'`
2121       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2122     done
2123   fi
2124 fi
2125
2126 # This loop does not appear to do anything, because it uses file
2127 # rather than $file when setting target.  It also appears to be
2128 # unnecessary, since the main loop processes symbolic links.
2129 #if $LINKS; then
2130 #  echo 'Making internal symbolic non-directory links'
2131 #  cd ${INPUT}
2132 #  files=`find . -type l -print`
2133 #  for file in $files; do
2134 #    dest=`ls -ld $file | sed -n 's/.*-> //p'`
2135 #    if expr "$dest" : '[^/].*' > /dev/null; then    
2136 #      target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
2137 #      if [ -f $target ]; then
2138 #        ln -s $dest ${LIB}/$file >/dev/null 2>&1
2139 #      fi
2140 #    fi
2141 #  done
2142 #fi
2143
2144 # Make sure that any include files referenced using double quotes
2145 # exist in the fixed directory.  This comes last since otherwise
2146 # we might end up deleting some of these files "because they don't
2147 # need any change."
2148 set x $required
2149 shift
2150 while [ $# != 0 ]; do
2151   newreq=
2152   while [ $# != 0 ]; do
2153     # $1 is the directory to copy from, $2 is the unfixed file,
2154     # $3 is the fixed file name.
2155     cd ${INPUT}
2156     cd $1
2157     if [ -r $2 ] && [ ! -r $3 ]; then
2158       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
2159       chmod +w $3 2>/dev/null
2160       chmod a+r $3 2>/dev/null
2161       echo Copied $2
2162       for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' $3 | sed -e 's/^[      ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2163         dir=`echo $2 | sed -e s'|/[^/]*$||'`
2164         dir2=`echo $3 | sed -e s'|/[^/]*$||'`
2165         newreq="$newreq $1 $dir/$include $dir2/$include"
2166       done
2167     fi
2168     shift; shift; shift
2169   done
2170   set x $newreq
2171   shift
2172 done
2173
2174 echo 'Cleaning up DONE files.'
2175 cd $LIB
2176 find . -name DONE -exec rm -f '{}' ';'
2177
2178 echo 'Removing unneeded directories:'
2179 cd $LIB
2180 files=`find . -type d -print | sort -r`
2181 for file in $files; do
2182   rmdir $LIB/$file > /dev/null 2>&1
2183 done
2184
2185 exit 0