OSDN Git Service

d792cbf6391fd65eff33272d25651b6f0864aaa9
[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 # Command to run gcc.
9 GCCCMD=${4-${GCCCMD-gcc}}
10
11 # Directory where gcc sources (and sometimes special include files) live.
12 # fixincludes doesn't use this, but fixinc.svr4 does, and I want to make
13 # sure somebody doesn't try to use arg3 for something incompatible. -- gumby
14 SRCDIR=${3-${SRCDIR-.}}
15
16 # Directory containing the original header files.
17 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
18 INPUT=${2-${INPUT-/usr/include}}
19
20 # Directory in which to store the results.
21 LIB=${1?"fixincludes: output directory not specified"}
22
23 # Define PWDCMD as a command to use to get the working dir
24 # in the form that we want.
25 PWDCMD=pwd
26 case "`pwd`" in
27 //*)
28         # On an Apollo, discard everything before `/usr'.
29         PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
30         ;;
31 esac
32
33 # Original directory.
34 ORIGDIR=`${PWDCMD}`
35
36 # Make sure it exists.
37 if [ ! -d $LIB ]; then
38   mkdir $LIB || exit 1
39 fi
40
41 # Make LIB absolute only if needed to avoid problems with the amd.
42 case $LIB in
43 /*)
44         ;;
45 *)
46         cd $LIB; LIB=`${PWDCMD}`
47         ;;
48 esac
49
50 # Make SRCDIR absolute only if needed to avoid problems with the amd.
51 cd $ORIGDIR
52 case $SRCDIR in
53 /*)
54         ;;
55 *)
56         cd $SRCDIR; SRCDIR=`${PWDCMD}`
57         ;;
58 esac
59
60 # Fail if no arg to specify a directory for the output.
61 if [ x$1 = x ]
62 then echo fixincludes: no output directory specified
63 exit 1
64 fi
65
66 echo Building fixed headers in ${LIB}
67
68 # Determine whether this system has symbolic links.
69 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
70   rm -f $LIB/ShouldNotExist
71   LINKS=true
72 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
73   rm -f /tmp/ShouldNotExist
74   LINKS=true
75 else
76   LINKS=false
77 fi
78
79 echo Finding directories and links to directories
80 cd ${INPUT}
81 # Find all directories and all symlinks that point to directories.
82 # Put the list in $files.
83 # Each time we find a symlink, add it to newdirs
84 # so that we do another find within the dir the link points to.
85 # Note that $files may have duplicates in it;
86 # later parts of this file are supposed to ignore them.
87 dirs="."
88 levels=2
89 while [ -n "$dirs" ] && [ $levels -gt 0 ]
90 do
91     levels=`expr $levels - 1`
92     newdirs=
93     for d in $dirs
94     do
95         echo " Searching $INPUT/$d"
96         if [ "$d" != . ]
97         then
98             d=$d/.
99         fi
100
101         # Find all directories under $d, relative to $d, excluding $d itself.
102         files="$files `find $d -type d -print | \
103                        sed -e '/\/\.$/d' -e '/^\.$/d'`"
104         # Find all links to directories.
105         # Using `-exec test -d' in find fails on some systems,
106         # and trying to run test via sh fails on others,
107         # so this is the simplest alternative left.
108         # First find all the links, then test each one.
109         theselinks=
110         $LINKS && \
111           theselinks=`find $d -type l -print`
112         for d1 in $theselinks --dummy--
113         do
114             # If the link points to a directory,
115             # add that dir to $newdirs
116             if [ -d $d1 ]
117             then
118                 newdirs="$newdirs $d1"
119             fi
120         done
121     done
122
123     files="$files $newdirs"
124     dirs="$newdirs"
125 done
126
127 dirs=
128 echo "All directories (including links to directories):"
129 echo $files
130
131 for file in $files; do
132   rm -rf $LIB/$file
133   if [ ! -d $LIB/$file ]
134   then mkdir $LIB/$file
135   fi
136 done
137 mkdir $LIB/root
138
139 # treetops gets an alternating list
140 # of old directories to copy
141 # and the new directories to copy to.
142 treetops="${INPUT} ${LIB}"
143
144 if $LINKS; then
145   echo 'Making symbolic directory links'
146   for file in $files; do
147     dest=`ls -ld $file | sed -n 's/.*-> //p'`
148     if [ "$dest" ]; then    
149       cwd=`${PWDCMD}`
150       # In case $dest is relative, get to $file's dir first.
151       cd ${INPUT}
152       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
153       # Check that the target directory exists.
154       # Redirections changed to avoid bug in sh on Ultrix.
155       (cd $dest) > /dev/null 2>&1
156       if [ $? = 0 ]; then
157         cd $dest
158         # X gets the dir that the link actually leads to.
159         x=`${PWDCMD}`
160         # If a link points to ., make a similar link to .
161         if [ $x = $INPUT ]; then
162           echo $file '->' . ': Making link'
163           rm -fr ${LIB}/$file > /dev/null 2>&1
164           ln -s . ${LIB}/$file > /dev/null 2>&1
165         # If link leads back into ${INPUT},
166         # make a similar link here.
167         elif expr $x : "${INPUT}/.*" > /dev/null; then
168           # Y gets the actual target dir name, relative to ${INPUT}.
169           y=`echo $x | sed -n "s&${INPUT}/&&p"`
170           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
171           dots=`echo "$file" |
172             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
173           echo $file '->' $dots$y ': Making link'
174           rm -fr ${LIB}/$file > /dev/null 2>&1
175           ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
176         else
177           # If the link is to a dir $target outside ${INPUT},
178           # repoint the link at ${INPUT}/root$target
179           # and process $target into ${INPUT}/root$target
180           # treat this directory as if it actually contained the files.
181           echo $file '->' root$x ': Making link'
182           if [ -d $LIB/root$x ]
183           then true
184           else
185             dirname=root$x/
186             dirmade=.
187             cd $LIB
188             while [ x$dirname != x ]; do
189               component=`echo $dirname | sed -e 's|/.*$||'`
190               mkdir $component >/dev/null 2>&1
191               cd $component
192               dirmade=$dirmade/$component
193               dirname=`echo $dirname | sed -e 's|[^/]*/||'`
194             done
195           fi
196           # Duplicate directory structure created in ${LIB}/$file in new
197           # root area.
198           for file2 in $files; do
199             case $file2 in
200               $file/./*)
201                 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
202                 echo "Duplicating ${file}'s ${dupdir}"
203                 if [ -d ${dupdir} ]
204                 then true
205                 else
206                   mkdir ${dupdir}
207                 fi
208                 ;;
209               *)
210                 ;;
211             esac
212           done
213           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
214           dots=`echo "$file" |
215             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
216           rm -fr ${LIB}/$file > /dev/null 2>&1
217           ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
218           treetops="$treetops $x ${LIB}/root$x"
219         fi
220       fi
221       cd $cwd
222     fi
223   done
224 fi
225
226 required=
227 set x $treetops
228 shift
229 while [ $# != 0 ]; do
230   # $1 is an old directory to copy, and $2 is the new directory to copy to.
231   cd ${INPUT}
232   cd $1
233 # The same dir can appear more than once in treetops.
234 # There's no need to scan it more than once.
235   if [ -f $2/DONE ]
236   then
237     files=
238   else
239     touch $2/DONE
240     echo Fixing directory $1 into $2
241 # Check .h files which are symlinks as well as those which are files.
242 # A link to a header file will not be processed by anything but this.
243     if $LINKS; then
244       files=`find . -name '*.h' \( -type f -o -type l \) -print`
245     else
246       files=`find . -name '*.h' -type f -print`
247     fi
248     echo Checking header files
249   fi
250 # Note that BSD43_* are used on recent MIPS systems.
251   for file in $files; do
252 # This call to egrep is essential, since checking a file with egrep
253 # is much faster than actually trying to fix it.
254 # It is also essential that most files *not* match!
255 # Thus, matching every #endif is unacceptable.
256 # But the argument to egrep must be kept small, or many versions of egrep
257 # won't be able to handle it.
258 #
259 # We use the pattern [!-.0-~] instead of [^/    ] to match a noncomment
260 # following #else or #endif because some buggy egreps think [^/] matches
261 # newline, and they thus think `#else ' matches `#e[ndiflse]*[  ]+[^/   ]'.
262 #
263 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
264 # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
265 # in this pattern lacks `d' and `l'; this means we don't worry about
266 # identifiers starting with `d' or `l'.  This is OK, since none of the
267 # identifiers below start with `d' or `l'.  It also greatly improves
268 # performance, since many files contain lines of the form `#if ... defined ...'
269 # or `#if lint'.
270     if egrep '//|[      _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[     ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-zA-Z][a-zA-Z0-9]' $file >/dev/null; then
271       if [ -r $file ]; then
272         cp $file $2/$file >/dev/null 2>&1       \
273         || echo "Can't copy $file"
274         chmod +w $2/$file
275         chmod a+r $2/$file
276         # Here is how the sed commands in braces work.
277         # (It doesn't work to put the comments inside the sed commands.)
278                 # Surround each word with spaces, to simplify matching below.
279                 # ANSIfy each pre-ANSI machine-dependent symbol
280                 # by surrounding it with __ __.
281                 # Remove the spaces that we inserted around each word.
282         sed -e '
283                                    :loop
284           /\\$/                 N
285           /\\$/                 b loop
286           s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
287           s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
288           s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
289           s%^\([        ]*#[    ]*endif\)[      ]*\*[^/].*%\1%
290           s%^\([        ]*#[    ]*endif\)[      ]*[^/*  ].*%\1%
291           /\/\/[^*]/                    s|//\(.*\)$|/*\1*/|
292           /[    ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[  ]*(\)\(.\),/\1'\''\2'\'',/
293           /[    ]BSD43__IO[A-Z]*[       ]*(/    s/(\(.\),/('\''\1'\'',/
294           /#define._IO/                 s/'\''\([cgxtf]\)'\''/\1/g
295           /#define.BSD43__IO/           s/'\''\([cgx]\)'\''/\1/g
296           /[^A-Z0-9_]CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
297           /[^A-Z0-9]_CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
298           /#define[     ]*[     ]CTRL/          s/'\''\([cgx]\)'\''/\1/g
299           /#define[     ]*[     ]_CTRL/         s/'\''\([cgx]\)'\''/\1/g
300           /#define.BSD43_CTRL/          s/'\''\([cgx]\)'\''/\1/g
301           /#[el]*if/{
302                 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
303
304                 s/ bsd4\([0-9]\) / __bsd4\1__ /g
305                 s/ _*host_mips / __host_mips__ /g
306                 s/ _*i386 / __i386__ /g
307                 s/ is68k / __is68k__ /g
308                 s/ m68k / __m68k__ /g
309                 s/ mc680\([0-9]\)0 / __mc680\10__ /g
310                 s/ _*mips / __mips__ /g
311                 s/ news\([0-9]*\) / __news\1__ /g
312                 s/ ns32000 / __ns32000__ /g
313                 s/ pyr / __pyr__ /g
314                 s/ sony_news / __sony_news__ /g
315                 s/ sparc / __sparc__ /g
316                 s/ sun\([a-z0-9]*\) / __sun\1__ /g
317                 s/ unix / __unix__ /g
318                 s/ vax / __vax__ /g
319                 s/ _*MIPSE\([LB]\) / __MIPSE\1__ /g
320                 s/ _*R\([34]\)000 / __R\1000__ /g
321                 s/ _*SYSTYPE_\([A-Z0-9]*\) / __SYSTYPE_\1__ /g
322
323                 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
324           }
325           /^#define.NULL[       ]/      i\
326                 #undef NULL
327         ' $2/$file > $2/$file.
328         mv $2/$file. $2/$file
329         if cmp $file $2/$file >/dev/null 2>&1; then
330            rm $2/$file
331         else
332            echo Fixed $file
333            # Find any include directives that use "file".
334            for include in `egrep '^[    ]*#[    ]*include[      ]*"[^/]' $2/$file | sed -e 's/^[        ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
335               dir=`echo $file | sed -e s'|/[^/]*$||'`
336               required="$required $1 $dir/$include $2/$dir/$include"
337            done
338         fi
339       fi
340     fi
341   done
342   shift; shift
343 done
344
345 cd ${INPUT}
346
347 # Install the proper definition of size_t in header files that it comes from.
348 for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
349   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
350     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
351     chmod +w ${LIB}/$file 2>/dev/null
352     chmod a+r ${LIB}/$file 2>/dev/null
353   fi
354
355   if [ -r ${LIB}/$file ]; then
356     echo Fixing $file comment
357     # Get the definition of __SIZE_TYPE__, if any.
358     # (This file must be called something.c).
359     echo "__SIZE_TYPE__" > ${LIB}/types.c
360     foo=`${GCCCMD} -E -P ${LIB}/types.c`
361     rm -f ${LIB}/types.c
362     # Default to our preferred type.
363     if [ "$foo" = __SIZE_TYPE__ ]; then foo="unsigned long int"; fi
364     sed -e "s/typedef[  ][      ]*[a-z_][       a-z_]*[         ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
365     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
366     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
367       rm ${LIB}/$file
368     fi
369   fi
370 done
371
372 # Fix one other error in this file: a mismatched quote not inside a C comment.
373 file=sundev/vuid_event.h
374 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
375   mkdir ${LIB}/sundev 2>/dev/null
376   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
377   chmod +w ${LIB}/$file 2>/dev/null
378   chmod a+r ${LIB}/$file 2>/dev/null
379 fi
380
381 if [ -r ${LIB}/$file ]; then
382   echo Fixing $file comment
383   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
384   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
385   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
386     rm ${LIB}/$file
387   fi
388 fi
389
390 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
391 file=sunwindow/win_cursor.h
392 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
393 #  mkdir ${LIB}/sunwindow 2>/dev/null
394   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
395   chmod +w ${LIB}/$file 2>/dev/null
396 fi
397 if [ -r ${LIB}/$file ]; then
398   echo Fixing $file
399   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
400   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
401   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
402     rm ${LIB}/$file
403   fi
404 fi
405 file=sunwindow/win_lock.h
406 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
407 #  mkdir ${LIB}/sunwindow 2>/dev/null
408   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
409   chmod +w ${LIB}/$file 2>/dev/null
410 fi
411 if [ -r ${LIB}/$file ]; then
412   echo Fixing $file
413   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
414   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
415   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
416     rm ${LIB}/$file
417   fi
418 fi
419
420 # Fix this Sun file to avoid interfering with stddef.h.
421 file=sys/stdtypes.h
422 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
423   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
424   chmod +w ${LIB}/$file 2>/dev/null
425   chmod a+r ${LIB}/$file 2>/dev/null
426 fi
427
428 if [ -r ${LIB}/$file ]; then
429   echo Fixing $file
430 sed -e '/[       ]size_t.*;/i\
431 #ifndef _GCC_SIZE_T\
432 #define _GCC_SIZE_T' \
433     -e '/[       ]size_t.*;/a\
434 #endif' \
435     -e '/[       ]ptrdiff_t.*;/i\
436 #ifndef _GCC_PTRDIFF_T\
437 #define _GCC_PTRDIFF_T' \
438     -e '/[       ]ptrdiff_t.*;/a\
439 #endif' \
440     -e '/[       ]wchar_t.*;/i\
441 #ifndef _GCC_WCHAR_T\
442 #define _GCC_WCHAR_T' \
443     -e '/[       ]wchar_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 this ARM/RISCiX file to avoid interfering with the use of __wchar_t
452 # in cc1plus.
453 file=stdlib.h
454 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
455   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
456   chmod +w ${LIB}/$file 2>/dev/null
457   chmod a+r ${LIB}/$file 2>/dev/null
458 fi
459
460 if [ -r ${LIB}/$file ]; then
461   echo Fixing $file
462   sed -e "s/\(#[        ]*ifndef[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
463       -e "s/\(#[        ]*define[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
464      ${LIB}/$file > ${LIB}/${file}.sed
465   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
466   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
467     rm ${LIB}/$file
468   fi
469 fi
470
471 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
472 # match ssize_t present in AIX for the ps/2, or typedefs which use (but do not
473 # set) size_t.
474 file=sys/types.h
475 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
476   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
477   chmod +w ${LIB}/$file 2>/dev/null
478   chmod a+r ${LIB}/$file 2>/dev/null
479 fi
480
481 if [ -r ${LIB}/$file ]; then
482   echo Fixing $file
483 sed -e '/typedef[       ][      ]*[a-z_][       a-z_]*[         ]size_t/i\
484 #ifndef _GCC_SIZE_T\
485 #define _GCC_SIZE_T' \
486     -e '/typedef[       ][      ]*[a-z_][       a-z_]*[         ]size_t/a\
487 #endif' ${LIB}/$file > ${LIB}/${file}.sed
488   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
489   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
490     rm ${LIB}/$file
491   fi
492 fi
493
494 # Fix HP's use of ../machine/inline.h to refer to
495 # /usr/include/machine/inline.h
496 file=sys/spinlock.h
497 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
498   cp $file ${LIB}/$file
499 fi
500 if [ -r ${LIB}/$file ] ; then
501   echo Fixing $file
502   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
503     -e 's,"../machine/psl.h",<machine/psl.h>,' \
504   ${LIB}/$file > ${LIB}/${file}.sed
505   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
506   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
507     rm ${LIB}/$file
508   fi
509 fi
510
511 # Fix an error in this file: the #if says _cplusplus, not the double
512 # underscore __cplusplus that it should be
513 file=tinfo.h
514 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
515   mkdir ${LIB}/rpcsvc 2>/dev/null
516   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
517   chmod +w ${LIB}/$file 2>/dev/null
518   chmod a+r ${LIB}/$file 2>/dev/null
519 fi
520
521 if [ -r ${LIB}/$file ]; then
522   echo Fixing $file, __cplusplus macro
523   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
524   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
525   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
526     rm ${LIB}/$file
527   fi
528 fi
529
530 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
531 # structure definition.
532 file=rpcsvc/rstat.h
533 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
534   mkdir ${LIB}/rpcsvc 2>/dev/null
535   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
536   chmod +w ${LIB}/$file 2>/dev/null
537   chmod a+r ${LIB}/$file 2>/dev/null
538 fi
539
540 if [ -r ${LIB}/$file ]; then
541   echo Fixing $file, definition of statsswtch
542   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
543   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
544   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
545     rm ${LIB}/$file
546   fi
547 fi
548
549 # Fix an error in this file: a missing semi-colon at the end of the nodeent
550 # structure definition.
551 file=netdnet/dnetdb.h
552 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
553   mkdir ${LIB}/netdnet 2>/dev/null
554   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
555   chmod +w ${LIB}/$file 2>/dev/null
556   chmod a+r ${LIB}/$file 2>/dev/null
557 fi
558
559 if [ -r ${LIB}/$file ]; then
560   echo Fixing $file, definition of nodeent
561   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
562   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
563   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
564     rm ${LIB}/$file
565   fi
566 fi
567
568 # Check for bad #ifdef line (in Ultrix 4.1)
569 file=sys/file.h
570 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
571   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
572   chmod +w ${LIB}/$file 2>/dev/null
573   chmod a+r ${LIB}/$file 2>/dev/null
574 fi
575
576 if [ -r ${LIB}/$file ]; then
577   echo Fixing $file, bad \#ifdef line
578   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
579   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
580   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
581     rm ${LIB}/$file
582   fi
583 fi
584
585 # Check for superfluous `static' (in Ultrix 4.2)
586 file=machine/cpu.h
587 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
588   mkdir ${LIB}/machine 2>/dev/null
589   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
590   chmod +w ${LIB}/$file 2>/dev/null
591   chmod a+r ${LIB}/$file 2>/dev/null
592 fi
593
594 if [ -r ${LIB}/$file ]; then
595   echo Fixing $file, superfluous static
596   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
597   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
598   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
599     rm ${LIB}/$file
600   else
601 # This file has an alternative name, mips/cpu.h.  Fix that name, too.
602     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
603       mkdir ${LIB}/mips 2>&-
604       ln ${LIB}/$file ${LIB}/mips/cpu.h 
605     fi
606   fi
607 fi
608
609 # Incorrect sprintf declaration in X11/Xmu.h
610 file=X11/Xmu.h
611 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
612   mkdir ${LIB}/X11 2>/dev/null
613   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
614   chmod +w ${LIB}/$file 2>/dev/null
615   chmod a+r ${LIB}/$file 2>/dev/null
616 fi
617
618 if [ -r ${LIB}/$file ]; then
619   echo Fixing $file sprintf declaration
620   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
621 extern char *   sprintf();\
622 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
623   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
624   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
625     rm ${LIB}/$file
626   fi
627 fi
628
629 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
630 # (It's not clear whether the right file name is this or X11/Xmu.h.)
631 file=X11/Xmu/Xmu.h
632 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
633   mkdir ${LIB}/X11/Xmu 2>/dev/null
634   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
635   chmod +w ${LIB}/$file 2>/dev/null
636   chmod a+r ${LIB}/$file 2>/dev/null
637 fi
638
639 if [ -r ${LIB}/$file ]; then
640   echo Fixing $file sprintf declaration
641   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
642 extern char *   sprintf();\
643 #endif /* !defined __STDC__ */,' ${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 ${LIB}/$file
647   fi
648 fi
649
650 # Check for missing ';' in struct
651 file=netinet/ip.h
652 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
653   mkdir ${LIB}/netinet 2>/dev/null
654   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
655   chmod +w ${LIB}/$file 2>/dev/null
656   chmod a+r ${LIB}/$file 2>/dev/null
657 fi
658
659 if [ -r ${LIB}/$file ]; then
660   echo Fixing $file
661   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
662   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
663   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
664     rm -f ${LIB}/$file
665   fi
666 fi
667
668 # Fix the CAT macro in SunOS memvar.h.
669 file=pixrect/memvar.h
670 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
671   mkdir ${LIB}/pixrect 2>/dev/null
672   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
673   chmod +w ${LIB}/$file 2>/dev/null
674   chmod a+r ${LIB}/$file 2>/dev/null
675 fi
676
677 if [ -r ${LIB}/$file ]; then
678   echo Fixing $file
679   sed -e '/^#define.CAT(a,b)/ i\
680 #ifdef __STDC__ \
681 #define CAT(a,b) a##b\
682 #else
683 /^#define.CAT(a,b)/ a\
684 #endif
685 ' ${LIB}/$file > ${LIB}/${file}.sed
686   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
687   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
688     rm -f ${LIB}/$file
689   fi
690 fi
691
692 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
693 file=rpcsvc/rusers.h
694 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
695   mkdir ${LIB}/rpcsvc 2>/dev/null
696   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
697   chmod +w ${LIB}/$file 2>/dev/null
698   chmod a+r ${LIB}/$file 2>/dev/null
699 fi
700
701 if [ -r ${LIB}/$file ]; then
702   echo Fixing $file
703   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
704   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${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 return type of exit and abort in <stdlib.h> on SunOS 4.1.
711 # Also wrap protection around size_t for m88k-sysv3 systems.
712 file=stdlib.h
713 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
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/int abort/void      abort/g' \
722   -e 's/int     free/void       free/g' \
723   -e 's/char \* calloc/void \*  calloc/g' \
724   -e 's/char \* malloc/void \*  malloc/g' \
725   -e 's/char \* realloc/void \* realloc/g' \
726   -e 's/int     exit/void       exit/g' \
727   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/i\
728 #ifndef _GCC_SIZE_T\
729 #define _GCC_SIZE_T' \
730   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/a\
731 #endif' \
732       ${LIB}/$file > ${LIB}/${file}.sed
733   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
734   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
735     rm -f ${LIB}/$file
736   fi
737 fi
738
739 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
740 file=malloc.h
741 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
742   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
743   chmod +w ${LIB}/$file 2>/dev/null
744   chmod a+r ${LIB}/$file 2>/dev/null
745 fi
746
747 if [ -r ${LIB}/$file ]; then
748   echo Fixing $file
749   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
750   -e 's/int[    ][      ]*free/void     free/g' \
751   ${LIB}/$file > ${LIB}/${file}.sed
752   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
753   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
754     rm -f ${LIB}/$file
755   fi
756 fi
757
758 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
759 file=hsfs/hsfs_spec.h
760 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
761   mkdir ${LIB}/hsfs 2>/dev/null
762   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
763   chmod +w ${LIB}/$file 2>/dev/null
764   chmod a+r ${LIB}/$file 2>/dev/null
765 fi
766
767 if [ -r ${LIB}/$file ]; then
768   echo Fixing $file
769   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
770     ${LIB}/$file > ${LIB}/${file}.
771   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
772   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
773     rm -f ${LIB}/$file
774   fi
775 fi
776
777 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
778 file=hsfs/hsnode.h
779 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
780   mkdir ${LIB}/hsfs 2>/dev/null
781   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
782   chmod +w ${LIB}/$file 2>/dev/null
783   chmod a+r ${LIB}/$file 2>/dev/null
784 fi
785
786 if [ -r ${LIB}/$file ]; then
787   echo Fixing $file
788   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
789     ${LIB}/$file > ${LIB}/${file}.sed
790   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
791   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
792     rm -f ${LIB}/$file
793   fi
794 fi
795
796 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
797 file=hsfs/iso_spec.h
798 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
799   mkdir ${LIB}/hsfs 2>/dev/null
800   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
801   chmod +w ${LIB}/$file 2>/dev/null
802   chmod a+r ${LIB}/$file 2>/dev/null
803 fi
804
805 if [ -r ${LIB}/$file ]; then
806   echo Fixing $file
807   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
808     ${LIB}/$file > ${LIB}/${file}.sed
809   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
810   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
811     rm -f ${LIB}/$file
812   fi
813 fi
814
815 # Incorrect #include in Sony News-OS 3.2.
816 file=machine/machparam.h
817 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
818   mkdir ${LIB}/machine 2>/dev/null
819   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
820   chmod +w ${LIB}/$file 2>/dev/null
821   chmod a+r ${LIB}/$file 2>/dev/null
822 fi
823
824 if [ -r ${LIB}/$file ]; then
825   echo Fixing $file, incorrect \#include
826   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
827     ${LIB}/$file > ${LIB}/${file}.
828   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
829   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
830     rm -f ${LIB}/$file
831   fi
832 fi
833
834 # Multiline comment after typedef on IRIX 4.0.1.
835 file=sys/types.h
836 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
837   mkdir ${LIB}/sys 2>/dev/null
838   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
839   chmod +w ${LIB}/$file 2>/dev/null
840   chmod a+r ${LIB}/$file 2>/dev/null
841 fi
842
843 if [ -r ${LIB}/$file ]; then
844   echo Fixing $file, comment in the middle of \#ifdef
845   sed -e 's@type of the result@type of the result */@' \
846     -e 's@of the sizeof@/* of the sizeof@' \
847     ${LIB}/$file > ${LIB}/${file}.sed
848   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
849   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
850     rm -f ${LIB}/$file
851   fi
852 fi
853
854 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
855 # header file, which embeds // comments inside multi-line /* */
856 # comments.  If this looks like the IRIX header file, we refix it by
857 # just throwing away the // comments.
858 file=fam.h
859 if [ -r ${LIB}/$file ]; then
860   if egrep indigo.esd ${LIB}/$file > /dev/null; then
861     echo Fixing $file, overeager sed script
862     rm ${LIB}/$file
863     sed -e 's|//.*$||g' $file > ${LIB}/$file
864     chmod +w ${LIB}/$file 2>/dev/null
865     chmod a+r ${LIB}/$file 2>/dev/null
866   fi
867 fi
868
869 # Some IRIX header files contains the string "//"
870 for file in elf_abi.h elf.h; do
871   if [ -r ${LIB}/$file ]; then
872     echo Fixing $file, overeager sed script
873     sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
874     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
875     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
876       rm -f ${LIB}/$file
877     fi
878   fi
879 done
880
881 # IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr in prototype without
882 # previous definition.
883 file=rpc/auth.h
884 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
885   mkdir ${LIB}/rpc 2>/dev/null
886   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
887   chmod +w ${LIB}/$file 2>/dev/null
888   chmod a+r ${LIB}/$file 2>/dev/null
889 fi
890
891 if [ -r ${LIB}/$file ]; then
892   echo Fixing $file, undefined type
893   sed -e '/authdes_create.*struct sockaddr/i\
894 struct sockaddr;' \
895     ${LIB}/$file > ${LIB}/$file.sed
896   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
897   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
898     rm -f ${LIB}/$file
899   fi
900 fi
901
902 # IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s in prototype without previous
903 # definition.
904 file=rpc/xdr.h
905 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
906   mkdir ${LIB}/rpc 2>/dev/null
907   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
908   chmod +w ${LIB}/$file 2>/dev/null
909   chmod a+r ${LIB}/$file 2>/dev/null
910 fi
911
912 if [ -r ${LIB}/$file ]; then
913   echo Fixing $file, undefined type
914   sed -e '/xdrstdio_create.*struct __file_s/i\
915 struct __file_s;' \
916     ${LIB}/$file > ${LIB}/$file.sed
917   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
918   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
919     rm -f ${LIB}/$file
920   fi
921 fi
922
923 # Same problem with a file from SunOS 4.1.3 : a header file containing
924 # the string "//" embedded in "/**/"
925 file=sbusdev/audiovar.h
926 if [ -r ${LIB}/$file ]; then
927   echo Fixing $file, overeager sed script
928   rm ${LIB}/$file
929   sed -e 's|//.*$||g' $file > ${LIB}/$file
930   chmod +w ${LIB}/$file 2>/dev/null
931   chmod a+r ${LIB}/$file 2>/dev/null
932 fi
933
934 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
935 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
936 # many other systems have similar text but correct versions of the file.
937 # To ensure only Sun's is fixed, we grep for a likely unique string.
938 file=memory.h
939 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
940   if [ ! -r ${LIB}/$file ]; then
941     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
942     chmod +w ${LIB}/$file 2>/dev/null
943     chmod a+r ${LIB}/$file 2>/dev/null
944   fi
945   if [ -r ${LIB}/$file ]; then
946     echo Replacing $file
947     cat > ${LIB}/$file << EOF
948 /* This file was generated by fixincludes */
949 #ifndef __memory_h__
950 #define __memory_h__
951
952 #ifdef __STDC__
953 extern void *memccpy();
954 extern void *memchr();
955 extern void *memcpy();
956 extern void *memset();
957 #else
958 extern char *memccpy();
959 extern char *memchr();
960 extern char *memcpy();
961 extern char *memset();
962 #endif /* __STDC__ */
963
964 extern int memcmp();
965
966 #endif /* __memory_h__ */
967 EOF
968   fi
969 fi
970
971 # parameters not const on DECstation Ultrix V4.0.
972 file=stdio.h
973 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
974   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
975   chmod +w ${LIB}/$file 2>/dev/null
976   chmod a+r ${LIB}/$file 2>/dev/null
977 fi
978
979 if [ -r ${LIB}/$file ]; then
980   echo Fixing $file, non-const arg
981   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
982       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
983       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
984       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
985       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
986       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
987       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
988     ${LIB}/$file > ${LIB}/${file}.sed
989   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
990   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
991     rm -f ${LIB}/$file
992   fi
993 fi
994
995 # parameters conflict with C++ new on rs/6000 
996 for file in stdio.h unistd.h ; do
997   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
998     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
999     chmod +w ${LIB}/$file 2>/dev/null
1000   fi
1001
1002   if [ -r ${LIB}/$file ]; then
1003     echo Fixing $file, parameter name conflicts
1004     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
1005       ${LIB}/$file > ${LIB}/${file}.sed
1006     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1007     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1008       rm -f ${LIB}/$file
1009     fi
1010   fi
1011 done
1012
1013 # function class(double x) conflicts with C++ keyword on rs/6000 
1014 file=math.h
1015 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1016   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1017   chmod +w ${LIB}/$file 2>/dev/null
1018   chmod a+r ${LIB}/$file 2>/dev/null
1019 fi
1020
1021 if [ -r ${LIB}/$file ]; then
1022   if grep 'class[(]' ${LIB}/$file >/dev/null; then
1023     echo Fixing $file
1024     sed -e '/class[(]/i\
1025 #ifndef __cplusplus' \
1026         -e '/class[(]/a\
1027 #endif' ${LIB}/$file > ${LIB}/${file}.sed
1028     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1029     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1030       rm ${LIB}/$file
1031     fi
1032   fi
1033 fi
1034
1035 # Wrong fchmod prototype on RS/6000.
1036 file=sys/stat.h
1037 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1038   mkdir ${LIB}/sys 2>/dev/null
1039   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1040   chmod +w ${LIB}/$file 2>/dev/null
1041   chmod a+r ${LIB}/$file 2>/dev/null
1042 fi
1043
1044 if [ -r ${LIB}/$file ]; then
1045   echo Fixing $file, fchmod prototype
1046   sed -e 's/fchmod(char \*/fchmod(int/' \
1047     ${LIB}/$file > ${LIB}/$file.sed
1048   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1049   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1050     rm -f ${LIB}/$file
1051   fi
1052 fi
1053
1054 # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1055 # Note that version 3 of the NeXT system has wait.h in a different directory,
1056 # so that this code won't do anything.  But wait.h in version 3 has a
1057 # conditional, so it doesn't need this fix.  So everything is okay.
1058 file=sys/wait.h
1059 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1060   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1061   chmod +w ${LIB}/$file 2>/dev/null
1062 fi
1063
1064 if [ -r ${LIB}/$file ] \
1065   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
1066   echo Fixing $file, bad wait formal
1067   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
1068   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1069   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1070     rm -f ${LIB}/$file
1071   fi
1072 fi
1073
1074 # Don't use or define the name va_list in stdio.h.
1075 # This is for ANSI and also to interoperate properly with gvarargs.h.
1076 file=stdio.h
1077 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1078   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1079   chmod +w ${LIB}/$file 2>/dev/null
1080   chmod a+r ${LIB}/$file 2>/dev/null
1081 fi
1082
1083 if [ -r ${LIB}/$file ]; then
1084   echo Fixing $file, use of va_list
1085   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1086   (echo "#define __need___va_list"
1087    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1088   # Use __gnuc_va_list in arg types in place of va_list.
1089   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1090   # trailing parentheses and semicolon save all other systems from this.
1091   # Define __va_list__ (something harmless and unused) instead of va_list.
1092   # Don't claim to have defined va_list.
1093   sed -e 's@ va_list @ __gnuc_va_list @' \
1094       -e 's@ va_list)@ __gnuc_va_list)@' \
1095       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1096       -e 's@ va_list@ __va_list__@' \
1097       -e 's@\*va_list@*__va_list__@' \
1098       -e 's@ __va_list)@ __gnuc_va_list)@' \
1099       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1100       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1101       -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
1102     ${LIB}/$file >> ${LIB}/${file}.sed
1103   
1104   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1105   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1106     rm -f ${LIB}/$file
1107   fi
1108 fi
1109
1110 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1111 file=ansi_compat.h
1112 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1113   if grep -s ULTRIX $file; then
1114     echo "/* This file intentionally left blank.  */" > $LIB/$file
1115   fi
1116 fi
1117
1118 # parameter to atof not const on DECstation Ultrix V4.0.
1119 # also get rid of bogus inline definitions in HP-UX 8.0
1120 file=math.h
1121 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1122   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1123   chmod +w ${LIB}/$file 2>/dev/null
1124   chmod a+r ${LIB}/$file 2>/dev/null
1125 fi
1126
1127 if [ -r ${LIB}/$file ]; then
1128   echo Fixing $file, non-const arg
1129   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
1130       -e 's@inline int abs(int [a-z][a-z]*) {.*}@@' \
1131       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
1132       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
1133       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
1134     ${LIB}/$file > ${LIB}/${file}.sed
1135   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1136   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1137     rm -f ${LIB}/$file
1138   fi
1139 fi
1140
1141 # Avoid nested comments on Ultrix 4.3.
1142 file=rpc/svc.h
1143 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1144   mkdir ${LIB}/rpc 2>/dev/null
1145   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1146   chmod +w ${LIB}/$file 2>/dev/null
1147   chmod a+r ${LIB}/$file 2>/dev/null
1148 fi
1149
1150 if [ -r ${LIB}/$file ]; then
1151   echo Fixing $file, nested comment
1152   sed -e 's@^\( \*      int protocol;  \)/\*@\1*/ /*@' \
1153     ${LIB}/$file > ${LIB}/$file.sed
1154   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1155   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1156     rm -f ${LIB}/$file
1157   fi
1158 fi
1159
1160 # This file in RISC/os uses /**/ to concatenate two tokens.
1161 file=bsd43/bsd43_.h
1162 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1163   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1164   chmod +w ${LIB}/$file 2>/dev/null
1165   chmod a+r ${LIB}/$file 2>/dev/null
1166 fi
1167 if [ -r ${LIB}/$file ]; then
1168   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
1169   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1170   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1171     rm -f ${LIB}/$file
1172   fi
1173 fi
1174
1175 file=rpc/rpc.h
1176 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1177   mkdir ${LIB}/rpc 2>/dev/null
1178   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1179   chmod +w ${LIB}/$file 2>/dev/null
1180   chmod a+r ${LIB}/$file 2>/dev/null
1181 fi
1182
1183 if [ -r ${LIB}/$file ]; then
1184   echo Fixing $file, nested comment
1185   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
1186     ${LIB}/$file > ${LIB}/$file.sed
1187   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1188   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1189     rm -f ${LIB}/$file
1190   fi
1191 fi
1192
1193 # In limits.h, put #ifndefs around things that are supposed to be defined
1194 # in float.h to avoid redefinition errors if float.h is included first.
1195 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1196 # multi line comments and the inserted #endif winds up inside the
1197 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1198 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1199 # are there, and we do not add them ourselves.
1200 for file in limits.h sys/limits.h; do
1201   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1202     mkdir ${LIB}/sys 2>/dev/null
1203     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1204     chmod +w ${LIB}/$file 2>/dev/null
1205     chmod a+r ${LIB}/$file 2>/dev/null
1206   fi
1207
1208   if [ -r ${LIB}/$file ]; then
1209     if egrep 'ifndef[   ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1210       true
1211     else
1212       echo Fixing $file
1213       sed -e '/[        ]FLT_MIN[       ]/i\
1214 #ifndef FLT_MIN'\
1215           -e '/[        ]FLT_MIN[       ]/a\
1216 #endif'\
1217           -e '/[        ]FLT_MAX[       ]/i\
1218 #ifndef FLT_MAX'\
1219           -e '/[        ]FLT_MAX[       ]/a\
1220 #endif'\
1221           -e '/[        ]FLT_DIG[       ]/i\
1222 #ifndef FLT_DIG'\
1223           -e '/[        ]FLT_DIG[       ]/a\
1224 #endif'\
1225           -e '/[        ]DBL_MIN[       ]/i\
1226 #ifndef DBL_MIN'\
1227           -e '/[        ]DBL_MIN[       ]/a\
1228 #endif'\
1229           -e '/[        ]DBL_MAX[       ]/i\
1230 #ifndef DBL_MAX'\
1231           -e '/[        ]DBL_MAX[       ]/a\
1232 #endif'\
1233           -e '/[        ]DBL_DIG[       ]/i\
1234 #ifndef DBL_DIG'\
1235           -e '/[        ]DBL_DIG[       ]/a\
1236 #endif'\
1237         ${LIB}/$file > ${LIB}/${file}.sed
1238       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1239     fi
1240     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1241       echo Deleting ${LIB}/$file\; no fixes were needed.
1242       rm -f ${LIB}/$file
1243     fi
1244   fi
1245 done
1246
1247 # In math.h, put #ifndefs around things that might be defined in a gcc
1248 # specific math-*.h file.
1249 file=math.h
1250 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1251   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1252   chmod +w ${LIB}/$file 2>/dev/null
1253   chmod a+r ${LIB}/$file 2>/dev/null
1254 fi
1255
1256 if [ -r ${LIB}/$file ]; then
1257   echo Fixing $file
1258   sed -e '/define[      ]HUGE_VAL[      ]/i\
1259 #ifndef HUGE_VAL'\
1260       -e '/define[      ]HUGE_VAL[      ]/a\
1261 #endif'\
1262     ${LIB}/$file > ${LIB}/${file}.sed
1263   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1264   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1265     echo Deleting ${LIB}/$file\; no fixes were needed.
1266     rm -f ${LIB}/$file
1267   fi
1268 fi
1269
1270 # Remove erroneous parentheses in sym.h on Alpha OSF/1.
1271 file=sym.h
1272 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1273   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1274   chmod +w ${LIB}/$file 2>/dev/null
1275   chmod a+r ${LIB}/$file 2>/dev/null
1276 fi
1277
1278 if [ -r ${LIB}/$file ]; then
1279   echo Fixing $file
1280   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
1281     ${LIB}/$file > ${LIB}/${file}.sed
1282   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1283   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1284     rm -f ${LIB}/$file
1285   fi
1286 fi
1287
1288 # Fix incorrect S_IF* definitions on m88k-sysv3.
1289 file=sys/stat.h
1290 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1291   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1292   chmod +w ${LIB}/$file 2>/dev/null
1293   chmod a+r ${LIB}/$file 2>/dev/null
1294 fi
1295
1296 if [ -r ${LIB}/$file ]; then
1297   echo Fixing $file
1298   sed -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(S_IF[A-Z][A-Z][A-Z][A-Z]*\)[        ]*)/\1 (((m)\&S_IFMT)==\2)/' \
1299       -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(0[0-9]*\)[  ]*)/\1 (((m)\&S_IFMT)==\2)/' \
1300     ${LIB}/$file > ${LIB}/${file}.sed
1301   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1302   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1303     rm -f ${LIB}/$file
1304   fi
1305 fi
1306
1307 # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1.
1308 for file in stdio.h stdlib.h; do
1309   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1310     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1311     chmod +w ${LIB}/$file 2>/dev/null
1312     chmod a+r ${LIB}/$file 2>/dev/null
1313   fi
1314
1315   if [ -r ${LIB}/$file ]; then
1316     echo Fixing $file, getopt declaration
1317     sed -e 's/getopt(int, char \*\[\],char \*)/getopt(int, char *const[], const char *)/' \
1318       ${LIB}/$file > ${LIB}/${file}.sed
1319     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1320     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1321       rm -f ${LIB}/$file
1322     fi
1323   fi
1324 done
1325
1326 # These two files on SunOS 4 are included by other files
1327 # in the same directory, using "...".  So we must make sure they exist
1328 # in the same directory as the other fixed files.
1329 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1330 then
1331   ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1332 fi
1333 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1334 then
1335   ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1336 fi
1337
1338 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1339 # need to fix some additional files.  This is the same test for ISC that
1340 # Autoconf uses.
1341 if test -d /etc/conf/kconfig.d \
1342     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1343   echo "Fixing ISC __STDC__ goof in several files..."
1344   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1345     echo $name
1346     if test -r ${LIB}/$name; then
1347       file=${LIB}/$name
1348     else
1349       file=${INPUT}/$name
1350     fi
1351     # On Interactive 2.2, certain traditional Unix definitions
1352     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1353     # defined, not just if _POSIX_SOURCE is defined.  This makes it
1354     # impossible to compile any nontrivial program except with -posix.
1355     sed \
1356 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1357             < $file > ${LIB}/$name.
1358     mv ${LIB}/$name. ${LIB}/$name
1359   done
1360   
1361   echo "Fixing ISC fmod declaration"
1362   # This one's already been fixed for other things.
1363   file=${LIB}/math.h
1364   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1365   mv $file. $file
1366   
1367   echo "Fixing nested comments in ISC <sys/limits.h>"
1368   file=sys/limits.h
1369   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1370   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1371 fi
1372
1373 # These files in Sun OS 4.x use /**/ to concatenate tokens.
1374 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
1375         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
1376         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
1377 do
1378   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1379     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1380     chmod +w ${LIB}/$file 2>/dev/null
1381     chmod a+r ${LIB}/$file 2>/dev/null
1382   fi
1383
1384   if [ -r ${LIB}/$file ]; then
1385     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1386     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1387     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1388       rm -f ${LIB}/$file
1389     fi
1390   fi
1391 done
1392
1393 # These files in ARM/RISCiX use /**/ to concatenate tokens.
1394 for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
1395         dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
1396 do
1397   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1398     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1399     chmod +w ${LIB}/$file 2>/dev/null
1400     chmod a+r ${LIB}/$file 2>/dev/null
1401   fi
1402
1403   if [ -r ${LIB}/$file ]; then
1404     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1405     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1406     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1407       rm -f ${LIB}/$file
1408     fi
1409   fi
1410 done
1411
1412 # This file on SunOS 4 has a very large macro.  When the sed loop
1413 # tries pull it in, it overflows the pattern space size of the SunOS
1414 # sed (GNU sed does not have this problem).  Since the file does not
1415 # require fixing, we remove it from the fixed directory.
1416 file=sundev/ipi_error.h
1417 if [ -r ${LIB}/$file ]; then
1418   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
1419   rm -f ${LIB}/$file
1420 fi
1421
1422 echo 'Removing unneeded directories:'
1423 cd $LIB
1424 files=`find . -type d -print | sort -r`
1425 for file in $files; do
1426   rmdir $LIB/$file > /dev/null 2>&1
1427 done
1428
1429 if $LINKS; then
1430   echo 'Making internal symbolic non-directory links'
1431   cd ${INPUT}
1432   files=`find . -type l -print`
1433   for file in $files; do
1434     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1435     if expr "$dest" : '[^/].*' > /dev/null; then    
1436       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1437       if [ -f $target ]; then
1438         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1439       fi
1440     fi
1441   done
1442 fi
1443
1444 # Make sure that any include files referenced using double quotes
1445 # exist in the fixed directory.  This comes last since otherwise
1446 # we might end up deleting some of these files "because they don't
1447 # need any change."
1448 while [ -n "$required" ]; do
1449   newreq=
1450   set x $required
1451   shift
1452   while [ $# != 0 ]; do
1453     # $1 is the directory to copy from, $2 is the unfixed file,
1454     # $3 is the fixed file name.
1455     cd ${INPUT}
1456     cd $1
1457     if [ -r $2 ] && [ ! -r $3 ]; then
1458       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
1459       chmod +w $3 2>/dev/null
1460       chmod a+r $3 2>/dev/null
1461       echo Copied $2
1462       for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' $3 | sed -e 's/^[      ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1463         dir=`echo $2 | sed -e s'|/[^/]*$||'`
1464         dir2=`echo $3 | sed -e s'|/[^/]*$||'`
1465         newreq="$newreq $1 $dir/$include $dir2/$include"
1466       done
1467     fi
1468     shift; shift; shift
1469   done
1470   required=$newreq
1471 done
1472
1473 echo 'Cleaning up DONE files.'
1474 cd $LIB
1475 find . -name DONE -exec rm -f '{}' ';'
1476
1477 exit 0