OSDN Git Service

Remove special case for IRIX 4.0.1 that was superseded
[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 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
788 # header file, which embeds // comments inside multi-line /* */
789 # comments.  If this looks like the IRIX header file, we refix it by
790 # just throwing away the // comments.
791 file=fam.h
792 if [ -r ${LIB}/$file ]; then
793   if egrep indigo.esd ${LIB}/$file > /dev/null; then
794     echo Fixing $file, overeager sed script
795     rm ${LIB}/$file
796     sed -e 's|//.*$||g' $file > ${LIB}/$file
797     chmod +w ${LIB}/$file 2>/dev/null
798     chmod a+r ${LIB}/$file 2>/dev/null
799   fi
800 fi
801
802 # Another IRIX 4.0.1 header file contains the string "//"
803 file=elf_abi.h
804 if [ -r ${LIB}/$file ]; then
805   echo Fixing $file, overeager sed script
806   sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
807   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
808   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
809     rm -f ${LIB}/$file
810   fi
811 fi
812
813 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
814 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
815 # many other systems have similar text but correct versions of the file.
816 # To ensure only Sun's is fixed, we grep for a likely unique string.
817 file=memory.h
818 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
819   if [ ! -r ${LIB}/$file ]; then
820     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
821     chmod +w ${LIB}/$file 2>/dev/null
822     chmod a+r ${LIB}/$file 2>/dev/null
823   fi
824   if [ -r ${LIB}/$file ]; then
825     echo Replacing $file
826     cat > ${LIB}/$file << EOF
827 /* This file was generated by fixincludes */
828 #ifndef __memory_h__
829 #define __memory_h__
830
831 #ifdef __STDC__
832 extern void *memccpy();
833 extern void *memchr();
834 extern void *memcpy();
835 extern void *memset();
836 #else
837 extern char *memccpy();
838 extern char *memchr();
839 extern char *memcpy();
840 extern char *memset();
841 #endif /* __STDC__ */
842
843 extern int memcmp();
844
845 #endif /* __memory_h__ */
846 EOF
847   fi
848 fi
849
850 # parameters not const on DECstation Ultrix V4.0.
851 file=stdio.h
852 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
853   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
854   chmod +w ${LIB}/$file 2>/dev/null
855   chmod a+r ${LIB}/$file 2>/dev/null
856 fi
857
858 if [ -r ${LIB}/$file ]; then
859   echo Fixing $file, non-const arg
860   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
861       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
862       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
863       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
864       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
865       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
866       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
867     ${LIB}/$file > ${LIB}/${file}.sed
868   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
869   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
870     rm -f ${LIB}/$file
871   fi
872 fi
873
874 # parameters conflict with C++ new on rs/6000 
875 file=stdio.h
876 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
877   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
878   chmod +w ${LIB}/$file 2>/dev/null
879 fi
880
881 if [ -r ${LIB}/$file ]; then
882   echo Fixing $file, parameter name conflicts
883   sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
884     ${LIB}/$file > ${LIB}/${file}.sed
885   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
886   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
887     rm -f ${LIB}/$file
888   fi
889 fi
890
891 # Don't use or define the name va_list in stdio.h.
892 # This is for ANSI and also to interoperate properly with gvarargs.h.
893 file=stdio.h
894 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
895   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
896   chmod +w ${LIB}/$file 2>/dev/null
897   chmod a+r ${LIB}/$file 2>/dev/null
898 fi
899
900 if [ -r ${LIB}/$file ]; then
901   echo Fixing $file, use of va_list
902   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
903   (echo "#define __need___va_list"
904    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
905   # Use __gnuc_va_list in arg types in place of va_list.
906   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
907   # trailing parentheses and semicolon save all other systems from this.
908   # Define __va_list__ (something harmless and unused) instead of va_list.
909   # Don't claim to have defined va_list.
910   sed -e 's@ va_list @ __gnuc_va_list @' \
911       -e 's@ va_list)@ __gnuc_va_list)@' \
912       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
913       -e 's@ va_list@ __va_list__@' \
914       -e 's@\*va_list@*__va_list__@' \
915       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
916       -e 's@VA_LIST@DUMMY_VA_LIST@' \
917       -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
918     ${LIB}/$file >> ${LIB}/${file}.sed
919   
920   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
921   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
922     rm -f ${LIB}/$file
923   fi
924 fi
925
926 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
927 file=ansi_compat.h
928 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
929   if grep -s ULTRIX $file; then
930     echo "/* This file intentionally left blank.  */" > $LIB/$file
931   fi
932 fi
933
934 # parameter to atof not const on DECstation Ultrix V4.0.
935 # also get rid of bogus inline definitions in HP-UX 8.0
936 file=math.h
937 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
938   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
939   chmod +w ${LIB}/$file 2>/dev/null
940   chmod a+r ${LIB}/$file 2>/dev/null
941 fi
942
943 if [ -r ${LIB}/$file ]; then
944   echo Fixing $file, non-const arg
945   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
946       -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
947       -e 's@inline double abs(double d) { return fabs(d); }@@' \
948     ${LIB}/$file > ${LIB}/${file}.sed
949   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
950   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
951     rm -f ${LIB}/$file
952   fi
953 fi
954
955 # In limits.h, put #ifndefs around things that are supposed to be defined
956 # in float.h to avoid redefinition errors if float.h is included first.
957 # On HP/UX this patch does not work, because on HP/UX limits.h uses
958 # multi line comments and the inserted #endif winds up inside the
959 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
960 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
961 # are there, and we do not add them ourselves.
962 file=limits.h
963 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
964   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
965   chmod +w ${LIB}/$file 2>/dev/null
966   chmod a+r ${LIB}/$file 2>/dev/null
967 fi
968
969 if [ -r ${LIB}/$file ]; then
970   if egrep 'ifndef[     ]+FLT_MIN' ${LIB}/$file >/dev/null; then
971     true
972   else
973     echo Fixing $file
974     sed -e '/[  ]FLT_MIN[       ]/i\
975 #ifndef FLT_MIN'\
976         -e '/[  ]FLT_MIN[       ]/a\
977 #endif'\
978         -e '/[  ]FLT_MAX[       ]/i\
979 #ifndef FLT_MAX'\
980         -e '/[  ]FLT_MAX[       ]/a\
981 #endif'\
982         -e '/[  ]FLT_DIG[       ]/i\
983 #ifndef FLT_DIG'\
984         -e '/[  ]FLT_DIG[       ]/a\
985 #endif'\
986         -e '/[  ]DBL_MIN[       ]/i\
987 #ifndef DBL_MIN'\
988         -e '/[  ]DBL_MIN[       ]/a\
989 #endif'\
990         -e '/[  ]DBL_MAX[       ]/i\
991 #ifndef DBL_MAX'\
992         -e '/[  ]DBL_MAX[       ]/a\
993 #endif'\
994         -e '/[  ]DBL_DIG[       ]/i\
995 #ifndef DBL_DIG'\
996         -e '/[  ]DBL_DIG[       ]/a\
997 #endif'\
998       ${LIB}/$file > ${LIB}/${file}.sed
999     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1000   fi
1001   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1002     echo Deleting ${LIB}/$file\; no fixes were needed.
1003     rm -f ${LIB}/$file
1004   fi
1005 fi
1006
1007 # These two files on SunOS 4 are included by other files
1008 # in the same directory, using "...".  So we must make sure they exist
1009 # in the same directory as the other fixed files.
1010 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1011 then
1012   ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1013 fi
1014 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1015 then
1016   ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1017 fi
1018
1019 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1020 # need to fix some additional files.  This is the same test for ISC that
1021 # Autoconf uses.
1022 if test -d /etc/conf/kconfig.d \
1023     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1024   echo "Fixing ISC __STDC__ goof in several files..."
1025   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1026     echo $name
1027     if test -r ${LIB}/$name; then
1028       file=${LIB}/$name
1029     else
1030       file=${INPUT}/$name
1031     fi
1032     # On Interactive 2.2, certain traditional Unix definitions
1033     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1034     # defined, not just if _POSIX_SOURCE is defined.  This makes it
1035     # impossible to compile any nontrivial program except with -posix.
1036     sed \
1037 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1038             < $file > ${LIB}/$name.
1039     mv ${LIB}/$name. ${LIB}/$name
1040   done
1041   
1042   echo "Fixing ISC fmod declaration"
1043   # This one's already been fixed for other things.
1044   file=${LIB}/math.h
1045   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1046   mv $file. $file
1047   
1048   echo "Fixing nested comments in ISC <sys/limits.h>"
1049   file=sys/limits.h
1050   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1051   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1052 fi
1053
1054 echo 'Removing unneeded directories:'
1055 cd $LIB
1056 files=`find . -type d -print | sort -r`
1057 for file in $files; do
1058   rmdir $LIB/$file > /dev/null 2>&1
1059 done
1060
1061 if $LINKS; then
1062   echo 'Making internal symbolic non-directory links'
1063   cd ${INPUT}
1064   files=`find . -type l -print`
1065   for file in $files; do
1066     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1067     if expr "$dest" : '[^/].*' > /dev/null; then    
1068       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1069       if [ -f $target ]; then
1070         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1071       fi
1072     fi
1073   done
1074 fi
1075
1076 echo 'Cleaning up DONE files.'
1077 cd $LIB
1078 find . -name DONE -exec rm -f {} ';'
1079
1080 exit 0