OSDN Git Service

(math.h): Delete inline definitions for sqr.
[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@..$@@'`
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@..$@@'`
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-z][a-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/ _*i386 / __i386__ /g
306                 s/ is68k / __is68k__ /g
307                 s/ m68k / __m68k__ /g
308                 s/ mc680\([0-9]\)0 / __mc680\10__ /g
309                 s/ news\([0-9]*\) / __news\1__ /g
310                 s/ ns32000 / __ns32000__ /g
311                 s/ pyr / __pyr__ /g
312                 s/ sony_news / __sony_news__ /g
313                 s/ sparc / __sparc__ /g
314                 s/ sun\([a-z0-9]*\) / __sun\1__ /g
315                 s/ unix / __unix__ /g
316                 s/ vax / __vax__ /g
317
318                 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
319           }
320           /^#define.NULL[       ]/      i\
321                 #undef NULL
322         ' $2/$file > $2/$file.
323         mv $2/$file. $2/$file
324         if cmp $file $2/$file >/dev/null 2>&1; then
325            rm $2/$file
326         else
327            echo Fixed $file
328            # Find any include directives that use "file".
329            for include in `egrep '^[    ]*#[    ]*include[      ]*"[^/]' $2/$file | sed -e 's/^[        ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
330               dir=`echo $file | sed -e s'|/[^/]*$||'`
331               required="$required $1 $dir/$include $2/$dir/$include"
332            done
333         fi
334       fi
335     fi
336   done
337   shift; shift
338 done
339
340 # Make sure that any include files referenced using double quotes
341 # exist in the fixed directory.
342 while [ -n "$required" ]; do
343   newreq=
344   set x $required
345   shift
346   while [ $# != 0 ]; do
347     # $1 is the directory to copy from, $2 is the unfixed file,
348     # $3 is the fixed file name.
349     cd ${INPUT}
350     cd $1
351     if [ -r $2 ] && [ ! -r $3 ]; then
352       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
353       chmod +w $3 2>/dev/null
354       chmod a+r $3 2>/dev/null
355       echo Copied $2
356       for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' $3 | sed -e 's/^[      ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
357         dir=`echo $2 | sed -e s'|/[^/]*$||'`
358         dir2=`echo $3 | sed -e s'|/[^/]*$||'`
359         newreq="$newreq $1 $dir/$include $dir2/$include"
360       done
361     fi
362     shift; shift; shift
363   done
364   required=$newreq
365 done
366
367 cd ${INPUT}
368
369 # Install the proper definition of size_t in header files that it comes from.
370 for file in sys/types.h stdlib.h sys/stdtypes.h; do
371   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
372     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
373     chmod +w ${LIB}/$file 2>/dev/null
374     chmod a+r ${LIB}/$file 2>/dev/null
375   fi
376
377   if [ -r ${LIB}/$file ]; then
378     echo Fixing $file comment
379     # Get the definition of __SIZE_TYPE__, if any.
380     # (This file must be called something.c).
381     echo "__SIZE_TYPE__" > ${LIB}/types.c
382     foo=`${GCCCMD} -E -P ${LIB}/types.c`
383     rm -f ${LIB}/types.c
384     # Default to our preferred type.
385     if [ "$foo" = __SIZE_TYPE__ ]; then foo="unsigned long int"; fi
386     sed -e "s/typedef[  a-z_]*[         ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
387     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
388     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
389       rm ${LIB}/$file
390     fi
391   fi
392 done
393
394 # Fix one other error in this file: a mismatched quote not inside a C comment.
395 file=sundev/vuid_event.h
396 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
397   mkdir ${LIB}/sundev 2>/dev/null
398   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
399   chmod +w ${LIB}/$file 2>/dev/null
400   chmod a+r ${LIB}/$file 2>/dev/null
401 fi
402
403 if [ -r ${LIB}/$file ]; then
404   echo Fixing $file comment
405   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
406   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
407   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
408     rm ${LIB}/$file
409   fi
410 fi
411
412 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
413 file=sunwindow/win_cursor.h
414 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
415 #  mkdir ${LIB}/sunwindow 2>/dev/null
416   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
417   chmod +w ${LIB}/$file 2>/dev/null
418 fi
419 if [ -r ${LIB}/$file ]; then
420   echo Fixing $file
421   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
422   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
423   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
424     rm ${LIB}/$file
425   fi
426 fi
427 file=sunwindow/win_lock.h
428 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
429 #  mkdir ${LIB}/sunwindow 2>/dev/null
430   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
431   chmod +w ${LIB}/$file 2>/dev/null
432 fi
433 if [ -r ${LIB}/$file ]; then
434   echo Fixing $file
435   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
436   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
437   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
438     rm ${LIB}/$file
439   fi
440 fi
441
442 # Fix this Sun file to avoid interfering with stddef.h.
443 file=sys/stdtypes.h
444 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
445   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
446   chmod +w ${LIB}/$file 2>/dev/null
447   chmod a+r ${LIB}/$file 2>/dev/null
448 fi
449
450 if [ -r ${LIB}/$file ]; then
451   echo Fixing $file
452 sed -e '/[       ]size_t.*;/i\
453 #ifndef _GCC_SIZE_T\
454 #define _GCC_SIZE_T' \
455     -e '/[       ]size_t.*;/a\
456 #endif' \
457     -e '/[       ]ptrdiff_t.*;/i\
458 #ifndef _GCC_PTRDIFF_T\
459 #define _GCC_PTRDIFF_T' \
460     -e '/[       ]ptrdiff_t.*;/a\
461 #endif' \
462     -e '/[       ]wchar_t.*;/i\
463 #ifndef _GCC_WCHAR_T\
464 #define _GCC_WCHAR_T' \
465     -e '/[       ]wchar_t.*;/a\
466 #endif' ${LIB}/$file > ${LIB}/${file}.sed
467   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
468   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
469     rm ${LIB}/$file
470   fi
471 fi
472
473 # Fix this ARM/RISCiX file to avoid interfering with the use of __wchar_t
474 # in cc1plus.
475 file=stdlib.h
476 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
477   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
478   chmod +w ${LIB}/$file 2>/dev/null
479   chmod a+r ${LIB}/$file 2>/dev/null
480 fi
481
482 if [ -r ${LIB}/$file ]; then
483   echo Fixing $file
484   sed -e "s/\(#[        ]*ifndef[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
485       -e "s/\(#[        ]*define[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
486      ${LIB}/$file > ${LIB}/${file}.sed
487   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
488   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
489     rm ${LIB}/$file
490   fi
491 fi
492
493 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
494 # match e.g. ssize_t present in AIX for the ps/2.
495 file=sys/types.h
496 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
497   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
498   chmod +w ${LIB}/$file 2>/dev/null
499   chmod a+r ${LIB}/$file 2>/dev/null
500 fi
501
502 if [ -r ${LIB}/$file ]; then
503   echo Fixing $file
504 sed -e '/[      ]size_t.*;/i\
505 #ifndef _GCC_SIZE_T\
506 #define _GCC_SIZE_T' \
507     -e '/[      ]size_t.*;/a\
508 #endif' ${LIB}/$file > ${LIB}/${file}.sed
509   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
510   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
511     rm ${LIB}/$file
512   fi
513 fi
514
515 # Fix HP's use of ../machine/inline.h to refer to
516 # /usr/include/machine/inline.h
517 file=sys/spinlock.h
518 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
519   cp $file ${LIB}/$file
520 fi
521 if [ -r ${LIB}/$file ] ; then
522   echo Fixing $file
523   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
524     -e 's,"../machine/psl.h",<machine/psl.h>,' \
525   ${LIB}/$file > ${LIB}/${file}.sed
526   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
527   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
528     rm ${LIB}/$file
529   fi
530 fi
531
532 # Fix an error in this file: the #if says _cplusplus, not the double
533 # underscore __cplusplus that it should be
534 file=tinfo.h
535 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
536   mkdir ${LIB}/rpcsvc 2>/dev/null
537   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
538   chmod +w ${LIB}/$file 2>/dev/null
539   chmod a+r ${LIB}/$file 2>/dev/null
540 fi
541
542 if [ -r ${LIB}/$file ]; then
543   echo Fixing $file, __cplusplus macro
544   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
545   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
546   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
547     rm ${LIB}/$file
548   fi
549 fi
550
551 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
552 # structure definition.
553 file=rpcsvc/rstat.h
554 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
555   mkdir ${LIB}/rpcsvc 2>/dev/null
556   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
557   chmod +w ${LIB}/$file 2>/dev/null
558   chmod a+r ${LIB}/$file 2>/dev/null
559 fi
560
561 if [ -r ${LIB}/$file ]; then
562   echo Fixing $file, definition of statsswtch
563   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
564   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
565   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
566     rm ${LIB}/$file
567   fi
568 fi
569
570 # Fix an error in this file: a missing semi-colon at the end of the nodeent
571 # structure definition.
572 file=netdnet/dnetdb.h
573 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
574   mkdir ${LIB}/netdnet 2>/dev/null
575   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
576   chmod +w ${LIB}/$file 2>/dev/null
577   chmod a+r ${LIB}/$file 2>/dev/null
578 fi
579
580 if [ -r ${LIB}/$file ]; then
581   echo Fixing $file, definition of nodeent
582   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
583   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
584   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
585     rm ${LIB}/$file
586   fi
587 fi
588
589 # Check for bad #ifdef line (in Ultrix 4.1)
590 file=sys/file.h
591 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
592   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
593   chmod +w ${LIB}/$file 2>/dev/null
594   chmod a+r ${LIB}/$file 2>/dev/null
595 fi
596
597 if [ -r ${LIB}/$file ]; then
598   echo Fixing $file, bad \#ifdef line
599   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
600   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
601   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
602     rm ${LIB}/$file
603   fi
604 fi
605
606 # Check for superfluous `static' (in Ultrix 4.2)
607 file=machine/cpu.h
608 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
609   mkdir ${LIB}/machine 2>/dev/null
610   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
611   chmod +w ${LIB}/$file 2>/dev/null
612   chmod a+r ${LIB}/$file 2>/dev/null
613 fi
614
615 if [ -r ${LIB}/$file ]; then
616   echo Fixing $file, superfluous static
617   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
618   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
619   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
620     rm ${LIB}/$file
621   else
622 # This file has an alternative name, mips/cpu.h.  Fix that name, too.
623     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
624       mkdir ${LIB}/mips 2>&-
625       ln ${LIB}/$file ${LIB}/mips/cpu.h 
626     fi
627   fi
628 fi
629
630 # Incorrect sprintf declaration in X11/Xmu.h
631 file=X11/Xmu.h
632 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
633   mkdir ${LIB}/X11 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 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
651 # (It's not clear whether the right file name is this or X11/Xmu.h.)
652 file=X11/Xmu/Xmu.h
653 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
654   mkdir ${LIB}/X11/Xmu 2>/dev/null
655   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
656   chmod +w ${LIB}/$file 2>/dev/null
657   chmod a+r ${LIB}/$file 2>/dev/null
658 fi
659
660 if [ -r ${LIB}/$file ]; then
661   echo Fixing $file sprintf declaration
662   sed -e 's,^extern char \*     sprintf();$,#ifndef __STDC__\
663 extern char *   sprintf();\
664 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
665   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
666   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
667     rm ${LIB}/$file
668   fi
669 fi
670
671 # Check for missing ';' in struct
672 file=netinet/ip.h
673 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
674   mkdir ${LIB}/netinet 2>/dev/null
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 '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
683   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
684   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
685     rm -f ${LIB}/$file
686   fi
687 fi
688
689 # Fix the CAT macro in SunOS memvar.h.
690 file=pixrect/memvar.h
691 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
692   mkdir ${LIB}/pixrect 2>/dev/null
693   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
694   chmod +w ${LIB}/$file 2>/dev/null
695   chmod a+r ${LIB}/$file 2>/dev/null
696 fi
697
698 if [ -r ${LIB}/$file ]; then
699   echo Fixing $file
700   sed -e '/^#define.CAT(a,b)/ i\
701 #ifdef __STDC__ \
702 #define CAT(a,b) a##b\
703 #else
704 /^#define.CAT(a,b)/ a\
705 #endif
706 ' ${LIB}/$file > ${LIB}/${file}.sed
707   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
708   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
709     rm -f ${LIB}/$file
710   fi
711 fi
712
713 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
714 file=rpcsvc/rusers.h
715 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
716   mkdir ${LIB}/rpcsvc 2>/dev/null
717   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
718   chmod +w ${LIB}/$file 2>/dev/null
719   chmod a+r ${LIB}/$file 2>/dev/null
720 fi
721
722 if [ -r ${LIB}/$file ]; then
723   echo Fixing $file
724   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
725   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
726   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
727     rm -f ${LIB}/$file
728   fi
729 fi
730
731 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
732 # Also wrap protection around size_t for m88k-sysv3 systems.
733 file=stdlib.h
734 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
735   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
736   chmod +w ${LIB}/$file 2>/dev/null
737   chmod a+r ${LIB}/$file 2>/dev/null
738 fi
739
740 if [ -r ${LIB}/$file ]; then
741   echo Fixing $file
742   sed -e 's/int abort/void      abort/g' \
743   -e 's/int     free/void       free/g' \
744   -e 's/char \* calloc/void \*  calloc/g' \
745   -e 's/char \* malloc/void \*  malloc/g' \
746   -e 's/char \* realloc/void \* realloc/g' \
747   -e 's/int     exit/void       exit/g' \
748   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/i\
749 #ifndef _GCC_SIZE_T\
750 #define _GCC_SIZE_T' \
751   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/a\
752 #endif' \
753       ${LIB}/$file > ${LIB}/${file}.sed
754   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
755   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
756     rm -f ${LIB}/$file
757   fi
758 fi
759
760 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
761 file=malloc.h
762 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
763   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
764   chmod +w ${LIB}/$file 2>/dev/null
765   chmod a+r ${LIB}/$file 2>/dev/null
766 fi
767
768 if [ -r ${LIB}/$file ]; then
769   echo Fixing $file
770   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
771   -e 's/int[    ][      ]*free/void     free/g' \
772   ${LIB}/$file > ${LIB}/${file}.sed
773   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
774   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
775     rm -f ${LIB}/$file
776   fi
777 fi
778
779 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
780 file=hsfs/hsfs_spec.h
781 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
782   mkdir ${LIB}/hsfs 2>/dev/null
783   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
784   chmod +w ${LIB}/$file 2>/dev/null
785   chmod a+r ${LIB}/$file 2>/dev/null
786 fi
787
788 if [ -r ${LIB}/$file ]; then
789   echo Fixing $file
790   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
791     ${LIB}/$file > ${LIB}/${file}.
792   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
793   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
794     rm -f ${LIB}/$file
795   fi
796 fi
797
798 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
799 file=hsfs/hsnode.h
800 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
801   mkdir ${LIB}/hsfs 2>/dev/null
802   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
803   chmod +w ${LIB}/$file 2>/dev/null
804   chmod a+r ${LIB}/$file 2>/dev/null
805 fi
806
807 if [ -r ${LIB}/$file ]; then
808   echo Fixing $file
809   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
810     ${LIB}/$file > ${LIB}/${file}.sed
811   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
812   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
813     rm -f ${LIB}/$file
814   fi
815 fi
816
817 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
818 file=hsfs/iso_spec.h
819 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
820   mkdir ${LIB}/hsfs 2>/dev/null
821   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
822   chmod +w ${LIB}/$file 2>/dev/null
823   chmod a+r ${LIB}/$file 2>/dev/null
824 fi
825
826 if [ -r ${LIB}/$file ]; then
827   echo Fixing $file
828   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
829     ${LIB}/$file > ${LIB}/${file}.sed
830   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
831   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
832     rm -f ${LIB}/$file
833   fi
834 fi
835
836 # Incorrect #include in Sony News-OS 3.2.
837 file=machine/machparam.h
838 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
839   mkdir ${LIB}/machine 2>/dev/null
840   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
841   chmod +w ${LIB}/$file 2>/dev/null
842   chmod a+r ${LIB}/$file 2>/dev/null
843 fi
844
845 if [ -r ${LIB}/$file ]; then
846   echo Fixing $file, incorrect \#include
847   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
848     ${LIB}/$file > ${LIB}/${file}.
849   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
850   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
851     rm -f ${LIB}/$file
852   fi
853 fi
854
855 # Multiline comment after typedef on IRIX 4.0.1.
856 file=sys/types.h
857 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
858   mkdir ${LIB}/sys 2>/dev/null
859   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
860   chmod +w ${LIB}/$file 2>/dev/null
861   chmod a+r ${LIB}/$file 2>/dev/null
862 fi
863
864 if [ -r ${LIB}/$file ]; then
865   echo Fixing $file, comment in the middle of \#ifdef
866   sed -e 's@type of the result@type of the result */@' \
867     -e 's@of the sizeof@/* of the sizeof@' \
868     ${LIB}/$file > ${LIB}/${file}.sed
869   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
870   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
871     rm -f ${LIB}/$file
872   fi
873 fi
874
875 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
876 # header file, which embeds // comments inside multi-line /* */
877 # comments.  If this looks like the IRIX header file, we refix it by
878 # just throwing away the // comments.
879 file=fam.h
880 if [ -r ${LIB}/$file ]; then
881   if egrep indigo.esd ${LIB}/$file > /dev/null; then
882     echo Fixing $file, overeager sed script
883     rm ${LIB}/$file
884     sed -e 's|//.*$||g' $file > ${LIB}/$file
885     chmod +w ${LIB}/$file 2>/dev/null
886     chmod a+r ${LIB}/$file 2>/dev/null
887   fi
888 fi
889
890 # Some IRIX header files contains the string "//"
891 for file in elf_abi.h elf.h; do
892   if [ -r ${LIB}/$file ]; then
893     echo Fixing $file, overeager sed script
894     sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
895     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
896     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
897       rm -f ${LIB}/$file
898     fi
899   fi
900 done
901
902 # Same problem with a file from SunOS 4.1.3 : a header file containing
903 # the string "//" embedded in "/**/"
904 file=sbusdev/audiovar.h
905 if [ -r ${LIB}/$file ]; then
906   echo Fixing $file, overeager sed script
907   rm ${LIB}/$file
908   sed -e 's|//.*$||g' $file > ${LIB}/$file
909   chmod +w ${LIB}/$file 2>/dev/null
910   chmod a+r ${LIB}/$file 2>/dev/null
911 fi
912
913 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
914 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
915 # many other systems have similar text but correct versions of the file.
916 # To ensure only Sun's is fixed, we grep for a likely unique string.
917 file=memory.h
918 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
919   if [ ! -r ${LIB}/$file ]; then
920     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
921     chmod +w ${LIB}/$file 2>/dev/null
922     chmod a+r ${LIB}/$file 2>/dev/null
923   fi
924   if [ -r ${LIB}/$file ]; then
925     echo Replacing $file
926     cat > ${LIB}/$file << EOF
927 /* This file was generated by fixincludes */
928 #ifndef __memory_h__
929 #define __memory_h__
930
931 #ifdef __STDC__
932 extern void *memccpy();
933 extern void *memchr();
934 extern void *memcpy();
935 extern void *memset();
936 #else
937 extern char *memccpy();
938 extern char *memchr();
939 extern char *memcpy();
940 extern char *memset();
941 #endif /* __STDC__ */
942
943 extern int memcmp();
944
945 #endif /* __memory_h__ */
946 EOF
947   fi
948 fi
949
950 # parameters not const on DECstation Ultrix V4.0.
951 file=stdio.h
952 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
953   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
954   chmod +w ${LIB}/$file 2>/dev/null
955   chmod a+r ${LIB}/$file 2>/dev/null
956 fi
957
958 if [ -r ${LIB}/$file ]; then
959   echo Fixing $file, non-const arg
960   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
961       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
962       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
963       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
964       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
965       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
966       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
967     ${LIB}/$file > ${LIB}/${file}.sed
968   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
969   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
970     rm -f ${LIB}/$file
971   fi
972 fi
973
974 # parameters conflict with C++ new on rs/6000 
975 for file in stdio.h unistd.h ; do
976   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
977     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
978     chmod +w ${LIB}/$file 2>/dev/null
979   fi
980
981   if [ -r ${LIB}/$file ]; then
982     echo Fixing $file, parameter name conflicts
983     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
984       ${LIB}/$file > ${LIB}/${file}.sed
985     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
986     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
987       rm -f ${LIB}/$file
988     fi
989   fi
990 done
991
992 # function class(double x) conflicts with C++ keyword on rs/6000 
993 file=math.h
994 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
995   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
996   chmod +w ${LIB}/$file 2>/dev/null
997   chmod a+r ${LIB}/$file 2>/dev/null
998 fi
999
1000 if [ -r ${LIB}/$file ]; then
1001   if grep 'class[(]' ${LIB}/$file >/dev/null; then
1002     echo Fixing $file
1003     sed -e '/class[(]/i\
1004 #ifndef __cplusplus' \
1005         -e '/class[(]/a\
1006 #endif' ${LIB}/$file > ${LIB}/${file}.sed
1007     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1008     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1009       rm ${LIB}/$file
1010     fi
1011   fi
1012 fi
1013
1014 # Wrong fchmod prototype on RS/6000.
1015 file=sys/stat.h
1016 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1017   mkdir ${LIB}/sys 2>/dev/null
1018   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1019   chmod +w ${LIB}/$file 2>/dev/null
1020   chmod a+r ${LIB}/$file 2>/dev/null
1021 fi
1022
1023 if [ -r ${LIB}/$file ]; then
1024   echo Fixing $file, fchmod prototype
1025   sed -e 's/fchmod(char \*/fchmod(int/' \
1026     ${LIB}/$file > ${LIB}/$file.sed
1027   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1028   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1029     rm -f ${LIB}/$file
1030   fi
1031 fi
1032
1033 # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1034 # Note that version 3 of the NeXT system has wait.h in a different directory,
1035 # so that this code won't do anything.  But wait.h in version 3 has a
1036 # conditional, so it doesn't need this fix.  So everything is okay.
1037 file=sys/wait.h
1038 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1039   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1040   chmod +w ${LIB}/$file 2>/dev/null
1041 fi
1042
1043 if [ -r ${LIB}/$file ] \
1044   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
1045   echo Fixing $file, bad wait formal
1046   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
1047   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1048   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1049     rm -f ${LIB}/$file
1050   fi
1051 fi
1052
1053 # Don't use or define the name va_list in stdio.h.
1054 # This is for ANSI and also to interoperate properly with gvarargs.h.
1055 file=stdio.h
1056 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1057   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1058   chmod +w ${LIB}/$file 2>/dev/null
1059   chmod a+r ${LIB}/$file 2>/dev/null
1060 fi
1061
1062 if [ -r ${LIB}/$file ]; then
1063   echo Fixing $file, use of va_list
1064   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1065   (echo "#define __need___va_list"
1066    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1067   # Use __gnuc_va_list in arg types in place of va_list.
1068   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1069   # trailing parentheses and semicolon save all other systems from this.
1070   # Define __va_list__ (something harmless and unused) instead of va_list.
1071   # Don't claim to have defined va_list.
1072   sed -e 's@ va_list @ __gnuc_va_list @' \
1073       -e 's@ va_list)@ __gnuc_va_list)@' \
1074       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1075       -e 's@ va_list@ __va_list__@' \
1076       -e 's@\*va_list@*__va_list__@' \
1077       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1078       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1079       -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
1080     ${LIB}/$file >> ${LIB}/${file}.sed
1081   
1082   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1083   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1084     rm -f ${LIB}/$file
1085   fi
1086 fi
1087
1088 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1089 file=ansi_compat.h
1090 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1091   if grep -s ULTRIX $file; then
1092     echo "/* This file intentionally left blank.  */" > $LIB/$file
1093   fi
1094 fi
1095
1096 # parameter to atof not const on DECstation Ultrix V4.0.
1097 # also get rid of bogus inline definitions in HP-UX 8.0
1098 file=math.h
1099 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1100   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1101   chmod +w ${LIB}/$file 2>/dev/null
1102   chmod a+r ${LIB}/$file 2>/dev/null
1103 fi
1104
1105 if [ -r ${LIB}/$file ]; then
1106   echo Fixing $file, non-const arg
1107   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
1108       -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
1109       -e 's@inline double abs(double d) { return fabs(d); }@@' \
1110       -e 's@inline int sqr(int x) {return(x*x);}  /* For AT&T compatibility */@@' \
1111       -e 's@inline double sqr(double x) {return(x*x);}@@' \
1112     ${LIB}/$file > ${LIB}/${file}.sed
1113   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1114   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1115     rm -f ${LIB}/$file
1116   fi
1117 fi
1118
1119 # Avoid nested comments on Ultrix 4.3.
1120 file=rpc/svc.h
1121 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1122   mkdir ${LIB}/rpc 2>/dev/null
1123   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1124   chmod +w ${LIB}/$file 2>/dev/null
1125   chmod a+r ${LIB}/$file 2>/dev/null
1126 fi
1127
1128 if [ -r ${LIB}/$file ]; then
1129   echo Fixing $file, nested comment
1130   sed -e 's@^\( \*      int protocol;  \)/\*@\1*/ /*@' \
1131     ${LIB}/$file > ${LIB}/$file.sed
1132   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1133   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1134     rm -f ${LIB}/$file
1135   fi
1136 fi
1137
1138 # In limits.h, put #ifndefs around things that are supposed to be defined
1139 # in float.h to avoid redefinition errors if float.h is included first.
1140 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1141 # multi line comments and the inserted #endif winds up inside the
1142 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1143 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1144 # are there, and we do not add them ourselves.
1145 for file in limits.h sys/limits.h; do
1146   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1147     mkdir ${LIB}/sys 2>/dev/null
1148     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1149     chmod +w ${LIB}/$file 2>/dev/null
1150     chmod a+r ${LIB}/$file 2>/dev/null
1151   fi
1152
1153   if [ -r ${LIB}/$file ]; then
1154     if egrep 'ifndef[   ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1155       true
1156     else
1157       echo Fixing $file
1158       sed -e '/[        ]FLT_MIN[       ]/i\
1159 #ifndef FLT_MIN'\
1160           -e '/[        ]FLT_MIN[       ]/a\
1161 #endif'\
1162           -e '/[        ]FLT_MAX[       ]/i\
1163 #ifndef FLT_MAX'\
1164           -e '/[        ]FLT_MAX[       ]/a\
1165 #endif'\
1166           -e '/[        ]FLT_DIG[       ]/i\
1167 #ifndef FLT_DIG'\
1168           -e '/[        ]FLT_DIG[       ]/a\
1169 #endif'\
1170           -e '/[        ]DBL_MIN[       ]/i\
1171 #ifndef DBL_MIN'\
1172           -e '/[        ]DBL_MIN[       ]/a\
1173 #endif'\
1174           -e '/[        ]DBL_MAX[       ]/i\
1175 #ifndef DBL_MAX'\
1176           -e '/[        ]DBL_MAX[       ]/a\
1177 #endif'\
1178           -e '/[        ]DBL_DIG[       ]/i\
1179 #ifndef DBL_DIG'\
1180           -e '/[        ]DBL_DIG[       ]/a\
1181 #endif'\
1182         ${LIB}/$file > ${LIB}/${file}.sed
1183       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1184     fi
1185     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1186       echo Deleting ${LIB}/$file\; no fixes were needed.
1187       rm -f ${LIB}/$file
1188     fi
1189   fi
1190 done
1191
1192 # In math.h, put #ifndefs around things that might be defined in a gcc
1193 # specific math-*.h file.
1194 file=math.h
1195 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1196   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1197   chmod +w ${LIB}/$file 2>/dev/null
1198   chmod a+r ${LIB}/$file 2>/dev/null
1199 fi
1200
1201 if [ -r ${LIB}/$file ]; then
1202   echo Fixing $file
1203   sed -e '/define[      ]HUGE_VAL[      ]/i\
1204 #ifndef HUGE_VAL'\
1205       -e '/define[      ]HUGE_VAL[      ]/a\
1206 #endif'\
1207     ${LIB}/$file > ${LIB}/${file}.sed
1208   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1209   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1210     echo Deleting ${LIB}/$file\; no fixes were needed.
1211     rm -f ${LIB}/$file
1212   fi
1213 fi
1214
1215 # Remove erroneous parentheses in sym.h on Alpha OSF/1.
1216 file=sym.h
1217 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1218   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1219   chmod +w ${LIB}/$file 2>/dev/null
1220   chmod a+r ${LIB}/$file 2>/dev/null
1221 fi
1222
1223 if [ -r ${LIB}/$file ]; then
1224   echo Fixing $file
1225   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
1226     ${LIB}/$file > ${LIB}/${file}.sed
1227   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1228   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1229     rm -f ${LIB}/$file
1230   fi
1231 fi
1232
1233 # Fix incorrect S_IF* definitions on m88k-sysv3.
1234 file=sys/stat.h
1235 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1236   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1237   chmod +w ${LIB}/$file 2>/dev/null
1238   chmod a+r ${LIB}/$file 2>/dev/null
1239 fi
1240
1241 if [ -r ${LIB}/$file ]; then
1242   echo Fixing $file
1243   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)/' \
1244       -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(0[0-9]*\)[  ]*)/\1 (((m)\&S_IFMT)==\2)/' \
1245     ${LIB}/$file > ${LIB}/${file}.sed
1246   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1247   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1248     rm -f ${LIB}/$file
1249   fi
1250 fi
1251
1252 # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1.
1253 for file in stdio.h stdlib.h; do
1254   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1255     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1256     chmod +w ${LIB}/$file 2>/dev/null
1257     chmod a+r ${LIB}/$file 2>/dev/null
1258   fi
1259
1260   if [ -r ${LIB}/$file ]; then
1261     echo Fixing $file, getopt declaration
1262     sed -e 's/getopt(int, char \*\[\],char \*)/getopt(int, char *const[], const char *)/' \
1263       ${LIB}/$file > ${LIB}/${file}.sed
1264     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1265     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1266       rm -f ${LIB}/$file
1267     fi
1268   fi
1269 done
1270
1271 # These two files on SunOS 4 are included by other files
1272 # in the same directory, using "...".  So we must make sure they exist
1273 # in the same directory as the other fixed files.
1274 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1275 then
1276   ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1277 fi
1278 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1279 then
1280   ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1281 fi
1282
1283 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1284 # need to fix some additional files.  This is the same test for ISC that
1285 # Autoconf uses.
1286 if test -d /etc/conf/kconfig.d \
1287     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1288   echo "Fixing ISC __STDC__ goof in several files..."
1289   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1290     echo $name
1291     if test -r ${LIB}/$name; then
1292       file=${LIB}/$name
1293     else
1294       file=${INPUT}/$name
1295     fi
1296     # On Interactive 2.2, certain traditional Unix definitions
1297     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1298     # defined, not just if _POSIX_SOURCE is defined.  This makes it
1299     # impossible to compile any nontrivial program except with -posix.
1300     sed \
1301 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1302             < $file > ${LIB}/$name.
1303     mv ${LIB}/$name. ${LIB}/$name
1304   done
1305   
1306   echo "Fixing ISC fmod declaration"
1307   # This one's already been fixed for other things.
1308   file=${LIB}/math.h
1309   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1310   mv $file. $file
1311   
1312   echo "Fixing nested comments in ISC <sys/limits.h>"
1313   file=sys/limits.h
1314   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1315   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1316 fi
1317
1318 # These files in Sun OS 4.x use /**/ to concatenate tokens.
1319 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
1320         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
1321         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
1322 do
1323   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1324     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1325     chmod +w ${LIB}/$file 2>/dev/null
1326     chmod a+r ${LIB}/$file 2>/dev/null
1327   fi
1328
1329   if [ -r ${LIB}/$file ]; then
1330     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1331     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1332     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1333       rm -f ${LIB}/$file
1334     fi
1335   fi
1336 done
1337
1338 # These files in ARM/RISCiX use /**/ to concatenate tokens.
1339 for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
1340         dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
1341 do
1342   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1343     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1344     chmod +w ${LIB}/$file 2>/dev/null
1345     chmod a+r ${LIB}/$file 2>/dev/null
1346   fi
1347
1348   if [ -r ${LIB}/$file ]; then
1349     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1350     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1351     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1352       rm -f ${LIB}/$file
1353     fi
1354   fi
1355 done
1356
1357 echo 'Removing unneeded directories:'
1358 cd $LIB
1359 files=`find . -type d -print | sort -r`
1360 for file in $files; do
1361   rmdir $LIB/$file > /dev/null 2>&1
1362 done
1363
1364 if $LINKS; then
1365   echo 'Making internal symbolic non-directory links'
1366   cd ${INPUT}
1367   files=`find . -type l -print`
1368   for file in $files; do
1369     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1370     if expr "$dest" : '[^/].*' > /dev/null; then    
1371       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1372       if [ -f $target ]; then
1373         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1374       fi
1375     fi
1376   done
1377 fi
1378
1379 echo 'Cleaning up DONE files.'
1380 cd $LIB
1381 find . -name DONE -exec rm -f '{}' ';'
1382
1383 exit 0