OSDN Git Service

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