OSDN Git Service

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