OSDN Git Service

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