OSDN Git Service

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