OSDN Git Service

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