OSDN Git Service

H
[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/wait.h on AIX 3.2.5 puts the declaration of wait3 before the definition
1661 # of struct rusage, so the prototype (added by fixproto) causes havoc.
1662 file=sys/wait.h
1663 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1664   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1665   chmod +w ${LIB}/$file 2>/dev/null
1666 fi
1667
1668 if [ -r ${LIB}/$file ] \
1669   && grep 'bos325,' ${LIB}/$file >/dev/null; then
1670   echo Fixing $file, wait3 declaration
1671   sed -e '/^extern pid_t wait3();$/i\
1672 struct rusage;
1673 '\
1674     ${LIB}/$file > ${LIB}/${file}.sed
1675   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1676   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1677     rm -f ${LIB}/$file
1678   else
1679     # Find any include directives that use "file".
1680     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1681       dir=`echo $file | sed -e s'|/[^/]*$||'`
1682       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1683     done
1684   fi
1685 fi
1686
1687 # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1688 # Note that version 3 of the NeXT system has wait.h in a different directory,
1689 # so that this code won't do anything.  But wait.h in version 3 has a
1690 # conditional, so it doesn't need this fix.  So everything is okay.
1691 file=sys/wait.h
1692 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1693   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1694   chmod +w ${LIB}/$file 2>/dev/null
1695 fi
1696
1697 if [ -r ${LIB}/$file ] \
1698   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
1699   echo Fixing $file, bad wait formal
1700   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
1701   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1702   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1703     rm -f ${LIB}/$file
1704   else
1705     # Find any include directives that use "file".
1706     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1707       dir=`echo $file | sed -e s'|/[^/]*$||'`
1708       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1709     done
1710   fi
1711 fi
1712
1713 # Don't use or define the name va_list in stdio.h.
1714 # This is for ANSI and also to interoperate properly with gcc's varargs.h.
1715 file=stdio.h
1716 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1717   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1718   chmod +w ${LIB}/$file 2>/dev/null
1719   chmod a+r ${LIB}/$file 2>/dev/null
1720 fi
1721
1722 if [ -r ${LIB}/$file ]; then
1723   echo Fixing $file, use of va_list
1724   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1725   if egrep "__need___va_list" ${LIB}/$file >/dev/null 2>&1; then
1726     touch ${LIB}/${file}.sed
1727   else
1728     (echo "#define __need___va_list"
1729      echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1730   fi
1731   # Use __gnuc_va_list in arg types in place of va_list.
1732   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1733   # trailing parentheses and semicolon save all other systems from this.
1734   # Define __va_list__ (something harmless and unused) instead of va_list.
1735   # Don't claim to have defined va_list.
1736   sed -e 's@ va_list @ __gnuc_va_list @' \
1737       -e 's@ va_list)@ __gnuc_va_list)@' \
1738       -e 's@ _BSD_VA_LIST_));@ __gnuc_va_list));@' \
1739       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1740       -e 's@ va_list@ __va_list__@' \
1741       -e 's@\*va_list@*__va_list__@' \
1742       -e 's@ __va_list)@ __gnuc_va_list)@' \
1743       -e 's@GNUC_VA_LIST@GNUC_Va_LIST@' \
1744       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1745       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1746       -e 's@_Va_LIST@_VA_LIST@' \
1747     ${LIB}/$file >> ${LIB}/${file}.sed
1748   
1749   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1750   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1751     rm -f ${LIB}/$file
1752   else
1753     # Find any include directives that use "file".
1754     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1755       dir=`echo $file | sed -e s'|/[^/]*$||'`
1756       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1757     done
1758   fi
1759 fi
1760
1761 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1762 file=ansi_compat.h
1763 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1764   if grep -s ULTRIX $file; then
1765     echo "/* This file intentionally left blank.  */" > $LIB/$file
1766   fi
1767 fi
1768
1769 # parameter to atof not const on DECstation Ultrix V4.0 and NEWS-OS 4.2R.
1770 # also get rid of bogus inline definitions in HP-UX 8.0
1771 file=math.h
1772 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1773   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1774   chmod +w ${LIB}/$file 2>/dev/null
1775   chmod a+r ${LIB}/$file 2>/dev/null
1776 fi
1777
1778 if [ -r ${LIB}/$file ]; then
1779   echo Fixing $file, non-const arg
1780   sed -e 's@atof(\([    ]*char[         ]*\*[^)]*\))@atof(const \1)@' \
1781       -e 's@inline int abs(int [a-z][a-z]*) {.*}@extern "C" int abs(int);@' \
1782       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
1783       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
1784       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
1785     ${LIB}/$file > ${LIB}/${file}.sed
1786   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1787   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1788     rm -f ${LIB}/$file
1789   else
1790     # Find any include directives that use "file".
1791     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1792       dir=`echo $file | sed -e s'|/[^/]*$||'`
1793       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1794     done
1795   fi
1796 fi
1797
1798 # fix bogus recursive stdlib.h in NEWS-OS 4.0C
1799 file=stdlib.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, recursive inclusion
1808   sed -e '/^#include <stdlib.h>/i\
1809 #if 0
1810 ' \
1811       -e '/^#include <stdlib.h>/a\
1812 #endif
1813 ' \
1814     ${LIB}/$file > ${LIB}/${file}.sed
1815   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1816   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1817     rm -f ${LIB}/$file
1818   else
1819     # Find any include directives that use "file".
1820     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1821       dir=`echo $file | sed -e s'|/[^/]*$||'`
1822       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1823     done
1824   fi
1825 fi
1826
1827 # Avoid nested comments on Ultrix 4.3.
1828 file=rpc/svc.h
1829 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1830   mkdir ${LIB}/rpc 2>/dev/null
1831   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1832   chmod +w ${LIB}/$file 2>/dev/null
1833   chmod a+r ${LIB}/$file 2>/dev/null
1834 fi
1835
1836 if [ -r ${LIB}/$file ]; then
1837   echo Fixing $file, nested comment
1838   sed -e 's@^\( \*      int protocol;  \)/\*@\1*/ /*@' \
1839     ${LIB}/$file > ${LIB}/$file.sed
1840   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1841   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1842     rm -f ${LIB}/$file
1843   else
1844     # Find any include directives that use "file".
1845     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1846       dir=`echo $file | sed -e s'|/[^/]*$||'`
1847       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1848     done
1849   fi
1850 fi
1851
1852 # This file in RISC/os uses /**/ to concatenate two tokens.
1853 file=bsd43/bsd43_.h
1854 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1855   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1856   chmod +w ${LIB}/$file 2>/dev/null
1857   chmod a+r ${LIB}/$file 2>/dev/null
1858 fi
1859 if [ -r ${LIB}/$file ]; then
1860   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
1861   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1862   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1863     rm -f ${LIB}/$file
1864   else
1865     # Find any include directives that use "file".
1866     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1867       dir=`echo $file | sed -e s'|/[^/]*$||'`
1868       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1869     done
1870   fi
1871 fi
1872
1873 file=rpc/rpc.h
1874 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1875   mkdir ${LIB}/rpc 2>/dev/null
1876   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1877   chmod +w ${LIB}/$file 2>/dev/null
1878   chmod a+r ${LIB}/$file 2>/dev/null
1879 fi
1880
1881 if [ -r ${LIB}/$file ]; then
1882   echo Fixing $file, nested comment
1883   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
1884     ${LIB}/$file > ${LIB}/$file.sed
1885   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1886   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1887     rm -f ${LIB}/$file
1888   else
1889     # Find any include directives that use "file".
1890     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1891       dir=`echo $file | sed -e s'|/[^/]*$||'`
1892       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1893     done
1894   fi
1895 fi
1896
1897 # rpc/types.h on OSF1/2.0 is not C++ ready, even though NO_IMPLICIT_EXTERN_C
1898 # is defined for the alpha.  The problem is the declaration of malloc.
1899 file=rpc/types.h
1900 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1901   mkdir ${LIB}/rpc 2>/dev/null
1902   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1903   chmod +w ${LIB}/$file 2>/dev/null
1904   chmod a+r ${LIB}/$file 2>/dev/null
1905 fi
1906 if [ -r ${LIB}/$file ]; then
1907   if egrep '"C"' ${LIB}/$file >/dev/null 2>&1; then
1908     true
1909   else
1910     echo Fixing $file
1911     echo '#ifdef __cplusplus
1912 extern "C" {
1913 #endif' > ${LIB}/${file}.sed
1914     cat ${LIB}/${file} >> ${LIB}/${file}.sed
1915     echo '#ifdef __cplusplus
1916 }
1917 #endif' >> ${LIB}/${file}.sed 
1918     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1919     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1920       rm -f ${LIB}/$file
1921     else
1922       # Find any include directives that use "file".
1923       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1924         dir=`echo $file | sed -e s'|/[^/]*$||'`
1925         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
1926       done
1927     fi
1928   fi
1929 fi
1930
1931 # In limits.h, put #ifndefs around things that are supposed to be defined
1932 # in float.h to avoid redefinition errors if float.h is included first.
1933 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1934 # multi line comments and the inserted #endif winds up inside the
1935 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1936 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1937 # are there, and we do not add them ourselves.
1938 # Also fix a nested comment problem in sys/limits.h on Motorola sysV68 R3V7.1
1939 for file in limits.h sys/limits.h; do
1940   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1941     mkdir ${LIB}/sys 2>/dev/null
1942     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1943     chmod +w ${LIB}/$file 2>/dev/null
1944     chmod a+r ${LIB}/$file 2>/dev/null
1945   fi
1946
1947   if [ -r ${LIB}/$file ]; then
1948     if egrep 'ifndef[   ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1949       true
1950     else
1951       echo Fixing $file
1952       sed -e '/[        ]FLT_MIN[       ]/i\
1953 #ifndef FLT_MIN
1954 '\
1955           -e '/[        ]FLT_MIN[       ]/a\
1956 #endif
1957 '\
1958           -e '/[        ]FLT_MAX[       ]/i\
1959 #ifndef FLT_MAX
1960 '\
1961           -e '/[        ]FLT_MAX[       ]/a\
1962 #endif
1963 '\
1964           -e '/[        ]FLT_DIG[       ]/i\
1965 #ifndef FLT_DIG
1966 '\
1967           -e '/[        ]FLT_DIG[       ]/a\
1968 #endif
1969 '\
1970           -e '/[        ]DBL_MIN[       ]/i\
1971 #ifndef DBL_MIN
1972 '\
1973           -e '/[        ]DBL_MIN[       ]/a\
1974 #endif
1975 '\
1976           -e '/[        ]DBL_MAX[       ]/i\
1977 #ifndef DBL_MAX
1978 '\
1979           -e '/[        ]DBL_MAX[       ]/a\
1980 #endif
1981 '\
1982           -e '/[        ]DBL_DIG[       ]/i\
1983 #ifndef DBL_DIG
1984 '\
1985           -e '/[        ]DBL_DIG[       ]/a\
1986 #endif
1987 '\
1988           -e '/^\(\/\*#define   HUGE_VAL        3\.[0-9e+]* *\)\/\*/s//\1/'\
1989         ${LIB}/$file > ${LIB}/${file}.sed
1990       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1991     fi
1992     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1993       echo Deleting ${LIB}/$file\; no fixes were needed.
1994       rm -f ${LIB}/$file
1995     else
1996       # Find any include directives that use "file".
1997       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1998         dir=`echo $file | sed -e s'|/[^/]*$||'`
1999         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2000       done
2001     fi
2002   fi
2003 done
2004
2005 # In math.h, put #ifndefs around things that might be defined in a gcc
2006 # specific math-*.h file.
2007 file=math.h
2008 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2009   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2010   chmod +w ${LIB}/$file 2>/dev/null
2011   chmod a+r ${LIB}/$file 2>/dev/null
2012 fi
2013
2014 if [ -r ${LIB}/$file ]; then
2015   echo Fixing $file
2016   sed -e '/define[      ]HUGE_VAL[      ]/i\
2017 #ifndef HUGE_VAL
2018 '\
2019       -e '/define[      ]HUGE_VAL[      ]/a\
2020 #endif
2021 '\
2022     ${LIB}/$file > ${LIB}/${file}.sed
2023   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2024
2025   # In addition, copy the definition of DBL_MAX from float.h
2026   # if math.h requires one.  The Lynx math.h requires it.
2027   if egrep '#define[    ]*HUGE_VAL[     ]+DBL_MAX' $file >/dev/null 2>&1; then
2028     if egrep '#define[  ]+DBL_MAX[      ]+' $file >/dev/null 2>&1; then
2029       true;
2030     else
2031       dbl_max_def=`egrep 'define[       ]+DBL_MAX[      ]+.*' float.h 2>/dev/null`
2032       if [ "$dbl_max_def" != "" ]; then
2033         dbl_max_def=`echo $dbl_max_def | sed 's/.*define[       ]*DBL_MAX[      ]*//'`
2034         sed -e "/define[        ]HUGE_VAL[      ]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
2035           ${LIB}/$file > ${LIB}/${file}.sed
2036         rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2037       fi
2038     fi
2039   fi
2040
2041   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2042     echo Deleting ${LIB}/$file\; no fixes were needed.
2043     rm -f ${LIB}/$file
2044   else
2045     # Find any include directives that use "file".
2046     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2047       dir=`echo $file | sed -e s'|/[^/]*$||'`
2048       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2049     done
2050   fi
2051 fi
2052
2053 # Remove erroneous parentheses in sym.h on Alpha OSF/1.
2054 file=sym.h
2055 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2056   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2057   chmod +w ${LIB}/$file 2>/dev/null
2058   chmod a+r ${LIB}/$file 2>/dev/null
2059 fi
2060
2061 if [ -r ${LIB}/$file ]; then
2062   echo Fixing $file
2063   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
2064     ${LIB}/$file > ${LIB}/${file}.sed
2065   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2066   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2067     rm -f ${LIB}/$file
2068   else
2069     # Find any include directives that use "file".
2070     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2071       dir=`echo $file | sed -e s'|/[^/]*$||'`
2072       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2073     done
2074   fi
2075 fi
2076
2077 # Fix return value of mem{ccpy,chr,cpy,set} and str{len,spn,cspn}
2078 # in string.h on sysV68
2079 # Correct the return type for strlen in string.h on Lynx.
2080 # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
2081 # Add missing const for strdup on OSF/1 V3.0.
2082 # On sysV88 layout is slightly different.
2083 file=string.h
2084 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2085   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2086   chmod +w ${LIB}/$file 2>/dev/null
2087   chmod a+r ${LIB}/$file 2>/dev/null
2088 fi
2089
2090 if [ -r ${LIB}/$file ]; then
2091   echo Fixing $file, mem{ccpy,chr,cpy,set} and str{len,spn,cspn} return value
2092   sed -e 's/extern[     ]*int[  ]*strlen();/extern unsigned int strlen();/' \
2093       -e 's/extern[     ]*int[  ]*ffs[  ]*(long);/extern int ffs(int);/' \
2094       -e 's/strdup(char \*s1);/strdup(const char *s1);/' \
2095       -e '/^extern char$/N' \
2096       -e 's/^extern char\(\n    \*memccpy(),\)$/extern void\1/'\
2097       -e '/^    strncmp(),$/N'\
2098       -e 's/^\( strncmp()\),\n\(        strlen(),\)$/\1;\
2099 extern unsigned int\
2100 \2/'\
2101       -e '/^extern int$/N'\
2102       -e 's/^extern int\(\n     strlen(),\)/extern size_t\1/' \
2103     ${LIB}/$file > ${LIB}/${file}.sed
2104   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2105   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2106     rm -f ${LIB}/$file
2107   else
2108     # Find any include directives that use "file".
2109     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2110       dir=`echo $file | sed -e s'|/[^/]*$||'`
2111       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2112     done
2113   fi
2114 fi
2115
2116 # Correct the return type for strlen in strings.h in SunOS 4.
2117 file=strings.h
2118 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2119   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2120   chmod +w ${LIB}/$file 2>/dev/null
2121   chmod a+r ${LIB}/$file 2>/dev/null
2122 fi
2123
2124 if [ -r ${LIB}/$file ]; then
2125   echo Fixing $file
2126   sed -e 's/int[        ]*strlen();/__SIZE_TYPE__ strlen();/' \
2127     ${LIB}/$file > ${LIB}/${file}.sed
2128   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2129   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2130     rm -f ${LIB}/$file
2131   else
2132     # Find any include directives that use "file".
2133     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2134       dir=`echo $file | sed -e s'|/[^/]*$||'`
2135       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2136     done
2137   fi
2138 fi
2139
2140 # Delete the '#define void int' line from curses.h on Lynx
2141 file=curses.h
2142 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2143   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2144   chmod +w ${LIB}/$file 2>/dev/null
2145   chmod a+r ${LIB}/$file 2>/dev/null
2146 fi
2147
2148 if [ -r ${LIB}/$file ]; then
2149   echo Fixing $file
2150   sed -e '/#[   ]*define[       ][      ]*void[         ]int/d' \
2151      ${LIB}/$file > ${LIB}/${file}.sed
2152   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2153   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2154     rm -f ${LIB}/$file
2155   else
2156     # Find any include directives that use "file".
2157     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2158       dir=`echo $file | sed -e s'|/[^/]*$||'`
2159       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2160     done
2161   fi
2162 fi
2163
2164 # Fix `typedef struct term;' on hppa1.1-hp-hpux9.
2165 file=curses.h
2166 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2167   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2168   chmod +w ${LIB}/$file 2>/dev/null
2169   chmod a+r ${LIB}/$file 2>/dev/null
2170 fi
2171
2172 if [ -r ${LIB}/$file ]; then
2173   echo Fixing $file
2174   sed -e 's/^[  ]*typedef[      ][      ]*\(struct[     ][      ]*term[         ]*;[    ]*\)$/\1/' \
2175      ${LIB}/$file > ${LIB}/${file}.sed
2176   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2177   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2178     rm -f ${LIB}/$file
2179   else
2180     # Find any include directives that use "file".
2181     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2182       dir=`echo $file | sed -e s'|/[^/]*$||'`
2183       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2184     done
2185   fi
2186 fi
2187
2188 # For C++, avoid any typedef or macro definition of bool, and use the
2189 # built in type instead.
2190 for files in curses.h; do
2191   if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then
2192     if [ ! -r ${LIB}/$file ]; then
2193       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2194       chmod +w ${LIB}/$file 2>/dev/null
2195       chmod a+r ${LIB}/$file 2>/dev/null
2196     fi
2197
2198     echo Fixing $file
2199     sed -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/i\
2200 #ifndef __cplusplus
2201 '\
2202         -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/a\
2203 #endif
2204 '\
2205         -e '/^typedef[  ][      ]*char[         ][      ]*bool[         ]*;/i\
2206 #ifndef __cplusplus
2207 '\
2208         -e '/^typedef[  ][      ]*char[         ][      ]*bool[         ]*;/a\
2209 #endif
2210 '\
2211         ${LIB}/$file > ${LIB}/${file}.sed
2212     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2213     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2214       rm -f ${LIB}/$file
2215     else
2216       # Find any include directives that use "file".
2217       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2218         dir=`echo $file | sed -e s'|/[^/]*$||'`
2219         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2220       done
2221     fi
2222   fi
2223 done
2224
2225 # Fix incorrect S_IF* definitions on m88k-sysv3.
2226 file=sys/stat.h
2227 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2228   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2229   chmod +w ${LIB}/$file 2>/dev/null
2230   chmod a+r ${LIB}/$file 2>/dev/null
2231 fi
2232
2233 if [ -r ${LIB}/$file ]; then
2234   echo Fixing $file
2235   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)/' \
2236       -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(0[0-9]*\)[  ]*)/\1 (((m)\&S_IFMT)==\2)/' \
2237     ${LIB}/$file > ${LIB}/${file}.sed
2238   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2239   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2240     rm -f ${LIB}/$file
2241   else
2242     # Find any include directives that use "file".
2243     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2244       dir=`echo $file | sed -e s'|/[^/]*$||'`
2245       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2246     done
2247   fi
2248 fi
2249
2250 # Fix nested comments in Motorola's <limits.h> and <sys/limits.h>
2251 for file in limits.h sys/limits.h; do
2252   if [ $target_canonical = m88k-motorola-sysv3 -o \
2253        $target_canonical = m68k-motorola-sysv ]; then
2254
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 nested comments in Motorola's $file"
2263       sed \
2264         -e 's@^\(#undef[        ][      ]*PIPE_BUF[     ]*/\* max # bytes atomic in write to a\)$@\1 */@' \
2265         -e 's@\(/\*#define      HUGE_VAL        3.40282346638528860e+38 \)\(/\*error value returned by Math lib\*/\)$@\1*/ \2@' \
2266           < ${LIB}/$file > ${LIB}/${file}.sed
2267       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2268       if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2269         rm -f ${LIB}/$file
2270       fi
2271     fi
2272   fi
2273 done
2274
2275 # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
2276 for file in stdio.h stdlib.h; do
2277   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2278     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2279     chmod +w ${LIB}/$file 2>/dev/null
2280     chmod a+r ${LIB}/$file 2>/dev/null
2281   fi
2282
2283   if [ -r ${LIB}/$file ]; then
2284     echo Fixing $file, getopt declaration
2285     sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
2286       ${LIB}/$file > ${LIB}/${file}.sed
2287     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2288     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2289       rm -f ${LIB}/$file
2290     else
2291       # Find any include directives that use "file".
2292       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2293         dir=`echo $file | sed -e s'|/[^/]*$||'`
2294         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2295       done
2296     fi
2297   fi
2298 done
2299
2300 # Fix __page_size* declarations in pthread.h AIX 4.1.[34].
2301 # The original ones fail if uninitialized externs are not common.
2302 # This is the default for all ANSI standard C++ compilers.
2303 for file in pthread.h; do
2304   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2305     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2306     chmod +w ${LIB}/$file 2>/dev/null
2307     chmod a+r ${LIB}/$file 2>/dev/null
2308   fi
2309
2310   if [ -r ${LIB}/$file ]; then
2311     echo Fixing $file, __page_size* declarations
2312     sed -e 's/^int __page_size/extern int __page_size/' \
2313       ${LIB}/$file > ${LIB}/${file}.sed
2314     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2315     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2316       rm -f ${LIB}/$file
2317     else
2318       # Find any include directives that use "file".
2319       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2320         dir=`echo $file | sed -e s'|/[^/]*$||'`
2321         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2322       done
2323     fi
2324   fi
2325 done
2326
2327 # Determine if we're on Interactive Unix 2.2 or later, in which case we
2328 # need to fix some additional files.  This is the same test for ISC that
2329 # Autoconf uses.
2330 if test -d /etc/conf/kconfig.d \
2331     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
2332   echo "Fixing ISC __STDC__ goof in several files..."
2333   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
2334     echo $name
2335     if test -r ${LIB}/$name; then
2336       file=${LIB}/$name
2337     else
2338       file=${INPUT}/$name
2339     fi
2340     # On Interactive 2.2, certain traditional Unix definitions
2341     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
2342     # defined, not just if _POSIX_SOURCE is defined.  This makes it
2343     # impossible to compile any nontrivial program except with -posix.
2344     sed \
2345 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
2346             < $file > ${LIB}/$name.
2347     mv ${LIB}/$name. ${LIB}/$name
2348   done
2349   
2350   echo "Fixing ISC fmod declaration"
2351   # This one's already been fixed for other things.
2352   file=${LIB}/math.h
2353   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
2354   mv $file. $file
2355   
2356   echo "Fixing nested comments in ISC <sys/limits.h>"
2357   file=sys/limits.h
2358   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
2359   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
2360 fi
2361
2362 # These files in Sun OS 4.x use /**/ to concatenate tokens.
2363 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
2364         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
2365         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
2366 do
2367   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2368     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2369     chmod +w ${LIB}/$file 2>/dev/null
2370     chmod a+r ${LIB}/$file 2>/dev/null
2371   fi
2372
2373   if [ -r ${LIB}/$file ]; then
2374     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
2375     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2376     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2377       rm -f ${LIB}/$file
2378     else
2379       # Find any include directives that use "file".
2380       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2381         dir=`echo $file | sed -e s'|/[^/]*$||'`
2382         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2383       done
2384     fi
2385   fi
2386 done
2387
2388 # These files in ARM/RISCiX use /**/ to concatenate tokens.
2389 for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
2390         dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
2391 do
2392   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2393     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2394     chmod +w ${LIB}/$file 2>/dev/null
2395     chmod a+r ${LIB}/$file 2>/dev/null
2396   fi
2397
2398   if [ -r ${LIB}/$file ]; then
2399     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
2400     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2401     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2402       rm -f ${LIB}/$file
2403   else
2404     # Find any include directives that use "file".
2405     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2406       dir=`echo $file | sed -e s'|/[^/]*$||'`
2407       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2408     done
2409     fi
2410   fi
2411 done
2412
2413 # libm.a on m88k-motorola-sysv3 contains a stupid optimization for function
2414 # hypot(), which returns the second argument without even looking at its value
2415 # if the other is 0.0
2416 # Another drawback is that fix-header doesn't fix fabs' prototype, and I have
2417 #  no idea why.
2418 file=math.h
2419 if [ $target_canonical = m88k-motorola-sysv3 ]; then
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     echo Fixing $file, fabs/hypot definition
2428     sed \
2429       -e 's/extern double floor(), ceil(), fmod(), fabs();/extern double floor(), ceil(), fmod(), fabs _PARAMS((double));/' \
2430       -e '/^extern double hypot();$/a\
2431 \/* Workaround a stupid Motorola optimization if one\
2432    of x or y is 0.0 and the other is negative!  *\/\
2433 #ifdef __STDC__\
2434 static __inline__ double fake_hypot (double x, double y)\
2435 #else\
2436 static __inline__ double fake_hypot (x, y)\
2437         double x, y;\
2438 #endif\
2439 {\
2440         return fabs (hypot (x, y));\
2441 }\
2442 #define hypot   fake_hypot
2443 ' \
2444       ${LIB}/$file > ${LIB}/${file}.sed
2445     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2446     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2447       rm -f ${LIB}/$file
2448     fi
2449   fi
2450 fi
2451
2452 # math.h on SunOS 4 puts the declaration of matherr before the definition
2453 # of struct exception, so the prototype (added by fixproto) causes havoc.
2454 file=math.h
2455 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2456   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2457   chmod +w ${LIB}/$file 2>/dev/null
2458   chmod a+r ${LIB}/$file 2>/dev/null
2459 fi
2460
2461 if [ -r ${LIB}/$file ]; then
2462   echo Fixing $file, matherr declaration
2463   sed -e '/^struct exception/,$b' \
2464       -e '/matherr/i\
2465 struct exception;
2466 '\
2467     ${LIB}/$file > ${LIB}/${file}.sed
2468   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2469   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2470     rm -f ${LIB}/$file
2471   else
2472     # Find any include directives that use "file".
2473     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2474       dir=`echo $file | sed -e s'|/[^/]*$||'`
2475       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2476     done
2477   fi
2478 fi
2479
2480 # sys/mman.h on HP/UX is not C++ ready, even though
2481 # NO_IMPLICIT_EXTERN_C is defined on HP/UX.
2482 for file in sys/mman.h; do
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     if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
2491        || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
2492       true
2493     else
2494       echo Fixing $file
2495       echo '#ifdef __cplusplus
2496 extern "C" {
2497 #endif' > ${LIB}/${file}.sed
2498       cat ${LIB}/${file} >> ${LIB}/${file}.sed
2499       echo '#ifdef __cplusplus
2500 }
2501 #endif' >> ${LIB}/${file}.sed 
2502       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2503     fi
2504     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2505       rm -f ${LIB}/$file
2506     else
2507       # Find any include directives that use "file".
2508       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2509         dir=`echo $file | sed -e s'|/[^/]*$||'`
2510         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2511       done
2512     fi
2513   fi
2514 done
2515
2516 # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
2517 file=unistd.h
2518 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2519   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2520   chmod +w ${LIB}/$file 2>/dev/null
2521   chmod a+r ${LIB}/$file 2>/dev/null
2522 fi
2523
2524 if [ -r ${LIB}/$file ]; then
2525   echo Fixing $file, sbrk declaration
2526   sed -e 's/char\([     ]*\*[    ]*sbrk[        ]*(\)/void\1/' \
2527     ${LIB}/$file > ${LIB}/${file}.sed
2528   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2529   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2530     rm -f ${LIB}/$file
2531   else
2532     # Find any include directives that use "file".
2533     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2534       dir=`echo $file | sed -e s'|/[^/]*$||'`
2535       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2536     done
2537   fi
2538 fi
2539
2540 # This file on SunOS 4 has a very large macro.  When the sed loop
2541 # tries pull it in, it overflows the pattern space size of the SunOS
2542 # sed (GNU sed does not have this problem).  Since the file does not
2543 # require fixing, we remove it from the fixed directory.
2544 file=sundev/ipi_error.h
2545 if [ -r ${LIB}/$file ]; then
2546   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
2547   rm -f ${LIB}/$file
2548 fi
2549
2550 # Put cpp wrappers around these include files to avoid redeclaration
2551 # errors during multiple inclusion on m88k-tektronix-sysv3.
2552 for file in time.h sys/time.h ; do
2553   if egrep '#ifndef' $file >/dev/null 2>&1; then
2554     true
2555   else
2556     if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2557       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2558       chmod +w ${LIB}/$file 2>/dev/null
2559     fi
2560     if [ -r ${LIB}/$file ]; then
2561       echo Fixing $file, to protect against multiple inclusion.
2562       cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
2563       (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
2564       echo "#define __GCC_GOT_${cpp_wrapper}_"
2565       cat ${LIB}/${file}
2566       echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
2567       rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
2568     fi
2569   fi
2570 done
2571
2572 # Fix fcntl prototype in fcntl.h on LynxOS.
2573 file=fcntl.h
2574 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2575   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2576   chmod +w ${LIB}/$file 2>/dev/null
2577   chmod a+r ${LIB}/$file 2>/dev/null
2578 fi
2579
2580 if [ -r ${LIB}/$file ]; then
2581   echo Fixing $file, fcntl declaration
2582   sed -e 's/\(fcntl.*(int, int, \)int)/\1...)/' \
2583     ${LIB}/$file > ${LIB}/${file}.sed
2584   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2585   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2586     rm -f ${LIB}/$file
2587   else
2588     # Find any include directives that use "file".
2589     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2590       dir=`echo $file | sed -e s'|/[^/]*$||'`
2591       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2592     done
2593   fi
2594 fi
2595
2596 # Fix definitions of macros used by va-i960.h in VxWorks header file.
2597 file=arch/i960/archI960.h
2598 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2599   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2600   chmod +w ${LIB}/$file 2>/dev/null
2601   chmod a+r ${LIB}/$file 2>/dev/null
2602 fi
2603
2604 if [ -r ${LIB}/$file ]; then
2605   echo Fixing $file
2606   sed -e 's/__vsiz/__vxvsiz/' -e 's/__vali/__vxvali/' \
2607       -e s'/__vpad/__vxvpad/' -e 's/__alignof__/__vxalignof__/' \
2608     ${LIB}/$file > ${LIB}/${file}.sed
2609   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2610   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2611     rm -f ${LIB}/$file
2612   else
2613     # Find any include directives that use "file".
2614     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2615       dir=`echo $file | sed -e s'|/[^/]*$||'`
2616       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2617     done
2618   fi
2619 fi
2620
2621 # Make VxWorks header which is almost gcc ready fully gcc ready.
2622 file=types/vxTypesBase.h
2623 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2624   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2625   chmod +w ${LIB}/$file 2>/dev/null
2626   chmod a+r ${LIB}/$file 2>/dev/null
2627 fi
2628
2629 if [ -r ${LIB}/$file ]; then
2630   echo Fixing $file
2631   sed -e 's/#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__/#if 1/' \
2632       -e '/[    ]size_t/i\
2633 #ifndef _GCC_SIZE_T\
2634 #define _GCC_SIZE_T
2635 ' \
2636       -e '/[    ]size_t/a\
2637 #endif
2638 ' \
2639       -e '/[    ]ptrdiff_t/i\
2640 #ifndef _GCC_PTRDIFF_T\
2641 #define _GCC_PTRDIFF_T
2642 ' \
2643       -e '/[    ]ptrdiff_t/a\
2644 #endif
2645 ' \
2646       -e '/[    ]wchar_t/i\
2647 #ifndef _GCC_WCHAR_T\
2648 #define _GCC_WCHAR_T
2649 ' \
2650       -e '/[    ]wchar_t/a\
2651 #endif
2652 ' \
2653     ${LIB}/$file > ${LIB}/${file}.sed
2654   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2655   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2656     rm -f ${LIB}/$file
2657   else
2658     # Find any include directives that use "file".
2659     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2660       dir=`echo $file | sed -e s'|/[^/]*$||'`
2661       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2662     done
2663   fi
2664 fi
2665
2666 # Fix VxWorks <sys/stat.h> to not require including <vxWorks.h>.
2667 file=sys/stat.h
2668 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2669   mkdir ${LIB}/sys 2>/dev/null
2670   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2671   chmod +w ${LIB}/$file 2>/dev/null
2672   chmod a+r ${LIB}/$file 2>/dev/null
2673 fi
2674
2675 if [ -r ${LIB}/$file ]; then
2676   if egrep '#include' ${LIB}/$file >/dev/null 2>&1; then
2677     :
2678   else
2679     if egrep 'ULONG' ${LIB}/$file >/dev/null 2>&1 \
2680        && [ -r types/vxTypesOld.h ]; then
2681       echo Fixing $file
2682       sed -e '/#define[         ][      ]*__INCstath/a\
2683 #include <types/vxTypesOld.h>
2684 ' \
2685     ${LIB}/$file > ${LIB}/${file}.sed
2686       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2687     fi
2688   fi
2689   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2690     rm -f ${LIB}/$file
2691   else
2692     # Find any include directives that use "file".
2693     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2694       dir=`echo $file | sed -e s'|/[^/]*$||'`
2695       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2696     done
2697   fi
2698 fi
2699
2700 # Fix VxWorks <time.h> to not require including <vxTypes.h>.
2701 file=time.h
2702 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2703   mkdir ${LIB}/sys 2>/dev/null
2704   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2705   chmod +w ${LIB}/$file 2>/dev/null
2706   chmod a+r ${LIB}/$file 2>/dev/null
2707 fi
2708
2709 if [ -r ${LIB}/$file ]; then
2710   if egrep 'uint_t[     ][      ]*_clocks_per_sec' ${LIB}/$file >/dev/null 2>&1; then
2711     echo Fixing $file
2712     sed -e 's/uint_t/unsigned int/' ${LIB}/$file > ${LIB}/${file}.sed
2713     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2714   fi
2715   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2716     rm -f ${LIB}/$file
2717   else
2718     # Find any include directives that use "file".
2719     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2720       dir=`echo $file | sed -e s'|/[^/]*$||'`
2721       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2722     done
2723   fi
2724 fi
2725     
2726 # Fix hpux10.20 <sys/time.h> to avoid invalid forward decl
2727 file=sys/time.h
2728 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2729   mkdir ${LIB}/sys 2>/dev/null
2730   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2731   chmod +w ${LIB}/$file 2>/dev/null
2732   chmod a+r ${LIB}/$file 2>/dev/null
2733 fi
2734
2735 if [ -r ${LIB}/$file ]; then
2736   if egrep '^extern struct sigevent;' ${LIB}/$file >/dev/null 2>&1; then
2737     echo Fixing $file
2738     sed -e 's/^extern struct sigevent;/struct sigevent;/' ${LIB}/$file > ${LIB}/${file}.sed
2739     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2740   fi
2741   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2742     rm -f ${LIB}/$file
2743   else
2744     # Find any include directives that use "file".
2745     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2746       dir=`echo $file | sed -e s'|/[^/]*$||'`
2747       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2748     done
2749   fi
2750 fi
2751     
2752 # Another bad dependency in VxWorks 5.2 <time.h>.
2753 file=time.h
2754 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2755   mkdir ${LIB}/sys 2>/dev/null
2756   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2757   chmod +w ${LIB}/$file 2>/dev/null
2758   chmod a+r ${LIB}/$file 2>/dev/null
2759 fi
2760
2761 if [ -r ${LIB}/$file ]; then
2762   if egrep VOIDFUNCPTR ${LIB}/$file >/dev/null 2>&1; then
2763     if [ -r vxWorks.h ]; then
2764       echo Fixing $file
2765       sed -e '/VOIDFUNCPTR/i\
2766 #ifndef __gcc_VOIDFUNCPTR_defined\
2767 #ifdef __cplusplus\
2768 typedef void (*__gcc_VOIDFUNCPTR) (...);\
2769 #else\
2770 typedef void (*__gcc_VOIDFUNCPTR) ();\
2771 #endif\
2772 #define __gcc_VOIDFUNCPTR_defined\
2773 #endif
2774 ' \
2775           -e 's/VOIDFUNCPTR/__gcc_VOIDFUNCPTR/g' \
2776         ${LIB}/$file > ${LIB}/${file}.sed
2777       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2778     fi
2779   fi
2780   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2781     rm -f ${LIB}/$file
2782   else
2783     # Find any include directives that use "file".
2784     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2785       dir=`echo $file | sed -e s'|/[^/]*$||'`
2786       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2787     done
2788   fi
2789 fi
2790     
2791 # This file in A/UX 3.0.x/3.1.x contains an __asm directive for c89; gcc
2792 # doesn't understand it.
2793 file=sys/param.h
2794 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2795   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2796   chmod +w ${LIB}/$file 2>/dev/null
2797   chmod a+r ${LIB}/$file 2>/dev/null
2798 fi
2799
2800 if [ -r ${LIB}/$file ]; then
2801   echo "Fixing __asm directive in sys/param.h"
2802   sed -e 's|#ifndef NOINLINE|#if !defined(NOINLINE) \&\& !defined(__GNUC__)|' \
2803     ${LIB}/$file > ${LIB}/${file}.sed
2804   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2805   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2806     rm -f ${LIB}/$file
2807   else
2808     # Find any include directives that use "file".
2809     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2810       dir=`echo $file | sed -e s'|/[^/]*$||'`
2811       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2812     done
2813   fi
2814 fi
2815
2816 # signal.h on SunOS defines signal using (), which causes trouble when
2817 # compiling with g++ -pedantic.
2818 for file in signal.h sys/signal.h; do
2819   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2820     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2821     chmod +w ${LIB}/$file 2>/dev/null
2822     chmod a+r ${LIB}/$file 2>/dev/null
2823   fi
2824
2825   if [ -r ${LIB}/$file ]; then
2826     echo "Checking for bad C++ prototype in $file"
2827     sed -e '/^void      (\*signal())();$/i\
2828   #ifdef __cplusplus\
2829   void  (*signal(...))(...);\
2830   #else
2831   ' \
2832         -e '/^void      (\*signal())();$/a\
2833   #endif
2834   ' \
2835       ${LIB}/$file > ${LIB}/${file}.sed
2836     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2837     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2838       rm -f ${LIB}/$file
2839     else
2840       # Find any include directives that use "file".
2841       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2842         dir=`echo $file | sed -e s'|/[^/]*$||'`
2843         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2844       done
2845     fi
2846   fi
2847 done
2848
2849 # sys/signal.h on some versions of AIX uses volatile in the typedef of
2850 # sig_atomic_t, which causes gcc to generate a warning about duplicate
2851 # volatile when a sig_atomic_t variable is declared volatile, as
2852 # required by ANSI C.
2853 file=sys/signal.h
2854 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2855   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2856   chmod +w ${LIB}/$file 2>/dev/null
2857   chmod a+r ${LIB}/$file 2>/dev/null
2858 fi
2859
2860 if [ -r ${LIB}/$file ]; then
2861   echo "Checking for duplicate volatile in sys/signal.h"
2862   sed -e 's/typedef volatile int sig_atomic_t/typedef int sig_atomic_t/' \
2863     ${LIB}/$file > ${LIB}/${file}.sed
2864   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2865   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2866     rm -f ${LIB}/$file
2867   else
2868     # Find any include directives that use "file".
2869     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2870       dir=`echo $file | sed -e s'|/[^/]*$||'`
2871       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2872     done
2873   fi
2874 fi
2875
2876 # Some math.h files define struct exception, which conflicts with
2877 # the class exception defined in the C++ file std/stdexcept.h.  We
2878 # redefine it to __math_exception.  This is not a great fix, but I
2879 # haven't been able to think of anything better.
2880 file=math.h
2881 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2882   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2883   chmod +w ${LIB}/$file 2>/dev/null
2884   chmod a+r ${LIB}/$file 2>/dev/null
2885 fi
2886
2887 if [ -r ${LIB}/$file ]; then
2888   echo Fixing $file, exception
2889   sed -e '/struct exception/i\
2890 #ifdef __cplusplus\
2891 #define exception __math_exception\
2892 #endif
2893 '\
2894       -e '/struct exception/a\
2895 #ifdef __cplusplus\
2896 #undef exception\
2897 #endif
2898 ' ${LIB}/$file > ${LIB}/${file}.sed
2899   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2900   if egrep 'matherr()' ${LIB}/$file >/dev/null 2>&1; then
2901     sed -e '/matherr/i\
2902 #ifdef __cplusplus\
2903 #define exception __math_exception\
2904 #endif
2905 '\
2906         -e '/matherr/a\
2907 #ifdef __cplusplus\
2908 #undef exception\
2909 #endif
2910 ' ${LIB}/$file > ${LIB}/${file}.sed
2911     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2912   fi
2913   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2914     rm -f ${LIB}/$file
2915   else
2916     # Find any include directives that use "file".
2917     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2918       dir=`echo $file | sed -e s'|/[^/]*$||'`
2919       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2920     done
2921   fi
2922 fi
2923
2924 # rpc/auth.h on SunOS needs prototypes for its AUTH->auth_ops function pointers
2925 # Similarly for 
2926 #   rpc/clnt.h CLIENT->clnt_ops
2927 #   rpc/svc.h SVCXPRT->xp_ops
2928 #   rpc/xdr.h XDR->xdr_ops
2929 for file in rpc/auth.h rpc/clnt.h rpc/svc.h rpc/xdr.h; do
2930   # each file has a different name to replace, so if you add a file to
2931   # that list please update the following case statement.
2932   case "$file" in
2933     rpc/auth.h)
2934       prefix="ah_"
2935       ;;
2936     rpc/clnt.h)
2937       prefix="cl_"
2938       ;;
2939     rpc/svc.h)
2940       prefix="xp_"
2941       ;;
2942     rpc/xdr.h)
2943       prefix="x_"
2944       ;;
2945     *)
2946       # Oh Oh, we shouldn't be here
2947       exit 1;
2948       ;;
2949   esac
2950
2951   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2952     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2953     chmod +w ${LIB}/$file 2>/dev/null
2954     chmod a+r ${LIB}/$file 2>/dev/null
2955   fi
2956
2957   if [ -r ${LIB}/$file ]; then
2958     echo "Checking for needed C++ prototype in $file"
2959     sed -e 's/^\(.*\)\*\('$prefix'.*\)();\(.*\)/\
2960 #ifdef __cplusplus\
2961 \1*\2(...);\3\
2962 #else\
2963 \1*\2();\3\
2964 #endif/g' \
2965      $LIB/$file > ${LIB}/${file}.sed
2966
2967     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
2968     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
2969       rm -f ${LIB}/$file
2970     else
2971       # Find any include directives that use "file".
2972       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
2973         dir=`echo $file | sed -e s'|/[^/]*$||'`
2974         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
2975       done
2976     fi
2977   fi
2978 done
2979
2980 # sys/lc_core.h on some versions of OSF1/4.x pollutes the namespace by
2981 # defining regex.h types.  This causes C++ library build and usage failures.
2982 # Fixing this correctly requires checking and modifying 3 files.
2983 for file in reg_types.h regex.h sys/lc_core.h; do
2984   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
2985     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
2986     chmod +w ${LIB}/$file 2>/dev/null
2987     chmod a+r ${LIB}/$file 2>/dev/null
2988   fi
2989 done
2990 if [ -r ${LIB}/reg_types.h ]; then
2991   if egrep '} regex_t;' ${LIB}/reg_types.h >/dev/null 2>&1; then
2992     if [ -r ${LIB}/sys/lc_core.h ]; then
2993       if egrep ' regex_t ' ${LIB}/sys/lc_core.h >/dev/null 2>&1; then
2994         if [ -r ${LIB}/regex.h ]; then
2995           if egrep '__regex_t' ${LIB}/regex.h >/dev/null 2>&1; then
2996             true;
2997           else
2998             echo Fixing reg_types.h, regex.h, sys/lc_core.h
2999             for file in reg_types.h sys/lc_core.h; do
3000               sed -e 's/regex_t/__regex_t/g' \
3001                 -e 's/regoff_t/__regoff_t/g' \
3002                 -e 's/regmatch_t/__regmatch_t/g' \
3003                 ${LIB}/$file > ${LIB}/${file}.sed
3004               rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
3005             done
3006             sed -e '/#include <reg_types.h>/a\
3007 typedef __regex_t       regex_t;\
3008 typedef __regoff_t      regoff_t;\
3009 typedef __regmatch_t    regmatch_t;\
3010 ' \
3011               ${LIB}/regex.h > ${LIB}/regex.h.sed
3012             rm -f ${LIB}/regex.h; mv ${LIB}/regex.h.sed ${LIB}/regex.h
3013           fi
3014         fi
3015       fi
3016     fi
3017   fi
3018 fi
3019 for file in reg_types.h regex.h sys/lc_core.h; do
3020   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
3021     rm -f ${LIB}/$file
3022   else
3023     # Find any include directives that use "file".
3024     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
3025       dir=`echo $file | sed -e s'|/[^/]*$||'`
3026       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
3027     done
3028   fi
3029 done
3030
3031 # AIX headers define NULL to be cast to a void pointer, which is illegal
3032 # in ANSI C++.
3033 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
3034   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
3035     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
3036     chmod +w ${LIB}/$file 2>/dev/null
3037     chmod a+r ${LIB}/$file 2>/dev/null
3038   fi
3039
3040   if [ -r ${LIB}/$file ]; then
3041     if egrep '#.*define.*NULL.*void' ${LIB}/$file >/dev/null 2>&1; then
3042       echo "Fixing $file, bad NULL macro"
3043       sed -e 's/^#[     ]*define[       ]*NULL[         ]*((void[       ]*\*)0)/#define NULL 0/' \
3044         ${LIB}/$file > ${LIB}/${file}.sed
3045       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
3046       if cmp $file ${LIB}/$file >/dev/null 2>&1; then
3047         rm -f ${LIB}/$file
3048       else
3049         # Find any include directives that use "file".
3050         for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
3051           dir=`echo $file | sed -e s'|/[^/]*$||'`
3052           required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
3053         done
3054       fi
3055     fi
3056   fi
3057 done
3058
3059 # HPUX 10.x sys/param.h defines MAXINT which clashes with values.h
3060 file=sys/param.h
3061 base=`basename $file`
3062 if [ -r ${LIB}/$file ]; then
3063   file_to_fix=${LIB}/$file
3064 else
3065   if [ -r ${INPUT}/$file ]; then
3066     file_to_fix=${INPUT}/$file
3067   else
3068     file_to_fix=""
3069   fi
3070 fi
3071 if [ \! -z "$file_to_fix" ]; then
3072   echo Checking $file_to_fix
3073   sed -e '/^#[  ]*define[       ]*MAXINT[       ]/i\
3074 #ifndef MAXINT
3075 '\
3076       -e '/^#[  ]*define[       ]*MAXINT[       ]/a\
3077 #endif
3078 ' $file_to_fix > /tmp/$base
3079   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
3080     true
3081   else
3082     echo Fixed $file_to_fix
3083     rm -f ${LIB}/$file
3084     cp /tmp/$base ${LIB}/$file
3085     chmod a+r ${LIB}/$file
3086     # Find any include directives that use "file".
3087     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[  ]*"\([^"]*\)".*$/\1/'`; do
3088       dir=`echo $file | sed -e s'|/[^/]*$||'`
3089       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
3090     done
3091   fi
3092   rm -f /tmp/$base
3093 fi
3094
3095
3096 # This loop does not appear to do anything, because it uses file
3097 # rather than $file when setting target.  It also appears to be
3098 # unnecessary, since the main loop processes symbolic links.
3099 #if $LINKS; then
3100 #  echo 'Making internal symbolic non-directory links'
3101 #  cd ${INPUT}
3102 #  files=`find . -type l -print`
3103 #  for file in $files; do
3104 #    dest=`ls -ld $file | sed -n 's/.*-> //p'`
3105 #    if expr "$dest" : '[^/].*' > /dev/null; then    
3106 #      target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
3107 #      if [ -f $target ]; then
3108 #        ln -s $dest ${LIB}/$file >/dev/null 2>&1
3109 #      fi
3110 #    fi
3111 #  done
3112 #fi
3113
3114 # Make sure that any include files referenced using double quotes
3115 # exist in the fixed directory.  This comes last since otherwise
3116 # we might end up deleting some of these files "because they don't
3117 # need any change."
3118 set x $required
3119 shift
3120 while [ $# != 0 ]; do
3121   newreq=
3122   while [ $# != 0 ]; do
3123     # $1 is the directory to copy from, $2 is the unfixed file,
3124     # $3 is the fixed file name.
3125     cd ${INPUT}
3126     cd $1
3127     if [ -r $2 ] && [ ! -r $3 ]; then
3128       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
3129       chmod +w $3 2>/dev/null
3130       chmod a+r $3 2>/dev/null
3131       echo Copied $2
3132       for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' $3 | sed -e 's/^[      ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
3133         dir=`echo $2 | sed -e s'|/[^/]*$||'`
3134         dir2=`echo $3 | sed -e s'|/[^/]*$||'`
3135         newreq="$newreq $1 $dir/$include $dir2/$include"
3136       done
3137     fi
3138     shift; shift; shift
3139   done
3140   set x $newreq
3141   shift
3142 done
3143
3144 echo 'Cleaning up DONE files.'
3145 cd $LIB
3146 find . -name DONE -exec rm -f '{}' ';'
3147
3148 echo 'Removing unneeded directories:'
3149 cd $LIB
3150 files=`find . -type d -print | sort -r`
3151 for file in $files; do
3152   rmdir $LIB/$file > /dev/null 2>&1
3153 done
3154
3155
3156 exit 0