OSDN Git Service

(stdlib.h): Check carefully for definition of size_t.
[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@..$@@'`
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@..$@@'`
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 set x $treetops
224 shift
225 while [ $# != 0 ]; do
226   # $1 is an old directory to copy, and $2 is the new directory to copy to.
227   cd ${INPUT}
228   cd $1
229 # The same dir can appear more than once in treetops.
230 # There's no need to scan it more than once.
231   if [ -f $2/DONE ]
232   then
233     files=
234   else
235     touch $2/DONE
236     echo Fixing directory $1 into $2
237 # Check .h files which are symlinks as well as those which are files.
238 # A link to a header file will not be processed by anything but this.
239     if $LINKS; then
240       files=`find . -name '*.h' \( -type f -o -type l \) -print`
241     else
242       files=`find . -name '*.h' -type f -print`
243     fi
244     echo Checking header files
245   fi
246 # Note that BSD43_* are used on recent MIPS systems.
247   for file in $files; do
248 # This call to egrep is essential, since checking a file with egrep
249 # is much faster than actually trying to fix it.
250 # It is also essential that most files *not* match!
251 # Thus, matching every #endif is unacceptable.
252 # But the argument to egrep must be kept small, or many versions of egrep
253 # won't be able to handle it.
254 #
255 # We use the pattern [!-.0-~] instead of [^/    ] to match a noncomment
256 # following #else or #endif because some buggy egreps think [^/] matches
257 # newline, and they thus think `#else ' matches `#e[ndiflse]*[  ]+[^/   ]'.
258 #
259 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
260 # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
261 # in this pattern lacks `d' and `l'; this means we don't worry about
262 # identifiers starting with `d' or `l'.  This is OK, since none of the
263 # identifiers below start with `d' or `l'.  It also greatly improves
264 # performance, since many files contain lines of the form `#if ... defined ...'
265 # or `#if lint'.
266     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
267       if [ -r $file ]; then
268         cp $file $2/$file >/dev/null 2>&1       \
269         || echo "Can't copy $file"
270         chmod +w $2/$file
271         chmod a+r $2/$file
272         # Here is how the sed commands in braces work.
273         # (It doesn't work to put the comments inside the sed commands.)
274                 # Surround each word with spaces, to simplify matching below.
275                 # ANSIfy each pre-ANSI machine-dependent symbol
276                 # by surrounding it with __ __.
277                 # Remove the spaces that we inserted around each word.
278         sed -e '
279                                    :loop
280           /\\$/                 N
281           /\\$/                 b loop
282           s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
283           s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
284           s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
285           s%^\([        ]*#[    ]*endif\)[      ]*\*[^/].*%\1%
286           s%^\([        ]*#[    ]*endif\)[      ]*[^/*  ].*%\1%
287           /\/\/[^*]/                    s|//\(.*\)$|/*\1*/|
288           /[    ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[  ]*(\)\(.\),/\1'\''\2'\'',/
289           /[    ]BSD43__IO[A-Z]*[       ]*(/    s/(\(.\),/('\''\1'\'',/
290           /#define._IO/                 s/'\''\([cgx]\)'\''/\1/g
291           /#define.BSD43__IO/           s/'\''\([cgx]\)'\''/\1/g
292           /[^A-Z0-9_]CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
293           /[^A-Z0-9]_CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
294           /#define[     ]*[     ]CTRL/          s/'\''\([cgx]\)'\''/\1/g
295           /#define[     ]*[     ]_CTRL/         s/'\''\([cgx]\)'\''/\1/g
296           /#define.BSD43_CTRL/          s/'\''\([cgx]\)'\''/\1/g
297           /#[el]*if/{
298                 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
299
300                 s/ bsd4\([0-9]\) / __bsd4\1__ /g
301                 s/ _*i386 / __i386__ /g
302                 s/ is68k / __is68k__ /g
303                 s/ m68k / __m68k__ /g
304                 s/ mc680\([0-9]\)0 / __mc680\10__ /g
305                 s/ news\([0-9]*\) / __news\1__ /g
306                 s/ ns32000 / __ns32000__ /g
307                 s/ pyr / __pyr__ /g
308                 s/ sony_news / __sony_news__ /g
309                 s/ sparc / __sparc__ /g
310                 s/ sun\([a-z0-9]*\) / __sun\1__ /g
311                 s/ unix / __unix__ /g
312                 s/ vax / __vax__ /g
313
314                 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
315           }
316           /^#define.NULL[       ]/      i\
317                 #undef NULL
318         ' $2/$file > $2/$file.
319         mv $2/$file. $2/$file
320         if cmp $file $2/$file >/dev/null 2>&1; then
321            rm $2/$file
322         else
323            echo Fixed $file
324         fi
325       fi
326     fi
327   done
328   shift; shift
329 done
330
331 cd ${INPUT}
332
333 # Install the proper definition of size_t in header files that it comes from.
334 for file in sys/types.h stdlib.h sys/stdtypes.h;
335 do
336   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
337     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
338     chmod +w ${LIB}/$file 2>/dev/null
339     chmod a+r ${LIB}/$file 2>/dev/null
340   fi
341
342   if [ -r ${LIB}/$file ]; then
343     echo Fixing $file comment
344     # Extract the definition of SIZE_TYPE, if any.
345     # (This file must be called something.c).
346     echo "#include \"tm.h\"
347 gobblegobble SIZE_TYPE" > ${LIB}/types.c
348     foo=`cd ${LIB}; cc -E -I${ORIGDIR} -I${SRCDIR} -I${SRCDIR}/config types.c | grep gobblegobble | sed -e "s/gobblegobble[     ]*//"`
349     rm -f ${LIB}/types.c
350     # Default to our preferred type.
351     if [ "$foo" = SIZE_TYPE ]; then foo="unsigned long int"; else foo=`echo $foo | sed -e 's/^.*"\(.*\)".*$/\1/'`; fi
352     sed -e "s/typedef[  a-z_]*[         ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
353     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
354     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
355       rm ${LIB}/$file
356     fi
357   fi
358 done
359
360 # Fix one other error in this file: a mismatched quote not inside a C comment.
361 file=sundev/vuid_event.h
362 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
363   mkdir ${LIB}/sundev 2>/dev/null
364   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
365   chmod +w ${LIB}/$file 2>/dev/null
366   chmod a+r ${LIB}/$file 2>/dev/null
367 fi
368
369 if [ -r ${LIB}/$file ]; then
370   echo Fixing $file comment
371   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
372   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
373   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
374     rm ${LIB}/$file
375   fi
376 fi
377
378 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
379 file=sunwindow/win_cursor.h
380 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
381 #  mkdir ${LIB}/sunwindow 2>/dev/null
382   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
383   chmod +w ${LIB}/$file 2>/dev/null
384 fi
385 if [ -r ${LIB}/$file ]; then
386   echo Fixing $file
387   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
388   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
389   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
390     rm ${LIB}/$file
391   fi
392 fi
393 file=sunwindow/win_lock.h
394 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
395 #  mkdir ${LIB}/sunwindow 2>/dev/null
396   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
397   chmod +w ${LIB}/$file 2>/dev/null
398 fi
399 if [ -r ${LIB}/$file ]; then
400   echo Fixing $file
401   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
402   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
403   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
404     rm ${LIB}/$file
405   fi
406 fi
407
408 # Fix this Sun file to avoid interfering with stddef.h.
409 file=sys/stdtypes.h
410 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
411   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
412   chmod +w ${LIB}/$file 2>/dev/null
413   chmod a+r ${LIB}/$file 2>/dev/null
414 fi
415
416 if [ -r ${LIB}/$file ]; then
417   echo Fixing $file
418 sed -e '/[       ]size_t.*;/i\
419 #ifndef _GCC_SIZE_T\
420 #define _GCC_SIZE_T' \
421     -e '/[       ]size_t.*;/a\
422 #endif' \
423     -e '/[       ]ptrdiff_t.*;/i\
424 #ifndef _GCC_PTRDIFF_T\
425 #define _GCC_PTRDIFF_T' \
426     -e '/[       ]ptrdiff_t.*;/a\
427 #endif' \
428     -e '/[       ]wchar_t.*;/i\
429 #ifndef _GCC_WCHAR_T\
430 #define _GCC_WCHAR_T' \
431     -e '/[       ]wchar_t.*;/a\
432 #endif' ${LIB}/$file > ${LIB}/${file}.sed
433   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
434   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
435     rm ${LIB}/$file
436   fi
437 fi
438
439 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
440 # match e.g. ssize_t present in AIX for the ps/2.
441 file=sys/types.h
442 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
443   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
444   chmod +w ${LIB}/$file 2>/dev/null
445   chmod a+r ${LIB}/$file 2>/dev/null
446 fi
447
448 if [ -r ${LIB}/$file ]; then
449   echo Fixing $file
450 sed -e '/[      ]size_t.*;/i\
451 #ifndef _GCC_SIZE_T\
452 #define _GCC_SIZE_T' \
453     -e '/[      ]size_t.*;/a\
454 #endif' ${LIB}/$file > ${LIB}/${file}.sed
455   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
456   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
457     rm ${LIB}/$file
458   fi
459 fi
460
461 # Fix an error in this file: the #if says _cplusplus, not the double
462 # underscore __cplusplus that it should be
463 file=tinfo.h
464 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
465   mkdir ${LIB}/rpcsvc 2>/dev/null
466   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
467   chmod +w ${LIB}/$file 2>/dev/null
468   chmod a+r ${LIB}/$file 2>/dev/null
469 fi
470
471 if [ -r ${LIB}/$file ]; then
472   echo Fixing $file, __cplusplus macro
473   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
474   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
475   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
476     rm ${LIB}/$file
477   fi
478 fi
479
480 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
481 # structure definition.
482 file=rpcsvc/rstat.h
483 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
484   mkdir ${LIB}/rpcsvc 2>/dev/null
485   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
486   chmod +w ${LIB}/$file 2>/dev/null
487   chmod a+r ${LIB}/$file 2>/dev/null
488 fi
489
490 if [ -r ${LIB}/$file ]; then
491   echo Fixing $file, definition of statsswtch
492   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
493   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
494   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
495     rm ${LIB}/$file
496   fi
497 fi
498
499 # Fix an error in this file: a missing semi-colon at the end of the nodeent
500 # structure definition.
501 file=netdnet/dnetdb.h
502 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
503   mkdir ${LIB}/netdnet 2>/dev/null
504   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
505   chmod +w ${LIB}/$file 2>/dev/null
506   chmod a+r ${LIB}/$file 2>/dev/null
507 fi
508
509 if [ -r ${LIB}/$file ]; then
510   echo Fixing $file, definition of nodeent
511   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
512   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
513   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
514     rm ${LIB}/$file
515   fi
516 fi
517
518 # Check for bad #ifdef line (in Ultrix 4.1)
519 file=sys/file.h
520 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
521   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
522   chmod +w ${LIB}/$file 2>/dev/null
523   chmod a+r ${LIB}/$file 2>/dev/null
524 fi
525
526 if [ -r ${LIB}/$file ]; then
527   echo Fixing $file, bad \#ifdef line
528   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
529   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
530   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
531     rm ${LIB}/$file
532   fi
533 fi
534
535 # Check for superfluous `static' (in Ultrix 4.2)
536 file=machine/cpu.h
537 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
538   mkdir ${LIB}/machine 2>/dev/null
539   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
540   chmod +w ${LIB}/$file 2>/dev/null
541   chmod a+r ${LIB}/$file 2>/dev/null
542 fi
543
544 if [ -r ${LIB}/$file ]; then
545   echo Fixing $file, superfluous static
546   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
547   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
548   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
549     rm ${LIB}/$file
550   else
551 # This file has an alternative name, mips/cpu.h.  Fix that name, too.
552     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
553       mkdir ${LIB}/mips 2>&-
554       ln ${LIB}/$file ${LIB}/mips/cpu.h 
555     fi
556   fi
557 fi
558
559 # Incorrect sprintf declaration in X11/Xmu.h
560 file=X11/Xmu.h
561 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
562   mkdir ${LIB}/X11 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 sprintf declaration
570   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
571 extern char *   sprintf();\
572 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
573   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
574   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
575     rm ${LIB}/$file
576   fi
577 fi
578
579 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
580 # (It's not clear whether the right file name is this or X11/Xmu.h.)
581 file=X11/Xmu/Xmu.h
582 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
583   mkdir ${LIB}/X11/Xmu 2>/dev/null
584   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
585   chmod +w ${LIB}/$file 2>/dev/null
586   chmod a+r ${LIB}/$file 2>/dev/null
587 fi
588
589 if [ -r ${LIB}/$file ]; then
590   echo Fixing $file sprintf declaration
591   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
592 extern char *   sprintf();\
593 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
594   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
595   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
596     rm ${LIB}/$file
597   fi
598 fi
599
600 # Check for missing ';' in struct
601 file=netinet/ip.h
602 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
603   mkdir ${LIB}/netinet 2>/dev/null
604   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
605   chmod +w ${LIB}/$file 2>/dev/null
606   chmod a+r ${LIB}/$file 2>/dev/null
607 fi
608
609 if [ -r ${LIB}/$file ]; then
610   echo Fixing $file
611   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
612   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
613   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
614     rm -f ${LIB}/$file
615   fi
616 fi
617
618 # Fix the CAT macro in SunOS memvar.h.
619 file=pixrect/memvar.h
620 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
621   mkdir ${LIB}/pixrect 2>/dev/null
622   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
623   chmod +w ${LIB}/$file 2>/dev/null
624   chmod a+r ${LIB}/$file 2>/dev/null
625 fi
626
627 if [ -r ${LIB}/$file ]; then
628   echo Fixing $file
629   sed -e '/^#define.CAT(a,b)/ i\
630 #ifdef __STDC__ \
631 #define CAT(a,b) a##b\
632 #else
633 /^#define.CAT(a,b)/ a\
634 #endif
635 ' ${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 -f ${LIB}/$file
639   fi
640 fi
641
642 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
643 file=rpcsvc/rusers.h
644 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
645   mkdir ${LIB}/rpcsvc 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/_cnt$/_cnt;/' ${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 return type of exit and abort in <stdlib.h> on SunOS 4.1.
661 # Also wrap protection around size_t for m88k-sysv3 systems.
662 file=stdlib.h
663 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
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 's/int abort/void      abort/g' \
672   -e 's/int     free/void       free/g' \
673   -e 's/char \* calloc/void \*  calloc/g' \
674   -e 's/char \* malloc/void \*  malloc/g' \
675   -e 's/char \* realloc/void \* realloc/g' \
676   -e 's/int     exit/void       exit/g' \
677   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/i\
678 #ifndef _GCC_SIZE_T\
679 #define _GCC_SIZE_T' \
680   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/a\
681 #endif' \
682       ${LIB}/$file > ${LIB}/${file}.sed
683   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
684   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
685     rm -f ${LIB}/$file
686   fi
687 fi
688
689 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
690 file=malloc.h
691 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
692   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
693   chmod +w ${LIB}/$file 2>/dev/null
694   chmod a+r ${LIB}/$file 2>/dev/null
695 fi
696
697 if [ -r ${LIB}/$file ]; then
698   echo Fixing $file
699   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
700   -e 's/int[    ][      ]*free/void     free/g' \
701   ${LIB}/$file > ${LIB}/${file}.sed
702   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
703   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
704     rm -f ${LIB}/$file
705   fi
706 fi
707
708 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
709 file=hsfs/hsfs_spec.h
710 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
711   mkdir ${LIB}/hsfs 2>/dev/null
712   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
713   chmod +w ${LIB}/$file 2>/dev/null
714   chmod a+r ${LIB}/$file 2>/dev/null
715 fi
716
717 if [ -r ${LIB}/$file ]; then
718   echo Fixing $file
719   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
720     ${LIB}/$file > ${LIB}/${file}.
721   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
722   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
723     rm -f ${LIB}/$file
724   fi
725 fi
726
727 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
728 file=hsfs/hsnode.h
729 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
730   mkdir ${LIB}/hsfs 2>/dev/null
731   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
732   chmod +w ${LIB}/$file 2>/dev/null
733   chmod a+r ${LIB}/$file 2>/dev/null
734 fi
735
736 if [ -r ${LIB}/$file ]; then
737   echo Fixing $file
738   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
739     ${LIB}/$file > ${LIB}/${file}.sed
740   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
741   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
742     rm -f ${LIB}/$file
743   fi
744 fi
745
746 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
747 file=hsfs/iso_spec.h
748 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
749   mkdir ${LIB}/hsfs 2>/dev/null
750   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
751   chmod +w ${LIB}/$file 2>/dev/null
752   chmod a+r ${LIB}/$file 2>/dev/null
753 fi
754
755 if [ -r ${LIB}/$file ]; then
756   echo Fixing $file
757   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
758     ${LIB}/$file > ${LIB}/${file}.sed
759   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
760   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
761     rm -f ${LIB}/$file
762   fi
763 fi
764
765 # Incorrect #include in Sony News-OS 3.2.
766 file=machine/machparam.h
767 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
768   mkdir ${LIB}/machine 2>/dev/null
769   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
770   chmod +w ${LIB}/$file 2>/dev/null
771   chmod a+r ${LIB}/$file 2>/dev/null
772 fi
773
774 if [ -r ${LIB}/$file ]; then
775   echo Fixing $file, incorrect \#include
776   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
777     ${LIB}/$file > ${LIB}/${file}.
778   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
779   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
780     rm -f ${LIB}/$file
781   fi
782 fi
783
784 # Multiline comment after typedef on IRIX 4.0.1.
785 file=sys/types.h
786 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
787   mkdir ${LIB}/sys 2>/dev/null
788   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
789   chmod +w ${LIB}/$file 2>/dev/null
790   chmod a+r ${LIB}/$file 2>/dev/null
791 fi
792
793 if [ -r ${LIB}/$file ]; then
794   echo Fixing $file, comment in the middle of \#ifdef
795   sed -e 's@type of the result@type of the result */@' \
796     -e 's@of the sizeof@/* of the sizeof@' \
797     ${LIB}/$file > ${LIB}/${file}.sed
798   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
799   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
800     rm -f ${LIB}/$file
801   fi
802 fi
803
804 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
805 # header file, which embeds // comments inside multi-line /* */
806 # comments.  If this looks like the IRIX header file, we refix it by
807 # just throwing away the // comments.
808 file=fam.h
809 if [ -r ${LIB}/$file ]; then
810   if egrep indigo.esd ${LIB}/$file > /dev/null; then
811     echo Fixing $file, overeager sed script
812     rm ${LIB}/$file
813     sed -e 's|//.*$||g' $file > ${LIB}/$file
814     chmod +w ${LIB}/$file 2>/dev/null
815     chmod a+r ${LIB}/$file 2>/dev/null
816   fi
817 fi
818
819 # Another IRIX 4.0.1 header file contains the string "//"
820 file=elf_abi.h
821 if [ -r ${LIB}/$file ]; then
822   echo Fixing $file, overeager sed script
823   sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
824   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
825   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
826     rm -f ${LIB}/$file
827   fi
828 fi
829
830 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
831 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
832 # many other systems have similar text but correct versions of the file.
833 # To ensure only Sun's is fixed, we grep for a likely unique string.
834 file=memory.h
835 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
836   if [ ! -r ${LIB}/$file ]; then
837     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
838     chmod +w ${LIB}/$file 2>/dev/null
839     chmod a+r ${LIB}/$file 2>/dev/null
840   fi
841   if [ -r ${LIB}/$file ]; then
842     echo Replacing $file
843     cat > ${LIB}/$file << EOF
844 /* This file was generated by fixincludes */
845 #ifndef __memory_h__
846 #define __memory_h__
847
848 #ifdef __STDC__
849 extern void *memccpy();
850 extern void *memchr();
851 extern void *memcpy();
852 extern void *memset();
853 #else
854 extern char *memccpy();
855 extern char *memchr();
856 extern char *memcpy();
857 extern char *memset();
858 #endif /* __STDC__ */
859
860 extern int memcmp();
861
862 #endif /* __memory_h__ */
863 EOF
864   fi
865 fi
866
867 # parameters not const on DECstation Ultrix V4.0.
868 file=stdio.h
869 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
870   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
871   chmod +w ${LIB}/$file 2>/dev/null
872   chmod a+r ${LIB}/$file 2>/dev/null
873 fi
874
875 if [ -r ${LIB}/$file ]; then
876   echo Fixing $file, non-const arg
877   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
878       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
879       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
880       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
881       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
882       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
883       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
884     ${LIB}/$file > ${LIB}/${file}.sed
885   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
886   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
887     rm -f ${LIB}/$file
888   fi
889 fi
890
891 # parameters conflict with C++ new on rs/6000 
892 file=stdio.h
893 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
894   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
895   chmod +w ${LIB}/$file 2>/dev/null
896 fi
897
898 if [ -r ${LIB}/$file ]; then
899   echo Fixing $file, parameter name conflicts
900   sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
901     ${LIB}/$file > ${LIB}/${file}.sed
902   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
903   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
904     rm -f ${LIB}/$file
905   fi
906 fi
907
908 # Don't use or define the name va_list in stdio.h.
909 # This is for ANSI and also to interoperate properly with gvarargs.h.
910 file=stdio.h
911 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
912   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
913   chmod +w ${LIB}/$file 2>/dev/null
914   chmod a+r ${LIB}/$file 2>/dev/null
915 fi
916
917 if [ -r ${LIB}/$file ]; then
918   echo Fixing $file, use of va_list
919   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
920   (echo "#define __need___va_list"
921    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
922   # Use __gnuc_va_list in arg types in place of va_list.
923   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
924   # trailing parentheses and semicolon save all other systems from this.
925   # Define __va_list__ (something harmless and unused) instead of va_list.
926   # Don't claim to have defined va_list.
927   sed -e 's@ va_list @ __gnuc_va_list @' \
928       -e 's@ va_list)@ __gnuc_va_list)@' \
929       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
930       -e 's@ va_list@ __va_list__@' \
931       -e 's@\*va_list@*__va_list__@' \
932       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
933       -e 's@VA_LIST@DUMMY_VA_LIST@' \
934       -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
935     ${LIB}/$file >> ${LIB}/${file}.sed
936   
937   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
938   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
939     rm -f ${LIB}/$file
940   fi
941 fi
942
943 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
944 file=ansi_compat.h
945 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
946   if grep -s ULTRIX $file; then
947     echo "/* This file intentionally left blank.  */" > $LIB/$file
948   fi
949 fi
950
951 # parameter to atof not const on DECstation Ultrix V4.0.
952 # also get rid of bogus inline definitions in HP-UX 8.0
953 file=math.h
954 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
955   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
956   chmod +w ${LIB}/$file 2>/dev/null
957   chmod a+r ${LIB}/$file 2>/dev/null
958 fi
959
960 if [ -r ${LIB}/$file ]; then
961   echo Fixing $file, non-const arg
962   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
963       -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
964       -e 's@inline double abs(double d) { return fabs(d); }@@' \
965     ${LIB}/$file > ${LIB}/${file}.sed
966   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
967   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
968     rm -f ${LIB}/$file
969   fi
970 fi
971
972 # In limits.h, put #ifndefs around things that are supposed to be defined
973 # in float.h to avoid redefinition errors if float.h is included first.
974 # On HP/UX this patch does not work, because on HP/UX limits.h uses
975 # multi line comments and the inserted #endif winds up inside the
976 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
977 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
978 # are there, and we do not add them ourselves.
979 file=limits.h
980 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
981   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
982   chmod +w ${LIB}/$file 2>/dev/null
983   chmod a+r ${LIB}/$file 2>/dev/null
984 fi
985
986 if [ -r ${LIB}/$file ]; then
987   if egrep 'ifndef[     ]+FLT_MIN' ${LIB}/$file >/dev/null; then
988     true
989   else
990     echo Fixing $file
991     sed -e '/[  ]FLT_MIN[       ]/i\
992 #ifndef FLT_MIN'\
993         -e '/[  ]FLT_MIN[       ]/a\
994 #endif'\
995         -e '/[  ]FLT_MAX[       ]/i\
996 #ifndef FLT_MAX'\
997         -e '/[  ]FLT_MAX[       ]/a\
998 #endif'\
999         -e '/[  ]FLT_DIG[       ]/i\
1000 #ifndef FLT_DIG'\
1001         -e '/[  ]FLT_DIG[       ]/a\
1002 #endif'\
1003         -e '/[  ]DBL_MIN[       ]/i\
1004 #ifndef DBL_MIN'\
1005         -e '/[  ]DBL_MIN[       ]/a\
1006 #endif'\
1007         -e '/[  ]DBL_MAX[       ]/i\
1008 #ifndef DBL_MAX'\
1009         -e '/[  ]DBL_MAX[       ]/a\
1010 #endif'\
1011         -e '/[  ]DBL_DIG[       ]/i\
1012 #ifndef DBL_DIG'\
1013         -e '/[  ]DBL_DIG[       ]/a\
1014 #endif'\
1015       ${LIB}/$file > ${LIB}/${file}.sed
1016     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1017   fi
1018   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1019     echo Deleting ${LIB}/$file\; no fixes were needed.
1020     rm -f ${LIB}/$file
1021   fi
1022 fi
1023
1024 # These two files on SunOS 4 are included by other files
1025 # in the same directory, using "...".  So we must make sure they exist
1026 # in the same directory as the other fixed files.
1027 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1028 then
1029   ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1030 fi
1031 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1032 then
1033   ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1034 fi
1035
1036 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1037 # need to fix some additional files.  This is the same test for ISC that
1038 # Autoconf uses.
1039 if test -d /etc/conf/kconfig.d \
1040     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1041   echo "Fixing ISC __STDC__ goof in several files..."
1042   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1043     echo $name
1044     if test -r ${LIB}/$name; then
1045       file=${LIB}/$name
1046     else
1047       file=${INPUT}/$name
1048     fi
1049     # On Interactive 2.2, certain traditional Unix definitions
1050     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1051     # defined, not just if _POSIX_SOURCE is defined.  This makes it
1052     # impossible to compile any nontrivial program except with -posix.
1053     sed \
1054 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1055             < $file > ${LIB}/$name.
1056     mv ${LIB}/$name. ${LIB}/$name
1057   done
1058   
1059   echo "Fixing ISC fmod declaration"
1060   # This one's already been fixed for other things.
1061   file=${LIB}/math.h
1062   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1063   mv $file. $file
1064   
1065   echo "Fixing nested comments in ISC <sys/limits.h>"
1066   file=sys/limits.h
1067   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1068   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1069 fi
1070
1071 echo 'Removing unneeded directories:'
1072 cd $LIB
1073 files=`find . -type d -print | sort -r`
1074 for file in $files; do
1075   rmdir $LIB/$file > /dev/null 2>&1
1076 done
1077
1078 if $LINKS; then
1079   echo 'Making internal symbolic non-directory links'
1080   cd ${INPUT}
1081   files=`find . -type l -print`
1082   for file in $files; do
1083     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1084     if expr "$dest" : '[^/].*' > /dev/null; then    
1085       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1086       if [ -f $target ]; then
1087         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1088       fi
1089     fi
1090   done
1091 fi
1092
1093 echo 'Cleaning up DONE files.'
1094 cd $LIB
1095 find . -name DONE -exec rm -f {} ';'
1096
1097 exit 0