OSDN Git Service

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