OSDN Git Service

Canonicalize ${INPUT} to avoid automounter problems.
[pf3gnuchains/gcc-fork.git] / gcc / fixincludes
1 #! /bin/sh
2 # Install modified versions of certain ANSI-incompatible system header files
3 # which are fixed to work correctly with ANSI C
4 # and placed in a directory that GNU C will search.
5
6 # See README-fixinc for more information.
7
8 # Directory containing the original header files.
9 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
10 INPUT=${2-${INPUT-/usr/include}}
11
12 # Directory in which to store the results.
13 LIB=${1?"fixincludes: output directory not specified"}
14
15 # Define PWDCMD as a command to use to get the working dir
16 # in the form that we want.
17 PWDCMD=pwd
18 case "`pwd`" in
19 //*)
20         # On an Apollo, discard everything before `/usr'.
21         PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
22         ;;
23 esac
24
25 # Original directory.
26 ORIGDIR=`${PWDCMD}`
27
28 # Make sure it exists.
29 if [ ! -d $LIB ]; then
30   mkdir $LIB || exit 1
31 fi
32
33 # Make LIB absolute only if needed to avoid problems with the amd.
34 case $LIB in
35 /*)
36         ;;
37 *)
38         cd $LIB; LIB=`${PWDCMD}`
39         ;;
40 esac
41
42 # Fail if no arg to specify a directory for the output.
43 if [ x$1 = x ]
44 then echo fixincludes: no output directory specified
45 exit 1
46 fi
47
48 echo Building fixed headers in ${LIB}
49
50 # Determine whether this system has symbolic links.
51 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
52   rm -f $LIB/ShouldNotExist
53   LINKS=true
54 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
55   rm -f /tmp/ShouldNotExist
56   LINKS=true
57 else
58   LINKS=false
59 fi
60
61 echo Finding directories and links to directories
62 cd ${INPUT}
63 # Find all directories and all symlinks that point to directories.
64 # Put the list in $files.
65 # Each time we find a symlink, add it to newdirs
66 # so that we do another find within the dir the link points to.
67 # Note that $files may have duplicates in it;
68 # later parts of this file are supposed to ignore them.
69 dirs="."
70 levels=2
71 while [ -n "$dirs" ] && [ $levels -gt 0 ]
72 do
73     levels=`expr $levels - 1`
74     newdirs=
75     for d in $dirs
76     do
77         echo " Searching $INPUT/$d"
78         if [ "$d" != . ]
79         then
80             d=$d/.
81         fi
82
83         # Find all directories under $d, relative to $d, excluding $d itself.
84         files="$files `find $d -type d -print | \
85                        sed -e '/\/\.$/d' -e '/^\.$/d'`"
86         # Find all links to directories.
87         # Using `-exec test -d' in find fails on some systems,
88         # and trying to run test via sh fails on others,
89         # so this is the simplest alternative left.
90         # First find all the links, then test each one.
91         theselinks=
92         $LINKS && \
93           theselinks=`find $d -type l -print`
94         for d1 in $theselinks --dummy--
95         do
96             # If the link points to a directory,
97             # add that dir to $newdirs
98             if [ -d $d1 ]
99             then
100                 files="$files $d1"
101                 if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
102                 then
103                     newdirs="$newdirs $d1"
104                 fi
105             fi
106         done
107     done
108
109     dirs="$newdirs"
110 done
111
112 dirs=
113 echo "All directories (including links to directories):"
114 echo $files
115
116 for file in $files; do
117   rm -rf $LIB/$file
118   if [ ! -d $LIB/$file ]
119   then mkdir $LIB/$file
120   fi
121 done
122 mkdir $LIB/root
123
124 # treetops gets an alternating list
125 # of old directories to copy
126 # and the new directories to copy to.
127 treetops="${INPUT} ${LIB}"
128
129 if $LINKS; then
130   echo 'Making symbolic directory links'
131   for file in $files; do
132     dest=`ls -ld $file | sed -n 's/.*-> //p'`
133     if [ "$dest" ]; then    
134       cwd=`${PWDCMD}`
135       # In case $dest is relative, get to $file's dir first.
136       cd ${INPUT}
137       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
138       # Check that the target directory exists.
139       # Redirections changed to avoid bug in sh on Ultrix.
140       (cd $dest) > /dev/null 2>&1
141       if [ $? = 0 ]; then
142         cd $dest
143         # X gets the dir that the link actually leads to.
144         x=`${PWDCMD}`
145         # Canonicalize ${INPUT} now to minimize the time an
146         # automounter has to change the result of ${PWDCMD}.
147         cinput=`cd ${INPUT}; ${PWDCMD}`
148         # If a link points to ., make a similar link to .
149         if [ $x = ${cinput} ]; then
150           echo $file '->' . ': Making link'
151           rm -fr ${LIB}/$file > /dev/null 2>&1
152           ln -s . ${LIB}/$file > /dev/null 2>&1
153         # If link leads back into ${INPUT},
154         # make a similar link here.
155         elif expr $x : "${cinput}/.*" > /dev/null; then
156           # Y gets the actual target dir name, relative to ${INPUT}.
157           y=`echo $x | sed -n "s&${cinput}/&&p"`
158           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
159           dots=`echo "$file" |
160             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
161           echo $file '->' $dots$y ': Making link'
162           rm -fr ${LIB}/$file > /dev/null 2>&1
163           ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
164         else
165           # If the link is to a dir $target outside ${INPUT},
166           # repoint the link at ${INPUT}/root$target
167           # and process $target into ${INPUT}/root$target
168           # treat this directory as if it actually contained the files.
169           echo $file '->' root$x ': Making link'
170           if [ -d $LIB/root$x ]
171           then true
172           else
173             dirname=root$x/
174             dirmade=.
175             cd $LIB
176             while [ x$dirname != x ]; do
177               component=`echo $dirname | sed -e 's|/.*$||'`
178               mkdir $component >/dev/null 2>&1
179               cd $component
180               dirmade=$dirmade/$component
181               dirname=`echo $dirname | sed -e 's|[^/]*/||'`
182             done
183           fi
184           # Duplicate directory structure created in ${LIB}/$file in new
185           # root area.
186           for file2 in $files; do
187             case $file2 in
188               $file/./*)
189                 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
190                 echo "Duplicating ${file}'s ${dupdir}"
191                 if [ -d ${dupdir} ]
192                 then true
193                 else
194                   mkdir ${dupdir}
195                 fi
196                 ;;
197               *)
198                 ;;
199             esac
200           done
201           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
202           dots=`echo "$file" |
203             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
204           rm -fr ${LIB}/$file > /dev/null 2>&1
205           ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
206           treetops="$treetops $x ${LIB}/root$x"
207         fi
208       fi
209       cd $cwd
210     fi
211   done
212 fi
213
214 required=
215 set x $treetops
216 shift
217 while [ $# != 0 ]; do
218   # $1 is an old directory to copy, and $2 is the new directory to copy to.
219   cd ${INPUT}
220   cd $1
221 # The same dir can appear more than once in treetops.
222 # There's no need to scan it more than once.
223   if [ -f $2/DONE ]
224   then
225     files=
226   else
227     touch $2/DONE
228     echo Fixing directory $1 into $2
229 # Check .h files which are symlinks as well as those which are files.
230 # A link to a header file will not be processed by anything but this.
231     if $LINKS; then
232       files=`find . -name '*.h' \( -type f -o -type l \) -print`
233     else
234       files=`find . -name '*.h' -type f -print`
235     fi
236     echo Checking header files
237   fi
238 # Note that BSD43_* are used on recent MIPS systems.
239   for file in $files; do
240 # This call to egrep is essential, since checking a file with egrep
241 # is much faster than actually trying to fix it.
242 # It is also essential that most files *not* match!
243 # Thus, matching every #endif is unacceptable.
244 # But the argument to egrep must be kept small, or many versions of egrep
245 # won't be able to handle it.
246 #
247 # We use the pattern [!-.0-~] instead of [^/    ] to match a noncomment
248 # following #else or #endif because some buggy egreps think [^/] matches
249 # newline, and they thus think `#else ' matches `#e[ndiflse]*[  ]+[^/   ]'.
250 #
251 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
252 # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
253 # in this pattern lacks `d' and `l'; this means we don't worry about
254 # identifiers starting with `d' or `l'.  This is OK, since none of the
255 # identifiers below start with `d' or `l'.  It also greatly improves
256 # performance, since many files contain lines of the form `#if ... defined ...'
257 # or `#if lint'.
258     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
259       if [ -r $file ]; then
260         cp $file $2/$file >/dev/null 2>&1       \
261         || echo "Can't copy $file"
262         chmod +w $2/$file
263         chmod a+r $2/$file
264         # Here is how the sed commands in braces work.
265         # (It doesn't work to put the comments inside the sed commands.)
266                 # Surround each word with spaces, to simplify matching below.
267                 # ANSIfy each pre-ANSI machine-dependent symbol
268                 # by surrounding it with __ __.
269                 # Remove the spaces that we inserted around each word.
270         sed -e '
271                                    :loop
272           /\\$/                 N
273           /\\$/                 b loop
274           s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
275           s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
276           s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
277           s%^\([        ]*#[    ]*endif\)[      ]*\*[^/].*%\1%
278           s%^\([        ]*#[    ]*endif\)[      ]*[^/*  ].*%\1%
279           /\/\/[^*]/                    s|//\(.*\)$|/*\1*/|
280           /[    ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[  ]*(\)\(.\),/\1'\''\2'\'',/
281           /[    ]BSD43__IO[A-Z]*[       ]*(/    s/(\(.\),/('\''\1'\'',/
282           /#define._IO/                 s/'\''\([cgxtf]\)'\''/\1/g
283           /#define.BSD43__IO/           s/'\''\([cgx]\)'\''/\1/g
284           /[^A-Z0-9_]CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
285           /[^A-Z0-9]_CTRL[      ]*(/            s/\([^'\'']\))/'\''\1'\'')/
286           /#define[     ]*[     ]CTRL/          s/'\''\([cgx]\)'\''/\1/g
287           /#define[     ]*[     ]_CTRL/         s/'\''\([cgx]\)'\''/\1/g
288           /#define.BSD43_CTRL/          s/'\''\([cgx]\)'\''/\1/g
289           /#[el]*if/{
290                 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
291
292                 s/ bsd4\([0-9]\) / __bsd4\1__ /g
293                 s/ _*host_mips / __host_mips__ /g
294                 s/ _*i386 / __i386__ /g
295                 s/ M32 / __M32__ /g
296                 s/ is68k / __is68k__ /g
297                 s/ m68k / __m68k__ /g
298                 s/ mc680\([0-9]\)0 / __mc680\10__ /g
299                 s/ m88k / __m88k__ /g
300                 s/ _*mips / __mips__ /g
301                 s/ news\([0-9]*\) / __news\1__ /g
302                 s/ ns32000 / __ns32000__ /g
303                 s/ pdp11 / __pdp11__ /g
304                 s/ pyr / __pyr__ /g
305                 s/ sony_news / __sony_news__ /g
306                 s/ sparc / __sparc__ /g
307                 s/ sun\([a-z0-9]*\) / __sun\1__ /g
308                 s/ tower\([_0-9]*\) / __tower\1__ /g
309                 s/ u370 / __u370__ /g
310                 s/ u3b\([0-9]*\) / __u3b\1__ /g
311                 s/ unix / __unix__ /g
312                 s/ vax / __vax__ /g
313                 s/ _*MIPSE\([LB]\) / __MIPSE\1__ /g
314                 s/ _*R\([34]\)000 / __R\1000__ /g
315                 s/ _*SYSTYPE_\([A-Z0-9]*\) / __SYSTYPE_\1__ /g
316
317                 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
318           }
319           /^#define.NULL[       ]/      i\
320                 #undef NULL
321         ' $2/$file > $2/$file.
322         mv $2/$file. $2/$file
323         if cmp $file $2/$file >/dev/null 2>&1 \
324             || egrep 'This file is part of the GNU C Library' $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 cd ${INPUT}
341
342 # Install the proper definition of the three standard types in header files
343 # that they come from.
344 for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
345   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
346     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
347     chmod +w ${LIB}/$file 2>/dev/null
348     chmod a+r ${LIB}/$file 2>/dev/null
349   fi
350
351   if [ -r ${LIB}/$file ]; then
352     echo Fixing size_t, ptrdiff_t and wchar_t in $file
353     sed \
354       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]size_t/i\
355 #ifndef __SIZE_TYPE__\
356 #define __SIZE_TYPE__ long unsigned int\
357 #endif
358 ' \
359       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]size_t/typedef __SIZE_TYPE__ size_t/' \
360       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/i\
361 #ifndef __PTRDIFF_TYPE__\
362 #define __PTRDIFF_TYPE__ long int\
363 #endif
364 ' \
365       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
366       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]wchar_t/i\
367 #ifndef __WCHAR_TYPE__\
368 #define __WCHAR_TYPE__ int\
369 #endif
370 ' \
371       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
372       ${LIB}/$file > ${LIB}/${file}.sed
373     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
374     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
375       rm ${LIB}/$file
376     fi
377   fi
378 done
379
380 # Fix one other error in this file: a mismatched quote not inside a C comment.
381 file=sundev/vuid_event.h
382 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
383   mkdir ${LIB}/sundev 2>/dev/null
384   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
385   chmod +w ${LIB}/$file 2>/dev/null
386   chmod a+r ${LIB}/$file 2>/dev/null
387 fi
388
389 if [ -r ${LIB}/$file ]; then
390   echo Fixing $file comment
391   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
392   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
393   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
394     rm ${LIB}/$file
395   fi
396 fi
397
398 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
399 file=sunwindow/win_cursor.h
400 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
401 #  mkdir ${LIB}/sunwindow 2>/dev/null
402   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
403   chmod +w ${LIB}/$file 2>/dev/null
404 fi
405 if [ -r ${LIB}/$file ]; then
406   echo Fixing $file
407   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
408   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
409   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
410     rm ${LIB}/$file
411   fi
412 fi
413 file=sunwindow/win_lock.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
428 # Fix this Sun file to avoid interfering with stddef.h.
429 file=sys/stdtypes.h
430 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
431   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
432   chmod +w ${LIB}/$file 2>/dev/null
433   chmod a+r ${LIB}/$file 2>/dev/null
434 fi
435
436 if [ -r ${LIB}/$file ]; then
437   echo Fixing $file
438 sed -e '/[       ]size_t.*;/i\
439 #ifndef _GCC_SIZE_T\
440 #define _GCC_SIZE_T
441 ' \
442     -e '/[       ]size_t.*;/a\
443 #endif
444 ' \
445     -e '/[       ]ptrdiff_t.*;/i\
446 #ifndef _GCC_PTRDIFF_T\
447 #define _GCC_PTRDIFF_T
448 ' \
449     -e '/[       ]ptrdiff_t.*;/a\
450 #endif
451 ' \
452     -e '/[       ]wchar_t.*;/i\
453 #ifndef _GCC_WCHAR_T\
454 #define _GCC_WCHAR_T
455 ' \
456     -e '/[       ]wchar_t.*;/a\
457 #endif
458 ' ${LIB}/$file > ${LIB}/${file}.sed
459   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
460   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
461     rm ${LIB}/$file
462   fi
463 fi
464
465 # Fix this ARM/RISCiX file to avoid interfering with the use of __wchar_t
466 # in cc1plus.
467 file=stdlib.h
468 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
469   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
470   chmod +w ${LIB}/$file 2>/dev/null
471   chmod a+r ${LIB}/$file 2>/dev/null
472 fi
473
474 if [ -r ${LIB}/$file ]; then
475   echo Fixing $file
476   sed -e "s/\(#[        ]*ifndef[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
477       -e "s/\(#[        ]*define[       ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
478      ${LIB}/$file > ${LIB}/${file}.sed
479   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
480   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
481     rm ${LIB}/$file
482   fi
483 fi
484
485 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
486 # match ssize_t present in AIX for the ps/2, or typedefs which use (but do not
487 # set) size_t.
488 file=sys/types.h
489 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
490   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
491   chmod +w ${LIB}/$file 2>/dev/null
492   chmod a+r ${LIB}/$file 2>/dev/null
493 fi
494
495 if [ -r ${LIB}/$file ]; then
496   echo Fixing $file
497 sed -e '/typedef[       ][      ]*[A-Za-z_][    A-Za-z_]*[      ]size_t/i\
498 #ifndef _GCC_SIZE_T\
499 #define _GCC_SIZE_T
500 ' \
501     -e '/typedef[       ][      ]*[A-Za-z_][    A-Za-z_]*[      ]size_t/a\
502 #endif
503 ' ${LIB}/$file > ${LIB}/${file}.sed
504   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
505   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
506     rm ${LIB}/$file
507   fi
508 fi
509
510 # Fix HP's use of ../machine/inline.h to refer to
511 # /usr/include/machine/inline.h
512 file=sys/spinlock.h
513 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
514   cp $file ${LIB}/$file
515 fi
516 if [ -r ${LIB}/$file ] ; then
517   echo Fixing $file
518   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
519     -e 's,"../machine/psl.h",<machine/psl.h>,' \
520   ${LIB}/$file > ${LIB}/${file}.sed
521   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
522   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
523     rm ${LIB}/$file
524   fi
525 fi
526
527 # Fix an error in this file: the #if says _cplusplus, not the double
528 # underscore __cplusplus that it should be
529 file=tinfo.h
530 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
531   mkdir ${LIB}/rpcsvc 2>/dev/null
532   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
533   chmod +w ${LIB}/$file 2>/dev/null
534   chmod a+r ${LIB}/$file 2>/dev/null
535 fi
536
537 if [ -r ${LIB}/$file ]; then
538   echo Fixing $file, __cplusplus macro
539   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
540   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
541   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
542     rm ${LIB}/$file
543   fi
544 fi
545
546 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
547 # structure definition.
548 file=rpcsvc/rstat.h
549 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
550   mkdir ${LIB}/rpcsvc 2>/dev/null
551   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
552   chmod +w ${LIB}/$file 2>/dev/null
553   chmod a+r ${LIB}/$file 2>/dev/null
554 fi
555
556 if [ -r ${LIB}/$file ]; then
557   echo Fixing $file, definition of statsswtch
558   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
559   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
560   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
561     rm ${LIB}/$file
562   fi
563 fi
564
565 # Fix an error in this file: a missing semi-colon at the end of the nodeent
566 # structure definition.
567 file=netdnet/dnetdb.h
568 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
569   mkdir ${LIB}/netdnet 2>/dev/null
570   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
571   chmod +w ${LIB}/$file 2>/dev/null
572   chmod a+r ${LIB}/$file 2>/dev/null
573 fi
574
575 if [ -r ${LIB}/$file ]; then
576   echo Fixing $file, definition of nodeent
577   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
578   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
579   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
580     rm ${LIB}/$file
581   fi
582 fi
583
584 # Check for bad #ifdef line (in Ultrix 4.1)
585 file=sys/file.h
586 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
587   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
588   chmod +w ${LIB}/$file 2>/dev/null
589   chmod a+r ${LIB}/$file 2>/dev/null
590 fi
591
592 if [ -r ${LIB}/$file ]; then
593   echo Fixing $file, bad \#ifdef line
594   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
595   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
596   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
597     rm ${LIB}/$file
598   fi
599 fi
600
601 # Check for superfluous `static' (in Ultrix 4.2)
602 # On Ultrix 4.3, includes of other files (r3_cpu.h,r4_cpu.h) is broken.
603 file=machine/cpu.h
604 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
605   mkdir ${LIB}/machine 2>/dev/null
606   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
607   chmod +w ${LIB}/$file 2>/dev/null
608   chmod a+r ${LIB}/$file 2>/dev/null
609 fi
610
611 if [ -r ${LIB}/$file ]; then
612   echo Fixing $file, superfluous static and broken includes of other files.
613   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' \
614       -e 's/^#include "r3_cpu\.h"$/#include <machine\/r3_cpu\.h>/' \
615       -e 's/^#include "r4_cpu\.h"$/#include <machine\/r4_cpu\.h>/' \
616       ${LIB}/$file > ${LIB}/${file}.sed
617   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
618   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
619     rm ${LIB}/$file
620   else
621 # This file has an alternative name, mips/cpu.h.  Fix that name, too.
622     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
623       mkdir ${LIB}/mips 2>&-
624 # Don't remove the file first, they may be the same file!
625       ln ${LIB}/$file ${LIB}/mips/cpu.h > /dev/null 2>&1
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 ' \
752   -e '/typedef[         a-zA-Z_]*[      ]size_t[        ]*;/a\
753 #endif
754 ' \
755       ${LIB}/$file > ${LIB}/${file}.sed
756   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
757   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
758     rm -f ${LIB}/$file
759   fi
760 fi
761
762 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
763 file=malloc.h
764 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
765   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
766   chmod +w ${LIB}/$file 2>/dev/null
767   chmod a+r ${LIB}/$file 2>/dev/null
768 fi
769
770 if [ -r ${LIB}/$file ]; then
771   echo Fixing $file
772   sed -e 's/typedef[    ]char \*        malloc_t/typedef void \*        malloc_t/g' \
773   -e 's/int[    ][      ]*free/void     free/g' \
774   ${LIB}/$file > ${LIB}/${file}.sed
775   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
776   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
777     rm -f ${LIB}/$file
778   fi
779 fi
780
781 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
782 file=hsfs/hsfs_spec.h
783 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
784   mkdir ${LIB}/hsfs 2>/dev/null
785   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
786   chmod +w ${LIB}/$file 2>/dev/null
787   chmod a+r ${LIB}/$file 2>/dev/null
788 fi
789
790 if [ -r ${LIB}/$file ]; then
791   echo Fixing $file
792   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
793     ${LIB}/$file > ${LIB}/${file}.
794   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
795   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
796     rm -f ${LIB}/$file
797   fi
798 fi
799
800 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
801 file=hsfs/hsnode.h
802 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
803   mkdir ${LIB}/hsfs 2>/dev/null
804   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
805   chmod +w ${LIB}/$file 2>/dev/null
806   chmod a+r ${LIB}/$file 2>/dev/null
807 fi
808
809 if [ -r ${LIB}/$file ]; then
810   echo Fixing $file
811   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
812     ${LIB}/$file > ${LIB}/${file}.sed
813   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
814   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
815     rm -f ${LIB}/$file
816   fi
817 fi
818
819 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
820 file=hsfs/iso_spec.h
821 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
822   mkdir ${LIB}/hsfs 2>/dev/null
823   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
824   chmod +w ${LIB}/$file 2>/dev/null
825   chmod a+r ${LIB}/$file 2>/dev/null
826 fi
827
828 if [ -r ${LIB}/$file ]; then
829   echo Fixing $file
830   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
831     ${LIB}/$file > ${LIB}/${file}.sed
832   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
833   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
834     rm -f ${LIB}/$file
835   fi
836 fi
837
838 # Incorrect #include in Sony News-OS 3.2.
839 file=machine/machparam.h
840 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
841   mkdir ${LIB}/machine 2>/dev/null
842   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
843   chmod +w ${LIB}/$file 2>/dev/null
844   chmod a+r ${LIB}/$file 2>/dev/null
845 fi
846
847 if [ -r ${LIB}/$file ]; then
848   echo Fixing $file, incorrect \#include
849   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
850     ${LIB}/$file > ${LIB}/${file}.
851   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
852   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
853     rm -f ${LIB}/$file
854   fi
855 fi
856
857 # Multiline comment after typedef on IRIX 4.0.1.
858 file=sys/types.h
859 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
860   mkdir ${LIB}/sys 2>/dev/null
861   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
862   chmod +w ${LIB}/$file 2>/dev/null
863   chmod a+r ${LIB}/$file 2>/dev/null
864 fi
865
866 if [ -r ${LIB}/$file ]; then
867   echo Fixing $file, comment in the middle of \#ifdef
868   sed -e 's@type of the result@type of the result */@' \
869     -e 's@of the sizeof@/* of the sizeof@' \
870     ${LIB}/$file > ${LIB}/${file}.sed
871   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
872   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
873     rm -f ${LIB}/$file
874   fi
875 fi
876
877 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
878 # header file, which embeds // comments inside multi-line /* */
879 # comments.  If this looks like the IRIX header file, we refix it by
880 # just throwing away the // comments.
881 file=fam.h
882 if [ -r ${LIB}/$file ]; then
883   if egrep indigo.esd ${LIB}/$file > /dev/null; then
884     echo Fixing $file, overeager sed script
885     rm ${LIB}/$file
886     sed -e 's|//.*$||g' $file > ${LIB}/$file
887     chmod +w ${LIB}/$file 2>/dev/null
888     chmod a+r ${LIB}/$file 2>/dev/null
889   fi
890 fi
891
892 # Some IRIX header files contains the string "//"
893 for file in elf_abi.h elf.h; do
894   if [ -r ${LIB}/$file ]; then
895     echo Fixing $file, overeager sed script
896     sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
897     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
898     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
899       rm -f ${LIB}/$file
900     fi
901   fi
902 done
903
904 # IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr in prototype without
905 # previous definition.
906 file=rpc/auth.h
907 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
908   mkdir ${LIB}/rpc 2>/dev/null
909   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
910   chmod +w ${LIB}/$file 2>/dev/null
911   chmod a+r ${LIB}/$file 2>/dev/null
912 fi
913
914 if [ -r ${LIB}/$file ]; then
915   echo Fixing $file, undefined type
916   sed -e '/authdes_create.*struct sockaddr/i\
917 struct sockaddr;
918 ' \
919     ${LIB}/$file > ${LIB}/$file.sed
920   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
921   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
922     rm -f ${LIB}/$file
923   fi
924 fi
925
926 # IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s in prototype without previous
927 # definition.
928 file=rpc/xdr.h
929 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
930   mkdir ${LIB}/rpc 2>/dev/null
931   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
932   chmod +w ${LIB}/$file 2>/dev/null
933   chmod a+r ${LIB}/$file 2>/dev/null
934 fi
935
936 if [ -r ${LIB}/$file ]; then
937   echo Fixing $file, undefined type
938   sed -e '/xdrstdio_create.*struct __file_s/i\
939 struct __file_s;
940 ' \
941     ${LIB}/$file > ${LIB}/$file.sed
942   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
943   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
944     rm -f ${LIB}/$file
945   fi
946 fi
947
948 # Same problem with a file from SunOS 4.1.3 : a header file containing
949 # the string "//" embedded in "/**/"
950 file=sbusdev/audiovar.h
951 if [ -r ${LIB}/$file ]; then
952   echo Fixing $file, overeager sed script
953   rm ${LIB}/$file
954   sed -e 's|//.*$||g' $file > ${LIB}/$file
955   chmod +w ${LIB}/$file 2>/dev/null
956   chmod a+r ${LIB}/$file 2>/dev/null
957 fi
958
959 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
960 # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
961 # many other systems have similar text but correct versions of the file.
962 # To ensure only Sun's is fixed, we grep for a likely unique string.
963 file=memory.h
964 if [ -r $file ] && egrep '/\*   @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2   \*/' $file > /dev/null; then
965   if [ ! -r ${LIB}/$file ]; then
966     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
967     chmod +w ${LIB}/$file 2>/dev/null
968     chmod a+r ${LIB}/$file 2>/dev/null
969   fi
970   if [ -r ${LIB}/$file ]; then
971     echo Replacing $file
972     cat > ${LIB}/$file << EOF
973 /* This file was generated by fixincludes */
974 #ifndef __memory_h__
975 #define __memory_h__
976
977 #ifdef __STDC__
978 extern void *memccpy();
979 extern void *memchr();
980 extern void *memcpy();
981 extern void *memset();
982 #else
983 extern char *memccpy();
984 extern char *memchr();
985 extern char *memcpy();
986 extern char *memset();
987 #endif /* __STDC__ */
988
989 extern int memcmp();
990
991 #endif /* __memory_h__ */
992 EOF
993   fi
994 fi
995
996 # parameters not const on DECstation Ultrix V4.0.
997 file=stdio.h
998 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
999   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1000   chmod +w ${LIB}/$file 2>/dev/null
1001   chmod a+r ${LIB}/$file 2>/dev/null
1002 fi
1003
1004 if [ -r ${LIB}/$file ]; then
1005   echo Fixing $file, non-const arg
1006   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
1007       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
1008       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
1009       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
1010       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
1011       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
1012       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
1013     ${LIB}/$file > ${LIB}/${file}.sed
1014   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1015   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1016     rm -f ${LIB}/$file
1017   fi
1018 fi
1019
1020 # parameters conflict with C++ new on rs/6000 
1021 for file in stdio.h unistd.h ; do
1022   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1023     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1024     chmod +w ${LIB}/$file 2>/dev/null
1025   fi
1026
1027   if [ -r ${LIB}/$file ]; then
1028     echo Fixing $file, parameter name conflicts
1029     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
1030       ${LIB}/$file > ${LIB}/${file}.sed
1031     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1032     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1033       rm -f ${LIB}/$file
1034     fi
1035   fi
1036 done
1037
1038 # function class(double x) conflicts with C++ keyword on rs/6000 
1039 file=math.h
1040 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1041   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1042   chmod +w ${LIB}/$file 2>/dev/null
1043   chmod a+r ${LIB}/$file 2>/dev/null
1044 fi
1045
1046 if [ -r ${LIB}/$file ]; then
1047   if grep 'class[(]' ${LIB}/$file >/dev/null; then
1048     echo Fixing $file
1049     sed -e '/class[(]/i\
1050 #ifndef __cplusplus
1051 ' \
1052         -e '/class[(]/a\
1053 #endif
1054 ' ${LIB}/$file > ${LIB}/${file}.sed
1055     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1056     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1057       rm ${LIB}/$file
1058     fi
1059   fi
1060 fi
1061
1062 # Wrong fchmod prototype on RS/6000.
1063 file=sys/stat.h
1064 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1065   mkdir ${LIB}/sys 2>/dev/null
1066   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1067   chmod +w ${LIB}/$file 2>/dev/null
1068   chmod a+r ${LIB}/$file 2>/dev/null
1069 fi
1070
1071 if [ -r ${LIB}/$file ]; then
1072   echo Fixing $file, fchmod prototype
1073   sed -e 's/fchmod(char \*/fchmod(int/' \
1074     ${LIB}/$file > ${LIB}/$file.sed
1075   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1076   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1077     rm -f ${LIB}/$file
1078   fi
1079 fi
1080
1081 # There are several name conflicts with C++ reserved words in X11
1082 # header files.  These are fixed in some versions, so don't do the
1083 # fixes if we find __cplusplus in the file.  These were found on the
1084 # RS/6000.
1085
1086 # class in X11/ShellP.h
1087 file=X11/ShellP.h
1088 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1089   mkdir ${LIB}/sys 2>/dev/null
1090   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1091   chmod +w ${LIB}/$file 2>/dev/null
1092   chmod a+r ${LIB}/$file 2>/dev/null
1093 fi
1094
1095 if [ -r ${LIB}/$file ]; then
1096   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1097     true;
1098   else
1099     echo Fixing $file, field class
1100     sed -e '/char [*]class;/i\
1101 #ifdef __cplusplus\
1102         char *c_class;\
1103 #else
1104 ' \
1105         -e '/char [*]class;/a\
1106 #endif
1107 ' ${LIB}/$file > ${LIB}/${file}.sed
1108     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1109   fi
1110   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1111     rm -f ${LIB}/$file
1112   fi
1113 fi
1114 # new in Xm/Traversal.h
1115 file=Xm/Traversal.h
1116 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1117   mkdir ${LIB}/sys 2>/dev/null
1118   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1119   chmod +w ${LIB}/$file 2>/dev/null
1120   chmod a+r ${LIB}/$file 2>/dev/null
1121 fi
1122
1123 if [ -r ${LIB}/$file ]; then
1124   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1125     true;
1126   else
1127     echo Fixing $file, uses of new
1128     sed -e '/Widget     old, new;/i\
1129 #ifdef __cplusplus\
1130         Widget  old, c_new;\
1131 #else
1132 ' \
1133         -e '/Widget     old, new;/a\
1134 #endif
1135 ' \
1136         -e 's/Widget new,/Widget c_new,/g' ${LIB}/$file > ${LIB}/${file}.sed
1137     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1138   fi
1139   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1140     rm -f ${LIB}/$file
1141   fi
1142 fi
1143 # class in Xm/BaseClassI.h
1144 file=Xm/BaseClassI.h
1145 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1146   mkdir ${LIB}/sys 2>/dev/null
1147   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1148   chmod +w ${LIB}/$file 2>/dev/null
1149   chmod a+r ${LIB}/$file 2>/dev/null
1150 fi
1151
1152 if [ -r ${LIB}/$file ]; then
1153   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
1154     true;
1155   else
1156     echo Fixing $file, prototype parameter name
1157     sed -e 's/ class[)]/ c_class)/g' ${LIB}/$file > ${LIB}/${file}.sed
1158     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1159   fi
1160   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1161     rm -f ${LIB}/$file
1162   fi
1163 fi
1164
1165
1166 # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
1167 # Note that version 3 of the NeXT system has wait.h in a different directory,
1168 # so that this code won't do anything.  But wait.h in version 3 has a
1169 # conditional, so it doesn't need this fix.  So everything is okay.
1170 file=sys/wait.h
1171 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1172   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1173   chmod +w ${LIB}/$file 2>/dev/null
1174 fi
1175
1176 if [ -r ${LIB}/$file ] \
1177   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
1178   echo Fixing $file, bad wait formal
1179   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
1180   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1181   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1182     rm -f ${LIB}/$file
1183   fi
1184 fi
1185
1186 # Don't use or define the name va_list in stdio.h.
1187 # This is for ANSI and also to interoperate properly with gcc's varargs.h.
1188 file=stdio.h
1189 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1190   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1191   chmod +w ${LIB}/$file 2>/dev/null
1192   chmod a+r ${LIB}/$file 2>/dev/null
1193 fi
1194
1195 if [ -r ${LIB}/$file ]; then
1196   echo Fixing $file, use of va_list
1197   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
1198   if egrep "__need___va_list" ${LIB}/$file >/dev/null 2>&1; then
1199     touch ${LIB}/${file}.sed
1200   else
1201     (echo "#define __need___va_list"
1202      echo "#include <stdarg.h>") > ${LIB}/${file}.sed
1203   fi
1204   # Use __gnuc_va_list in arg types in place of va_list.
1205   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
1206   # trailing parentheses and semicolon save all other systems from this.
1207   # Define __va_list__ (something harmless and unused) instead of va_list.
1208   # Don't claim to have defined va_list.
1209   sed -e 's@ va_list @ __gnuc_va_list @' \
1210       -e 's@ va_list)@ __gnuc_va_list)@' \
1211       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
1212       -e 's@ va_list@ __va_list__@' \
1213       -e 's@\*va_list@*__va_list__@' \
1214       -e 's@ __va_list)@ __gnuc_va_list)@' \
1215       -e 's@GNUC_VA_LIST@GNUC_Va_LIST@' \
1216       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
1217       -e 's@VA_LIST@DUMMY_VA_LIST@' \
1218       -e 's@_Va_LIST@_VA_LIST@' \
1219     ${LIB}/$file >> ${LIB}/${file}.sed
1220   
1221   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1222   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1223     rm -f ${LIB}/$file
1224   fi
1225 fi
1226
1227 # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
1228 file=ansi_compat.h
1229 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1230   if grep -s ULTRIX $file; then
1231     echo "/* This file intentionally left blank.  */" > $LIB/$file
1232   fi
1233 fi
1234
1235 # parameter to atof not const on DECstation Ultrix V4.0.
1236 # also get rid of bogus inline definitions in HP-UX 8.0
1237 file=math.h
1238 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1239   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1240   chmod +w ${LIB}/$file 2>/dev/null
1241   chmod a+r ${LIB}/$file 2>/dev/null
1242 fi
1243
1244 if [ -r ${LIB}/$file ]; then
1245   echo Fixing $file, non-const arg
1246   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
1247       -e 's@inline int abs(int [a-z][a-z]*) {.*}@@' \
1248       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
1249       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
1250       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
1251     ${LIB}/$file > ${LIB}/${file}.sed
1252   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1253   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1254     rm -f ${LIB}/$file
1255   fi
1256 fi
1257
1258 # Avoid nested comments on Ultrix 4.3.
1259 file=rpc/svc.h
1260 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1261   mkdir ${LIB}/rpc 2>/dev/null
1262   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1263   chmod +w ${LIB}/$file 2>/dev/null
1264   chmod a+r ${LIB}/$file 2>/dev/null
1265 fi
1266
1267 if [ -r ${LIB}/$file ]; then
1268   echo Fixing $file, nested comment
1269   sed -e 's@^\( \*      int protocol;  \)/\*@\1*/ /*@' \
1270     ${LIB}/$file > ${LIB}/$file.sed
1271   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1272   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1273     rm -f ${LIB}/$file
1274   fi
1275 fi
1276
1277 # This file in RISC/os uses /**/ to concatenate two tokens.
1278 file=bsd43/bsd43_.h
1279 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1280   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1281   chmod +w ${LIB}/$file 2>/dev/null
1282   chmod a+r ${LIB}/$file 2>/dev/null
1283 fi
1284 if [ -r ${LIB}/$file ]; then
1285   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
1286   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1287   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1288     rm -f ${LIB}/$file
1289   fi
1290 fi
1291
1292 file=rpc/rpc.h
1293 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1294   mkdir ${LIB}/rpc 2>/dev/null
1295   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1296   chmod +w ${LIB}/$file 2>/dev/null
1297   chmod a+r ${LIB}/$file 2>/dev/null
1298 fi
1299
1300 if [ -r ${LIB}/$file ]; then
1301   echo Fixing $file, nested comment
1302   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
1303     ${LIB}/$file > ${LIB}/$file.sed
1304   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1305   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1306     rm -f ${LIB}/$file
1307   fi
1308 fi
1309
1310 # In limits.h, put #ifndefs around things that are supposed to be defined
1311 # in float.h to avoid redefinition errors if float.h is included first.
1312 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1313 # multi line comments and the inserted #endif winds up inside the
1314 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
1315 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1316 # are there, and we do not add them ourselves.
1317 for file in limits.h sys/limits.h; do
1318   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1319     mkdir ${LIB}/sys 2>/dev/null
1320     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1321     chmod +w ${LIB}/$file 2>/dev/null
1322     chmod a+r ${LIB}/$file 2>/dev/null
1323   fi
1324
1325   if [ -r ${LIB}/$file ]; then
1326     if egrep 'ifndef[   ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1327       true
1328     else
1329       echo Fixing $file
1330       sed -e '/[        ]FLT_MIN[       ]/i\
1331 #ifndef FLT_MIN
1332 '\
1333           -e '/[        ]FLT_MIN[       ]/a\
1334 #endif
1335 '\
1336           -e '/[        ]FLT_MAX[       ]/i\
1337 #ifndef FLT_MAX
1338 '\
1339           -e '/[        ]FLT_MAX[       ]/a\
1340 #endif
1341 '\
1342           -e '/[        ]FLT_DIG[       ]/i\
1343 #ifndef FLT_DIG
1344 '\
1345           -e '/[        ]FLT_DIG[       ]/a\
1346 #endif
1347 '\
1348           -e '/[        ]DBL_MIN[       ]/i\
1349 #ifndef DBL_MIN
1350 '\
1351           -e '/[        ]DBL_MIN[       ]/a\
1352 #endif
1353 '\
1354           -e '/[        ]DBL_MAX[       ]/i\
1355 #ifndef DBL_MAX
1356 '\
1357           -e '/[        ]DBL_MAX[       ]/a\
1358 #endif
1359 '\
1360           -e '/[        ]DBL_DIG[       ]/i\
1361 #ifndef DBL_DIG
1362 '\
1363           -e '/[        ]DBL_DIG[       ]/a\
1364 #endif
1365 '\
1366         ${LIB}/$file > ${LIB}/${file}.sed
1367       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1368     fi
1369     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1370       echo Deleting ${LIB}/$file\; no fixes were needed.
1371       rm -f ${LIB}/$file
1372     fi
1373   fi
1374 done
1375
1376 # In math.h, put #ifndefs around things that might be defined in a gcc
1377 # specific math-*.h file.
1378 file=math.h
1379 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1380   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1381   chmod +w ${LIB}/$file 2>/dev/null
1382   chmod a+r ${LIB}/$file 2>/dev/null
1383 fi
1384
1385 if [ -r ${LIB}/$file ]; then
1386   echo Fixing $file
1387   sed -e '/define[      ]HUGE_VAL[      ]/i\
1388 #ifndef HUGE_VAL
1389 '\
1390       -e '/define[      ]HUGE_VAL[      ]/a\
1391 #endif
1392 '\
1393     ${LIB}/$file > ${LIB}/${file}.sed
1394   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1395
1396   # In addition, copy the definition of DBL_MAX from float.h
1397   # if math.h requires one.  The Lynx math.h requires it.
1398   if egrep '#define[    ]*HUGE_VAL[     ]+DBL_MAX' $file >/dev/null 2>&1; then
1399     if egrep '#define[  ]+DBL_MAX[      ]+' $file >/dev/null 2>&1; then
1400       true;
1401     else
1402       dbl_max_def=`egrep 'define[       ]+DBL_MAX[      ]+.*' float.h 2>/dev/null`
1403       if [ "$dbl_max_def" != "" ]; then
1404         dbl_max_def=`echo $dbl_max_def | sed 's/.*define[       ]*DBL_MAX[      ]*//'`
1405         sed -e "/define[        ]HUGE_VAL[      ]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
1406           ${LIB}/$file > ${LIB}/${file}.sed
1407         rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1408       fi
1409     fi
1410   fi
1411
1412   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1413     echo Deleting ${LIB}/$file\; no fixes were needed.
1414     rm -f ${LIB}/$file
1415   fi
1416 fi
1417
1418 # Remove erroneous parentheses in sym.h on Alpha OSF/1.
1419 file=sym.h
1420 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1421   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1422   chmod +w ${LIB}/$file 2>/dev/null
1423   chmod a+r ${LIB}/$file 2>/dev/null
1424 fi
1425
1426 if [ -r ${LIB}/$file ]; then
1427   echo Fixing $file
1428   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
1429     ${LIB}/$file > ${LIB}/${file}.sed
1430   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1431   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1432     rm -f ${LIB}/$file
1433   fi
1434 fi
1435
1436 # Correct the return type for strlen in string.h on Lynx.
1437 # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
1438 file=string.h
1439 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1440   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1441   chmod +w ${LIB}/$file 2>/dev/null
1442   chmod a+r ${LIB}/$file 2>/dev/null
1443 fi
1444
1445 if [ -r ${LIB}/$file ]; then
1446   echo Fixing $file
1447   sed -e 's/extern[     ]*int[  ]*strlen();/extern unsigned int strlen();/' \
1448       -e 's/extern[     ]*int[  ]*ffs[  ]*(long);/extern int ffs(int);/' \
1449     ${LIB}/$file > ${LIB}/${file}.sed
1450   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1451   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1452     rm -f ${LIB}/$file
1453   fi
1454 fi
1455
1456 # Delete the '#define void int' line from curses.h on Lynx
1457 file=curses.h
1458 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1459   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1460   chmod +w ${LIB}/$file 2>/dev/null
1461   chmod a+r ${LIB}/$file 2>/dev/null
1462 fi
1463
1464 if [ -r ${LIB}/$file ]; then
1465   echo Fixing $file
1466   sed -e '/#define[     ][      ]*void[         ]int/d' \
1467      ${LIB}/$file > ${LIB}/${file}.sed
1468   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1469     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1470       rm -f ${LIB}/$file
1471   fi
1472 fi
1473
1474 # For C++, avoid any typedef or macro definition of bool, and use the
1475 # built in type instead.
1476 for files in curses.h; do
1477   if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then
1478     if [ ! -r ${LIB}/$file ]; then
1479       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1480       chmod +w ${LIB}/$file 2>/dev/null
1481       chmod a+r ${LIB}/$file 2>/dev/null
1482     fi
1483
1484     echo Fixing $file
1485     sed -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/i\
1486 #ifndef __cplusplus'\
1487         -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/a\
1488 #endif'\
1489         -e '/^typedef[  ][      ]*char[         ][      ]*bool;[        ]*$/i\
1490 #ifndef __cplusplus'\
1491         -e '/^typedef[  ][      ]*char[         ][      ]*bool;[        ]*$/a\
1492 #endif'\
1493         ${LIB}/$file > ${LIB}/${file}.sed
1494     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1495     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1496       rm -f ${LIB}/$file
1497     fi
1498   fi
1499 done
1500
1501 # Fix incorrect S_IF* definitions on m88k-sysv3.
1502 file=sys/stat.h
1503 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1504   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1505   chmod +w ${LIB}/$file 2>/dev/null
1506   chmod a+r ${LIB}/$file 2>/dev/null
1507 fi
1508
1509 if [ -r ${LIB}/$file ]; then
1510   echo Fixing $file
1511   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)/' \
1512       -e 's/^\(#define[         ]*S_IS[A-Z]*(m)\)[      ]*(m[   ]*&[    ]*\(0[0-9]*\)[  ]*)/\1 (((m)\&S_IFMT)==\2)/' \
1513     ${LIB}/$file > ${LIB}/${file}.sed
1514   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1515   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1516     rm -f ${LIB}/$file
1517   fi
1518 fi
1519
1520 # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
1521 for file in stdio.h stdlib.h; do
1522   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1523     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1524     chmod +w ${LIB}/$file 2>/dev/null
1525     chmod a+r ${LIB}/$file 2>/dev/null
1526   fi
1527
1528   if [ -r ${LIB}/$file ]; then
1529     echo Fixing $file, getopt declaration
1530     sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
1531       ${LIB}/$file > ${LIB}/${file}.sed
1532     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1533     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1534       rm -f ${LIB}/$file
1535     fi
1536   fi
1537 done
1538
1539 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1540 # need to fix some additional files.  This is the same test for ISC that
1541 # Autoconf uses.
1542 if test -d /etc/conf/kconfig.d \
1543     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1544   echo "Fixing ISC __STDC__ goof in several files..."
1545   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1546     echo $name
1547     if test -r ${LIB}/$name; then
1548       file=${LIB}/$name
1549     else
1550       file=${INPUT}/$name
1551     fi
1552     # On Interactive 2.2, certain traditional Unix definitions
1553     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1554     # defined, not just if _POSIX_SOURCE is defined.  This makes it
1555     # impossible to compile any nontrivial program except with -posix.
1556     sed \
1557 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1558             < $file > ${LIB}/$name.
1559     mv ${LIB}/$name. ${LIB}/$name
1560   done
1561   
1562   echo "Fixing ISC fmod declaration"
1563   # This one's already been fixed for other things.
1564   file=${LIB}/math.h
1565   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1566   mv $file. $file
1567   
1568   echo "Fixing nested comments in ISC <sys/limits.h>"
1569   file=sys/limits.h
1570   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1571   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1572 fi
1573
1574 # These files in Sun OS 4.x use /**/ to concatenate tokens.
1575 for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h  \
1576         sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h      \
1577         sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
1578 do
1579   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1580     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1581     chmod +w ${LIB}/$file 2>/dev/null
1582     chmod a+r ${LIB}/$file 2>/dev/null
1583   fi
1584
1585   if [ -r ${LIB}/$file ]; then
1586     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1587     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1588     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1589       rm -f ${LIB}/$file
1590     fi
1591   fi
1592 done
1593
1594 # These files in ARM/RISCiX use /**/ to concatenate tokens.
1595 for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
1596         dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
1597 do
1598   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1599     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1600     chmod +w ${LIB}/$file 2>/dev/null
1601     chmod a+r ${LIB}/$file 2>/dev/null
1602   fi
1603
1604   if [ -r ${LIB}/$file ]; then
1605     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
1606     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1607     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1608       rm -f ${LIB}/$file
1609     fi
1610   fi
1611 done
1612
1613 # math.h on SunOS 4 puts the declaration of matherr before the definition
1614 # of struct exception, so the prototype (added by fixproto) causes havoc.
1615 file=math.h
1616 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1617   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1618   chmod +w ${LIB}/$file 2>/dev/null
1619   chmod a+r ${LIB}/$file 2>/dev/null
1620 fi
1621
1622 if [ -r ${LIB}/$file ]; then
1623   echo Fixing $file, matherr declaration
1624   sed -e '/^struct exception/,$b' \
1625       -e '/matherr/i\
1626 struct exception;
1627 '\
1628     ${LIB}/$file > ${LIB}/${file}.sed
1629   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1630   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1631     rm -f ${LIB}/$file
1632   fi
1633 fi
1634
1635 # assert.h on HP/UX is not C++ ready, even though NO_IMPLICIT_EXTERN_C
1636 # is defined on HP/UX.
1637 file=assert.h
1638 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1639   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1640   chmod +w ${LIB}/$file 2>/dev/null
1641   chmod a+r ${LIB}/$file 2>/dev/null
1642 fi
1643
1644 if [ -r ${LIB}/$file ]; then
1645   if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
1646      || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
1647     true
1648   else
1649     echo Fixing $file
1650     echo '#ifdef __cplusplus
1651 extern "C" {
1652 #endif' > ${LIB}/${file}.sed
1653     cat ${LIB}/${file} >> ${LIB}/${file}.sed
1654     echo '#ifdef __cplusplus
1655 }
1656 #endif' >> ${LIB}/${file}.sed 
1657     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1658     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1659       rm -f ${LIB}/$file
1660     fi
1661   fi
1662 fi
1663
1664 # check for broken assert.h that needs stdio.h or stdlib.h
1665 file=assert.h
1666 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1667   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1668   chmod +w ${LIB}/$file 2>/dev/null
1669   chmod a+r ${LIB}/$file 2>/dev/null
1670 fi
1671
1672 if [ -r ${LIB}/$file ]; then
1673   if grep 'stderr' ${LIB}/$file >/dev/null 2>/dev/null; then
1674     if grep 'include.*stdio.h' ${LIB}/$file >/dev/null 2>/dev/null; then
1675       true
1676     else
1677       echo "Fixing $file (needs stdio.h)"
1678       echo '#include <stdio.h>' >>${LIB}/$file
1679     fi
1680   fi
1681   if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
1682      grep 'abort *(' ${LIB}/$file >/dev/null 2>/dev/null; then
1683     if grep 'include.*stdlib.h' ${LIB}/$file >/dev/null 2>/dev/null; then
1684       true
1685     else
1686       echo "Fixing $file (needs stdlib.h)"
1687       echo '#include <stdlib.h>' >>${LIB}/$file
1688     fi
1689   fi
1690   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1691     rm -f ${LIB}/$file
1692   fi
1693 fi
1694
1695 # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
1696 file=unistd.h
1697 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1698   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1699   chmod +w ${LIB}/$file 2>/dev/null
1700   chmod a+r ${LIB}/$file 2>/dev/null
1701 fi
1702
1703 if [ -r ${LIB}/$file ]; then
1704   echo Fixing $file, sbrk declaration
1705   sed -e 's/char\([     ]*\*[    ]*sbrk[        ]*(\)/void\1/' \
1706     ${LIB}/$file > ${LIB}/${file}.sed
1707   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1708   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1709     rm -f ${LIB}/$file
1710   fi
1711 fi
1712
1713 # This file on SunOS 4 has a very large macro.  When the sed loop
1714 # tries pull it in, it overflows the pattern space size of the SunOS
1715 # sed (GNU sed does not have this problem).  Since the file does not
1716 # require fixing, we remove it from the fixed directory.
1717 file=sundev/ipi_error.h
1718 if [ -r ${LIB}/$file ]; then
1719   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
1720   rm -f ${LIB}/$file
1721 fi
1722
1723 # Put cpp wrappers around these include files to avoid redeclaration
1724 # errors during multiple inclusion on m88k-tektronix-sysv3.
1725 for file in time.h sys/time.h ; do
1726   if egrep '#ifndef' $file >/dev/null 2>&1; then
1727     true
1728   else
1729     if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1730       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1731       chmod +w ${LIB}/$file 2>/dev/null
1732     fi
1733     if [ -r ${LIB}/$file ]; then
1734       echo Fixing $file, to protect against multiple inclusion.
1735       cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
1736       (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
1737       echo "#define __GCC_GOT_${cpp_wrapper}_"
1738       cat ${LIB}/${file}
1739       echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
1740       rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
1741     fi
1742   fi
1743 done
1744
1745 echo 'Removing unneeded directories:'
1746 cd $LIB
1747 files=`find . -type d -print | sort -r`
1748 for file in $files; do
1749   rmdir $LIB/$file > /dev/null 2>&1
1750 done
1751
1752 if $LINKS; then
1753   echo 'Making internal symbolic non-directory links'
1754   cd ${INPUT}
1755   files=`find . -type l -print`
1756   for file in $files; do
1757     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1758     if expr "$dest" : '[^/].*' > /dev/null; then    
1759       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1760       if [ -f $target ]; then
1761         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1762       fi
1763     fi
1764   done
1765 fi
1766
1767 # Make sure that any include files referenced using double quotes
1768 # exist in the fixed directory.  This comes last since otherwise
1769 # we might end up deleting some of these files "because they don't
1770 # need any change."
1771 set x $required
1772 shift
1773 while [ $# != 0 ]; do
1774   newreq=
1775   while [ $# != 0 ]; do
1776     # $1 is the directory to copy from, $2 is the unfixed file,
1777     # $3 is the fixed file name.
1778     cd ${INPUT}
1779     cd $1
1780     if [ -r $2 ] && [ ! -r $3 ]; then
1781       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
1782       chmod +w $3 2>/dev/null
1783       chmod a+r $3 2>/dev/null
1784       echo Copied $2
1785       for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' $3 | sed -e 's/^[      ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
1786         dir=`echo $2 | sed -e s'|/[^/]*$||'`
1787         dir2=`echo $3 | sed -e s'|/[^/]*$||'`
1788         newreq="$newreq $1 $dir/$include $dir2/$include"
1789       done
1790     fi
1791     shift; shift; shift
1792   done
1793   set x $newreq
1794   shift
1795 done
1796
1797 echo 'Cleaning up DONE files.'
1798 cd $LIB
1799 find . -name DONE -exec rm -f '{}' ';'
1800
1801 exit 0