OSDN Git Service

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