OSDN Git Service

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