OSDN Git Service

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