OSDN Git Service

Various changes to avoid clobbering glibc header files
[pf3gnuchains/gcc-fork.git] / gcc / fixincludes
1 #! /bin/sh
2 # Install modified versions of certain ANSI-incompatible system header files
3 # which are fixed to work correctly with ANSI C
4 # and placed in a directory that GNU C will search.
5
6 # See README-fixinc for more information.
7
8 # Directory containing the original header files.
9 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
10 INPUT=${2-${INPUT-/usr/include}}
11
12 # Directory in which to store the results.
13 LIB=${1?"fixincludes: output directory not specified"}
14
15 # Define PWDCMD as a command to use to get the working dir
16 # in the form that we want.
17 PWDCMD=pwd
18 case "`pwd`" in
19 //*)
20         # On an Apollo, discard everything before `/usr'.
21         PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
22         ;;
23 esac
24
25 # Original directory.
26 ORIGDIR=`${PWDCMD}`
27
28 # Make sure it exists.
29 if [ ! -d $LIB ]; then
30   mkdir $LIB || exit 1
31 fi
32
33 # Make LIB absolute only if needed to avoid problems with the amd.
34 case $LIB in
35 /*)
36         ;;
37 *)
38         cd $LIB; LIB=`${PWDCMD}`
39         ;;
40 esac
41
42 # Fail if no arg to specify a directory for the output.
43 if [ x$1 = x ]
44 then echo fixincludes: no output directory specified
45 exit 1
46 fi
47
48 echo Building fixed headers in ${LIB}
49
50 # Determine whether this system has symbolic links.
51 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
52   rm -f $LIB/ShouldNotExist
53   LINKS=true
54 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
55   rm -f /tmp/ShouldNotExist
56   LINKS=true
57 else
58   LINKS=false
59 fi
60
61 echo Finding directories and links to directories
62 cd ${INPUT}
63 # Find all directories and all symlinks that point to directories.
64 # Put the list in $files.
65 # Each time we find a symlink, add it to newdirs
66 # so that we do another find within the dir the link points to.
67 # Note that $files may have duplicates in it;
68 # later parts of this file are supposed to ignore them.
69 dirs="."
70 levels=2
71 while [ -n "$dirs" ] && [ $levels -gt 0 ]
72 do
73     levels=`expr $levels - 1`
74     newdirs=
75     for d in $dirs
76     do
77         echo " Searching $INPUT/$d"
78         if [ "$d" != . ]
79         then
80             d=$d/.
81         fi
82
83         # Find all directories under $d, relative to $d, excluding $d itself.
84         files="$files `find $d -type d -print | \
85                        sed -e '/\/\.$/d' -e '/^\.$/d'`"
86         # Find all links to directories.
87         # Using `-exec test -d' in find fails on some systems,
88         # and trying to run test via sh fails on others,
89         # so this is the simplest alternative left.
90         # First find all the links, then test each one.
91         theselinks=
92         $LINKS && \
93           theselinks=`find $d -type l -print`
94         for d1 in $theselinks --dummy--
95         do
96             # If the link points to a directory,
97             # add that dir to $newdirs
98             if [ -d $d1 ]
99             then
100                 files="$files $d1"
101                 if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
102                 then
103                     newdirs="$newdirs $d1"
104                 fi
105             fi
106         done
107     done
108
109     dirs="$newdirs"
110 done
111
112 dirs=
113 echo "All directories (including links to directories):"
114 echo $files
115
116 for file in $files; do
117   rm -rf $LIB/$file
118   if [ ! -d $LIB/$file ]
119   then mkdir $LIB/$file
120   fi
121 done
122 mkdir $LIB/root
123
124 # treetops gets an alternating list
125 # of old directories to copy
126 # and the new directories to copy to.
127 treetops="${INPUT} ${LIB}"
128
129 if $LINKS; then
130   echo 'Making symbolic directory links'
131   for file in $files; do
132     dest=`ls -ld $file | sed -n 's/.*-> //p'`
133     if [ "$dest" ]; then    
134       cwd=`${PWDCMD}`
135       # In case $dest is relative, get to $file's dir first.
136       cd ${INPUT}
137       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
138       # Check that the target directory exists.
139       # Redirections changed to avoid bug in sh on Ultrix.
140       (cd $dest) > /dev/null 2>&1
141       if [ $? = 0 ]; then
142         cd $dest
143         # X gets the dir that the link actually leads to.
144         x=`${PWDCMD}`
145         # If a link points to ., make a similar link to .
146         if [ $x = $INPUT ]; 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 : "${INPUT}/.*" > /dev/null; then
153           # Y gets the actual target dir name, relative to ${INPUT}.
154           y=`echo $x | sed -n "s&${INPUT}/&&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           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
199           dots=`echo "$file" |
200             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
201           rm -fr ${LIB}/$file > /dev/null 2>&1
202           ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
203           treetops="$treetops $x ${LIB}/root$x"
204         fi
205       fi
206       cd $cwd
207     fi
208   done
209 fi
210
211 required=
212 set x $treetops
213 shift
214 while [ $# != 0 ]; do
215   # $1 is an old directory to copy, and $2 is the new directory to copy to.
216   cd ${INPUT}
217   cd $1
218 # The same dir can appear more than once in treetops.
219 # There's no need to scan it more than once.
220   if [ -f $2/DONE ]
221   then
222     files=
223   else
224     touch $2/DONE
225     echo Fixing directory $1 into $2
226 # Check .h files which are symlinks as well as those which are files.
227 # A link to a header file will not be processed by anything but this.
228     if $LINKS; then
229       files=`find . -name '*.h' \( -type f -o -type l \) -print`
230     else
231       files=`find . -name '*.h' -type f -print`
232     fi
233     echo Checking header files
234   fi
235 # Note that BSD43_* are used on recent MIPS systems.
236   for file in $files; do
237 # This call to egrep is essential, since checking a file with egrep
238 # is much faster than actually trying to fix it.
239 # It is also essential that most files *not* match!
240 # Thus, matching every #endif is unacceptable.
241 # But the argument to egrep must be kept small, or many versions of egrep
242 # won't be able to handle it.
243 #
244 # We use the pattern [!-.0-~] instead of [^/    ] to match a noncomment
245 # following #else or #endif because some buggy egreps think [^/] matches
246 # newline, and they thus think `#else ' matches `#e[ndiflse]*[  ]+[^/   ]'.
247 #
248 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
249 # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
250 # in this pattern lacks `d' and `l'; this means we don't worry about
251 # identifiers starting with `d' or `l'.  This is OK, since none of the
252 # identifiers below start with `d' or `l'.  It also greatly improves
253 # performance, since many files contain lines of the form `#if ... defined ...'
254 # or `#if lint'.
255     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
256       if [ -r $file ]; then
257         cp $file $2/$file >/dev/null 2>&1       \
258         || echo "Can't copy $file"
259         chmod +w $2/$file
260         chmod a+r $2/$file
261         # Here is how the sed commands in braces work.
262         # (It doesn't work to put the comments inside the sed commands.)
263                 # Surround each word with spaces, to simplify matching below.
264                 # ANSIfy each pre-ANSI machine-dependent symbol
265                 # by surrounding it with __ __.
266                 # Remove the spaces that we inserted around each word.
267         sed -e '
268                                    :loop
269           /\\$/                 N
270           /\\$/                 b loop
271           s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
272           s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
273           s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
274           s%^\([        ]*#[    ]*endif\)[      ]*\*[^/].*%\1%
275           s%^\([        ]*#[    ]*endif\)[      ]*[^/*  ].*%\1%
276           /\/\/[^*]/                    s|//\(.*\)$|/*\1*/|
277           /[    ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[  ]*(\)\(.\),/\1'\''\2'\'',/
278           /[    ]BSD43__IO[A-Z]*[       ]*(/    s/(\(.\),/('\''\1'\'',/
279           /#define._IO/                 s/'\''\([cgxtf]\)'\''/\1/g
280           /#define.BSD43__IO/           s/'\''\([cgx]\)'\''/\1/g
281           /[^A-Z0-9_]CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
282           /[^A-Z0-9]_CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
283           /#define[     ]*[     ]CTRL/          s/'\''\([cgx]\)'\''/\1/g
284           /#define[     ]*[     ]_CTRL/         s/'\''\([cgx]\)'\''/\1/g
285           /#define.BSD43_CTRL/          s/'\''\([cgx]\)'\''/\1/g
286           /#[el]*if/{
287                 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
288
289                 s/ bsd4\([0-9]\) / __bsd4\1__ /g
290                 s/ _*host_mips / __host_mips__ /g
291                 s/ _*i386 / __i386__ /g
292                 s/ M32 / __M32__ /g
293                 s/ is68k / __is68k__ /g
294                 s/ m68k / __m68k__ /g
295                 s/ mc680\([0-9]\)0 / __mc680\10__ /g
296                 s/ m88k / __m88k__ /g
297                 s/ _*mips / __mips__ /g
298                 s/ news\([0-9]*\) / __news\1__ /g
299                 s/ ns32000 / __ns32000__ /g
300                 s/ pdp11 / __pdp11__ /g
301                 s/ pyr / __pyr__ /g
302                 s/ sony_news / __sony_news__ /g
303                 s/ sparc / __sparc__ /g
304                 s/ sun\([a-z0-9]*\) / __sun\1__ /g
305                 s/ tower\([_0-9]*\) / __tower\1__ /g
306                 s/ u370 / __u370__ /g
307                 s/ u3b\([0-9]*\) / __u3b\1__ /g
308                 s/ unix / __unix__ /g
309                 s/ vax / __vax__ /g
310                 s/ _*MIPSE\([LB]\) / __MIPSE\1__ /g
311                 s/ _*R\([34]\)000 / __R\1000__ /g
312                 s/ _*SYSTYPE_\([A-Z0-9]*\) / __SYSTYPE_\1__ /g
313
314                 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
315           }
316           /^#define.NULL[       ]/      i\
317                 #undef NULL
318         ' $2/$file > $2/$file.
319         mv $2/$file. $2/$file
320         if cmp $file $2/$file >/dev/null 2>&1 \
321             || egrep 'This file is part of the GNU C Library' $2/$file >/dev/null 2>&1; then
322            rm $2/$file
323         else
324            echo Fixed $file
325            # Find any include directives that use "file".
326            for include in `egrep '^[    ]*#[    ]*include[      ]*"[^/]' $2/$file | sed -e 's/^[        ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
327               dir=`echo $file | sed -e s'|/[^/]*$||'`
328               required="$required $1 $dir/$include $2/$dir/$include"
329            done
330         fi
331       fi
332     fi
333   done
334   shift; shift
335 done
336
337 cd ${INPUT}
338
339 # Install the proper definition of the three standard types in header files
340 # that they come from.
341 for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
342   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
343     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
344     chmod +w ${LIB}/$file 2>/dev/null
345     chmod a+r ${LIB}/$file 2>/dev/null
346   fi
347
348   if [ -r ${LIB}/$file ]; then
349     echo Fixing size_t, ptrdiff_t and wchar_t in $file
350     sed \
351       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]size_t/i\
352 #ifndef __SIZE_TYPE__\
353 #define __SIZE_TYPE__ long unsigned int\
354 #endif
355 ' \
356       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]size_t/typedef __SIZE_TYPE__ size_t/' \
357       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/i\
358 #ifndef __PTRDIFF_TYPE__\
359 #define __PTRDIFF_TYPE__ long int\
360 #endif
361 ' \
362       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
363       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]wchar_t/i\
364 #ifndef __WCHAR_TYPE__\
365 #define __WCHAR_TYPE__ int\
366 #endif
367 ' \
368       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
369       ${LIB}/$file > ${LIB}/${file}.sed
370     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
371     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
372       rm ${LIB}/$file
373     fi
374   fi
375 done
376
377 # Fix one other error in this file: a mismatched quote not inside a C comment.
378 file=sundev/vuid_event.h
379 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
380   mkdir ${LIB}/sundev 2>/dev/null
381   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
382   chmod +w ${LIB}/$file 2>/dev/null
383   chmod a+r ${LIB}/$file 2>/dev/null
384 fi
385
386 if [ -r ${LIB}/$file ]; then
387   echo Fixing $file comment
388   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
389   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
390   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
391     rm ${LIB}/$file
392   fi
393 fi
394
395 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
396 file=sunwindow/win_cursor.h
397 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
398 #  mkdir ${LIB}/sunwindow 2>/dev/null
399   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
400   chmod +w ${LIB}/$file 2>/dev/null
401 fi
402 if [ -r ${LIB}/$file ]; then
403   echo Fixing $file
404   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
405   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
406   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
407     rm ${LIB}/$file
408   fi
409 fi
410 file=sunwindow/win_lock.h
411 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
412 #  mkdir ${LIB}/sunwindow 2>/dev/null
413   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
414   chmod +w ${LIB}/$file 2>/dev/null
415 fi
416 if [ -r ${LIB}/$file ]; then
417   echo Fixing $file
418   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
419   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
420   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
421     rm ${LIB}/$file
422   fi
423 fi
424
425 # Fix this Sun file to avoid interfering with stddef.h.
426 file=sys/stdtypes.h
427 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
428   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
429   chmod +w ${LIB}/$file 2>/dev/null
430   chmod a+r ${LIB}/$file 2>/dev/null
431 fi
432
433 if [ -r ${LIB}/$file ]; then
434   echo Fixing $file
435 sed -e '/[       ]size_t.*;/i\
436 #ifndef _GCC_SIZE_T\
437 #define _GCC_SIZE_T
438 ' \
439     -e '/[       ]size_t.*;/a\
440 #endif
441 ' \
442     -e '/[       ]ptrdiff_t.*;/i\
443 #ifndef _GCC_PTRDIFF_T\
444 #define _GCC_PTRDIFF_T
445 ' \
446     -e '/[       ]ptrdiff_t.*;/a\
447 #endif
448 ' \
449     -e '/[       ]wchar_t.*;/i\
450 #ifndef _GCC_WCHAR_T\
451 #define _GCC_WCHAR_T
452 ' \
453     -e '/[       ]wchar_t.*;/a\
454 #endif
455 ' ${LIB}/$file > ${LIB}/${file}.sed
456   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
457   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
458     rm ${LIB}/$file
459   fi
460 fi
461
462 # Fix this ARM/RISCiX file to avoid interfering with the use of __wchar_t
463 # in cc1plus.
464 file=stdlib.h
465 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
466   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
467   chmod +w ${LIB}/$file 2>/dev/null
468   chmod a+r ${LIB}/$file 2>/dev/null
469 fi
470
471 if [ -r ${LIB}/$file ]; then
472   echo Fixing $file
473   sed -e "s/\(#[        ]*ifndef[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
474       -e "s/\(#[        ]*define[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
475      ${LIB}/$file > ${LIB}/${file}.sed
476   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
477   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
478     rm ${LIB}/$file
479   fi
480 fi
481
482 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
483 # match ssize_t present in AIX for the ps/2, or typedefs which use (but do not
484 # set) size_t.
485 file=sys/types.h
486 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
487   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
488   chmod +w ${LIB}/$file 2>/dev/null
489   chmod a+r ${LIB}/$file 2>/dev/null
490 fi
491
492 if [ -r ${LIB}/$file ]; then
493   echo Fixing $file
494 sed -e '/typedef[       ][      ]*[A-Za-z_][    A-Za-z_]*[      ]size_t/i\
495 #ifndef _GCC_SIZE_T\
496 #define _GCC_SIZE_T
497 ' \
498     -e '/typedef[       ][      ]*[A-Za-z_][    A-Za-z_]*[      ]size_t/a\
499 #endif
500 ' ${LIB}/$file > ${LIB}/${file}.sed
501   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
502   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
503     rm ${LIB}/$file
504   fi
505 fi
506
507 # Fix HP's use of ../machine/inline.h to refer to
508 # /usr/include/machine/inline.h
509 file=sys/spinlock.h
510 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
511   cp $file ${LIB}/$file
512 fi
513 if [ -r ${LIB}/$file ] ; then
514   echo Fixing $file
515   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
516     -e 's,"../machine/psl.h",<machine/psl.h>,' \
517   ${LIB}/$file > ${LIB}/${file}.sed
518   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
519   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
520     rm ${LIB}/$file
521   fi
522 fi
523
524 # Fix an error in this file: the #if says _cplusplus, not the double
525 # underscore __cplusplus that it should be
526 file=tinfo.h
527 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
528   mkdir ${LIB}/rpcsvc 2>/dev/null
529   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
530   chmod +w ${LIB}/$file 2>/dev/null
531   chmod a+r ${LIB}/$file 2>/dev/null
532 fi
533
534 if [ -r ${LIB}/$file ]; then
535   echo Fixing $file, __cplusplus macro
536   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
537   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
538   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
539     rm ${LIB}/$file
540   fi
541 fi
542
543 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
544 # structure definition.
545 file=rpcsvc/rstat.h
546 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
547   mkdir ${LIB}/rpcsvc 2>/dev/null
548   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
549   chmod +w ${LIB}/$file 2>/dev/null
550   chmod a+r ${LIB}/$file 2>/dev/null
551 fi
552
553 if [ -r ${LIB}/$file ]; then
554   echo Fixing $file, definition of statsswtch
555   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
556   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
557   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
558     rm ${LIB}/$file
559   fi
560 fi
561
562 # Fix an error in this file: a missing semi-colon at the end of the nodeent
563 # structure definition.
564 file=netdnet/dnetdb.h
565 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
566   mkdir ${LIB}/netdnet 2>/dev/null
567   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
568   chmod +w ${LIB}/$file 2>/dev/null
569   chmod a+r ${LIB}/$file 2>/dev/null
570 fi
571
572 if [ -r ${LIB}/$file ]; then
573   echo Fixing $file, definition of nodeent
574   sed -e 's/char.*na_addr *$/char *na_addr;/' ${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   fi
579 fi
580
581 # Check for bad #ifdef line (in Ultrix 4.1)
582 file=sys/file.h
583 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
584   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
585   chmod +w ${LIB}/$file 2>/dev/null
586   chmod a+r ${LIB}/$file 2>/dev/null
587 fi
588
589 if [ -r ${LIB}/$file ]; then
590   echo Fixing $file, bad \#ifdef line
591   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
592   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
593   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
594     rm ${LIB}/$file
595   fi
596 fi
597
598 # Check for superfluous `static' (in Ultrix 4.2)
599 # On Ultrix 4.3, includes of other files (r3_cpu.h,r4_cpu.h) is broken.
600 file=machine/cpu.h
601 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
602   mkdir ${LIB}/machine 2>/dev/null
603   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
604   chmod +w ${LIB}/$file 2>/dev/null
605   chmod a+r ${LIB}/$file 2>/dev/null
606 fi
607
608 if [ -r ${LIB}/$file ]; then
609   echo Fixing $file, superfluous static and broken includes of other files.
610   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' \
611       -e 's/^#include "r3_cpu\.h"$/#include <machine\/r3_cpu\.h>/' \
612       -e 's/^#include "r4_cpu\.h"$/#include <machine\/r4_cpu\.h>/' \
613       ${LIB}/$file > ${LIB}/${file}.sed
614   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
615   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
616     rm ${LIB}/$file
617   else
618 # This file has an alternative name, mips/cpu.h.  Fix that name, too.
619     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
620       mkdir ${LIB}/mips 2>&-
621 # Don't remove the file first, they may be the same file!
622       ln ${LIB}/$file ${LIB}/mips/cpu.h > /dev/null 2>&1
623     fi
624   fi
625 fi
626
627 # Incorrect sprintf declaration in X11/Xmu.h
628 file=X11/Xmu.h
629 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
630   mkdir ${LIB}/X11 2>/dev/null
631   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
632   chmod +w ${LIB}/$file 2>/dev/null
633   chmod a+r ${LIB}/$file 2>/dev/null
634 fi
635
636 if [ -r ${LIB}/$file ]; then
637   echo Fixing $file sprintf declaration
638   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
639 extern char *   sprintf();\
640 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
641   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
642   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
643     rm ${LIB}/$file
644   fi
645 fi
646
647 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
648 # (It's not clear whether the right file name is this or X11/Xmu.h.)
649 file=X11/Xmu/Xmu.h
650 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
651   mkdir ${LIB}/X11/Xmu 2>/dev/null
652   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
653   chmod +w ${LIB}/$file 2>/dev/null
654   chmod a+r ${LIB}/$file 2>/dev/null
655 fi
656
657 if [ -r ${LIB}/$file ]; then
658   echo Fixing $file sprintf declaration
659   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
660 extern char *   sprintf();\
661 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
662   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
663   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
664     rm ${LIB}/$file
665   fi
666 fi
667
668 # Check for missing ';' in struct
669 file=netinet/ip.h
670 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
671   mkdir ${LIB}/netinet 2>/dev/null
672   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
673   chmod +w ${LIB}/$file 2>/dev/null
674   chmod a+r ${LIB}/$file 2>/dev/null
675 fi
676
677 if [ -r ${LIB}/$file ]; then
678   echo Fixing $file
679   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
680   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
681   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
682     rm -f ${LIB}/$file
683   fi
684 fi
685
686 # Fix the CAT macro in SunOS memvar.h.
687 file=pixrect/memvar.h
688 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
689   mkdir ${LIB}/pixrect 2>/dev/null
690   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
691   chmod +w ${LIB}/$file 2>/dev/null
692   chmod a+r ${LIB}/$file 2>/dev/null
693 fi
694
695 if [ -r ${LIB}/$file ]; then
696   echo Fixing $file
697   sed -e '/^#define.CAT(a,b)/ i\
698 #ifdef __STDC__ \
699 #define CAT(a,b) a##b\
700 #else
701 /^#define.CAT(a,b)/ a\
702 #endif
703 ' ${LIB}/$file > ${LIB}/${file}.sed
704   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
705   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
706     rm -f ${LIB}/$file
707   fi
708 fi
709
710 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
711 file=rpcsvc/rusers.h
712 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
713   mkdir ${LIB}/rpcsvc 2>/dev/null
714   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
715   chmod +w ${LIB}/$file 2>/dev/null
716   chmod a+r ${LIB}/$file 2>/dev/null
717 fi
718
719 if [ -r ${LIB}/$file ]; then
720   echo Fixing $file
721   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
722   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
723   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
724     rm -f ${LIB}/$file
725   fi
726 fi
727
728 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
729 # Also wrap protection around size_t for m88k-sysv3 systems.
730 file=stdlib.h
731 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
732   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
733   chmod +w ${LIB}/$file 2>/dev/null
734   chmod a+r ${LIB}/$file 2>/dev/null
735 fi
736
737 if [ -r ${LIB}/$file ]; then
738   echo Fixing $file
739   sed -e 's/int abort/void      abort/g' \
740   -e 's/int     free/void       free/g' \
741   -e 's/char \* calloc/void \*  calloc/g' \
742   -e 's/char \* malloc/void \*  malloc/g' \
743   -e 's/char \* realloc/void \* realloc/g' \
744   -e 's/int     exit/void       exit/g' \
745   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/i\
746 #ifndef _GCC_SIZE_T\
747 #define _GCC_SIZE_T
748 ' \
749   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/a\
750 #endif
751 ' \
752       ${LIB}/$file > ${LIB}/${file}.sed
753   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
754   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
755     rm -f ${LIB}/$file
756   fi
757 fi
758
759 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
760 file=malloc.h
761 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
762   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
763   chmod +w ${LIB}/$file 2>/dev/null
764   chmod a+r ${LIB}/$file 2>/dev/null
765 fi
766
767 if [ -r ${LIB}/$file ]; then
768   echo Fixing $file
769   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
770   -e 's/int[    ][      ]*free/void     free/g' \
771   ${LIB}/$file > ${LIB}/${file}.sed
772   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
773   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
774     rm -f ${LIB}/$file
775   fi
776 fi
777
778 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
779 file=hsfs/hsfs_spec.h
780 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
781   mkdir ${LIB}/hsfs 2>/dev/null
782   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
783   chmod +w ${LIB}/$file 2>/dev/null
784   chmod a+r ${LIB}/$file 2>/dev/null
785 fi
786
787 if [ -r ${LIB}/$file ]; then
788   echo Fixing $file
789   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
790     ${LIB}/$file > ${LIB}/${file}.
791   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
792   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
793     rm -f ${LIB}/$file
794   fi
795 fi
796
797 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
798 file=hsfs/hsnode.h
799 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
800   mkdir ${LIB}/hsfs 2>/dev/null
801   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
802   chmod +w ${LIB}/$file 2>/dev/null
803   chmod a+r ${LIB}/$file 2>/dev/null
804 fi
805
806 if [ -r ${LIB}/$file ]; then
807   echo Fixing $file
808   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
809     ${LIB}/$file > ${LIB}/${file}.sed
810   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
811   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
812     rm -f ${LIB}/$file
813   fi
814 fi
815
816 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
817 file=hsfs/iso_spec.h
818 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
819   mkdir ${LIB}/hsfs 2>/dev/null
820   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
821   chmod +w ${LIB}/$file 2>/dev/null
822   chmod a+r ${LIB}/$file 2>/dev/null
823 fi
824
825 if [ -r ${LIB}/$file ]; then
826   echo Fixing $file
827   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
828     ${LIB}/$file > ${LIB}/${file}.sed
829   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
830   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
831     rm -f ${LIB}/$file
832   fi
833 fi
834
835 # Incorrect #include in Sony News-OS 3.2.
836 file=machine/machparam.h
837 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
838   mkdir ${LIB}/machine 2>/dev/null
839   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
840   chmod +w ${LIB}/$file 2>/dev/null
841   chmod a+r ${LIB}/$file 2>/dev/null
842 fi
843
844 if [ -r ${LIB}/$file ]; then
845   echo Fixing $file, incorrect \#include
846   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
847     ${LIB}/$file > ${LIB}/${file}.
848   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
849   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
850     rm -f ${LIB}/$file
851   fi
852 fi
853
854 # Multiline comment after typedef on IRIX 4.0.1.
855 file=sys/types.h
856 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
857   mkdir ${LIB}/sys 2>/dev/null
858   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
859   chmod +w ${LIB}/$file 2>/dev/null
860   chmod a+r ${LIB}/$file 2>/dev/null
861 fi
862
863 if [ -r ${LIB}/$file ]; then
864   echo Fixing $file, comment in the middle of \#ifdef
865   sed -e 's@type of the result@type of the result */@' \
866     -e 's@of the sizeof@/* of the sizeof@' \
867     ${LIB}/$file > ${LIB}/${file}.sed
868   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
869   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
870     rm -f ${LIB}/$file
871   fi
872 fi
873
874 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
875 # header file, which embeds // comments inside multi-line /* */
876 # comments.  If this looks like the IRIX header file, we refix it by
877 # just throwing away the // comments.
878 file=fam.h
879 if [ -r ${LIB}/$file ]; then
880   if egrep indigo.esd ${LIB}/$file > /dev/null; then
881     echo Fixing $file, overeager sed script
882     rm ${LIB}/$file
883     sed -e 's|//.*$||g' $file > ${LIB}/$file
884     chmod +w ${LIB}/$file 2>/dev/null
885     chmod a+r ${LIB}/$file 2>/dev/null
886   fi
887 fi
888
889 # Some IRIX header files contains the string "//"
890 for file in elf_abi.h elf.h; do
891   if [ -r ${LIB}/$file ]; then
892     echo Fixing $file, overeager sed script
893     sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
894     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
895     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
896       rm -f ${LIB}/$file
897     fi
898   fi
899 done
900
901 # IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr in prototype without
902 # previous definition.
903 file=rpc/auth.h
904 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
905   mkdir ${LIB}/rpc 2>/dev/null
906   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
907   chmod +w ${LIB}/$file 2>/dev/null
908   chmod a+r ${LIB}/$file 2>/dev/null
909 fi
910
911 if [ -r ${LIB}/$file ]; then
912   echo Fixing $file, undefined type
913   sed -e '/authdes_create.*struct sockaddr/i\
914 struct sockaddr;
915 ' \
916     ${LIB}/$file > ${LIB}/$file.sed
917   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
918   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
919     rm -f ${LIB}/$file
920   fi
921 fi
922
923 # IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s in prototype without previous
924 # definition.
925 file=rpc/xdr.h
926 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
927   mkdir ${LIB}/rpc 2>/dev/null
928   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
929   chmod +w ${LIB}/$file 2>/dev/null
930   chmod a+r ${LIB}/$file 2>/dev/null
931 fi
932
933 if [ -r ${LIB}/$file ]; then
934   echo Fixing $file, undefined type
935   sed -e '/xdrstdio_create.*struct __file_s/i\
936 struct __file_s;
937 ' \
938     ${LIB}/$file > ${LIB}/$file.sed
939   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
940   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
941     rm -f ${LIB}/$file
942   fi
943 fi
944
945 # Same problem with a file from SunOS 4.1.3 : a header file containing
946 # the string "//" embedded in "/**/"
947 file=sbusdev/audiovar.h
948 if [ -r ${LIB}/$file ]; then
949   echo Fixing $file, overeager sed script
950   rm ${LIB}/$file
951   sed -e 's|//.*$||g' $file > ${LIB}/$file
952   chmod +w ${LIB}/$file 2>/dev/null
953   chmod a+r ${LIB}/$file 2>/dev/null
954 fi
955
956 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
957 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
958 # many other systems have similar text but correct versions of the file.
959 # To ensure only Sun's is fixed, we grep for a likely unique string.
960 file=memory.h
961 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
962   if [ ! -r ${LIB}/$file ]; then
963     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
964     chmod +w ${LIB}/$file 2>/dev/null
965     chmod a+r ${LIB}/$file 2>/dev/null
966   fi
967   if [ -r ${LIB}/$file ]; then
968     echo Replacing $file
969     cat > ${LIB}/$file << EOF
970 /* This file was generated by fixincludes */
971 #ifndef __memory_h__
972 #define __memory_h__
973
974 #ifdef __STDC__
975 extern void *memccpy();
976 extern void *memchr();
977 extern void *memcpy();
978 extern void *memset();
979 #else
980 extern char *memccpy();
981 extern char *memchr();
982 extern char *memcpy();
983 extern char *memset();
984 #endif /* __STDC__ */
985
986 extern int memcmp();
987
988 #endif /* __memory_h__ */
989 EOF
990   fi
991 fi
992
993 # parameters not const on DECstation Ultrix V4.0.
994 file=stdio.h
995 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
996   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
997   chmod +w ${LIB}/$file 2>/dev/null
998   chmod a+r ${LIB}/$file 2>/dev/null
999 fi
1000
1001 if [ -r ${LIB}/$file ]; then
1002   echo Fixing $file, non-const arg
1003   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
1004       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
1005       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
1006       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
1007       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
1008       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
1009       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
1010     ${LIB}/$file > ${LIB}/${file}.sed
1011   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1012   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1013     rm -f ${LIB}/$file
1014   fi
1015 fi
1016
1017 # parameters conflict with C++ new on rs/6000 
1018 for file in stdio.h unistd.h ; do
1019   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1020     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1021     chmod +w ${LIB}/$file 2>/dev/null
1022   fi
1023
1024   if [ -r ${LIB}/$file ]; then
1025     echo Fixing $file, parameter name conflicts
1026     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
1027       ${LIB}/$file > ${LIB}/${file}.sed
1028     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1029     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1030       rm -f ${LIB}/$file
1031     fi
1032   fi
1033 done
1034
1035 # function class(double x) conflicts with C++ keyword on rs/6000 
1036 file=math.h
1037 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1038   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1039   chmod +w ${LIB}/$file 2>/dev/null
1040   chmod a+r ${LIB}/$file 2>/dev/null
1041 fi
1042
1043 if [ -r ${LIB}/$file ]; then
1044   if grep 'class[(]' ${LIB}/$file >/dev/null; then
1045     echo Fixing $file
1046     sed -e '/class[(]/i\
1047 #ifndef __cplusplus
1048 ' \
1049         -e '/class[(]/a\
1050 #endif
1051 ' ${LIB}/$file > ${LIB}/${file}.sed
1052     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1053     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1054       rm ${LIB}/$file
1055     fi
1056   fi
1057 fi
1058
1059 # Wrong fchmod prototype on RS/6000.
1060 file=sys/stat.h
1061 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1062   mkdir ${LIB}/sys 2>/dev/null
1063   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1064   chmod +w ${LIB}/$file 2>/dev/null
1065   chmod a+r ${LIB}/$file 2>/dev/null
1066 fi
1067
1068 if [ -r ${LIB}/$file ]; then
1069   echo Fixing $file, fchmod prototype
1070   sed -e 's/fchmod(char \*/fchmod(int/' \
1071     ${LIB}/$file > ${LIB}/$file.sed
1072   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1073   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1074     rm -f ${LIB}/$file
1075   fi
1076 fi
1077
1078 # There are several name conflicts with C++ reserved words in X11
1079 # header files.  These are fixed in some versions, so don't do the
1080 # fixes if we find __cplusplus in the file.  These were found on the
1081 # RS/6000.
1082
1083 # class in X11/ShellP.h
1084 file=X11/ShellP.h
1085 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1086   mkdir ${LIB}/sys 2>/dev/null
1087   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1088   chmod +w ${LIB}/$file 2>/dev/null
1089   chmod a+r ${LIB}/$file 2>/dev/null
1090 fi
1091
1092 if [ -r ${LIB}/$file ]; then
1093   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1094     true;
1095   else
1096     echo Fixing $file, field class
1097     sed -e '/char [*]class;/i\
1098 #ifdef __cplusplus\
1099         char *c_class;\
1100 #else
1101 ' \
1102         -e '/char [*]class;/a\
1103 #endif
1104 ' ${LIB}/$file > ${LIB}/${file}.sed
1105     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1106   fi
1107   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1108     rm -f ${LIB}/$file
1109   fi
1110 fi
1111 # new in Xm/Traversal.h
1112 file=Xm/Traversal.h
1113 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1114   mkdir ${LIB}/sys 2>/dev/null
1115   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1116   chmod +w ${LIB}/$file 2>/dev/null
1117   chmod a+r ${LIB}/$file 2>/dev/null
1118 fi
1119
1120 if [ -r ${LIB}/$file ]; then
1121   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1122     true;
1123   else
1124     echo Fixing $file, uses of new
1125     sed -e '/Widget     old, new;/i\
1126 #ifdef __cplusplus\
1127         Widget  old, c_new;\
1128 #else
1129 ' \
1130         -e '/Widget     old, new;/a\
1131 #endif
1132 ' \
1133         -e 's/Widget new,/Widget c_new,/g' ${LIB}/$file > ${LIB}/${file}.sed
1134     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1135   fi
1136   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1137     rm -f ${LIB}/$file
1138   fi
1139 fi
1140 # class in Xm/BaseClassI.h
1141 file=Xm/BaseClassI.h
1142 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1143   mkdir ${LIB}/sys 2>/dev/null
1144   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1145   chmod +w ${LIB}/$file 2>/dev/null
1146   chmod a+r ${LIB}/$file 2>/dev/null
1147 fi
1148
1149 if [ -r ${LIB}/$file ]; then
1150   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1151     true;
1152   else
1153     echo Fixing $file, prototype parameter name
1154     sed -e 's/ class[)]/ c_class)/g' ${LIB}/$file > ${LIB}/${file}.sed
1155     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1156   fi
1157   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1158     rm -f ${LIB}/$file
1159   fi
1160 fi
1161
1162
1163 # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1164 # Note that version 3 of the NeXT system has wait.h in a different directory,
1165 # so that this code won't do anything.  But wait.h in version 3 has a
1166 # conditional, so it doesn't need this fix.  So everything is okay.
1167 file=sys/wait.h
1168 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1169   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1170   chmod +w ${LIB}/$file 2>/dev/null
1171 fi
1172
1173 if [ -r ${LIB}/$file ] \
1174   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
1175   echo Fixing $file, bad wait formal
1176   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
1177   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1178   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1179     rm -f ${LIB}/$file
1180   fi
1181 fi
1182
1183 # Don't use or define the name va_list in stdio.h.
1184 # This is for ANSI and also to interoperate properly with gcc's varargs.h.
1185 file=stdio.h
1186 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1187   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1188   chmod +w ${LIB}/$file 2>/dev/null
1189   chmod a+r ${LIB}/$file 2>/dev/null
1190 fi
1191
1192 if [ -r ${LIB}/$file ]; then
1193   echo Fixing $file, use of va_list
1194   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1195   if egrep "__need___va_list" ${LIB}/$file >/dev/null 2>&1; then
1196     touch ${LIB}/${file}.sed
1197   else
1198     (echo "#define __need___va_list"
1199      echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1200   fi
1201   # Use __gnuc_va_list in arg types in place of va_list.
1202   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1203   # trailing parentheses and semicolon save all other systems from this.
1204   # Define __va_list__ (something harmless and unused) instead of va_list.
1205   # Don't claim to have defined va_list.
1206   sed -e 's@ va_list @ __gnuc_va_list @' \
1207       -e 's@ va_list)@ __gnuc_va_list)@' \
1208       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1209       -e 's@ va_list@ __va_list__@' \
1210       -e 's@\*va_list@*__va_list__@' \
1211       -e 's@ __va_list)@ __gnuc_va_list)@' \
1212       -e 's@GNUC_VA_LIST@GNUC_Va_LIST@' \
1213       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1214       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1215       -e 's@_Va_LIST@_VA_LIST@' \
1216     ${LIB}/$file >> ${LIB}/${file}.sed
1217   
1218   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1219   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1220     rm -f ${LIB}/$file
1221   fi
1222 fi
1223
1224 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1225 file=ansi_compat.h
1226 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1227   if grep -s ULTRIX $file; then
1228     echo "/* This file intentionally left blank.  */" > $LIB/$file
1229   fi
1230 fi
1231
1232 # parameter to atof not const on DECstation Ultrix V4.0.
1233 # also get rid of bogus inline definitions in HP-UX 8.0
1234 file=math.h
1235 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1236   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1237   chmod +w ${LIB}/$file 2>/dev/null
1238   chmod a+r ${LIB}/$file 2>/dev/null
1239 fi
1240
1241 if [ -r ${LIB}/$file ]; then
1242   echo Fixing $file, non-const arg
1243   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
1244       -e 's@inline int abs(int [a-z][a-z]*) {.*}@@' \
1245       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
1246       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
1247       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
1248     ${LIB}/$file > ${LIB}/${file}.sed
1249   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1250   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1251     rm -f ${LIB}/$file
1252   fi
1253 fi
1254
1255 # Avoid nested comments on Ultrix 4.3.
1256 file=rpc/svc.h
1257 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1258   mkdir ${LIB}/rpc 2>/dev/null
1259   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1260   chmod +w ${LIB}/$file 2>/dev/null
1261   chmod a+r ${LIB}/$file 2>/dev/null
1262 fi
1263
1264 if [ -r ${LIB}/$file ]; then
1265   echo Fixing $file, nested comment
1266   sed -e 's@^\( \*      int protocol;  \)/\*@\1*/ /*@' \
1267     ${LIB}/$file > ${LIB}/$file.sed
1268   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1269   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1270     rm -f ${LIB}/$file
1271   fi
1272 fi
1273
1274 # This file in RISC/os uses /**/ to concatenate two tokens.
1275 file=bsd43/bsd43_.h
1276 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1277   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1278   chmod +w ${LIB}/$file 2>/dev/null
1279   chmod a+r ${LIB}/$file 2>/dev/null
1280 fi
1281 if [ -r ${LIB}/$file ]; then
1282   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
1283   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1284   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1285     rm -f ${LIB}/$file
1286   fi
1287 fi
1288
1289 file=rpc/rpc.h
1290 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1291   mkdir ${LIB}/rpc 2>/dev/null
1292   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1293   chmod +w ${LIB}/$file 2>/dev/null
1294   chmod a+r ${LIB}/$file 2>/dev/null
1295 fi
1296
1297 if [ -r ${LIB}/$file ]; then
1298   echo Fixing $file, nested comment
1299   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
1300     ${LIB}/$file > ${LIB}/$file.sed
1301   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1302   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1303     rm -f ${LIB}/$file
1304   fi
1305 fi
1306
1307 # In limits.h, put #ifndefs around things that are supposed to be defined
1308 # in float.h to avoid redefinition errors if float.h is included first.
1309 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1310 # multi line comments and the inserted #endif winds up inside the
1311 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1312 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1313 # are there, and we do not add them ourselves.
1314 for file in limits.h sys/limits.h; do
1315   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1316     mkdir ${LIB}/sys 2>/dev/null
1317     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1318     chmod +w ${LIB}/$file 2>/dev/null
1319     chmod a+r ${LIB}/$file 2>/dev/null
1320   fi
1321
1322   if [ -r ${LIB}/$file ]; then
1323     if egrep 'ifndef[   ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1324       true
1325     else
1326       echo Fixing $file
1327       sed -e '/[        ]FLT_MIN[       ]/i\
1328 #ifndef FLT_MIN
1329 '\
1330           -e '/[        ]FLT_MIN[       ]/a\
1331 #endif
1332 '\
1333           -e '/[        ]FLT_MAX[       ]/i\
1334 #ifndef FLT_MAX
1335 '\
1336           -e '/[        ]FLT_MAX[       ]/a\
1337 #endif
1338 '\
1339           -e '/[        ]FLT_DIG[       ]/i\
1340 #ifndef FLT_DIG
1341 '\
1342           -e '/[        ]FLT_DIG[       ]/a\
1343 #endif
1344 '\
1345           -e '/[        ]DBL_MIN[       ]/i\
1346 #ifndef DBL_MIN
1347 '\
1348           -e '/[        ]DBL_MIN[       ]/a\
1349 #endif
1350 '\
1351           -e '/[        ]DBL_MAX[       ]/i\
1352 #ifndef DBL_MAX
1353 '\
1354           -e '/[        ]DBL_MAX[       ]/a\
1355 #endif
1356 '\
1357           -e '/[        ]DBL_DIG[       ]/i\
1358 #ifndef DBL_DIG
1359 '\
1360           -e '/[        ]DBL_DIG[       ]/a\
1361 #endif
1362 '\
1363         ${LIB}/$file > ${LIB}/${file}.sed
1364       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1365     fi
1366     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1367       echo Deleting ${LIB}/$file\; no fixes were needed.
1368       rm -f ${LIB}/$file
1369     fi
1370   fi
1371 done
1372
1373 # In math.h, put #ifndefs around things that might be defined in a gcc
1374 # specific math-*.h file.
1375 file=math.h
1376 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1377   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1378   chmod +w ${LIB}/$file 2>/dev/null
1379   chmod a+r ${LIB}/$file 2>/dev/null
1380 fi
1381
1382 if [ -r ${LIB}/$file ]; then
1383   echo Fixing $file
1384   sed -e '/define[      ]HUGE_VAL[      ]/i\
1385 #ifndef HUGE_VAL
1386 '\
1387       -e '/define[      ]HUGE_VAL[      ]/a\
1388 #endif
1389 '\
1390     ${LIB}/$file > ${LIB}/${file}.sed
1391   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1392
1393   # In addition, copy the definition of DBL_MAX from float.h
1394   # if math.h requires one.  The Lynx math.h requires it.
1395   if egrep '#define[    ]*HUGE_VAL[     ]+DBL_MAX' $file >/dev/null 2>&1; then
1396     if egrep '#define[  ]+DBL_MAX[      ]+' $file >/dev/null 2>&1; then
1397       true;
1398     else
1399       dbl_max_def=`egrep 'define[       ]+DBL_MAX[      ]+.*' float.h 2>/dev/null`
1400       if [ "$dbl_max_def" != "" ]; then
1401         dbl_max_def=`echo $dbl_max_def | sed 's/.*define[       ]*DBL_MAX[      ]*//'`
1402         sed -e "/define[        ]HUGE_VAL[      ]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
1403           ${LIB}/$file > ${LIB}/${file}.sed
1404         rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1405       fi
1406     fi
1407   fi
1408
1409   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1410     echo Deleting ${LIB}/$file\; no fixes were needed.
1411     rm -f ${LIB}/$file
1412   fi
1413 fi
1414
1415 # Remove erroneous parentheses in sym.h on Alpha OSF/1.
1416 file=sym.h
1417 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
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   echo Fixing $file
1425   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
1426     ${LIB}/$file > ${LIB}/${file}.sed
1427   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1428   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1429     rm -f ${LIB}/$file
1430   fi
1431 fi
1432
1433 # Correct the return type for strlen in string.h on Lynx.
1434 # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
1435 file=string.h
1436 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1437   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1438   chmod +w ${LIB}/$file 2>/dev/null
1439   chmod a+r ${LIB}/$file 2>/dev/null
1440 fi
1441
1442 if [ -r ${LIB}/$file ]; then
1443   echo Fixing $file
1444   sed -e 's/extern[     ]*int[  ]*strlen();/extern unsigned int strlen();/' \
1445       -e 's/extern[     ]*int[  ]*ffs[  ]*(long);/extern int ffs(int);/' \
1446     ${LIB}/$file > ${LIB}/${file}.sed
1447   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1448   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1449     rm -f ${LIB}/$file
1450   fi
1451 fi
1452
1453 # Delete the '#define void int' line from curses.h on Lynx
1454 file=curses.h
1455 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1456   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1457   chmod +w ${LIB}/$file 2>/dev/null
1458   chmod a+r ${LIB}/$file 2>/dev/null
1459 fi
1460
1461 if [ -r ${LIB}/$file ]; then
1462   echo Fixing $file
1463   sed -e '/#define[     ][      ]*void[         ]int/d' \
1464      ${LIB}/$file > ${LIB}/${file}.sed
1465   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1466     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1467       rm -f ${LIB}/$file
1468   fi
1469 fi
1470
1471 # For C++, avoid any typedef or macro definition of bool, and use the
1472 # built in type instead.
1473 for files in curses.h; do
1474   if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then
1475     if [ ! -r ${LIB}/$file ]; then
1476       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1477       chmod +w ${LIB}/$file 2>/dev/null
1478       chmod a+r ${LIB}/$file 2>/dev/null
1479     fi
1480
1481     echo Fixing $file
1482     sed -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/i\
1483 #ifndef __cplusplus'\
1484         -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/a\
1485 #endif'\
1486         -e '/^typedef[  ][      ]*char[         ][      ]*bool;[        ]*$/i\
1487 #ifndef __cplusplus'\
1488         -e '/^typedef[  ][      ]*char[         ][      ]*bool;[        ]*$/a\
1489 #endif'\
1490         ${LIB}/$file > ${LIB}/${file}.sed
1491     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1492     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1493       rm -f ${LIB}/$file
1494     fi
1495   fi
1496 done
1497
1498 # Fix incorrect S_IF* definitions on m88k-sysv3.
1499 file=sys/stat.h
1500 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1501   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1502   chmod +w ${LIB}/$file 2>/dev/null
1503   chmod a+r ${LIB}/$file 2>/dev/null
1504 fi
1505
1506 if [ -r ${LIB}/$file ]; then
1507   echo Fixing $file
1508   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)/' \
1509       -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(0[0-9]*\)[  ]*)/\1 (((m)\&S_IFMT)==\2)/' \
1510     ${LIB}/$file > ${LIB}/${file}.sed
1511   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1512   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1513     rm -f ${LIB}/$file
1514   fi
1515 fi
1516
1517 # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
1518 for file in stdio.h stdlib.h; do
1519   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1520     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1521     chmod +w ${LIB}/$file 2>/dev/null
1522     chmod a+r ${LIB}/$file 2>/dev/null
1523   fi
1524
1525   if [ -r ${LIB}/$file ]; then
1526     echo Fixing $file, getopt declaration
1527     sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
1528       ${LIB}/$file > ${LIB}/${file}.sed
1529     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1530     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1531       rm -f ${LIB}/$file
1532     fi
1533   fi
1534 done
1535
1536 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1537 # need to fix some additional files.  This is the same test for ISC that
1538 # Autoconf uses.
1539 if test -d /etc/conf/kconfig.d \
1540     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1541   echo "Fixing ISC __STDC__ goof in several files..."
1542   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1543     echo $name
1544     if test -r ${LIB}/$name; then
1545       file=${LIB}/$name
1546     else
1547       file=${INPUT}/$name
1548     fi
1549     # On Interactive 2.2, certain traditional Unix definitions
1550     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1551     # defined, not just if _POSIX_SOURCE is defined.  This makes it
1552     # impossible to compile any nontrivial program except with -posix.
1553     sed \
1554 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1555             < $file > ${LIB}/$name.
1556     mv ${LIB}/$name. ${LIB}/$name
1557   done
1558   
1559   echo "Fixing ISC fmod declaration"
1560   # This one's already been fixed for other things.
1561   file=${LIB}/math.h
1562   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1563   mv $file. $file
1564   
1565   echo "Fixing nested comments in ISC <sys/limits.h>"
1566   file=sys/limits.h
1567   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1568   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1569 fi
1570
1571 # These files in Sun OS 4.x use /**/ to concatenate tokens.
1572 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
1573         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
1574         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
1575 do
1576   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1577     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1578     chmod +w ${LIB}/$file 2>/dev/null
1579     chmod a+r ${LIB}/$file 2>/dev/null
1580   fi
1581
1582   if [ -r ${LIB}/$file ]; then
1583     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1584     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1585     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1586       rm -f ${LIB}/$file
1587     fi
1588   fi
1589 done
1590
1591 # These files in ARM/RISCiX use /**/ to concatenate tokens.
1592 for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
1593         dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
1594 do
1595   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1596     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1597     chmod +w ${LIB}/$file 2>/dev/null
1598     chmod a+r ${LIB}/$file 2>/dev/null
1599   fi
1600
1601   if [ -r ${LIB}/$file ]; then
1602     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1603     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1604     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1605       rm -f ${LIB}/$file
1606     fi
1607   fi
1608 done
1609
1610 # math.h on SunOS 4 puts the declaration of matherr before the definition
1611 # of struct exception, so the prototype (added by fixproto) causes havoc.
1612 file=math.h
1613 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1614   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1615   chmod +w ${LIB}/$file 2>/dev/null
1616   chmod a+r ${LIB}/$file 2>/dev/null
1617 fi
1618
1619 if [ -r ${LIB}/$file ]; then
1620   echo Fixing $file, matherr declaration
1621   sed -e '/^struct exception/,$b' \
1622       -e '/matherr/i\
1623 struct exception;
1624 '\
1625     ${LIB}/$file > ${LIB}/${file}.sed
1626   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1627   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1628     rm -f ${LIB}/$file
1629   fi
1630 fi
1631
1632 # assert.h on HP/UX is not C++ ready, even though NO_IMPLICIT_EXTERN_C
1633 # is defined on HP/UX.
1634 file=assert.h
1635 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1636   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1637   chmod +w ${LIB}/$file 2>/dev/null
1638   chmod a+r ${LIB}/$file 2>/dev/null
1639 fi
1640
1641 if [ -r ${LIB}/$file ]; then
1642   if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
1643      || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
1644     true
1645   else
1646     echo Fixing $file
1647     echo '#ifdef __cplusplus
1648 extern "C" {
1649 #endif' > ${LIB}/${file}.sed
1650     cat ${LIB}/${file} >> ${LIB}/${file}.sed
1651     echo '#ifdef __cplusplus
1652 }
1653 #endif' >> ${LIB}/${file}.sed 
1654     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1655     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1656       rm -f ${LIB}/$file
1657     fi
1658   fi
1659 fi
1660
1661 # check for broken assert.h that needs stdio.h or stdlib.h
1662 file=assert.h
1663 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1664   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1665   chmod +w ${LIB}/$file 2>/dev/null
1666   chmod a+r ${LIB}/$file 2>/dev/null
1667 fi
1668
1669 if [ -r ${LIB}/$file ]; then
1670   if grep 'stderr' ${LIB}/$file >/dev/null 2>/dev/null; then
1671     if grep 'include.*stdio.h' ${LIB}/$file >/dev/null 2>/dev/null; then
1672       true
1673     else
1674       echo "Fixing $file (needs stdio.h)"
1675       echo '#include <stdio.h>' >>${LIB}/$file
1676     fi
1677   fi
1678   if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
1679      grep 'abort *(' ${LIB}/$file >/dev/null 2>/dev/null; then
1680     if grep 'include.*stdlib.h' ${LIB}/$file >/dev/null 2>/dev/null; then
1681       true
1682     else
1683       echo "Fixing $file (needs stdlib.h)"
1684       echo '#include <stdlib.h>' >>${LIB}/$file
1685     fi
1686   fi
1687   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1688     rm -f ${LIB}/$file
1689   fi
1690 fi
1691
1692 # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
1693 file=unistd.h
1694 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1695   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1696   chmod +w ${LIB}/$file 2>/dev/null
1697   chmod a+r ${LIB}/$file 2>/dev/null
1698 fi
1699
1700 if [ -r ${LIB}/$file ]; then
1701   echo Fixing $file, sbrk declaration
1702   sed -e 's/char\([     ]*\*[    ]*sbrk[        ]*(\)/void\1/' \
1703     ${LIB}/$file > ${LIB}/${file}.sed
1704   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1705   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1706     rm -f ${LIB}/$file
1707   fi
1708 fi
1709
1710 # This file on SunOS 4 has a very large macro.  When the sed loop
1711 # tries pull it in, it overflows the pattern space size of the SunOS
1712 # sed (GNU sed does not have this problem).  Since the file does not
1713 # require fixing, we remove it from the fixed directory.
1714 file=sundev/ipi_error.h
1715 if [ -r ${LIB}/$file ]; then
1716   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
1717   rm -f ${LIB}/$file
1718 fi
1719
1720 # Put cpp wrappers around these include files to avoid redeclaration
1721 # errors during multiple inclusion on m88k-tektronix-sysv3.
1722 for file in time.h sys/time.h ; do
1723   if egrep '#ifndef' $file >/dev/null 2>&1; then
1724     true
1725   else
1726     if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1727       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1728       chmod +w ${LIB}/$file 2>/dev/null
1729     fi
1730     if [ -r ${LIB}/$file ]; then
1731       echo Fixing $file, to protect against multiple inclusion.
1732       cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
1733       (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
1734       echo "#define __GCC_GOT_${cpp_wrapper}_"
1735       cat ${LIB}/${file}
1736       echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
1737       rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
1738     fi
1739   fi
1740 done
1741
1742 echo 'Removing unneeded directories:'
1743 cd $LIB
1744 files=`find . -type d -print | sort -r`
1745 for file in $files; do
1746   rmdir $LIB/$file > /dev/null 2>&1
1747 done
1748
1749 if $LINKS; then
1750   echo 'Making internal symbolic non-directory links'
1751   cd ${INPUT}
1752   files=`find . -type l -print`
1753   for file in $files; do
1754     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1755     if expr "$dest" : '[^/].*' > /dev/null; then    
1756       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1757       if [ -f $target ]; then
1758         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1759       fi
1760     fi
1761   done
1762 fi
1763
1764 # Make sure that any include files referenced using double quotes
1765 # exist in the fixed directory.  This comes last since otherwise
1766 # we might end up deleting some of these files "because they don't
1767 # need any change."
1768 set x $required
1769 shift
1770 while [ $# != 0 ]; do
1771   newreq=
1772   while [ $# != 0 ]; do
1773     # $1 is the directory to copy from, $2 is the unfixed file,
1774     # $3 is the fixed file name.
1775     cd ${INPUT}
1776     cd $1
1777     if [ -r $2 ] && [ ! -r $3 ]; then
1778       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
1779       chmod +w $3 2>/dev/null
1780       chmod a+r $3 2>/dev/null
1781       echo Copied $2
1782       for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' $3 | sed -e 's/^[      ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1783         dir=`echo $2 | sed -e s'|/[^/]*$||'`
1784         dir2=`echo $3 | sed -e s'|/[^/]*$||'`
1785         newreq="$newreq $1 $dir/$include $dir2/$include"
1786       done
1787     fi
1788     shift; shift; shift
1789   done
1790   set x $newreq
1791   shift
1792 done
1793
1794 echo 'Cleaning up DONE files.'
1795 cd $LIB
1796 find . -name DONE -exec rm -f '{}' ';'
1797
1798 exit 0