OSDN Git Service

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