OSDN Git Service

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