OSDN Git Service

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