OSDN Git Service

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