OSDN Git Service

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