OSDN Git Service

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