OSDN Git Service

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