3 # fixinc.svr4 -- Install modified versions of certain ANSI-incompatible
4 # native System V Release 4 system include files.
6 # Written by Ron Guilmette (rfg@ncd.com).
8 # This file is part of GNU CC.
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)
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.
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.
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.
32 # See README-fixinc for more information.
34 # Directory where gcc sources (and sometimes special include files) live.
35 SRCDIR=${3-${SRCDIR-.}}
37 # Directory containing the original header files.
38 INPUT=${2-${INPUT-/usr/include}}
40 # Fail if no arg to specify a directory for the output.
42 then echo fixincludes: no output directory specified
46 # Directory in which to store the results.
47 LIB=${1?"fixincludes: output directory not specified"}
49 # Make sure it exists.
50 if [ ! -d $LIB ]; then
56 # Make LIB absolute if it is relative.
57 # Don't do this if not necessary, since may screw up automounters.
62 cd $LIB; LIB=`${PWDCMD-pwd}`
66 echo 'Building fixincludes in ' ${LIB}
68 # Determine whether this filesystem has symbolic links.
69 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
70 rm -f $LIB/ShouldNotExist
76 echo 'Making directories:'
79 files=`ls -LR | sed -n s/:$//p`
81 files=`find . -type d -print | sed '/^.$/d'`
83 for file in $files; do
85 if [ ! -d $LIB/$file ]
90 # treetops gets an alternating list
91 # of old directories to copy
92 # and the new directories to copy to.
93 treetops="${INPUT} ${LIB}"
96 echo 'Making internal symbolic directory links'
97 for file in $files; do
98 dest=`ls -ld $file | sed -n 's/.*-> //p'`
101 # In case $dest is relative, get to $file's dir first.
103 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
104 # Check that the target directory exists.
105 # Redirections changed to avoid bug in sh on Ultrix.
106 (cd $dest) > /dev/null 2>&1
109 # X gets the dir that the link actually leads to.
111 # If link leads back into ${INPUT},
112 # make a similar link here.
113 if expr $x : "${INPUT}/.*" > /dev/null; then
114 # Y gets the actual target dir name, relative to ${INPUT}.
115 y=`echo $x | sed -n "s&${INPUT}/&&p"`
116 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
118 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
119 echo $file '->' $dots$y ': Making link'
120 rm -fr ${LIB}/$file > /dev/null 2>&1
121 ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
123 # If the link is to outside ${INPUT},
124 # treat this directory as if it actually contained the files.
125 # This line used to have $dest instead of $x.
126 # $dest seemed to be wrong for links found in subdirectories
127 # of ${INPUT}. Does this change break anything?
128 treetops="$treetops $x ${LIB}/$file"
137 while [ $# != 0 ]; do
138 # $1 is an old directory to copy, and $2 is the new directory to copy to.
139 echo "Finding header files in $1:"
142 files=`find . -name '*.h' -type f -print`
143 echo 'Checking header files:'
144 for file in $files; do
145 if [ -r $file ]; then
146 cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
150 # The following have been removed from the sed command below
151 # because it is more useful to leave these things in.
152 # The only reason to remove them was for -pedantic,
153 # which isn't much of a reason. -- rms.
156 # This code makes Solaris SCSI fail, because it changes the
157 # alignment within some critical structures. See <sys/scsi/impl/commands.h>.
158 # s/u_char\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
159 # Disable these also, since they probably aren't safe either.
160 # s/u_short\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
161 # s/ushort\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
162 # s/evcm_t\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
163 # s/Pbyte\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*SEQSIZ\)/unsigned int\1/
165 # The change of u_char, etc, to u_int
166 # applies to bit fields.
168 s%^\([ ]*#[ ]*else\)[ ]*/[^*].*%\1%
169 s%^\([ ]*#[ ]*else\)[ ]*[^/ ].*%\1%
170 s%^\([ ]*#[ ]*endif\)[ ]*/[^*].*%\1%
171 s%^\([ ]*#[ ]*endif\)[ ]*[^/ ].*%\1%
172 s/#lint(on)/defined(lint)/g
173 s/#lint(off)/!defined(lint)/g
174 s/#machine(\([^)]*\))/defined(__\1__)/g
175 s/#system(\([^)]*\))/defined(__\1__)/g
176 s/#cpu(\([^)]*\))/defined(__\1__)/g
177 /#[a-z]*if.*[ (]m68k/ s/\([^_]\)m68k/\1__m68k__/g
178 /#[a-z]*if.*[ (]__i386\([^_]\)/ s/__i386/__i386__/g
179 /#[a-z]*if.*[ (]i386/ s/\([^_]\)i386/\1__i386__/g
180 /#[a-z]*if.*[ (]sparc/ s/\([^_]\)sparc/\1__sparc__/g
181 /#[a-z]*if.*[ (]mc68000/ s/\([^_]\)mc68000/\1__mc68000__/g
182 /#[a-z]*if.*[ (]vax/ s/\([^_]\)vax/\1__vax__/g
183 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
184 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
185 /#[a-z]*if.*[ (]ns32000/ s/\([^_]\)ns32000/\1__ns32000__/g
186 /#[a-z]*if.*[ (]pyr/ s/\([^_]\)pyr/\1__pyr__/g
187 /#[a-z]*if.*[ (]is68k/ s/\([^_]\)is68k/\1__is68k__/g
188 s/__STDC__ == 0/!defined (__STRICT_ANSI__)/g
189 s/__STDC__ != 0/defined (__STRICT_ANSI__)/g
190 s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
191 ' $2/$file > $2/$file.sed
192 mv $2/$file.sed $2/$file
193 if cmp $file $2/$file >/dev/null 2>&1; then
203 # Fix first broken decl of getcwd present on some svr4 systems.
206 base=`basename $file`
207 if [ -r ${LIB}/$file ]; then
208 file_to_fix=${LIB}/$file
210 if [ -r ${INPUT}/$file ]; then
211 file_to_fix=${INPUT}/$file
216 if [ \! -z "$file_to_fix" ]; then
217 echo Checking $file_to_fix
218 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
219 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
222 echo Fixed $file_to_fix
224 cp /tmp/$base ${LIB}/$file
225 chmod a+r ${LIB}/$file
230 # Fix second broken decl of getcwd present on some svr4 systems. Also
231 # fix the incorrect decl of profil present on some svr4 systems.
234 base=`basename $file`
235 if [ -r ${LIB}/$file ]; then
236 file_to_fix=${LIB}/$file
238 if [ -r ${INPUT}/$file ]; then
239 file_to_fix=${INPUT}/$file
244 if [ \! -z "$file_to_fix" ]; then
245 echo Checking $file_to_fix
246 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
247 | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
248 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
251 echo Fixed $file_to_fix
253 cp /tmp/$base ${LIB}/$file
254 chmod a+r ${LIB}/$file
259 # Fix the definition of NULL in <sys/param.h> so that it is conditional
260 # and so that it is correct for both C and C++.
263 base=`basename $file`
264 if [ -r ${LIB}/$file ]; then
265 file_to_fix=${LIB}/$file
267 if [ -r ${INPUT}/$file ]; then
268 file_to_fix=${INPUT}/$file
273 if [ \! -z "$file_to_fix" ]; then
274 echo Checking $file_to_fix
275 cp $file_to_fix /tmp/$base
278 sed -e '/^#define[ ]*NULL[ ]*0$/c\
282 #else /* !defined(__cplusplus) */\
283 #define __NULL_TYPE (void *)\
284 #endif /* !defined(__cplusplus) */\
285 #define NULL (__NULL_TYPE 0)\
286 #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
287 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
290 echo Fixed $file_to_fix
292 cp /tmp/$base.sed ${LIB}/$file
293 chmod a+r ${LIB}/$file
295 rm -f /tmp/$base /tmp/$base.sed
298 # Likewise fix the definition of NULL in <stdio.h> so that it is conditional
299 # and so that it is correct for both C and C++.
302 base=`basename $file`
303 if [ -r ${LIB}/$file ]; then
304 file_to_fix=${LIB}/$file
306 if [ -r ${INPUT}/$file ]; then
307 file_to_fix=${INPUT}/$file
312 if [ \! -z "$file_to_fix" ]; then
313 echo Checking $file_to_fix
314 cp $file_to_fix /tmp/$base
316 sed -e '/^#define[ ]*NULL[ ]*0$/c\
319 #else /* !defined(__cplusplus) */\
320 #define __NULL_TYPE (void *)\
321 #endif /* !defined(__cplusplus) */\
322 #define NULL (__NULL_TYPE 0)' /tmp/$base > /tmp/$base.sed
323 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
326 echo Fixed $file_to_fix
328 cp /tmp/$base.sed ${LIB}/$file
329 chmod a+r ${LIB}/$file
331 rm -f /tmp/$base /tmp/$base.sed
334 # Likewise fix the definition of NULL in <dbm.h> so that it is conditional
335 # and so that it is correct for both C and C++.
338 base=`basename $file`
339 if [ -r ${LIB}/$file ]; then
340 file_to_fix=${LIB}/$file
342 if [ -r ${INPUT}/$file ]; then
343 file_to_fix=${INPUT}/$file
348 if [ \! -z "$file_to_fix" ]; then
349 echo Checking $file_to_fix
350 cp $file_to_fix /tmp/$base
352 sed -e '/^#define[ ]*NULL[ ]*((char \*) 0)$/c\
356 #else /* !defined(__cplusplus) */\
357 #define __NULL_TYPE (void *)\
358 #endif /* !defined(__cplusplus) */\
359 #define NULL (__NULL_TYPE 0)\
360 #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
361 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
364 echo Fixed $file_to_fix
366 cp /tmp/$base.sed ${LIB}/$file
367 chmod a+r ${LIB}/$file
369 rm -f /tmp/$base /tmp/$base.sed
372 # Add a prototyped declaration of mmap to <sys/mman.h>.
375 base=`basename $file`
376 if [ -r ${LIB}/$file ]; then
377 file_to_fix=${LIB}/$file
379 if [ -r ${INPUT}/$file ]; then
380 file_to_fix=${INPUT}/$file
385 if [ \! -z "$file_to_fix" ]; then
386 echo Checking $file_to_fix
387 cp $file_to_fix /tmp/$base
389 sed -e '/^extern caddr_t mmap();$/c\
391 extern caddr_t mmap (caddr_t addr, size_t len, int prot, int flags,\
393 #else /* !defined(__STDC__) */\
394 extern caddr_t mmap ();\
395 #endif /* !defined(__STDC__) */' /tmp/$base > /tmp/$base.sed
396 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
399 echo Fixed $file_to_fix
401 cp /tmp/$base.sed ${LIB}/$file
402 chmod a+r ${LIB}/$file
404 rm -f /tmp/$base /tmp/$base.sed
407 # Fix declarations of `ftw' and `nftw' in <ftw.h>.
410 base=`basename $file`
411 if [ -r ${LIB}/$file ]; then
412 file_to_fix=${LIB}/$file
414 if [ -r ${INPUT}/$file ]; then
415 file_to_fix=${INPUT}/$file
420 if [ \! -z "$file_to_fix" ]; then
421 echo Checking $file_to_fix
422 cp $file_to_fix /tmp/$base
424 sed -e '/^extern int ftw(const/c\
425 #if !defined(_STYPES)\
430 int ftw(const char *, int (*)(const char *, const struct stat *, int), int);' \
431 -e '/^extern int nftw/c\
432 #if defined(_STYPES)\
437 int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *),int, int);' \
438 -e '/^extern int ftw(),/c\
439 #if !defined(_STYPES)\
445 #if defined(_STYPES)\
450 int nftw();' /tmp/$base > /tmp/$base.sed
451 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
454 echo Fixed $file_to_fix
456 cp /tmp/$base.sed ${LIB}/$file
457 chmod a+r ${LIB}/$file
459 rm -f /tmp/$base /tmp/$base.sed
462 # Add a `static' declaration of `getrnge' into <regexp.h>.
464 # Don't do this if there is already a `static void getrnge' declaration
465 # present, since this would cause a redeclaration error. Solaris 2.x has
466 # such a declaration.
469 base=`basename $file`
470 if [ -r ${LIB}/$file ]; then
471 file_to_fix=${LIB}/$file
473 if [ -r ${INPUT}/$file ]; then
474 file_to_fix=${INPUT}/$file
479 if [ \! -z "$file_to_fix" ]; then
480 echo Checking $file_to_fix
481 if grep "static void getrnge" $file_to_fix > /dev/null; then
484 cp $file_to_fix /tmp/$base
486 sed -e '/^static int[ ]*size;/c\
489 static int getrnge ();' /tmp/$base > /tmp/$base.sed
490 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
493 echo Fixed $file_to_fix
495 cp /tmp/$base.sed ${LIB}/$file
496 chmod a+r ${LIB}/$file
499 rm -f /tmp/$base /tmp/$base.sed
502 # Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
503 # that is visible to any ANSI compiler using this include. Simply
504 # delete the lines that #define some string functions to internal forms.
507 base=`basename $file`
508 if [ -r ${LIB}/$file ]; then
509 file_to_fix=${LIB}/$file
511 if [ -r ${INPUT}/$file ]; then
512 file_to_fix=${INPUT}/$file
517 if [ \! -z "$file_to_fix" ]; then
518 echo Checking $file_to_fix
519 cp $file_to_fix /tmp/$base
521 sed -e '/#define.*__std_hdr_/d' /tmp/$base > /tmp/$base.sed
522 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
525 echo Fixed $file_to_fix
527 cp /tmp/$base.sed ${LIB}/$file
528 chmod a+r ${LIB}/$file
530 rm -f /tmp/$base /tmp/$base.sed
533 # Delete any #defines of `__i386' which may be present in <ieeefp.h>. They
534 # tend to conflict with the compiler's own definition of this symbol. (We
535 # will use the compiler's definition.)
536 # Likewise __sparc, for Solaris, and __i860, and a few others
537 # (guessing it is necessary for all of them).
540 base=`basename $file`
541 if [ -r ${LIB}/$file ]; then
542 file_to_fix=${LIB}/$file
544 if [ -r ${INPUT}/$file ]; then
545 file_to_fix=${INPUT}/$file
550 if [ \! -z "$file_to_fix" ]; then
551 echo Checking $file_to_fix
552 cp $file_to_fix /tmp/$base
554 sed -e '/#define[ ]*__i386 /d' -e '/#define[ ]*__sparc /d' \
555 -e '/#define[ ]*__i860 /d' -e '/#define[ ]*__m88k /d' \
556 -e '/#define[ ]*__mips /d' -e '/#define[ ]*__m68k /d' \
557 /tmp/$base > /tmp/$base.sed
558 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
561 echo Fixed $file_to_fix
563 cp /tmp/$base.sed ${LIB}/$file
564 chmod a+r ${LIB}/$file
566 rm -f /tmp/$base /tmp/$base.sed
569 # Add a #define of _SIGACTION_ into <sys/signal.h>.
570 # Also fix types of SIG_DFL, SIG_ERR, SIG_IGN, and SIG_HOLD.
573 base=`basename $file`
574 if [ -r ${LIB}/$file ]; then
575 file_to_fix=${LIB}/$file
577 if [ -r ${INPUT}/$file ]; then
578 file_to_fix=${INPUT}/$file
583 if [ \! -z "$file_to_fix" ]; then
584 echo Checking $file_to_fix
585 cp $file_to_fix /tmp/$base
587 sed -e '/^struct sigaction {/c\
589 struct sigaction {' \
590 -e '1,$s/(void *(\*)())/(void (*)(int))/' /tmp/$base > /tmp/$base.sed
591 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
594 echo Fixed $file_to_fix
596 cp /tmp/$base.sed ${LIB}/$file
597 chmod a+r ${LIB}/$file
599 rm -f /tmp/$base /tmp/$base.sed
602 # Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
605 base=`basename $file`
606 if [ -r ${LIB}/$file ]; then
607 file_to_fix=${LIB}/$file
609 if [ -r ${INPUT}/$file ]; then
610 file_to_fix=${INPUT}/$file
615 if [ \! -z "$file_to_fix" ]; then
616 echo Checking $file_to_fix
617 cp $file_to_fix /tmp/$base
619 sed -e '/^dev_t makedev(const/c\
620 static dev_t makedev(const major_t, const minor_t);' \
621 -e '/^dev_t makedev()/c\
622 static dev_t makedev();' \
623 -e '/^major_t major(const/c\
624 static major_t major(const dev_t);' \
625 -e '/^major_t major()/c\
626 static major_t major();' \
627 -e '/^minor_t minor(const/c\
628 static minor_t minor(const dev_t);' \
629 -e '/^minor_t minor()/c\
630 static minor_t minor();' /tmp/$base > /tmp/$base.sed
631 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
634 echo Fixed $file_to_fix
636 cp /tmp/$base.sed ${LIB}/$file
637 chmod a+r ${LIB}/$file
639 rm -f /tmp/$base /tmp/$base.sed
642 # Fix reference to NMSZ in <sys/adv.h>.
645 base=`basename $file`
646 if [ -r ${LIB}/$file ]; then
647 file_to_fix=${LIB}/$file
649 if [ -r ${INPUT}/$file ]; then
650 file_to_fix=${INPUT}/$file
655 if [ \! -z "$file_to_fix" ]; then
656 echo Checking $file_to_fix
657 sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp/$base
658 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
661 echo Fixed $file_to_fix
663 cp /tmp/$base ${LIB}/$file
664 chmod a+r ${LIB}/$file
669 # Fix reference to NC_NPI_RAW in <sys/netcspace.h>. Also fix types of
670 # array initializers.
673 base=`basename $file`
674 if [ -r ${LIB}/$file ]; then
675 file_to_fix=${LIB}/$file
677 if [ -r ${INPUT}/$file ]; then
678 file_to_fix=${INPUT}/$file
683 if [ \! -z "$file_to_fix" ]; then
684 echo Checking $file_to_fix
685 sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
686 | sed 's/NC_/(unsigned long) NC_/' > /tmp/$base
687 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
690 echo Fixed $file_to_fix
692 cp /tmp/$base ${LIB}/$file
693 chmod a+r ${LIB}/$file
698 # Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
700 file=fs/rfs/rf_cache.h
701 base=`basename $file`
702 if [ -r ${LIB}/$file ]; then
703 file_to_fix=${LIB}/$file
705 if [ -r ${INPUT}/$file ]; then
706 file_to_fix=${INPUT}/$file
711 if [ \! -z "$file_to_fix" ]; then
712 echo Checking $file_to_fix
713 if grep _KERNEL $file_to_fix > /dev/null; then
716 echo '#ifdef _KERNEL' > /tmp/$base
717 cat $file_to_fix >> /tmp/$base
718 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
719 echo Fixed $file_to_fix
721 cp /tmp/$base ${LIB}/$file
722 chmod a+r ${LIB}/$file
727 # Conditionalize all of <sys/erec.h> on _KERNEL being defined.
730 base=`basename $file`
731 if [ -r ${LIB}/$file ]; then
732 file_to_fix=${LIB}/$file
734 if [ -r ${INPUT}/$file ]; then
735 file_to_fix=${INPUT}/$file
740 if [ \! -z "$file_to_fix" ]; then
741 echo Checking $file_to_fix
742 if grep _KERNEL $file_to_fix > /dev/null; then
745 echo '#ifdef _KERNEL' > /tmp/$base
746 cat $file_to_fix >> /tmp/$base
747 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
748 echo Fixed $file_to_fix
750 cp /tmp/$base ${LIB}/$file
751 chmod a+r ${LIB}/$file
756 # Conditionalize all of <sys/err.h> on _KERNEL being defined.
759 base=`basename $file`
760 if [ -r ${LIB}/$file ]; then
761 file_to_fix=${LIB}/$file
763 if [ -r ${INPUT}/$file ]; then
764 file_to_fix=${INPUT}/$file
769 if [ \! -z "$file_to_fix" ]; then
770 echo Checking $file_to_fix
771 if grep _KERNEL $file_to_fix > /dev/null; then
774 echo '#ifdef _KERNEL' > /tmp/$base
775 cat $file_to_fix >> /tmp/$base
776 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
777 echo Fixed $file_to_fix
779 cp /tmp/$base ${LIB}/$file
780 chmod a+r ${LIB}/$file
785 # Conditionalize all of <sys/char.h> on _KERNEL being defined.
788 base=`basename $file`
789 if [ -r ${LIB}/$file ]; then
790 file_to_fix=${LIB}/$file
792 if [ -r ${INPUT}/$file ]; then
793 file_to_fix=${INPUT}/$file
798 if [ \! -z "$file_to_fix" ]; then
799 echo Checking $file_to_fix
800 if grep _KERNEL $file_to_fix > /dev/null; then
803 echo '#ifdef _KERNEL' > /tmp/$base
804 cat $file_to_fix >> /tmp/$base
805 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
806 echo Fixed $file_to_fix
808 cp /tmp/$base ${LIB}/$file
809 chmod a+r ${LIB}/$file
814 # Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
817 base=`basename $file`
818 if [ -r ${LIB}/$file ]; then
819 file_to_fix=${LIB}/$file
821 if [ -r ${INPUT}/$file ]; then
822 file_to_fix=${INPUT}/$file
827 if [ \! -z "$file_to_fix" ]; then
828 echo Checking $file_to_fix
829 if grep _KERNEL $file_to_fix > /dev/null; then
832 echo '#ifdef _KERNEL' > /tmp/$base
833 cat $file_to_fix >> /tmp/$base
834 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
835 echo Fixed $file_to_fix
837 cp /tmp/$base ${LIB}/$file
838 chmod a+r ${LIB}/$file
843 # Conditionalize all of <sys/map.h> on _KERNEL being defined.
846 base=`basename $file`
847 if [ -r ${LIB}/$file ]; then
848 file_to_fix=${LIB}/$file
850 if [ -r ${INPUT}/$file ]; then
851 file_to_fix=${INPUT}/$file
856 if [ \! -z "$file_to_fix" ]; then
857 echo Checking $file_to_fix
858 if grep _KERNEL $file_to_fix > /dev/null; then
861 echo '#ifdef _KERNEL' > /tmp/$base
862 cat $file_to_fix >> /tmp/$base
863 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
864 echo Fixed $file_to_fix
866 cp /tmp/$base ${LIB}/$file
867 chmod a+r ${LIB}/$file
872 # Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
875 base=`basename $file`
876 if [ -r ${LIB}/$file ]; then
877 file_to_fix=${LIB}/$file
879 if [ -r ${INPUT}/$file ]; then
880 file_to_fix=${INPUT}/$file
885 if [ \! -z "$file_to_fix" ]; then
886 echo Checking $file_to_fix
887 if grep _KERNEL $file_to_fix > /dev/null; then
890 echo '#ifdef _KERNEL' > /tmp/$base
891 cat $file_to_fix >> /tmp/$base
892 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
893 echo Fixed $file_to_fix
895 cp /tmp/$base ${LIB}/$file
896 chmod a+r ${LIB}/$file
901 # Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
904 base=`basename $file`
905 if [ -r ${LIB}/$file ]; then
906 file_to_fix=${LIB}/$file
908 if [ -r ${INPUT}/$file ]; then
909 file_to_fix=${INPUT}/$file
914 if [ \! -z "$file_to_fix" ]; then
915 echo Checking $file_to_fix
916 if grep _KERNEL $file_to_fix > /dev/null; then
919 echo '#ifdef _KERNEL' > /tmp/$base
920 cat $file_to_fix >> /tmp/$base
921 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
922 echo Fixed $file_to_fix
924 cp /tmp/$base ${LIB}/$file
925 chmod a+r ${LIB}/$file
930 # Conditionalize some of <netinet/in.h> on _KERNEL being defined.
933 base=`basename $file`
934 if [ -r ${LIB}/$file ]; then
935 file_to_fix=${LIB}/$file
937 if [ -r ${INPUT}/$file ]; then
938 file_to_fix=${INPUT}/$file
943 if [ \! -z "$file_to_fix" ]; then
944 echo Checking $file_to_fix
945 if grep _KERNEL $file_to_fix > /dev/null; then
948 sed -e '/#ifdef INKERNEL/i\
950 -e '/#endif[ ]*\/\* INKERNEL \*\//a\
951 #endif /* _KERNEL */' \
952 $file_to_fix > ${LIB}/${file}.sed
953 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
954 echo Fixed $file_to_fix
958 # Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
961 base=`basename $file`
962 if [ -r ${LIB}/$file ]; then
963 file_to_fix=${LIB}/$file
965 if [ -r ${INPUT}/$file ]; then
966 file_to_fix=${INPUT}/$file
971 if [ \! -z "$file_to_fix" ]; then
972 echo Checking $file_to_fix
973 if grep __GNUC__ $file_to_fix > /dev/null; then
976 sed -e '/# ifdef __STDC__/i\
977 # if !defined (__GNUC__) && !defined (__GNUG__)' \
978 -e '/# include <sys\/byteorder.h>/s/ / /'\
979 -e '/# include <sys\/byteorder.h>/i\
980 # endif /* !defined (__GNUC__) && !defined (__GNUG__) */'\
981 $file_to_fix > ${LIB}/${file}.sed
982 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
983 echo Fixed $file_to_fix
987 # Commented out because tmcconne@sedona.intel.com says we don't clearly need it
988 # and the text in types.h is not erroneous.
989 ## In sys/types.h, don't name the enum for booleans.
992 #base=`basename $file`
993 #if [ -r ${LIB}/$file ]; then
994 # file_to_fix=${LIB}/$file
996 # if [ -r ${INPUT}/$file ]; then
997 # file_to_fix=${INPUT}/$file
1002 #if [ \! -z "$file_to_fix" ]; then
1003 # echo Checking $file_to_fix
1004 # if grep "enum boolean" $file_to_fix > /dev/null; then
1005 # sed -e 's/enum boolean/enum/' ${LIB}/$file > ${LIB}/${file}.sed
1006 # rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1007 # echo Fixed $file_to_fix
1013 # Remove useless extern keyword from struct forward declarations in
1014 # <sys/stream.h> and <sys/strsubr.h>
1017 base=`basename $file`
1018 if [ -r ${LIB}/$file ]; then
1019 file_to_fix=${LIB}/$file
1021 if [ -r ${INPUT}/$file ]; then
1022 file_to_fix=${INPUT}/$file
1027 if [ \! -z "$file_to_fix" ]; then
1028 echo Checking $file_to_fix
1030 s/extern struct stdata;/struct stdata;/g
1031 s/extern struct strevent;/struct strevent;/g
1032 ' $file_to_fix > /tmp/$base
1033 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1036 echo Fixed $file_to_fix
1038 cp /tmp/$base ${LIB}/$file
1039 chmod a+r ${LIB}/$file
1045 base=`basename $file`
1046 if [ -r ${LIB}/$file ]; then
1047 file_to_fix=${LIB}/$file
1049 if [ -r ${INPUT}/$file ]; then
1050 file_to_fix=${INPUT}/$file
1055 if [ \! -z "$file_to_fix" ]; then
1056 echo Checking $file_to_fix
1058 s/extern struct strbuf;/struct strbuf;/g
1059 s/extern struct uio;/struct uio;/g
1060 s/extern struct thread;/struct thread;/g
1061 s/extern struct proc;/struct proc;/g
1062 ' $file_to_fix > /tmp/$base
1063 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1066 echo Fixed $file_to_fix
1068 cp /tmp/$base ${LIB}/$file
1069 chmod a+r ${LIB}/$file
1074 # Put storage class at start of decl, to avoid warning.
1076 base=`basename $file`
1077 if [ -r ${LIB}/$file ]; then
1078 file_to_fix=${LIB}/$file
1080 if [ -r ${INPUT}/$file ]; then
1081 file_to_fix=${INPUT}/$file
1086 if [ \! -z "$file_to_fix" ]; then
1087 echo Checking $file_to_fix
1089 s/const extern/extern const/g
1090 ' $file_to_fix > /tmp/$base
1091 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1094 echo Fixed $file_to_fix
1096 cp /tmp/$base ${LIB}/$file
1097 chmod a+r ${LIB}/$file
1102 # Convert functions to prototype form, and fix arg names in <sys/stat.h>.
1105 base=`basename $file`
1106 if [ -r ${LIB}/$file ]; then
1107 file_to_fix=${LIB}/$file
1109 if [ -r ${INPUT}/$file ]; then
1110 file_to_fix=${INPUT}/$file
1115 if [ \! -z "$file_to_fix" ]; then
1116 echo Checking $file_to_fix
1117 cp $file_to_fix /tmp/$base
1148 -e '1,$s/\([^A-Za-z]\)path\([^A-Za-z]\)/\1__path\2/g' \
1149 -e '1,$s/\([^A-Za-z]\)buf\([^A-Za-z]\)/\1__buf\2/g' \
1150 -e '1,$s/\([^A-Za-z]\)fd\([^A-Za-z]\)/\1__fd\2/g' \
1151 -e '1,$s/ret\([^u]\)/__ret\1/g' \
1152 -e '1,$s/\([^_]\)mode\([^_]\)/\1__mode\2/g' \
1153 -e '1,$s/\([^_r]\)dev\([^_]\)/\1__dev\2/g' /tmp/$base > /tmp/$base.sed
1154 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
1157 echo Fixed $file_to_fix
1159 cp /tmp/$base.sed ${LIB}/$file
1160 chmod a+r ${LIB}/$file
1162 rm -f /tmp/$base /tmp/$base.sed
1165 # Sony NEWSOS 5.0 does not support the complete ANSI C standard.
1167 if [ -x /bin/sony ]; then
1170 # Change <stdio.h> to not define __filbuf, __flsbuf, and __iob
1173 base=`basename $file`
1174 if [ -r ${LIB}/$file ]; then
1175 file_to_fix=${LIB}/$file
1177 if [ -r ${INPUT}/$file ]; then
1178 file_to_fix=${INPUT}/$file
1183 if [ \! -z "$file_to_fix" ]; then
1184 echo Checking $file_to_fix
1185 cp $file_to_fix /tmp/$base
1188 s/__filbuf/_filbuf/g
1189 s/__flsbuf/_flsbuf/g
1191 ' /tmp/$base > /tmp/$base.sed
1192 mv /tmp/$base.sed /tmp/$base
1193 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1196 echo Fixed $file_to_fix
1198 cp /tmp/$base ${LIB}/$file
1199 chmod a+r ${LIB}/$file
1204 # Change <ctype.h> to not define __ctype
1207 base=`basename $file`
1208 if [ -r ${LIB}/$file ]; then
1209 file_to_fix=${LIB}/$file
1211 if [ -r ${INPUT}/$file ]; then
1212 file_to_fix=${INPUT}/$file
1217 if [ \! -z "$file_to_fix" ]; then
1218 echo Checking $file_to_fix
1219 cp $file_to_fix /tmp/$base
1223 ' /tmp/$base > /tmp/$base.sed
1224 mv /tmp/$base.sed /tmp/$base
1225 if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
1228 echo Fixed $file_to_fix
1230 cp /tmp/$base ${LIB}/$file
1231 chmod a+r ${LIB}/$file
1238 # In limits.h, put #ifndefs around things that are supposed to be defined
1239 # in float.h to avoid redefinition errors if float.h is included first.
1240 # Solaris 2.1 has this problem.
1243 base=`basename $file`
1244 if [ -r ${LIB}/$file ]; then
1245 file_to_fix=${LIB}/$file
1247 if [ -r ${INPUT}/$file ]; then
1248 file_to_fix=${INPUT}/$file
1253 if [ \! -z "$file_to_fix" ]; then
1254 echo Checking $file_to_fix
1255 sed -e '/[ ]FLT_MIN[ ]/i\
1257 -e '/[ ]FLT_MIN[ ]/a\
1259 -e '/[ ]FLT_MAX[ ]/i\
1261 -e '/[ ]FLT_MAX[ ]/a\
1263 -e '/[ ]FLT_DIG[ ]/i\
1265 -e '/[ ]FLT_DIG[ ]/a\
1267 -e '/[ ]DBL_MIN[ ]/i\
1269 -e '/[ ]DBL_MIN[ ]/a\
1271 -e '/[ ]DBL_MAX[ ]/i\
1273 -e '/[ ]DBL_MAX[ ]/a\
1275 -e '/[ ]DBL_DIG[ ]/i\
1277 -e '/[ ]DBL_DIG[ ]/a\
1278 #endif' $file_to_fix > /tmp/$base
1279 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
1282 echo Fixed $file_to_fix
1284 cp /tmp/$base ${LIB}/$file
1285 chmod a+r ${LIB}/$file
1290 # Completely replace <sys/varargs.h> with a file that includes gcc's
1291 # stdarg.h or varargs.h files as appropriate.
1294 if [ -r ${INPUT}/$file ]; then
1295 echo Replacing $file
1296 cat > ${LIB}/$file << EOF
1297 /* This file was generated by fixincludes. */
1298 #ifndef _SYS_VARARGS_H
1299 #define _SYS_VARARGS_H
1304 #include <varargs.h>
1307 #endif /* _SYS_VARARGS_H */
1309 chmod a+r ${LIB}/$file
1312 echo 'Removing unneeded directories:'
1314 files=`find . -type d -print | sort -r`
1315 for file in $files; do
1316 rmdir $LIB/$file > /dev/null 2>&1
1320 echo 'Making internal symbolic non-directory links'
1322 files=`find . -type l -print`
1323 for file in $files; do
1324 dest=`ls -ld $file | sed -n 's/.*-> //p'`
1325 if expr "$dest" : '[^/].*' > /dev/null; then
1326 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1327 if [ -f $target ]; then
1328 ln -s $dest ${LIB}/$file >/dev/null 2>&1
1336 echo 'Replacing <sys/byteorder.h>'
1337 rm -f ${LIB}/sys/byteorder.h
1338 cp ${SRCDIR}/byteorder.h ${LIB}/sys/byteorder.h