OSDN Git Service

* fixinc/fixtests.c(stdc_0_in_system_headers_test): Must return "FIX"
[pf3gnuchains/gcc-fork.git] / gcc / fixinc / fixinc.svr4
1 #! /bin/sh
2 # Install modified versions of certain ANSI-incompatible
3 # native System V Release 4 system include files.
4 # Copyright (C) 1994, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
5 # Contributed by Ron Guilmette (rfg@monkeys.com).
6 #
7 # This file is part of GNU CC.
8
9 # GNU CC is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
12 # any later version.
13
14 # GNU CC is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18
19 # You should have received a copy of the GNU General Public License
20 # along with GNU CC; see the file COPYING.  If not, write to
21 # the Free Software Foundation, 59 Temple Place - Suite 330,
22 # Boston, MA 02111-1307, USA.
23 #
24 #       This script munges the native include files provided with System V
25 #       Release 4 systems so as to remove things which are violations of the
26 #       ANSI C standard.  Once munged, the resulting new system include files
27 #       are placed in a directory that GNU C will search *before* searching
28 #       the /usr/include directory. This script should work properly for most
29 #       System V Release 4 systems.  For other types of systems, you should
30 #       use the `fixincludes' script instead.
31 #
32 #       See README-fixinc for more information.
33
34 # Fail if no arg to specify a directory for the output.
35 if [ x$1 = x ]
36 then echo fixincludes: no output directory specified
37 exit 1
38 fi
39
40 # Directory in which to store the results.
41 LIB=${1?"fixincludes: output directory not specified"}
42
43 # Make sure it exists.
44 if [ ! -d $LIB ]; then
45   mkdir $LIB || exit 1
46 fi
47
48 ORIG_DIR=`${PWDCMD-pwd}`
49
50 # Make LIB absolute if it is relative.
51 # Don't do this if not necessary, since may screw up automounters.
52 case $LIB in
53 /*)
54         ;;
55 *)
56         cd $LIB; LIB=`${PWDCMD-pwd}`
57         ;;
58 esac
59
60 echo 'Building fixincludes in ' ${LIB}
61
62 # Determine whether this filesystem has symbolic links.
63 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
64   rm -f $LIB/ShouldNotExist
65   LINKS=true
66 else
67   LINKS=false
68 fi
69
70 echo 'Making directories:'
71
72 # Directory containing the original header files.
73 shift
74 if [ $# -eq 0 ] ; then
75   set /usr/include
76 fi
77
78 INLIST="$@"
79
80 for INPUT in ${INLIST} ; do
81 cd ${ORIG_DIR}
82 cd ${INPUT}
83
84 if $LINKS; then
85   files=`find . -follow -type d -print 2>/dev/null | sed '/^.$/d'`
86 else
87   files=`find . -type d -print | sed '/^.$/d'`
88 fi
89 for file in $files; do
90   rm -rf $LIB/$file
91   if [ ! -d $LIB/$file ]
92   then mkdir $LIB/$file
93   fi
94 done
95
96 # treetops gets an alternating list
97 # of old directories to copy
98 # and the new directories to copy to.
99 treetops="${INPUT} ${LIB}"
100
101 if $LINKS; then
102   echo 'Making internal symbolic directory links'
103   for file in $files; do
104     dest=`ls -ld $file | sed -n 's/.*-> //p'`
105     if [ "$dest" ]; then    
106       cwd=`pwd`
107       # In case $dest is relative, get to $file's dir first.
108       cd ${INPUT}
109       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
110       rwd=`pwd`
111       # Check that the target directory exists.
112       # Redirections changed to avoid bug in sh on Ultrix.
113       (cd $dest) > /dev/null 2>&1
114       if [ $? = 0 ]; then
115         cd $dest
116         # X gets the dir that the link actually leads to.
117         x=`pwd`
118         # If link leads back into ${INPUT},
119         # make a similar link here.
120         if expr "$dest" : '[^/][^/]*' >/dev/null && [ ! -h $dest ]; then
121           echo $file '->'  $dest': Making link'
122           rm -fr ${LIB}/$file > /dev/null 2>&1
123           ln -s $dest ${LIB}/$file > /dev/null 2>&1
124         elif expr $x : "${INPUT}/.*" > /dev/null; then
125           # Y gets the actual target dir name, relative to ${INPUT}.
126           y=`echo $x | sed -n "s&${INPUT}/&&p"`
127           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
128           dots=`echo "$file" |
129             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
130           echo $file '->' $dots$y ': Making link'
131           rm -fr ${LIB}/$file > /dev/null 2>&1
132           ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
133         elif expr $x : "${rwd}/.*" > /dev/null; then
134           # Y gets the actual target dir name, relative to the directory where the link is.
135           y=`echo $x | sed -n "s&${rwd}/&&p"`
136           # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
137           dots=`echo "$file" |
138             sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
139           echo $file '->' $dots$y ': Making link'
140           rm -fr ${LIB}/$file > /dev/null 2>&1
141           ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
142         else
143           # If the link is to outside ${INPUT},
144           # treat this directory as if it actually contained the files.
145 # This line used to have $dest instead of $x.
146 # $dest seemed to be wrong for links found in subdirectories
147 # of ${INPUT}.  Does this change break anything?
148           treetops="$treetops $x ${LIB}/$file"
149         fi
150       fi
151       cd $cwd
152     fi
153   done
154 fi
155
156 set - $treetops
157 while [ $# != 0 ]; do
158   # $1 is an old directory to copy, and $2 is the new directory to copy to.
159   echo "Finding header files in $1:"
160   cd ${INPUT}
161   cd $1
162   files=`find . -name '*.h' -type f -print`
163   echo 'Checking header files:'
164   for file in $files; do
165       if [ -r $file ]; then
166         cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
167         chmod +w $2/$file
168         chmod a+r $2/$file
169
170 # The following have been removed from the sed command below
171 # because it is more useful to leave these things in.
172 # The only reason to remove them was for -pedantic,
173 # which isn't much of a reason. -- rms.
174 #         /^[   ]*#[    ]*ident/d
175
176 # This code makes Solaris SCSI fail, because it changes the
177 # alignment within some critical structures.  See <sys/scsi/impl/commands.h>.
178 #         s/u_char\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
179 # Disable these also, since they probably aren't safe either.
180 #         s/u_short\([  ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
181 #         s/ushort\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
182 #         s/evcm_t\([   ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*[0-9][0-9]*\)/u_int\1/
183 #         s/Pbyte\([    ][      ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[    ]*:[    ]*SEQSIZ\)/unsigned int\1/
184
185 # The change of u_char, etc, to u_int
186 # applies to bit fields.
187         sed -e '
188           s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
189           s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
190           s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
191           s%^\([        ]*#[    ]*endif\)[      ]*[^/   ].*%\1%
192           s/#lint(on)/defined(lint)/g
193           s/#lint(off)/!defined(lint)/g
194           s/#machine(\([^)]*\))/defined(__\1__)/g
195           s/#system(\([^)]*\))/defined(__\1__)/g
196           s/#cpu(\([^)]*\))/defined(__\1__)/g
197           /#[a-z]*if.*[  (]m68k/                s/\([^_]\)m68k/\1__m68k__/g
198           /#[a-z]*if.*[  (]__i386\([^_]\)/      s/__i386/__i386__/g
199           /#[a-z]*if.*[  (]i386/                s/\([^_]\)i386/\1__i386__/g
200           /#[a-z]*if.*[  (!]__i860\([^_]\)/     s/__i860/__i860__/g
201           /#[a-z]*if.*[  (!]i860/               s/\([^_]\)i860/\1__i860__/g
202           /#[a-z]*if.*[  (]sparc/       s/\([^_]\)sparc/\1__sparc__/g
203           /#[a-z]*if.*[  (]mc68000/     s/\([^_]\)mc68000/\1__mc68000__/g
204           /#[a-z]*if.*[  (]vax/         s/\([^_]\)vax/\1__vax__/g
205           /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
206           /#[a-z]*if.*[  (]sun/         s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
207           /#[a-z]*if.*[  (]ns32000/     s/\([^_]\)ns32000/\1__ns32000__/g
208           /#[a-z]*if.*[  (]pyr/         s/\([^_]\)pyr/\1__pyr__/g
209           /#[a-z]*if.*[  (]is68k/       s/\([^_]\)is68k/\1__is68k__/g
210           s/__STDC__[   ][      ]*==[   ][      ]*0/!defined (__STRICT_ANSI__)/g
211           s/__STDC__[   ][      ]*==[   ][      ]*1/defined (__STRICT_ANSI__)/g
212           s/__STDC__[   ][      ]*!=[   ][      ]*0/defined (__STRICT_ANSI__)/g
213           s/__STDC__[   ][      ]*!=[   ][      ]*1/!defined (__STRICT_ANSI__)/g
214           s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
215           s/__STDC__ - 0 == 1/defined (__STRICT_ANSI__)/g
216           /^typedef[    ][      ]*[unsigned     ]*long[         ][      ]*[u_]*longlong_t;/s/long/long long/
217         ' $2/$file > $2/$file.sed
218         mv $2/$file.sed $2/$file
219         if cmp $file $2/$file >/dev/null 2>&1; then
220            rm $2/$file
221         else
222            echo Fixed $file
223         fi
224       fi
225   done
226   shift; shift
227 done
228
229 # Install the proper definition of the three standard types in header files
230 # that they come from.
231 for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
232   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
233     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
234     chmod +w ${LIB}/$file 2>/dev/null
235     chmod a+r ${LIB}/$file 2>/dev/null
236   fi
237
238   if [ -r ${LIB}/$file ]; then
239     echo Fixing size_t, ptrdiff_t and wchar_t in $file
240     sed \
241       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]size_t/i\
242 #ifndef __SIZE_TYPE__\
243 #define __SIZE_TYPE__ long unsigned int\
244 #endif
245 ' \
246       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]size_t/typedef __SIZE_TYPE__ size_t/' \
247       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/i\
248 #ifndef __PTRDIFF_TYPE__\
249 #define __PTRDIFF_TYPE__ long int\
250 #endif
251 ' \
252       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
253       -e '/typedef[     ][      ]*[a-z_][       a-z_]*[         ]wchar_t/i\
254 #ifndef __WCHAR_TYPE__\
255 #define __WCHAR_TYPE__ int\
256 #endif
257 ' \
258       -e 's/typedef[    ][      ]*[a-z_][       a-z_]*[         ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
259       ${LIB}/$file > ${LIB}/${file}.sed
260     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
261     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
262       rm ${LIB}/$file
263     fi
264   fi
265 done
266
267 # Fix first broken decl of getcwd present on some svr4 systems.
268
269 file=stdlib.h
270 base=`basename $file`.$$
271 if [ -r ${LIB}/$file ]; then
272   file_to_fix=${LIB}/$file
273 else
274   if [ -r ${INPUT}/$file ]; then
275     file_to_fix=${INPUT}/$file
276   else
277     file_to_fix=""
278   fi
279 fi
280 if [ \! -z "$file_to_fix" ]; then
281   echo Checking $file_to_fix
282   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
283   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
284     true
285   else
286     echo Fixed $file_to_fix
287     rm -f ${LIB}/$file
288     cp /tmp/$base ${LIB}/$file
289     chmod a+r ${LIB}/$file
290   fi
291   rm -f /tmp/$base
292 fi
293
294 # Fix second broken decl of getcwd present on some svr4 systems.  Also
295 # fix the incorrect decl of profil present on some svr4 systems.
296
297 file=unistd.h
298 base=`basename $file`.$$
299 if [ -r ${LIB}/$file ]; then
300   file_to_fix=${LIB}/$file
301 else
302   if [ -r ${INPUT}/$file ]; then
303     file_to_fix=${INPUT}/$file
304   else
305     file_to_fix=""
306   fi
307 fi
308 if [ \! -z "$file_to_fix" ]; then
309   echo Checking $file_to_fix
310   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
311     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
312   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
313     true
314   else
315     echo Fixed $file_to_fix
316     rm -f ${LIB}/$file
317     cp /tmp/$base ${LIB}/$file
318     chmod a+r ${LIB}/$file
319   fi
320   rm -f /tmp/$base
321 fi
322
323 # Fix the definition of NULL in <sys/param.h> so that it is conditional
324 # and so that it is correct for both C and C++.
325
326 file=sys/param.h
327 base=`basename $file`.$$
328 if [ -r ${LIB}/$file ]; then
329   file_to_fix=${LIB}/$file
330 else
331   if [ -r ${INPUT}/$file ]; then
332     file_to_fix=${INPUT}/$file
333   else
334     file_to_fix=""
335   fi
336 fi
337 if [ \! -z "$file_to_fix" ]; then
338   echo Checking $file_to_fix
339   cp $file_to_fix /tmp/$base
340   chmod +w /tmp/$base
341   chmod a+r /tmp/$base
342   sed -e '/^#define[    ]*NULL[         ]*0$/c\
343 #ifndef NULL\
344 #ifdef __cplusplus\
345 #define __NULL_TYPE\
346 #else /* !defined(__cplusplus) */\
347 #define __NULL_TYPE (void *)\
348 #endif /* !defined(__cplusplus) */\
349 #define NULL (__NULL_TYPE 0)\
350 #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
351   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
352     true
353   else
354     echo Fixed $file_to_fix
355     rm -f ${LIB}/$file
356     cp /tmp/$base.sed ${LIB}/$file
357     chmod a+r ${LIB}/$file
358   fi
359   rm -f /tmp/$base /tmp/$base.sed
360 fi
361
362 # Likewise fix the definition of NULL in <stdio.h> so that it is conditional
363 # and so that it is correct for both C and C++.
364
365 file=stdio.h
366 base=`basename $file`.$$
367 if [ -r ${LIB}/$file ]; then
368   file_to_fix=${LIB}/$file
369 else
370   if [ -r ${INPUT}/$file ]; then
371     file_to_fix=${INPUT}/$file
372   else
373     file_to_fix=""
374   fi
375 fi
376 if [ \! -z "$file_to_fix" ]; then
377   echo Checking $file_to_fix
378   cp $file_to_fix /tmp/$base
379   chmod +w /tmp/$base
380   sed -e '/^#define[    ]*NULL[         ]*0$/c\
381 #ifdef __cplusplus\
382 #define __NULL_TYPE\
383 #else /* !defined(__cplusplus) */\
384 #define __NULL_TYPE (void *)\
385 #endif /* !defined(__cplusplus) */\
386 #define NULL (__NULL_TYPE 0)' /tmp/$base > /tmp/$base.sed
387   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
388     true
389   else
390     echo Fixed $file_to_fix
391     rm -f ${LIB}/$file
392     cp /tmp/$base.sed ${LIB}/$file
393     chmod a+r ${LIB}/$file
394   fi
395   rm -f /tmp/$base /tmp/$base.sed
396 fi
397
398 # Likewise fix the definition of NULL in <dbm.h> so that it is conditional
399 # and so that it is correct for both C and C++.
400
401 file=dbm.h
402 base=`basename $file`.$$
403 if [ -r ${LIB}/$file ]; then
404   file_to_fix=${LIB}/$file
405 else
406   if [ -r ${INPUT}/$file ]; then
407     file_to_fix=${INPUT}/$file
408   else
409     file_to_fix=""
410   fi
411 fi
412 if [ \! -z "$file_to_fix" ]; then
413   echo Checking $file_to_fix
414   cp $file_to_fix /tmp/$base
415   chmod +w /tmp/$base
416   sed -e '/^#define[    ]*NULL[         ]*((char \*) 0)$/c\
417 #ifndef NULL\
418 #ifdef __cplusplus\
419 #define __NULL_TYPE\
420 #else /* !defined(__cplusplus) */\
421 #define __NULL_TYPE (void *)\
422 #endif /* !defined(__cplusplus) */\
423 #define NULL (__NULL_TYPE 0)\
424 #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
425   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
426     true
427   else
428     echo Fixed $file_to_fix
429     rm -f ${LIB}/$file
430     cp /tmp/$base.sed ${LIB}/$file
431     chmod a+r ${LIB}/$file
432   fi
433   rm -f /tmp/$base /tmp/$base.sed
434 fi
435
436 # Add a prototyped declaration of mmap to <sys/mman.h>.
437
438 file=sys/mman.h
439 base=`basename $file`.$$
440 if [ -r ${LIB}/$file ]; then
441   file_to_fix=${LIB}/$file
442 else
443   if [ -r ${INPUT}/$file ]; then
444     file_to_fix=${INPUT}/$file
445   else
446     file_to_fix=""
447   fi
448 fi
449 if [ \! -z "$file_to_fix" ]; then
450   echo Checking $file_to_fix
451   cp $file_to_fix /tmp/$base
452   chmod +w /tmp/$base
453   sed -e '/^extern caddr_t mmap();$/c\
454 #ifdef __STDC__\
455 extern caddr_t mmap (caddr_t, size_t, int, int, int, off_t);\
456 #else /* !defined(__STDC__) */\
457 extern caddr_t mmap ();\
458 #endif /* !defined(__STDC__) */' /tmp/$base > /tmp/$base.sed
459   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
460     true
461   else
462     echo Fixed $file_to_fix
463     rm -f ${LIB}/$file
464     cp /tmp/$base.sed ${LIB}/$file
465     chmod a+r ${LIB}/$file
466   fi
467   rm -f /tmp/$base /tmp/$base.sed
468 fi
469
470 # Fix declarations of `ftw' and `nftw' in <ftw.h>.  On some/most SVR4 systems
471 # the file <ftw.h> contains extern declarations of these functions followed
472 # by explicitly `static' definitions of these functions... and that's not
473 # allowed according to ANSI C.  (Note however that on Solaris, this header
474 # file glitch has been pre-fixed by Sun.  In the Solaris version of <ftw.h>
475 # there are no static definitions of any function so we don't need to do
476 # any of this stuff when on Solaris.
477
478 file=ftw.h
479 base=`basename $file`.$$
480 if [ -r ${LIB}/$file ]; then
481   file_to_fix=${LIB}/$file
482 else
483   if [ -r ${INPUT}/$file ]; then
484     file_to_fix=${INPUT}/$file
485   else
486     file_to_fix=""
487   fi
488 fi
489 if test -z "$file_to_fix" || grep 'define       ftw' $file_to_fix > /dev/null; then
490 # Either we have no <ftw.h> file at all, or else we have the pre-fixed Solaris
491 # one.  Either way, we don't have to do anything.
492   true
493 else
494   echo Checking $file_to_fix
495   cp $file_to_fix /tmp/$base
496   chmod +w /tmp/$base
497   sed -e '/^extern int ftw(const/i\
498 #if !defined(_STYPES)\
499 static\
500 #else\
501 extern\
502 #endif
503 '\
504   -e 's/extern \(int ftw(const.*\)$/\1/' \
505   -e '/^extern int nftw/i\
506 #if defined(_STYPES)\
507 static\
508 #else\
509 extern\
510 #endif
511 '\
512   -e 's/extern \(int nftw.*\)$/\1/' \
513   -e '/^extern int ftw(),/c\
514 #if !defined(_STYPES)\
515 static\
516 #else\
517 extern\
518 #endif\
519   int ftw();\
520 #if defined(_STYPES)\
521 static\
522 #else\
523 extern\
524 #endif\
525   int nftw();' /tmp/$base > /tmp/$base.sed
526   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
527     true
528   else
529     echo Fixed $file_to_fix
530     rm -f ${LIB}/$file
531     cp /tmp/$base.sed ${LIB}/$file
532     chmod a+r ${LIB}/$file
533   fi
534   rm -f /tmp/$base /tmp/$base.sed
535 fi
536
537 # Avoid the definition of the bool type in the Solaris 2.x curses.h when using
538 # g++, since it's now an official type in the C++ language.
539 file=curses.h
540 base=`basename $file`.$$
541 if [ -r ${LIB}/$file ]; then
542   file_to_fix=${LIB}/$file
543 else
544   if [ -r ${INPUT}/$file ]; then
545     file_to_fix=${INPUT}/$file
546   else
547     file_to_fix=""
548   fi
549 fi
550
551 if [ \! -z "$file_to_fix" ]; then
552   echo Checking $file_to_fix
553   cp $file_to_fix /tmp/$base
554   chmod +w /tmp/$base
555   sed -e 's,^typedef[   ]char[  ]bool;$,#ifndef __cplusplus\
556 typedef char bool;\
557 #endif /* !defined __cplusplus */,' /tmp/$base > /tmp/$base.sed
558   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
559     true
560   else
561     echo Fixed $file_to_fix
562     rm -f ${LIB}/$file
563     cp /tmp/$base.sed ${LIB}/$file
564     chmod a+r ${LIB}/$file
565   fi
566   rm -f /tmp/$base /tmp/$base.sed
567 fi
568
569 # Add a `static' declaration of `getrnge' into <regexp.h>.
570
571 # Don't do this if there is already a `static void getrnge' declaration
572 # present, since this would cause a redeclaration error.  Solaris 2.x has
573 # such a declaration.
574
575 file=regexp.h
576 base=`basename $file`.$$
577 if [ -r ${LIB}/$file ]; then
578   file_to_fix=${LIB}/$file
579 else
580   if [ -r ${INPUT}/$file ]; then
581     file_to_fix=${INPUT}/$file
582   else
583     file_to_fix=""
584   fi
585 fi
586 if [ \! -z "$file_to_fix" ]; then
587   echo Checking $file_to_fix
588   if grep "static void getrnge" $file_to_fix > /dev/null; then
589     true
590   else
591     cp $file_to_fix /tmp/$base
592     chmod +w /tmp/$base
593     sed -e '/^static int[       ]*size;/c\
594 static int      size ;\
595 \
596 static int getrnge ();' /tmp/$base > /tmp/$base.sed
597     if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
598       true
599     else
600       echo Fixed $file_to_fix
601       rm -f ${LIB}/$file
602       cp /tmp/$base.sed ${LIB}/$file
603       chmod a+r ${LIB}/$file
604     fi
605   fi
606   rm -f /tmp/$base /tmp/$base.sed
607 fi
608
609 # Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
610 # that is visible to any ANSI compiler using this include.  Simply
611 # delete the lines that #define some string functions to internal forms.
612
613 file=string.h
614 base=`basename $file`.$$
615 if [ -r ${LIB}/$file ]; then
616   file_to_fix=${LIB}/$file
617 else
618   if [ -r ${INPUT}/$file ]; then
619     file_to_fix=${INPUT}/$file
620   else
621     file_to_fix=""
622   fi
623 fi
624 if [ \! -z "$file_to_fix" ]; then
625   echo Checking $file_to_fix
626   cp $file_to_fix /tmp/$base
627   chmod +w /tmp/$base
628   sed -e '/#define.*__std_hdr_/d' /tmp/$base > /tmp/$base.sed
629   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
630     true
631   else
632     echo Fixed $file_to_fix
633     rm -f ${LIB}/$file
634     cp /tmp/$base.sed ${LIB}/$file
635     chmod a+r ${LIB}/$file
636   fi
637   rm -f /tmp/$base /tmp/$base.sed
638 fi
639
640 # Delete any #defines of `__i386' which may be present in <ieeefp.h>.  They
641 # tend to conflict with the compiler's own definition of this symbol.  (We
642 # will use the compiler's definition.)
643 # Likewise __sparc, for Solaris, and __i860, and a few others
644 # (guessing it is necessary for all of them).
645
646 file=ieeefp.h
647 base=`basename $file`.$$
648 if [ -r ${LIB}/$file ]; then
649   file_to_fix=${LIB}/$file
650 else
651   if [ -r ${INPUT}/$file ]; then
652     file_to_fix=${INPUT}/$file
653   else
654     file_to_fix=""
655   fi
656 fi
657 if [ \! -z "$file_to_fix" ]; then
658   echo Checking $file_to_fix
659   cp $file_to_fix /tmp/$base
660   chmod +w /tmp/$base
661   sed -e '/#define[     ]*__i386 /d' -e '/#define[      ]*__sparc /d' \
662       -e '/#define[     ]*__i860 /d' -e '/#define[      ]*__m88k /d' \
663       -e '/#define[     ]*__mips /d' -e '/#define[      ]*__m68k /d' \
664      /tmp/$base > /tmp/$base.sed
665   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
666     true
667   else
668     echo Fixed $file_to_fix 
669     rm -f ${LIB}/$file
670     cp /tmp/$base.sed ${LIB}/$file 
671     chmod a+r ${LIB}/$file
672   fi
673   rm -f /tmp/$base /tmp/$base.sed 
674 fi 
675
676 # Add a #define of _SIGACTION_ into <sys/signal.h>.
677 # Also fix types of SIG_DFL, SIG_ERR, SIG_IGN, and SIG_HOLD.
678
679 file=sys/signal.h
680 base=`basename $file`.$$
681 if [ -r ${LIB}/$file ]; then
682   file_to_fix=${LIB}/$file
683 else
684   if [ -r ${INPUT}/$file ]; then
685     file_to_fix=${INPUT}/$file
686   else
687     file_to_fix=""
688   fi
689 fi
690 if [ \! -z "$file_to_fix" ]; then
691   echo Checking $file_to_fix
692   cp $file_to_fix /tmp/$base
693   chmod +w /tmp/$base
694   sed -e '/^struct sigaction {/c\
695 #define _SIGACTION_\
696 struct  sigaction  {' \
697   -e '1,$s/(void *(\*)())/(void (*)(int))/' /tmp/$base > /tmp/$base.sed
698   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
699     true
700   else
701     echo Fixed $file_to_fix
702     rm -f ${LIB}/$file
703     cp /tmp/$base.sed ${LIB}/$file
704     chmod a+r ${LIB}/$file
705   fi
706   rm -f /tmp/$base /tmp/$base.sed
707 fi
708
709 # Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
710
711 file=sys/mkdev.h
712 base=`basename $file`.$$
713 if [ -r ${LIB}/$file ]; then
714   file_to_fix=${LIB}/$file
715 else
716   if [ -r ${INPUT}/$file ]; then
717     file_to_fix=${INPUT}/$file
718   else
719     file_to_fix=""
720   fi
721 fi
722 if [ \! -z "$file_to_fix" ]; then
723   echo Checking $file_to_fix
724   cp $file_to_fix /tmp/$base
725   chmod +w /tmp/$base
726   sed -e '/^dev_t makedev(const/c\
727 static dev_t makedev(const major_t, const minor_t);' \
728   -e '/^dev_t makedev()/c\
729 static dev_t makedev();' \
730   -e '/^major_t major(const/c\
731 static major_t major(const dev_t);' \
732   -e '/^major_t major()/c\
733 static major_t major();' \
734   -e '/^minor_t minor(const/c\
735 static minor_t minor(const dev_t);' \
736   -e '/^minor_t minor()/c\
737 static minor_t minor();' /tmp/$base > /tmp/$base.sed
738   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
739     true
740   else
741     echo Fixed $file_to_fix
742     rm -f ${LIB}/$file
743     cp /tmp/$base.sed ${LIB}/$file
744     chmod a+r ${LIB}/$file
745   fi
746   rm -f /tmp/$base /tmp/$base.sed
747 fi
748
749 # Fix reference to NMSZ in <sys/adv.h>.
750
751 file=sys/adv.h
752 base=`basename $file`.$$
753 if [ -r ${LIB}/$file ]; then
754   file_to_fix=${LIB}/$file
755 else
756   if [ -r ${INPUT}/$file ]; then
757     file_to_fix=${INPUT}/$file
758   else
759     file_to_fix=""
760   fi
761 fi
762 if [ \! -z "$file_to_fix" ]; then
763   echo Checking $file_to_fix
764   sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp/$base
765   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
766     true
767   else
768     echo Fixed $file_to_fix
769     rm -f ${LIB}/$file
770     cp /tmp/$base ${LIB}/$file
771     chmod a+r ${LIB}/$file
772   fi
773   rm -f /tmp/$base
774 fi
775
776 # Fix reference to NC_NPI_RAW in <sys/netcspace.h>.  Also fix types of
777 # array initializers.
778
779 file=sys/netcspace.h
780 base=`basename $file`.$$
781 if [ -r ${LIB}/$file ]; then
782   file_to_fix=${LIB}/$file
783 else
784   if [ -r ${INPUT}/$file ]; then
785     file_to_fix=${INPUT}/$file
786   else
787     file_to_fix=""
788   fi
789 fi
790 if [ \! -z "$file_to_fix" ]; then
791   echo Checking $file_to_fix
792   sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
793     | sed 's/NC_/(unsigned long) NC_/' > /tmp/$base
794   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
795     true
796   else
797     echo Fixed $file_to_fix
798     rm -f ${LIB}/$file
799     cp /tmp/$base ${LIB}/$file
800     chmod a+r ${LIB}/$file
801   fi
802   rm -f /tmp/$base
803 fi
804
805 # Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
806
807 file=fs/rfs/rf_cache.h
808 base=`basename $file`.$$
809 if [ -r ${LIB}/$file ]; then
810   file_to_fix=${LIB}/$file
811 else
812   if [ -r ${INPUT}/$file ]; then
813     file_to_fix=${INPUT}/$file
814   else
815     file_to_fix=""
816   fi
817 fi
818 if [ \! -z "$file_to_fix" ]; then
819   echo Checking $file_to_fix
820   if grep _KERNEL $file_to_fix > /dev/null; then
821     true
822   else
823     echo '#ifdef _KERNEL' > /tmp/$base
824     cat $file_to_fix >> /tmp/$base
825     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
826     echo Fixed $file_to_fix
827     rm -f ${LIB}/$file
828     cp /tmp/$base ${LIB}/$file
829     chmod a+r ${LIB}/$file
830     rm -f /tmp/$base
831   fi
832 fi
833
834 # Conditionalize all of <sys/erec.h> on _KERNEL being defined.
835
836 file=sys/erec.h
837 base=`basename $file`.$$
838 if [ -r ${LIB}/$file ]; then
839   file_to_fix=${LIB}/$file
840 else
841   if [ -r ${INPUT}/$file ]; then
842     file_to_fix=${INPUT}/$file
843   else
844     file_to_fix=""
845   fi
846 fi
847 if [ \! -z "$file_to_fix" ]; then
848   echo Checking $file_to_fix
849   if grep _KERNEL $file_to_fix > /dev/null; then
850     true
851   else
852     echo '#ifdef _KERNEL' > /tmp/$base
853     cat $file_to_fix >> /tmp/$base
854     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
855     echo Fixed $file_to_fix
856     rm -f ${LIB}/$file
857     cp /tmp/$base ${LIB}/$file
858     chmod a+r ${LIB}/$file
859     rm -f /tmp/$base
860   fi
861 fi
862
863 # Conditionalize all of <sys/err.h> on _KERNEL being defined.
864
865 file=sys/err.h
866 base=`basename $file`.$$
867 if [ -r ${LIB}/$file ]; then
868   file_to_fix=${LIB}/$file
869 else
870   if [ -r ${INPUT}/$file ]; then
871     file_to_fix=${INPUT}/$file
872   else
873     file_to_fix=""
874   fi
875 fi
876 if [ \! -z "$file_to_fix" ]; then
877   echo Checking $file_to_fix
878   if grep _KERNEL $file_to_fix > /dev/null; then
879     true
880   else
881     echo '#ifdef _KERNEL' > /tmp/$base
882     cat $file_to_fix >> /tmp/$base
883     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
884     echo Fixed $file_to_fix
885     rm -f ${LIB}/$file
886     cp /tmp/$base ${LIB}/$file
887     chmod a+r ${LIB}/$file
888     rm -f /tmp/$base
889   fi
890 fi
891
892 # Conditionalize all of <sys/char.h> on _KERNEL being defined.
893
894 file=sys/char.h
895 base=`basename $file`.$$
896 if [ -r ${LIB}/$file ]; then
897   file_to_fix=${LIB}/$file
898 else
899   if [ -r ${INPUT}/$file ]; then
900     file_to_fix=${INPUT}/$file
901   else
902     file_to_fix=""
903   fi
904 fi
905 if [ \! -z "$file_to_fix" ]; then
906   echo Checking $file_to_fix
907   if grep _KERNEL $file_to_fix > /dev/null; then
908     true
909   else
910     echo '#ifdef _KERNEL' > /tmp/$base
911     cat $file_to_fix >> /tmp/$base
912     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
913     echo Fixed $file_to_fix
914     rm -f ${LIB}/$file
915     cp /tmp/$base ${LIB}/$file
916     chmod a+r ${LIB}/$file
917     rm -f /tmp/$base
918   fi
919 fi
920
921 # Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
922
923 file=sys/getpages.h
924 base=`basename $file`.$$
925 if [ -r ${LIB}/$file ]; then
926   file_to_fix=${LIB}/$file
927 else
928   if [ -r ${INPUT}/$file ]; then
929     file_to_fix=${INPUT}/$file
930   else
931     file_to_fix=""
932   fi
933 fi
934 if [ \! -z "$file_to_fix" ]; then
935   echo Checking $file_to_fix
936   if grep _KERNEL $file_to_fix > /dev/null; then
937     true
938   else
939     echo '#ifdef _KERNEL' > /tmp/$base
940     cat $file_to_fix >> /tmp/$base
941     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
942     echo Fixed $file_to_fix
943     rm -f ${LIB}/$file
944     cp /tmp/$base ${LIB}/$file
945     chmod a+r ${LIB}/$file
946     rm -f /tmp/$base
947   fi
948 fi
949
950 # Conditionalize all of <sys/map.h> on _KERNEL being defined.
951
952 file=sys/map.h
953 base=`basename $file`.$$
954 if [ -r ${LIB}/$file ]; then
955   file_to_fix=${LIB}/$file
956 else
957   if [ -r ${INPUT}/$file ]; then
958     file_to_fix=${INPUT}/$file
959   else
960     file_to_fix=""
961   fi
962 fi
963 if [ \! -z "$file_to_fix" ]; then
964   echo Checking $file_to_fix
965   if grep _KERNEL $file_to_fix > /dev/null; then
966     true
967   else
968     echo '#ifdef _KERNEL' > /tmp/$base
969     cat $file_to_fix >> /tmp/$base
970     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
971     echo Fixed $file_to_fix
972     rm -f ${LIB}/$file
973     cp /tmp/$base ${LIB}/$file
974     chmod a+r ${LIB}/$file
975     rm -f /tmp/$base
976   fi
977 fi
978
979 # Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
980
981 file=sys/cmn_err.h
982 base=`basename $file`.$$
983 if [ -r ${LIB}/$file ]; then
984   file_to_fix=${LIB}/$file
985 else
986   if [ -r ${INPUT}/$file ]; then
987     file_to_fix=${INPUT}/$file
988   else
989     file_to_fix=""
990   fi
991 fi
992 if [ \! -z "$file_to_fix" ]; then
993   echo Checking $file_to_fix
994   if grep _KERNEL $file_to_fix > /dev/null; then
995     true
996   else
997     echo '#ifdef _KERNEL' > /tmp/$base
998     cat $file_to_fix >> /tmp/$base
999     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
1000     echo Fixed $file_to_fix
1001     rm -f ${LIB}/$file
1002     cp /tmp/$base ${LIB}/$file
1003     chmod a+r ${LIB}/$file
1004     rm -f /tmp/$base
1005   fi
1006 fi
1007
1008 # Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
1009
1010 file=sys/kdebugger.h
1011 base=`basename $file`.$$
1012 if [ -r ${LIB}/$file ]; then
1013   file_to_fix=${LIB}/$file
1014 else
1015   if [ -r ${INPUT}/$file ]; then
1016     file_to_fix=${INPUT}/$file
1017   else
1018     file_to_fix=""
1019   fi
1020 fi
1021 if [ \! -z "$file_to_fix" ]; then
1022   echo Checking $file_to_fix
1023   if grep _KERNEL $file_to_fix > /dev/null; then
1024     true
1025   else
1026     echo '#ifdef _KERNEL' > /tmp/$base
1027     cat $file_to_fix >> /tmp/$base
1028     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
1029     echo Fixed $file_to_fix
1030     rm -f ${LIB}/$file
1031     cp /tmp/$base ${LIB}/$file
1032     chmod a+r ${LIB}/$file
1033     rm -f /tmp/$base
1034   fi
1035 fi
1036
1037 # Conditionalize some of <netinet/in.h> on _KERNEL being defined.
1038 # This has been taken out because it breaks on some versions of
1039 # DYNIX/ptx, and it does not seem to do much good on any system.
1040 # file=netinet/in.h
1041 # base=`basename $file`.$$
1042 # if [ -r ${LIB}/$file ]; then
1043 #   file_to_fix=${LIB}/$file
1044 # else
1045 #   if [ -r ${INPUT}/$file ]; then
1046 #     file_to_fix=${INPUT}/$file
1047 #   else
1048 #     file_to_fix=""
1049 #   fi
1050 # fi
1051 # if [ \! -z "$file_to_fix" ]; then
1052 #   echo Checking $file_to_fix
1053 #   if grep _KERNEL $file_to_fix > /dev/null; then
1054 #     true
1055 #   else
1056 #     sed -e '/#ifdef INKERNEL/i\
1057 # #ifdef _KERNEL
1058 # ' \
1059 #     -e '/#endif[      ]*\/\* INKERNEL \*\//a\
1060 # #endif /* _KERNEL */
1061 # ' \
1062 #     $file_to_fix > ${LIB}/${file}.sed
1063 #     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1064 #     echo Fixed $file_to_fix
1065 #   fi
1066 # fi
1067
1068 # Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
1069
1070 file=sys/endian.h
1071 base=`basename $file`.$$
1072 if [ -r ${LIB}/$file ]; then
1073   file_to_fix=${LIB}/$file
1074 else
1075   if [ -r ${INPUT}/$file ]; then
1076     file_to_fix=${INPUT}/$file
1077   else
1078     file_to_fix=""
1079   fi
1080 fi
1081 if [ \! -z "$file_to_fix" ]; then
1082   echo Checking $file_to_fix
1083   if grep __GNUC__ $file_to_fix > /dev/null; then
1084     true
1085   else
1086     sed -e '/#  ifdef   __STDC__/i\
1087 #   if !defined (__GNUC__) && !defined (__GNUG__)
1088 ' \
1089     -e '/#              include <sys\/byteorder.h>/s/           /   /'\
1090     -e '/#   include    <sys\/byteorder.h>/i\
1091 #   endif /* !defined (__GNUC__) && !defined (__GNUG__) */
1092 '\
1093     $file_to_fix > ${LIB}/${file}.sed
1094     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1095     echo Fixed $file_to_fix
1096   fi
1097 fi
1098
1099 # Commented out because tmcconne@sedona.intel.com says we don't clearly need it
1100 # and the text in types.h is not erroneous.
1101 ## In sys/types.h, don't name the enum for booleans.
1102 #
1103 #file=sys/types.h
1104 #base=`basename $file`.$$
1105 #if [ -r ${LIB}/$file ]; then
1106 #  file_to_fix=${LIB}/$file
1107 #else
1108 #  if [ -r ${INPUT}/$file ]; then
1109 #    file_to_fix=${INPUT}/$file
1110 #  else
1111 #    file_to_fix=""
1112 #  fi
1113 #fi
1114 #if [ \! -z "$file_to_fix" ]; then
1115 #  echo Checking $file_to_fix
1116 #  if grep "enum boolean" $file_to_fix > /dev/null; then
1117 #    sed -e 's/enum boolean/enum/' ${LIB}/$file > ${LIB}/${file}.sed
1118 #    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1119 #    echo Fixed $file_to_fix
1120 #  else
1121 #    true
1122 #  fi
1123 #fi
1124
1125 # Remove useless extern keyword from struct forward declarations in
1126 # <sys/stream.h> and <sys/strsubr.h>
1127
1128 file=sys/stream.h
1129 base=`basename $file`.$$
1130 if [ -r ${LIB}/$file ]; then
1131   file_to_fix=${LIB}/$file
1132 else
1133   if [ -r ${INPUT}/$file ]; then
1134     file_to_fix=${INPUT}/$file
1135   else
1136     file_to_fix=""
1137   fi
1138 fi
1139 if [ \! -z "$file_to_fix" ]; then
1140   echo Checking $file_to_fix
1141   sed -e '
1142     s/extern struct stdata;/struct stdata;/g
1143     s/extern struct strevent;/struct strevent;/g
1144   ' $file_to_fix > /tmp/$base 
1145   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1146     true
1147   else
1148     echo Fixed $file_to_fix
1149     rm -f ${LIB}/$file
1150     cp /tmp/$base ${LIB}/$file
1151     chmod a+r ${LIB}/$file
1152   fi
1153   rm -f /tmp/$base
1154 fi
1155
1156 file=sys/strsubr.h
1157 base=`basename $file`.$$
1158 if [ -r ${LIB}/$file ]; then
1159   file_to_fix=${LIB}/$file
1160 else
1161   if [ -r ${INPUT}/$file ]; then
1162     file_to_fix=${INPUT}/$file
1163   else
1164     file_to_fix=""
1165   fi
1166 fi
1167 if [ \! -z "$file_to_fix" ]; then
1168   echo Checking $file_to_fix
1169   sed -e '
1170     s/extern struct strbuf;/struct strbuf;/g
1171     s/extern struct uio;/struct uio;/g
1172     s/extern struct thread;/struct thread;/g
1173     s/extern struct proc;/struct proc;/g
1174   ' $file_to_fix > /tmp/$base 
1175   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1176     true
1177   else
1178     echo Fixed $file_to_fix
1179     rm -f ${LIB}/$file
1180     cp /tmp/$base ${LIB}/$file
1181     chmod a+r ${LIB}/$file
1182   fi
1183   rm -f /tmp/$base
1184 fi
1185
1186 # Put storage class at start of decl, to avoid warning.
1187 file=rpc/types.h
1188 base=`basename $file`.$$
1189 if [ -r ${LIB}/$file ]; then
1190   file_to_fix=${LIB}/$file
1191 else
1192   if [ -r ${INPUT}/$file ]; then
1193     file_to_fix=${INPUT}/$file
1194   else
1195     file_to_fix=""
1196   fi
1197 fi
1198 if [ \! -z "$file_to_fix" ]; then
1199   echo Checking $file_to_fix
1200   sed -e '
1201     s/const extern/extern const/g
1202   ' $file_to_fix > /tmp/$base 
1203   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1204     true
1205   else
1206     echo Fixed $file_to_fix
1207     rm -f ${LIB}/$file
1208     cp /tmp/$base ${LIB}/$file
1209     chmod a+r ${LIB}/$file
1210   fi
1211   rm -f /tmp/$base
1212 fi
1213
1214 # Convert functions to prototype form, and fix arg names in <sys/stat.h>.
1215
1216 file=sys/stat.h
1217 base=`basename $file`.$$
1218 if [ -r ${LIB}/$file ]; then
1219   file_to_fix=${LIB}/$file
1220 else
1221   if [ -r ${INPUT}/$file ]; then
1222     file_to_fix=${INPUT}/$file
1223   else
1224     file_to_fix=""
1225   fi
1226 fi
1227 if [ \! -z "$file_to_fix" ]; then
1228   echo Checking $file_to_fix
1229   cp $file_to_fix /tmp/$base
1230   chmod +w /tmp/$base
1231   sed -e '/^stat([      ]*[^c]/{
1232 N
1233 N
1234 s/(.*)\n/( /
1235 s/;\n/, /
1236 s/;$/)/
1237 }' \
1238   -e '/^lstat([         ]*[^c]/{
1239 N
1240 N
1241 s/(.*)\n/( /
1242 s/;\n/, /
1243 s/;$/)/
1244 }' \
1245   -e '/^fstat([         ]*[^i]/{
1246 N
1247 N
1248 s/(.*)\n/( /
1249 s/;\n/, /
1250 s/;$/)/
1251 }' \
1252   -e '/^mknod([         ]*[^c]/{
1253 N
1254 N
1255 N
1256 s/(.*)\n/( /
1257 s/;\n/, /g
1258 s/;$/)/
1259 }' \
1260   -e '1,$s/\([^A-Za-z]\)path\([^A-Za-z]\)/\1__path\2/g' \
1261   -e '1,$s/\([^A-Za-z]\)buf\([^A-Za-z]\)/\1__buf\2/g' \
1262   -e '1,$s/\([^A-Za-z]\)fd\([^A-Za-z]\)/\1__fd\2/g' \
1263   -e '1,$s/ret\([^u]\)/__ret\1/g' \
1264   -e '1,$s/\([^_]\)mode\([^_]\)/\1__mode\2/g' \
1265   -e '1,$s/\([^_r]\)dev\([^_]\)/\1__dev\2/g' /tmp/$base > /tmp/$base.sed
1266   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
1267     true
1268   else
1269     echo Fixed $file_to_fix
1270     rm -f ${LIB}/$file
1271     cp /tmp/$base.sed ${LIB}/$file
1272     chmod a+r ${LIB}/$file
1273   fi
1274   rm -f /tmp/$base /tmp/$base.sed
1275 fi
1276
1277 # Sony NEWSOS 5.0 does not support the complete ANSI C standard.
1278
1279 if [ -x /bin/sony ]; then
1280   if /bin/sony; then
1281
1282     # Change <stdio.h> to not define __filbuf, __flsbuf, and __iob
1283
1284     file=stdio.h
1285     base=`basename $file`.$$
1286     if [ -r ${LIB}/$file ]; then
1287       file_to_fix=${LIB}/$file
1288     else
1289       if [ -r ${INPUT}/$file ]; then
1290         file_to_fix=${INPUT}/$file
1291       else
1292         file_to_fix=""
1293       fi
1294     fi
1295     if [ \! -z "$file_to_fix" ]; then
1296       echo Checking $file_to_fix
1297       cp $file_to_fix /tmp/$base
1298       chmod +w /tmp/$base
1299       sed -e '
1300         s/__filbuf/_filbuf/g
1301         s/__flsbuf/_flsbuf/g
1302         s/__iob/_iob/g
1303       ' /tmp/$base > /tmp/$base.sed
1304       mv /tmp/$base.sed /tmp/$base
1305       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1306         true
1307       else
1308         echo Fixed $file_to_fix
1309         rm -f ${LIB}/$file
1310         cp /tmp/$base ${LIB}/$file
1311         chmod a+r ${LIB}/$file
1312       fi
1313       rm -f /tmp/$base
1314     fi
1315
1316     # Change <ctype.h> to not define __ctype
1317
1318     file=ctype.h
1319     base=`basename $file`.$$
1320     if [ -r ${LIB}/$file ]; then
1321       file_to_fix=${LIB}/$file
1322     else
1323       if [ -r ${INPUT}/$file ]; then
1324         file_to_fix=${INPUT}/$file
1325       else
1326         file_to_fix=""
1327       fi
1328     fi
1329     if [ \! -z "$file_to_fix" ]; then
1330       echo Checking $file_to_fix
1331       cp $file_to_fix /tmp/$base
1332       chmod +w /tmp/$base
1333       sed -e '
1334         s/__ctype/_ctype/g
1335       ' /tmp/$base > /tmp/$base.sed
1336       mv /tmp/$base.sed /tmp/$base
1337       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1338         true
1339       else
1340         echo Fixed $file_to_fix
1341         rm -f ${LIB}/$file
1342         cp /tmp/$base ${LIB}/$file
1343         chmod a+r ${LIB}/$file
1344       fi
1345       rm -f /tmp/$base
1346     fi
1347   fi
1348 fi
1349
1350 # In limits.h, put #ifndefs around things that are supposed to be defined
1351 # in float.h to avoid redefinition errors if float.h is included first.
1352 # Solaris 2.1 has this problem.
1353
1354 file=limits.h
1355 base=`basename $file`.$$
1356 if [ -r ${LIB}/$file ]; then
1357   file_to_fix=${LIB}/$file
1358 else
1359   if [ -r ${INPUT}/$file ]; then
1360     file_to_fix=${INPUT}/$file
1361   else
1362     file_to_fix=""
1363   fi
1364 fi
1365 if [ \! -z "$file_to_fix" ]; then
1366   echo Checking $file_to_fix
1367   sed -e '/[    ]FLT_MIN[       ]/i\
1368 #ifndef FLT_MIN
1369 '\
1370       -e '/[    ]FLT_MIN[       ]/a\
1371 #endif
1372 '\
1373       -e '/[    ]FLT_MAX[       ]/i\
1374 #ifndef FLT_MAX
1375 '\
1376       -e '/[    ]FLT_MAX[       ]/a\
1377 #endif
1378 '\
1379       -e '/[    ]FLT_DIG[       ]/i\
1380 #ifndef FLT_DIG
1381 '\
1382       -e '/[    ]FLT_DIG[       ]/a\
1383 #endif
1384 '\
1385       -e '/[    ]DBL_MIN[       ]/i\
1386 #ifndef DBL_MIN
1387 '\
1388       -e '/[    ]DBL_MIN[       ]/a\
1389 #endif
1390 '\
1391       -e '/[    ]DBL_MAX[       ]/i\
1392 #ifndef DBL_MAX
1393 '\
1394       -e '/[    ]DBL_MAX[       ]/a\
1395 #endif
1396 '\
1397       -e '/[    ]DBL_DIG[       ]/i\
1398 #ifndef DBL_DIG
1399 '\
1400       -e '/[    ]DBL_DIG[       ]/a\
1401 #endif
1402 ' $file_to_fix > /tmp/$base
1403   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1404     true
1405   else
1406     echo Fixed $file_to_fix
1407     rm -f ${LIB}/$file
1408     cp /tmp/$base ${LIB}/$file
1409     chmod a+r ${LIB}/$file
1410   fi
1411   rm -f /tmp/$base
1412 fi
1413
1414 # Completely replace <sys/varargs.h> with a file that includes gcc's
1415 # stdarg.h or varargs.h files as appropriate.
1416
1417 file=sys/varargs.h
1418 if [ -r ${INPUT}/$file ]; then
1419   echo Replacing $file
1420   cat > ${LIB}/$file << EOF
1421 /* This file was generated by fixincludes.  */
1422 #ifndef _SYS_VARARGS_H
1423 #define _SYS_VARARGS_H
1424
1425 #ifdef __STDC__
1426 #include <stdarg.h>
1427 #else
1428 #include <varargs.h>
1429 #endif
1430
1431 #endif  /* _SYS_VARARGS_H */
1432 EOF
1433   chmod a+r ${LIB}/$file
1434 fi
1435
1436 # In math.h, put #ifndefs around things that might be defined in a gcc
1437 # specific math-*.h file.
1438
1439 file=math.h
1440 base=`basename $file`.$$
1441 if [ -r ${LIB}/$file ]; then
1442   file_to_fix=${LIB}/$file
1443 else
1444   if [ -r ${INPUT}/$file ]; then
1445     file_to_fix=${INPUT}/$file
1446   else
1447     file_to_fix=""
1448   fi
1449 fi
1450 if [ \! -z "$file_to_fix" ]; then
1451   echo Checking $file_to_fix
1452   sed -e '/define[      ]HUGE_VAL[      ]/i\
1453 #ifndef HUGE_VAL
1454 '\
1455       -e '/define[      ]HUGE_VAL[      ]/a\
1456 #endif
1457 ' $file_to_fix > /tmp/$base
1458   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1459     true
1460   else
1461     echo Fixed $file_to_fix
1462     rm -f ${LIB}/$file
1463     cp /tmp/$base ${LIB}/$file
1464     chmod a+r ${LIB}/$file
1465   fi
1466   rm -f /tmp/$base
1467 fi
1468
1469 # Solaris math.h and floatingpoint.h define __P without protection,
1470 # which conflicts with the fixproto definition.  The fixproto
1471 # definition and the Solaris definition are used the same way.
1472 for file in math.h floatingpoint.h; do
1473   base=`basename $file`.$$
1474   if [ -r ${LIB}/$file ]; then
1475     file_to_fix=${LIB}/$file
1476   else
1477     if [ -r ${INPUT}/$file ]; then
1478       file_to_fix=${INPUT}/$file
1479     else
1480       file_to_fix=""
1481     fi
1482   fi
1483   if [ \! -z "$file_to_fix" ]; then
1484     echo Checking $file_to_fix
1485     sed -e '/^#define[  ]*__P/i\
1486 #ifndef __P
1487 '\
1488         -e '/^#define[  ]*__P/a\
1489 #endif
1490 ' $file_to_fix > /tmp/$base
1491     if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1492       true
1493     else
1494       echo Fixed $file_to_fix
1495       rm -f ${LIB}/$file
1496       cp /tmp/$base ${LIB}/$file
1497       chmod a+r ${LIB}/$file
1498     fi
1499    rm -f /tmp/$base
1500   fi
1501 done
1502
1503 # The Solaris math.h defines struct exception, which conflicts with
1504 # the class exception defined in the C++ file std/stdexcept.h.  We
1505 # redefine it to __math_exception.  This is not a great fix, but I
1506 # haven't been able to think of anything better.
1507 file=math.h
1508 base=`basename $file`.$$
1509 if [ -r ${LIB}/$file ]; then
1510   file_to_fix=${LIB}/$file
1511 else
1512   if [ -r ${INPUT}/$file ]; then
1513     file_to_fix=${INPUT}/$file
1514   else
1515     file_to_fix=""
1516   fi
1517 fi
1518 if [ \! -z "$file_to_fix" ]; then
1519   echo Checking $file_to_fix
1520   sed -e '/struct exception/i\
1521 #ifdef __cplusplus\
1522 #define exception __math_exception\
1523 #endif'\
1524       -e '/struct exception/a\
1525 #ifdef __cplusplus\
1526 #undef exception\
1527 #endif' $file_to_fix > /tmp/$base
1528   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1529     true
1530   else
1531     echo Fixed $file_to_fix
1532     rm -f ${LIB}/$file
1533     cp /tmp/$base ${LIB}/$file
1534     chmod a+r ${LIB}/$file
1535   fi
1536   rm -f /tmp/$base
1537 fi
1538
1539 # Similarly for struct queue in sys/stream.h.
1540 file=sys/stream.h
1541 base=`basename $file`.$$
1542 if [ -r ${LIB}/$file ]; then
1543   file_to_fix=${LIB}/$file
1544 else
1545   if [ -r ${INPUT}/$file ]; then
1546     file_to_fix=${INPUT}/$file
1547   else
1548     file_to_fix=""
1549   fi
1550 fi
1551 if [ \! -z "$file_to_fix" ]; then
1552   echo Checking $file_to_fix
1553   sed -e '/struct[      ]*queue/i\
1554 #ifdef __cplusplus\
1555 #define queue __stream_queue\
1556 #endif'\
1557       -e '/struct[      ]*queue/a\
1558 #ifdef __cplusplus\
1559 #undef queue\
1560 #endif' $file_to_fix > /tmp/$base
1561   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1562     true
1563   else
1564     echo Fixed $file_to_fix
1565     mkdir -p $LIB/`dirname $file`
1566     rm -f ${LIB}/$file
1567     cp /tmp/$base ${LIB}/$file
1568     chmod a+r ${LIB}/$file
1569   fi
1570   rm -f /tmp/$base
1571 fi
1572
1573 # If arpa/inet.h prototypes are incompatible with the ones we just
1574 # installed in <sys/byteorder.h>, just remove the protos.
1575 set -x
1576 file=arpa/inet.h
1577 base=`basename $file`.$$
1578 if [ -r ${LIB}/$file ]; then
1579   file_to_fix=${LIB}/$file
1580 else
1581   if [ -r ${INPUT}/$file ]; then
1582     file_to_fix=${INPUT}/$file
1583   else
1584     file_to_fix=""
1585   fi
1586 fi
1587 if [ \! -z "$file_to_fix" ]; then
1588   echo Checking $file_to_fix
1589   sed -e '/^extern.*htons.*(in_port_t)/d' \
1590       -e '/^extern.*ntohs.*(in_port_t)/d' \
1591   $file_to_fix > /tmp/$base
1592   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1593     true
1594   else
1595     echo Fixed $file_to_fix
1596     mkdir -p $LIB/`dirname $file`
1597     rm -f ${LIB}/$file
1598     cp /tmp/$base ${LIB}/$file
1599     chmod a+r ${LIB}/$file
1600   fi
1601   rm -f /tmp/$base
1602 fi
1603
1604 echo 'Removing unneeded directories:'
1605 cd $LIB
1606 files=`find . -type d \! -name '.' -print | sort -r`
1607 for file in $files; do
1608   rmdir $LIB/$file > /dev/null 2>&1
1609 done
1610
1611 if $LINKS; then
1612   echo 'Making internal symbolic non-directory links'
1613   cd ${INPUT}
1614   files=`find . -type l -print`
1615   for file in $files; do
1616     dest=`ls -ld $file | sed -n 's/.*-> //p'`
1617     if expr "$dest" : '[^/].*' > /dev/null; then    
1618       target=${LIB}/`echo $file | sed "s|[^/]*\$|$dest|"`
1619       if [ -f $target ]; then
1620         ln -s $dest ${LIB}/$file >/dev/null 2>&1
1621       fi
1622     fi
1623   done
1624 fi
1625
1626 cd ${ORIG_DIR}
1627
1628 echo 'Replacing <sys/byteorder.h>'
1629 if [ \! -d $LIB/sys ]; then
1630   mkdir $LIB/sys
1631 fi
1632 rm -f ${LIB}/sys/byteorder.h
1633 cat <<'__EOF__' >${LIB}/sys/byteorder.h
1634 #ifndef _SYS_BYTEORDER_H
1635 #define _SYS_BYTEORDER_H
1636
1637 /* Functions to convert `short' and `long' quantities from host byte order
1638    to (internet) network byte order (i.e. big-endian).
1639
1640    Written by Ron Guilmette (rfg@ncd.com).
1641
1642    This isn't actually used by GCC.  It is installed by fixinc.svr4.
1643
1644    For big-endian machines these functions are essentially no-ops.
1645
1646    For little-endian machines, we define the functions using specialized
1647    asm sequences in cases where doing so yields better code (e.g. i386).  */
1648
1649 #if !defined (__GNUC__) && !defined (__GNUG__)
1650 #error You lose!  This file is only useful with GNU compilers.
1651 #endif
1652
1653 #ifdef __cplusplus
1654 extern "C" {
1655 #endif
1656
1657 #ifndef __BYTE_ORDER__
1658 /* Byte order defines.  These are as defined on UnixWare 1.1, but with
1659    double underscores added at the front and back.  */
1660 #define __LITTLE_ENDIAN__   1234
1661 #define __BIG_ENDIAN__      4321
1662 #define __PDP_ENDIAN__      3412
1663 #endif
1664
1665 #ifdef __STDC__
1666 static __inline__ unsigned long htonl (unsigned long);
1667 static __inline__ unsigned short htons (unsigned int);
1668 static __inline__ unsigned long ntohl (unsigned long);
1669 static __inline__ unsigned short ntohs (unsigned int);
1670 #endif /* defined (__STDC__) */
1671
1672 #if defined (__i386__)
1673
1674 #ifndef __BYTE_ORDER__
1675 #define __BYTE_ORDER__ __LITTLE_ENDIAN__
1676 #endif
1677
1678 /* Convert a host long to a network long.  */
1679
1680 /* We must use a new-style function definition, so that this will also
1681    be valid for C++.  */
1682 static __inline__ unsigned long
1683 htonl (unsigned long __arg)
1684 {
1685   register unsigned long __result;
1686
1687   __asm__ ("xchg%B0 %b0,%h0\n\
1688         ror%L0 $16,%0\n\
1689         xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1690   return __result;
1691 }
1692
1693 /* Convert a host short to a network short.  */
1694
1695 static __inline__ unsigned short
1696 htons (unsigned int __arg)
1697 {
1698   register unsigned short __result;
1699
1700   __asm__ ("xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
1701   return __result;
1702 }
1703
1704 #elif ((defined (__i860__) && !defined (__i860_big_endian__))   \
1705        || defined (__ns32k__) || defined (__vax__)              \
1706        || defined (__spur__) || defined (__arm__))
1707
1708 #ifndef __BYTE_ORDER__
1709 #define __BYTE_ORDER__ __LITTLE_ENDIAN__
1710 #endif
1711
1712 /* For other little-endian machines, using C code is just as efficient as
1713    using assembly code.  */
1714
1715 /* Convert a host long to a network long.  */
1716
1717 static __inline__ unsigned long
1718 htonl (unsigned long __arg)
1719 {
1720   register unsigned long __result;
1721
1722   __result = (__arg >> 24) & 0x000000ff;
1723   __result |= (__arg >> 8) & 0x0000ff00;
1724   __result |= (__arg << 8) & 0x00ff0000;
1725   __result |= (__arg << 24) & 0xff000000;
1726   return __result;
1727 }
1728
1729 /* Convert a host short to a network short.  */
1730
1731 static __inline__ unsigned short
1732 htons (unsigned int __arg)
1733 {
1734   register unsigned short __result;
1735
1736   __result = (__arg << 8) & 0xff00;
1737   __result |= (__arg >> 8) & 0x00ff;
1738   return __result;
1739 }
1740
1741 #else /* must be a big-endian machine */
1742
1743 #ifndef __BYTE_ORDER__
1744 #define __BYTE_ORDER__ __BIG_ENDIAN__
1745 #endif
1746
1747 /* Convert a host long to a network long.  */
1748
1749 static __inline__ unsigned long
1750 htonl (unsigned long __arg)
1751 {
1752   return __arg;
1753 }
1754
1755 /* Convert a host short to a network short.  */
1756
1757 static __inline__ unsigned short
1758 htons (unsigned int __arg)
1759 {
1760   return __arg;
1761 }
1762
1763 #endif /* big-endian */
1764
1765 /* Convert a network long to a host long.  */
1766
1767 static __inline__ unsigned long
1768 ntohl (unsigned long __arg)
1769 {
1770   return htonl (__arg);
1771 }
1772
1773 /* Convert a network short to a host short.  */
1774
1775 static __inline__ unsigned short
1776 ntohs (unsigned int __arg)
1777 {
1778   return htons (__arg);
1779 }
1780
1781 #ifdef __cplusplus
1782 } /* extern "C" */
1783 #endif
1784
1785 __EOF__
1786
1787 if [ -r ${INPUT}/sys/byteorder.h ]; then
1788   if grep BYTE_ORDER ${INPUT}/sys/byteorder.h >/dev/null 2>/dev/null; then
1789     cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1790 #ifndef BYTE_ORDER
1791 #define LITTLE_ENDIAN __LITTLE_ENDIAN__
1792 #define BIG_ENDIAN __BIG_ENDIAN__
1793 #define PDP_ENDIAN __PDP_ENDIAN__
1794 #define BYTE_ORDER __BYTE_ORDER__
1795 #endif
1796
1797 __EOF__
1798   fi
1799 fi
1800
1801 cat <<'__EOF__' >>${LIB}/sys/byteorder.h
1802 #endif /* !defined (_SYS_BYTEORDER_H) */
1803 __EOF__
1804
1805 chmod a+r ${LIB}/sys/byteorder.h
1806
1807 done
1808
1809 exit 0