OSDN Git Service

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