OSDN Git Service

If a file is referenced with double quotes from
[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 # Command to run gcc.
9 GCCCMD=${4-${GCCCMD-gcc}}
10
11 # Directory where gcc sources (and sometimes special include files) live.
12 # fixincludes doesn't use this, but fixinc.svr4 does, and I want to make
13 # sure somebody doesn't try to use arg3 for something incompatible. -- gumby
14 SRCDIR=${3-${SRCDIR-.}}
15
16 # Directory containing the original header files.
17 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
18 INPUT=${2-${INPUT-/usr/include}}
19
20 # Directory in which to store the results.
21 LIB=${1?"fixincludes: output directory not specified"}
22
23 # Define PWDCMD as a command to use to get the working dir
24 # in the form that we want.
25 PWDCMD=pwd
26 case "`pwd`" in
27 //*)
28         # On an Apollo, discard everything before `/usr'.
29         PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
30         ;;
31 esac
32
33 # Original directory.
34 ORIGDIR=`${PWDCMD}`
35
36 # Make sure it exists.
37 if [ ! -d $LIB ]; then
38   mkdir $LIB || exit 1
39 fi
40
41 # Make LIB absolute only if needed to avoid problems with the amd.
42 case $LIB in
43 /*)
44         ;;
45 *)
46         cd $LIB; LIB=`${PWDCMD}`
47         ;;
48 esac
49
50 # Make SRCDIR absolute only if needed to avoid problems with the amd.
51 cd $ORIGDIR
52 case $SRCDIR in
53 /*)
54         ;;
55 *)
56         cd $SRCDIR; SRCDIR=`${PWDCMD}`
57         ;;
58 esac
59
60 # Fail if no arg to specify a directory for the output.
61 if [ x$1 = x ]
62 then echo fixincludes: no output directory specified
63 exit 1
64 fi
65
66 echo Building fixed headers in ${LIB}
67
68 # Determine whether this system has symbolic links.
69 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
70   rm -f $LIB/ShouldNotExist
71   LINKS=true
72 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
73   rm -f /tmp/ShouldNotExist
74   LINKS=true
75 else
76   LINKS=false
77 fi
78
79 echo Finding directories and links to directories
80 cd ${INPUT}
81 # Find all directories and all symlinks that point to directories.
82 # Put the list in $files.
83 # Each time we find a symlink, add it to newdirs
84 # so that we do another find within the dir the link points to.
85 # Note that $files may have duplicates in it;
86 # later parts of this file are supposed to ignore them.
87 dirs="."
88 levels=2
89 while [ -n "$dirs" ] && [ $levels -gt 0 ]
90 do
91     levels=`expr $levels - 1`
92     newdirs=
93     for d in $dirs
94     do
95         echo " Searching $INPUT/$d"
96         if [ "$d" != . ]
97         then
98             d=$d/.
99         fi
100
101         # Find all directories under $d, relative to $d, excluding $d itself.
102         files="$files `find $d -type d -print | \
103                        sed -e '/\/\.$/d' -e '/^\.$/d'`"
104         # Find all links to directories.
105         # Using `-exec test -d' in find fails on some systems,
106         # and trying to run test via sh fails on others,
107         # so this is the simplest alternative left.
108         # First find all the links, then test each one.
109         theselinks=
110         $LINKS && \
111           theselinks=`find $d -type l -print`
112         for d1 in $theselinks --dummy--
113         do
114             # If the link points to a directory,
115             # add that dir to $newdirs
116             if [ -d $d1 ]
117             then
118                 newdirs="$newdirs $d1"
119             fi
120         done
121     done
122
123     files="$files $newdirs"
124     dirs="$newdirs"
125 done
126
127 dirs=
128 echo "All directories (including links to directories):"
129 echo $files
130
131 for file in $files; do
132   rm -rf $LIB/$file
133   if [ ! -d $LIB/$file ]
134   then mkdir $LIB/$file
135   fi
136 done
137 mkdir $LIB/root
138
139 # treetops gets an alternating list
140 # of old directories to copy
141 # and the new directories to copy to.
142 treetops="${INPUT} ${LIB}"
143
144 if $LINKS; then
145   echo 'Making symbolic directory links'
146   for file in $files; do
147     dest=`ls -ld $file | sed -n 's/.*-> //p'`
148     if [ "$dest" ]; then    
149       cwd=`${PWDCMD}`
150       # In case $dest is relative, get to $file's dir first.
151       cd ${INPUT}
152       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
153       # Check that the target directory exists.
154       # Redirections changed to avoid bug in sh on Ultrix.
155       (cd $dest) > /dev/null 2>&1
156       if [ $? = 0 ]; then
157         cd $dest
158         # X gets the dir that the link actually leads to.
159         x=`${PWDCMD}`
160         # If a link points to ., make a similar link to .
161         if [ $x = $INPUT ]; then
162           echo $file '->' . ': Making link'
163           rm -fr ${LIB}/$file > /dev/null 2>&1
164           ln -s . ${LIB}/$file > /dev/null 2>&1
165         # If link leads back into ${INPUT},
166         # make a similar link here.
167         elif expr $x : "${INPUT}/.*" > /dev/null; then
168           # Y gets the actual target dir name, relative to ${INPUT}.
169           y=`echo $x | sed -n "s&${INPUT}/&&p"`
170           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
171           dots=`echo "$file" |
172                 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
173           echo $file '->' $dots$y ': Making link'
174           rm -fr ${LIB}/$file > /dev/null 2>&1
175           ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
176         else
177           # If the link is to a dir $target outside ${INPUT},
178           # repoint the link at ${INPUT}/root$target
179           # and process $target into ${INPUT}/root$target
180           # treat this directory as if it actually contained the files.
181           echo $file '->' root$x ': Making link'
182           if [ -d $LIB/root$x ]
183           then true
184           else
185             dirname=root$x/
186             dirmade=.
187             cd $LIB
188             while [ x$dirname != x ]; do
189               component=`echo $dirname | sed -e 's|/.*$||'`
190               mkdir $component >/dev/null 2>&1
191               cd $component
192               dirmade=$dirmade/$component
193               dirname=`echo $dirname | sed -e 's|[^/]*/||'`
194             done
195           fi
196           # Duplicate directory structure created in ${LIB}/$file in new
197           # root area.
198           for file2 in $files; do
199             case $file2 in
200               $file/./*)
201                 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
202                 echo "Duplicating ${file}'s ${dupdir}"
203                 if [ -d ${dupdir} ]
204                 then true
205                 else
206                   mkdir ${dupdir}
207                 fi
208                 ;;
209               *)
210                 ;;
211             esac
212           done
213           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
214           dots=`echo "$file" |
215                 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
216           rm -fr ${LIB}/$file > /dev/null 2>&1
217           ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
218           treetops="$treetops $x ${LIB}/root$x"
219         fi
220       fi
221       cd $cwd
222     fi
223   done
224 fi
225
226 required=
227 set x $treetops
228 shift
229 while [ $# != 0 ]; do
230   # $1 is an old directory to copy, and $2 is the new directory to copy to.
231   cd ${INPUT}
232   cd $1
233 # The same dir can appear more than once in treetops.
234 # There's no need to scan it more than once.
235   if [ -f $2/DONE ]
236   then
237     files=
238   else
239     touch $2/DONE
240     echo Fixing directory $1 into $2
241 # Check .h files which are symlinks as well as those which are files.
242 # A link to a header file will not be processed by anything but this.
243     if $LINKS; then
244       files=`find . -name '*.h' \( -type f -o -type l \) -print`
245     else
246       files=`find . -name '*.h' -type f -print`
247     fi
248     echo Checking header files
249   fi
250 # Note that BSD43_* are used on recent MIPS systems.
251   for file in $files; do
252 # This call to egrep is essential, since checking a file with egrep
253 # is much faster than actually trying to fix it.
254 # It is also essential that most files *not* match!
255 # Thus, matching every #endif is unacceptable.
256 # But the argument to egrep must be kept small, or many versions of egrep
257 # won't be able to handle it.
258 #
259 # We use the pattern [!-.0-~] instead of [^/    ] to match a noncomment
260 # following #else or #endif because some buggy egreps think [^/] matches
261 # newline, and they thus think `#else ' matches `#e[ndiflse]*[  ]+[^/   ]'.
262 #
263 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
264 # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
265 # in this pattern lacks `d' and `l'; this means we don't worry about
266 # identifiers starting with `d' or `l'.  This is OK, since none of the
267 # identifiers below start with `d' or `l'.  It also greatly improves
268 # performance, since many files contain lines of the form `#if ... defined ...'
269 # or `#if lint'.
270     if egrep '//|[      _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[     ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-z][a-z0-9]' $file >/dev/null; then
271       if [ -r $file ]; then
272         cp $file $2/$file >/dev/null 2>&1       \
273         || echo "Can't copy $file"
274         chmod +w $2/$file
275         chmod a+r $2/$file
276         # Here is how the sed commands in braces work.
277         # (It doesn't work to put the comments inside the sed commands.)
278                 # Surround each word with spaces, to simplify matching below.
279                 # ANSIfy each pre-ANSI machine-dependent symbol
280                 # by surrounding it with __ __.
281                 # Remove the spaces that we inserted around each word.
282         sed -e '
283                                    :loop
284           /\\$/                 N
285           /\\$/                 b loop
286           s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
287           s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
288           s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
289           s%^\([        ]*#[    ]*endif\)[      ]*\*[^/].*%\1%
290           s%^\([        ]*#[    ]*endif\)[      ]*[^/*  ].*%\1%
291           /\/\/[^*]/                    s|//\(.*\)$|/*\1*/|
292           /[    ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[  ]*(\)\(.\),/\1'\''\2'\'',/
293           /[    ]BSD43__IO[A-Z]*[       ]*(/    s/(\(.\),/('\''\1'\'',/
294           /#define._IO/                 s/'\''\([cgxt]\)'\''/\1/g
295           /#define.BSD43__IO/           s/'\''\([cgx]\)'\''/\1/g
296           /[^A-Z0-9_]CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
297           /[^A-Z0-9]_CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
298           /#define[     ]*[     ]CTRL/          s/'\''\([cgx]\)'\''/\1/g
299           /#define[     ]*[     ]_CTRL/         s/'\''\([cgx]\)'\''/\1/g
300           /#define.BSD43_CTRL/          s/'\''\([cgx]\)'\''/\1/g
301           /#[el]*if/{
302                 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
303
304                 s/ bsd4\([0-9]\) / __bsd4\1__ /g
305                 s/ _*i386 / __i386__ /g
306                 s/ is68k / __is68k__ /g
307                 s/ m68k / __m68k__ /g
308                 s/ mc680\([0-9]\)0 / __mc680\10__ /g
309                 s/ news\([0-9]*\) / __news\1__ /g
310                 s/ ns32000 / __ns32000__ /g
311                 s/ pyr / __pyr__ /g
312                 s/ sony_news / __sony_news__ /g
313                 s/ sparc / __sparc__ /g
314                 s/ sun\([a-z0-9]*\) / __sun\1__ /g
315                 s/ unix / __unix__ /g
316                 s/ vax / __vax__ /g
317
318                 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
319           }
320           /^#define.NULL[       ]/      i\
321                 #undef NULL
322         ' $2/$file > $2/$file.
323         mv $2/$file. $2/$file
324         if cmp $file $2/$file >/dev/null 2>&1; then
325            rm $2/$file
326         else
327            echo Fixed $file
328            # Find any include directives that use "file".
329            for include in `egrep '^[    ]*#[    ]*include[      ]*"[^/]' $2/$file | sed -e 's/^[        ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
330               dir=`echo $file | sed -e s'|/[^/]*$||'`
331               required="$required $1 $dir/$include $2/$dir/$include"
332            done
333         fi
334       fi
335     fi
336   done
337   shift; shift
338 done
339
340 # Make sure that any include files referenced using double quotes
341 # exist in the fixed directory.
342 set x $required
343 shift
344 while [ $# != 0 ]; do
345   # $1 is the directory to copy from, $2 is the unfixed file,
346   # $3 is the fixed file name.
347   cd ${INPUT}
348   cd $1
349   if [ -r $2 ] && [ ! -r $3 ]; then
350     cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
351     chmod +w $3 2>/dev/null
352     chmod a+r $3 2>/dev/null
353     echo Copied $2
354   fi
355   shift; shift; shift
356 done
357
358 cd ${INPUT}
359
360 # Install the proper definition of size_t in header files that it comes from.
361 for file in sys/types.h stdlib.h sys/stdtypes.h; do
362   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
363     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
364     chmod +w ${LIB}/$file 2>/dev/null
365     chmod a+r ${LIB}/$file 2>/dev/null
366   fi
367
368   if [ -r ${LIB}/$file ]; then
369     echo Fixing $file comment
370     # Get the definition of __SIZE_TYPE__, if any.
371     # (This file must be called something.c).
372     echo "__SIZE_TYPE__" > ${LIB}/types.c
373     foo=`${GCCCMD} -E -P ${LIB}/types.c`
374     rm -f ${LIB}/types.c
375     # Default to our preferred type.
376     if [ "$foo" = __SIZE_TYPE__ ]; then foo="unsigned long int"; fi
377     sed -e "s/typedef[  a-z_]*[         ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
378     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
379     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
380       rm ${LIB}/$file
381     fi
382   fi
383 done
384
385 # Fix one other error in this file: a mismatched quote not inside a C comment.
386 file=sundev/vuid_event.h
387 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
388   mkdir ${LIB}/sundev 2>/dev/null
389   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
390   chmod +w ${LIB}/$file 2>/dev/null
391   chmod a+r ${LIB}/$file 2>/dev/null
392 fi
393
394 if [ -r ${LIB}/$file ]; then
395   echo Fixing $file comment
396   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
397   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
398   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
399     rm ${LIB}/$file
400   fi
401 fi
402
403 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
404 file=sunwindow/win_cursor.h
405 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
406 #  mkdir ${LIB}/sunwindow 2>/dev/null
407   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
408   chmod +w ${LIB}/$file 2>/dev/null
409 fi
410 if [ -r ${LIB}/$file ]; then
411   echo Fixing $file
412   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
413   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
414   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
415     rm ${LIB}/$file
416   fi
417 fi
418 file=sunwindow/win_lock.h
419 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
420 #  mkdir ${LIB}/sunwindow 2>/dev/null
421   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
422   chmod +w ${LIB}/$file 2>/dev/null
423 fi
424 if [ -r ${LIB}/$file ]; then
425   echo Fixing $file
426   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
427   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
428   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
429     rm ${LIB}/$file
430   fi
431 fi
432
433 # Fix this Sun file to avoid interfering with stddef.h.
434 file=sys/stdtypes.h
435 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
436   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
437   chmod +w ${LIB}/$file 2>/dev/null
438   chmod a+r ${LIB}/$file 2>/dev/null
439 fi
440
441 if [ -r ${LIB}/$file ]; then
442   echo Fixing $file
443 sed -e '/[       ]size_t.*;/i\
444 #ifndef _GCC_SIZE_T\
445 #define _GCC_SIZE_T' \
446     -e '/[       ]size_t.*;/a\
447 #endif' \
448     -e '/[       ]ptrdiff_t.*;/i\
449 #ifndef _GCC_PTRDIFF_T\
450 #define _GCC_PTRDIFF_T' \
451     -e '/[       ]ptrdiff_t.*;/a\
452 #endif' \
453     -e '/[       ]wchar_t.*;/i\
454 #ifndef _GCC_WCHAR_T\
455 #define _GCC_WCHAR_T' \
456     -e '/[       ]wchar_t.*;/a\
457 #endif' ${LIB}/$file > ${LIB}/${file}.sed
458   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
459   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
460     rm ${LIB}/$file
461   fi
462 fi
463
464 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
465 # match e.g. ssize_t present in AIX for the ps/2.
466 file=sys/types.h
467 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
468   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
469   chmod +w ${LIB}/$file 2>/dev/null
470   chmod a+r ${LIB}/$file 2>/dev/null
471 fi
472
473 if [ -r ${LIB}/$file ]; then
474   echo Fixing $file
475 sed -e '/[      ]size_t.*;/i\
476 #ifndef _GCC_SIZE_T\
477 #define _GCC_SIZE_T' \
478     -e '/[      ]size_t.*;/a\
479 #endif' ${LIB}/$file > ${LIB}/${file}.sed
480   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
481   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
482     rm ${LIB}/$file
483   fi
484 fi
485
486 # Fix HP's use of ../machine/inline.h to refer to
487 # /usr/include/machine/inline.h
488 file=sys/spinlock.h
489 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
490   cp $file ${LIB}/$file
491 fi
492 if [ -r ${LIB}/$file ] ; then
493   echo Fixing $file
494   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
495     -e 's,"../machine/psl.h",<machine/psl.h>,' \
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 an error in this file: the #if says _cplusplus, not the double
504 # underscore __cplusplus that it should be
505 file=tinfo.h
506 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
507   mkdir ${LIB}/rpcsvc 2>/dev/null
508   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
509   chmod +w ${LIB}/$file 2>/dev/null
510   chmod a+r ${LIB}/$file 2>/dev/null
511 fi
512
513 if [ -r ${LIB}/$file ]; then
514   echo Fixing $file, __cplusplus macro
515   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
516   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
517   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
518     rm ${LIB}/$file
519   fi
520 fi
521
522 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
523 # structure definition.
524 file=rpcsvc/rstat.h
525 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
526   mkdir ${LIB}/rpcsvc 2>/dev/null
527   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
528   chmod +w ${LIB}/$file 2>/dev/null
529   chmod a+r ${LIB}/$file 2>/dev/null
530 fi
531
532 if [ -r ${LIB}/$file ]; then
533   echo Fixing $file, definition of statsswtch
534   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
535   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
536   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
537     rm ${LIB}/$file
538   fi
539 fi
540
541 # Fix an error in this file: a missing semi-colon at the end of the nodeent
542 # structure definition.
543 file=netdnet/dnetdb.h
544 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
545   mkdir ${LIB}/netdnet 2>/dev/null
546   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
547   chmod +w ${LIB}/$file 2>/dev/null
548   chmod a+r ${LIB}/$file 2>/dev/null
549 fi
550
551 if [ -r ${LIB}/$file ]; then
552   echo Fixing $file, definition of nodeent
553   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
554   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
555   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
556     rm ${LIB}/$file
557   fi
558 fi
559
560 # Check for bad #ifdef line (in Ultrix 4.1)
561 file=sys/file.h
562 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
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, bad \#ifdef line
570   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${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 superfluous `static' (in Ultrix 4.2)
578 file=machine/cpu.h
579 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
580   mkdir ${LIB}/machine 2>/dev/null
581   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
582   chmod +w ${LIB}/$file 2>/dev/null
583   chmod a+r ${LIB}/$file 2>/dev/null
584 fi
585
586 if [ -r ${LIB}/$file ]; then
587   echo Fixing $file, superfluous static
588   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
589   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
590   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
591     rm ${LIB}/$file
592   else
593 # This file has an alternative name, mips/cpu.h.  Fix that name, too.
594     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
595       mkdir ${LIB}/mips 2>&-
596       ln ${LIB}/$file ${LIB}/mips/cpu.h 
597     fi
598   fi
599 fi
600
601 # Incorrect sprintf declaration in X11/Xmu.h
602 file=X11/Xmu.h
603 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
604   mkdir ${LIB}/X11 2>/dev/null
605   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
606   chmod +w ${LIB}/$file 2>/dev/null
607   chmod a+r ${LIB}/$file 2>/dev/null
608 fi
609
610 if [ -r ${LIB}/$file ]; then
611   echo Fixing $file sprintf declaration
612   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
613 extern char *   sprintf();\
614 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
615   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
616   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
617     rm ${LIB}/$file
618   fi
619 fi
620
621 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
622 # (It's not clear whether the right file name is this or X11/Xmu.h.)
623 file=X11/Xmu/Xmu.h
624 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
625   mkdir ${LIB}/X11/Xmu 2>/dev/null
626   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
627   chmod +w ${LIB}/$file 2>/dev/null
628   chmod a+r ${LIB}/$file 2>/dev/null
629 fi
630
631 if [ -r ${LIB}/$file ]; then
632   echo Fixing $file sprintf declaration
633   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
634 extern char *   sprintf();\
635 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
636   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
637   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
638     rm ${LIB}/$file
639   fi
640 fi
641
642 # Check for missing ';' in struct
643 file=netinet/ip.h
644 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
645   mkdir ${LIB}/netinet 2>/dev/null
646   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
647   chmod +w ${LIB}/$file 2>/dev/null
648   chmod a+r ${LIB}/$file 2>/dev/null
649 fi
650
651 if [ -r ${LIB}/$file ]; then
652   echo Fixing $file
653   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
654   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
655   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
656     rm -f ${LIB}/$file
657   fi
658 fi
659
660 # Fix the CAT macro in SunOS memvar.h.
661 file=pixrect/memvar.h
662 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
663   mkdir ${LIB}/pixrect 2>/dev/null
664   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
665   chmod +w ${LIB}/$file 2>/dev/null
666   chmod a+r ${LIB}/$file 2>/dev/null
667 fi
668
669 if [ -r ${LIB}/$file ]; then
670   echo Fixing $file
671   sed -e '/^#define.CAT(a,b)/ i\
672 #ifdef __STDC__ \
673 #define CAT(a,b) a##b\
674 #else
675 /^#define.CAT(a,b)/ a\
676 #endif
677 ' ${LIB}/$file > ${LIB}/${file}.sed
678   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
679   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
680     rm -f ${LIB}/$file
681   fi
682 fi
683
684 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
685 file=rpcsvc/rusers.h
686 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
687   mkdir ${LIB}/rpcsvc 2>/dev/null
688   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
689   chmod +w ${LIB}/$file 2>/dev/null
690   chmod a+r ${LIB}/$file 2>/dev/null
691 fi
692
693 if [ -r ${LIB}/$file ]; then
694   echo Fixing $file
695   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
696   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
697   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
698     rm -f ${LIB}/$file
699   fi
700 fi
701
702 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
703 # Also wrap protection around size_t for m88k-sysv3 systems.
704 file=stdlib.h
705 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
706   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
707   chmod +w ${LIB}/$file 2>/dev/null
708   chmod a+r ${LIB}/$file 2>/dev/null
709 fi
710
711 if [ -r ${LIB}/$file ]; then
712   echo Fixing $file
713   sed -e 's/int abort/void      abort/g' \
714   -e 's/int     free/void       free/g' \
715   -e 's/char \* calloc/void \*  calloc/g' \
716   -e 's/char \* malloc/void \*  malloc/g' \
717   -e 's/char \* realloc/void \* realloc/g' \
718   -e 's/int     exit/void       exit/g' \
719   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/i\
720 #ifndef _GCC_SIZE_T\
721 #define _GCC_SIZE_T' \
722   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/a\
723 #endif' \
724       ${LIB}/$file > ${LIB}/${file}.sed
725   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
726   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
727     rm -f ${LIB}/$file
728   fi
729 fi
730
731 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
732 file=malloc.h
733 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
734   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
735   chmod +w ${LIB}/$file 2>/dev/null
736   chmod a+r ${LIB}/$file 2>/dev/null
737 fi
738
739 if [ -r ${LIB}/$file ]; then
740   echo Fixing $file
741   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
742   -e 's/int[    ][      ]*free/void     free/g' \
743   ${LIB}/$file > ${LIB}/${file}.sed
744   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
745   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
746     rm -f ${LIB}/$file
747   fi
748 fi
749
750 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
751 file=hsfs/hsfs_spec.h
752 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
753   mkdir ${LIB}/hsfs 2>/dev/null
754   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
755   chmod +w ${LIB}/$file 2>/dev/null
756   chmod a+r ${LIB}/$file 2>/dev/null
757 fi
758
759 if [ -r ${LIB}/$file ]; then
760   echo Fixing $file
761   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
762     ${LIB}/$file > ${LIB}/${file}.
763   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
764   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
765     rm -f ${LIB}/$file
766   fi
767 fi
768
769 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
770 file=hsfs/hsnode.h
771 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
772   mkdir ${LIB}/hsfs 2>/dev/null
773   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
774   chmod +w ${LIB}/$file 2>/dev/null
775   chmod a+r ${LIB}/$file 2>/dev/null
776 fi
777
778 if [ -r ${LIB}/$file ]; then
779   echo Fixing $file
780   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
781     ${LIB}/$file > ${LIB}/${file}.sed
782   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
783   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
784     rm -f ${LIB}/$file
785   fi
786 fi
787
788 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
789 file=hsfs/iso_spec.h
790 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
791   mkdir ${LIB}/hsfs 2>/dev/null
792   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
793   chmod +w ${LIB}/$file 2>/dev/null
794   chmod a+r ${LIB}/$file 2>/dev/null
795 fi
796
797 if [ -r ${LIB}/$file ]; then
798   echo Fixing $file
799   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
800     ${LIB}/$file > ${LIB}/${file}.sed
801   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
802   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
803     rm -f ${LIB}/$file
804   fi
805 fi
806
807 # Incorrect #include in Sony News-OS 3.2.
808 file=machine/machparam.h
809 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
810   mkdir ${LIB}/machine 2>/dev/null
811   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
812   chmod +w ${LIB}/$file 2>/dev/null
813   chmod a+r ${LIB}/$file 2>/dev/null
814 fi
815
816 if [ -r ${LIB}/$file ]; then
817   echo Fixing $file, incorrect \#include
818   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
819     ${LIB}/$file > ${LIB}/${file}.
820   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
821   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
822     rm -f ${LIB}/$file
823   fi
824 fi
825
826 # Multiline comment after typedef on IRIX 4.0.1.
827 file=sys/types.h
828 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
829   mkdir ${LIB}/sys 2>/dev/null
830   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
831   chmod +w ${LIB}/$file 2>/dev/null
832   chmod a+r ${LIB}/$file 2>/dev/null
833 fi
834
835 if [ -r ${LIB}/$file ]; then
836   echo Fixing $file, comment in the middle of \#ifdef
837   sed -e 's@type of the result@type of the result */@' \
838     -e 's@of the sizeof@/* of the sizeof@' \
839     ${LIB}/$file > ${LIB}/${file}.sed
840   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
841   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
842     rm -f ${LIB}/$file
843   fi
844 fi
845
846 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
847 # header file, which embeds // comments inside multi-line /* */
848 # comments.  If this looks like the IRIX header file, we refix it by
849 # just throwing away the // comments.
850 file=fam.h
851 if [ -r ${LIB}/$file ]; then
852   if egrep indigo.esd ${LIB}/$file > /dev/null; then
853     echo Fixing $file, overeager sed script
854     rm ${LIB}/$file
855     sed -e 's|//.*$||g' $file > ${LIB}/$file
856     chmod +w ${LIB}/$file 2>/dev/null
857     chmod a+r ${LIB}/$file 2>/dev/null
858   fi
859 fi
860
861 # Another IRIX 4.0.1 header file contains the string "//"
862 file=elf_abi.h
863 if [ -r ${LIB}/$file ]; then
864   echo Fixing $file, overeager sed script
865   sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
866   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
867   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
868     rm -f ${LIB}/$file
869   fi
870 fi
871
872 # Same problem with a file from SunOS 4.1.3 : a header file containing
873 # the string "//" embedded in "/**/"
874 file=sbusdev/audiovar.h
875 if [ -r ${LIB}/$file ]; then
876   echo Fixing $file, overeager sed script
877   rm ${LIB}/$file
878   sed -e 's|//.*$||g' $file > ${LIB}/$file
879   chmod +w ${LIB}/$file 2>/dev/null
880   chmod a+r ${LIB}/$file 2>/dev/null
881 fi
882
883 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
884 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
885 # many other systems have similar text but correct versions of the file.
886 # To ensure only Sun's is fixed, we grep for a likely unique string.
887 file=memory.h
888 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
889   if [ ! -r ${LIB}/$file ]; then
890     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
891     chmod +w ${LIB}/$file 2>/dev/null
892     chmod a+r ${LIB}/$file 2>/dev/null
893   fi
894   if [ -r ${LIB}/$file ]; then
895     echo Replacing $file
896     cat > ${LIB}/$file << EOF
897 /* This file was generated by fixincludes */
898 #ifndef __memory_h__
899 #define __memory_h__
900
901 #ifdef __STDC__
902 extern void *memccpy();
903 extern void *memchr();
904 extern void *memcpy();
905 extern void *memset();
906 #else
907 extern char *memccpy();
908 extern char *memchr();
909 extern char *memcpy();
910 extern char *memset();
911 #endif /* __STDC__ */
912
913 extern int memcmp();
914
915 #endif /* __memory_h__ */
916 EOF
917   fi
918 fi
919
920 # parameters not const on DECstation Ultrix V4.0.
921 file=stdio.h
922 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
923   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
924   chmod +w ${LIB}/$file 2>/dev/null
925   chmod a+r ${LIB}/$file 2>/dev/null
926 fi
927
928 if [ -r ${LIB}/$file ]; then
929   echo Fixing $file, non-const arg
930   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
931       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
932       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
933       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
934       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
935       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
936       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
937     ${LIB}/$file > ${LIB}/${file}.sed
938   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
939   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
940     rm -f ${LIB}/$file
941   fi
942 fi
943
944 # parameters conflict with C++ new on rs/6000 
945 for file in stdio.h unistd.h ; do
946   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
947     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
948     chmod +w ${LIB}/$file 2>/dev/null
949   fi
950
951   if [ -r ${LIB}/$file ]; then
952     echo Fixing $file, parameter name conflicts
953     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
954       ${LIB}/$file > ${LIB}/${file}.sed
955     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
956     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
957       rm -f ${LIB}/$file
958     fi
959   fi
960 done
961
962 # function class(double x) conflicts with C++ keyword on rs/6000 
963 file=math.h
964 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
965   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
966   chmod +w ${LIB}/$file 2>/dev/null
967   chmod a+r ${LIB}/$file 2>/dev/null
968 fi
969
970 if [ -r ${LIB}/$file ]; then
971   if grep 'class[(]' ${LIB}/$file >/dev/null; then
972     echo Fixing $file
973     sed -e '/class[(]/i\
974 #ifndef __cplusplus' \
975         -e '/class[(]/a\
976 #endif' ${LIB}/$file > ${LIB}/${file}.sed
977     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
978     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
979       rm ${LIB}/$file
980     fi
981   fi
982 fi
983
984 # NeXT defines 'int wait(union wait*)', which conflicts with Posix.1.
985 file=sys/wait.h
986 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
987   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
988   chmod +w ${LIB}/$file 2>/dev/null
989 fi
990
991 if [ -r ${LIB}/$file ] \
992   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
993   echo Fixing $file, bad wait formal
994   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
995   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
996   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
997     rm -f ${LIB}/$file
998   fi
999 fi
1000
1001 # Don't use or define the name va_list in stdio.h.
1002 # This is for ANSI and also to interoperate properly with gvarargs.h.
1003 file=stdio.h
1004 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1005   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1006   chmod +w ${LIB}/$file 2>/dev/null
1007   chmod a+r ${LIB}/$file 2>/dev/null
1008 fi
1009
1010 if [ -r ${LIB}/$file ]; then
1011   echo Fixing $file, use of va_list
1012   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1013   (echo "#define __need___va_list"
1014    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1015   # Use __gnuc_va_list in arg types in place of va_list.
1016   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1017   # trailing parentheses and semicolon save all other systems from this.
1018   # Define __va_list__ (something harmless and unused) instead of va_list.
1019   # Don't claim to have defined va_list.
1020   sed -e 's@ va_list @ __gnuc_va_list @' \
1021       -e 's@ va_list)@ __gnuc_va_list)@' \
1022       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1023       -e 's@ va_list@ __va_list__@' \
1024       -e 's@\*va_list@*__va_list__@' \
1025       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1026       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1027       -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
1028     ${LIB}/$file >> ${LIB}/${file}.sed
1029   
1030   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1031   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1032     rm -f ${LIB}/$file
1033   fi
1034 fi
1035
1036 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1037 file=ansi_compat.h
1038 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1039   if grep -s ULTRIX $file; then
1040     echo "/* This file intentionally left blank.  */" > $LIB/$file
1041   fi
1042 fi
1043
1044 # parameter to atof not const on DECstation Ultrix V4.0.
1045 # also get rid of bogus inline definitions in HP-UX 8.0
1046 file=math.h
1047 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1048   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1049   chmod +w ${LIB}/$file 2>/dev/null
1050   chmod a+r ${LIB}/$file 2>/dev/null
1051 fi
1052
1053 if [ -r ${LIB}/$file ]; then
1054   echo Fixing $file, non-const arg
1055   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
1056       -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
1057       -e 's@inline double abs(double d) { return fabs(d); }@@' \
1058     ${LIB}/$file > ${LIB}/${file}.sed
1059   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1060   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1061     rm -f ${LIB}/$file
1062   fi
1063 fi
1064
1065 # In limits.h, put #ifndefs around things that are supposed to be defined
1066 # in float.h to avoid redefinition errors if float.h is included first.
1067 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1068 # multi line comments and the inserted #endif winds up inside the
1069 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1070 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1071 # are there, and we do not add them ourselves.
1072 file=limits.h
1073 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1074   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1075   chmod +w ${LIB}/$file 2>/dev/null
1076   chmod a+r ${LIB}/$file 2>/dev/null
1077 fi
1078
1079 if [ -r ${LIB}/$file ]; then
1080   if egrep 'ifndef[     ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1081     true
1082   else
1083     echo Fixing $file
1084     sed -e '/[  ]FLT_MIN[       ]/i\
1085 #ifndef FLT_MIN'\
1086         -e '/[  ]FLT_MIN[       ]/a\
1087 #endif'\
1088         -e '/[  ]FLT_MAX[       ]/i\
1089 #ifndef FLT_MAX'\
1090         -e '/[  ]FLT_MAX[       ]/a\
1091 #endif'\
1092         -e '/[  ]FLT_DIG[       ]/i\
1093 #ifndef FLT_DIG'\
1094         -e '/[  ]FLT_DIG[       ]/a\
1095 #endif'\
1096         -e '/[  ]DBL_MIN[       ]/i\
1097 #ifndef DBL_MIN'\
1098         -e '/[  ]DBL_MIN[       ]/a\
1099 #endif'\
1100         -e '/[  ]DBL_MAX[       ]/i\
1101 #ifndef DBL_MAX'\
1102         -e '/[  ]DBL_MAX[       ]/a\
1103 #endif'\
1104         -e '/[  ]DBL_DIG[       ]/i\
1105 #ifndef DBL_DIG'\
1106         -e '/[  ]DBL_DIG[       ]/a\
1107 #endif'\
1108       ${LIB}/$file > ${LIB}/${file}.sed
1109     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1110   fi
1111   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1112     echo Deleting ${LIB}/$file\; no fixes were needed.
1113     rm -f ${LIB}/$file
1114   fi
1115 fi
1116
1117 # In math.h, put #ifndefs around things that might be defined in a gcc
1118 # specific math-*.h file.
1119 file=math.h
1120 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
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   echo Fixing $file
1128   sed -e '/define[      ]HUGE_VAL[      ]/i\
1129 #ifndef HUGE_VAL'\
1130       -e '/define[      ]HUGE_VAL[      ]/a\
1131 #endif'\
1132     ${LIB}/$file > ${LIB}/${file}.sed
1133   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1134   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1135     echo Deleting ${LIB}/$file\; no fixes were needed.
1136     rm -f ${LIB}/$file
1137   fi
1138 fi
1139
1140 # These two files on SunOS 4 are included by other files
1141 # in the same directory, using "...".  So we must make sure they exist
1142 # in the same directory as the other fixed files.
1143 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1144 then
1145   ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1146 fi
1147 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1148 then
1149   ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1150 fi
1151
1152 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1153 # need to fix some additional files.  This is the same test for ISC that
1154 # Autoconf uses.
1155 if test -d /etc/conf/kconfig.d \
1156     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1157   echo "Fixing ISC __STDC__ goof in several files..."
1158   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1159     echo $name
1160     if test -r ${LIB}/$name; then
1161       file=${LIB}/$name
1162     else
1163       file=${INPUT}/$name
1164     fi
1165     # On Interactive 2.2, certain traditional Unix definitions
1166     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1167     # defined, not just if _POSIX_SOURCE is defined.  This makes it
1168     # impossible to compile any nontrivial program except with -posix.
1169     sed \
1170 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1171             < $file > ${LIB}/$name.
1172     mv ${LIB}/$name. ${LIB}/$name
1173   done
1174   
1175   echo "Fixing ISC fmod declaration"
1176   # This one's already been fixed for other things.
1177   file=${LIB}/math.h
1178   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1179   mv $file. $file
1180   
1181   echo "Fixing nested comments in ISC <sys/limits.h>"
1182   file=sys/limits.h
1183   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1184   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1185 fi
1186
1187 # These files in Sun OS 4.x use /**/ to concatenate tokens.
1188 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
1189         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
1190         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
1191 do
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     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1200     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1201     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1202       rm -f ${LIB}/$file
1203     fi
1204   fi
1205 done
1206
1207 echo 'Removing unneeded directories:'
1208 cd $LIB
1209 files=`find . -type d -print | sort -r`
1210 for file in $files; do
1211   rmdir $LIB/$file > /dev/null 2>&1
1212 done
1213
1214 if $LINKS; then
1215   echo 'Making internal symbolic non-directory links'
1216   cd ${INPUT}
1217   files=`find . -type l -print`
1218   for file in $files; do
1219     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1220     if expr "$dest" : '[^/].*' > /dev/null; then    
1221       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1222       if [ -f $target ]; then
1223         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1224       fi
1225     fi
1226   done
1227 fi
1228
1229 echo 'Cleaning up DONE files.'
1230 cd $LIB
1231 find . -name DONE -exec rm -f '{}' ';'
1232
1233 exit 0