OSDN Git Service

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