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 containing the original header files.
35 INPUT=${2-${INPUT-/usr/include}}
37 # Fail if no arg to specify a directory for the output.
39 then echo fixincludes: no output directory specified
43 # Directory in which to store the results.
44 LIB=${1-${LIB-/usr/local/lib/gcc-include}}
46 # Make sure it exists.
47 if [ ! -d $LIB ]; then
56 # This prevents /bin/ex from failing if the current terminal type is
61 echo 'Building fixincludes in ' ${LIB}
63 # Determine whether this filesystem has symbolic links.
64 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
65 rm -f $LIB/ShouldNotExist
71 echo 'Making directories:'
74 files=`ls -LR | sed -n s/:$//p`
76 files=`find . -type d -print | sed '/^.$/d'`
78 for file in $files; do
80 if [ ! -d $LIB/$file ]
85 # treetops gets an alternating list
86 # of old directories to copy
87 # and the new directories to copy to.
88 treetops="${INPUT} ${LIB}"
91 echo 'Making internal symbolic directory links'
92 for file in $files; do
93 dest=`ls -ld $file | sed -n 's/.*-> //p'`
96 # In case $dest is relative, get to $file's dir first.
98 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
99 # Check that the target directory exists.
100 # Redirections changed to avoid bug in sh on Ultrix.
101 (cd $dest) > /dev/null 2>&1
104 # X gets the dir that the link actually leads to.
106 # If link leads back into ${INPUT},
107 # make a similar link here.
108 if expr $x : "${INPUT}/.*" > /dev/null; then
109 # Y gets the actual target dir name, relative to ${INPUT}.
110 y=`echo $x | sed -n "s&${INPUT}/&&p"`
111 echo $file '->' $y ': Making link'
112 rm -fr ${LIB}/$file > /dev/null 2>&1
113 ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
115 # If the link is to outside ${INPUT},
116 # treat this directory as if it actually contained the files.
117 # This line used to have $dest instead of $x.
118 # $dest seemed to be wrong for links found in subdirectories
119 # of ${INPUT}. Does this change break anything?
120 treetops="$treetops $x ${LIB}/$file"
129 while [ $# != 0 ]; do
130 # $1 is an old directory to copy, and $2 is the new directory to copy to.
131 echo "Finding header files in $1:"
134 files=`find . -name '*.h' -type f -print`
135 echo 'Checking header files:'
136 for file in $files; do
138 if [ -r $file ]; then
139 cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
142 # The following have been removed from the sed command below
143 # because it is more useful to leave these things in.
144 # The only reason to remove them was for -pedantic,
145 # which isn't much of a reason. -- rms.
148 # The change of u_char, etc, to u_int
149 # applies to bit fields.
151 s%^\([ ]*#[ ]*endif[ ]*\)\([^/ ].*\)$%\1/* \2 */%
152 s%^\([ ]*#[ ]*else[ ]*\)\([^/ ].*\)$%\1/* \2 */%
153 s/#lint(on)/defined(lint)/g
154 s/#lint(off)/!defined(lint)/g
155 s/#machine(\([^)]*\))/defined(__\1__)/g
156 s/#system(\([^)]*\))/defined(__\1__)/g
157 s/#cpu(\([^)]*\))/defined(__\1__)/g
158 /#[a-z]*if.*[ (]m68k/ s/\([^_]\)m68k/\1__m68k__/g
159 /#[a-z]*if.*[ (]__i386/ s/__i386/__i386__/g
160 /#[a-z]*if.*[ (]i386/ s/\([^_]\)i386/\1__i386__/g
161 /#[a-z]*if.*[ (]sparc/ s/\([^_]\)sparc/\1__sparc__/g
162 /#[a-z]*if.*[ (]mc68000/ s/\([^_]\)mc68000/\1__mc68000__/g
163 /#[a-z]*if.*[ (]vax/ s/\([^_]\)vax/\1__vax__/g
164 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
165 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
166 /#[a-z]*if.*[ (]ns32000/ s/\([^_]\)ns32000/\1__ns32000__/g
167 /#[a-z]*if.*[ (]pyr/ s/\([^_]\)pyr/\1__pyr__/g
168 /#[a-z]*if.*[ (]is68k/ s/\([^_]\)is68k/\1__is68k__/g
169 s/u_char\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
170 s/u_short\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
171 s/ushort\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
172 s/evcm_t\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*[0-9][0-9]*\)/u_int\1/
173 s/Pbyte\([ ][ ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[ ]*:[ ]*SEQSIZ\)/unsigned int\1/
174 s/__STDC__ == 0/!defined (__STRICT_ANSI__)/g
175 s/__STDC__ != 0/defined (__STRICT_ANSI__)/g
176 s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
177 ' $2/$file > $2/$file.sed
178 mv $2/$file.sed $2/$file
179 if cmp $file $2/$file >/dev/null 2>&1; then
180 echo Deleting $2/$file\; no fixes were needed.
188 # Fix first broken decl of getcwd present on some svr4 systems.
191 base=`basename $file`
192 if [ -r ${LIB}/$file ]; then
193 file_to_fix=${LIB}/$file
195 if [ -r ${INPUT}/$file ]; then
196 file_to_fix=${INPUT}/$file
201 if [ \! -z "$file_to_fix" ]; then
202 echo Checking $file_to_fix
203 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
204 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
205 echo No change needed in $file_to_fix
207 echo Fixed $file_to_fix
209 cp /tmp/$base ${LIB}/$file
214 # Fix second broken decl of getcwd present on some svr4 systems. Also
215 # fix the incorrect decl of profil present on some svr4 systems.
218 base=`basename $file`
219 if [ -r ${LIB}/$file ]; then
220 file_to_fix=${LIB}/$file
222 if [ -r ${INPUT}/$file ]; then
223 file_to_fix=${INPUT}/$file
228 if [ \! -z "$file_to_fix" ]; then
229 echo Checking $file_to_fix
230 sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
231 | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
232 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
233 echo No change needed in $file_to_fix
235 echo Fixed $file_to_fix
237 cp /tmp/$base ${LIB}/$file
242 # Fix the definition of NULL in <sys/param.h> so that it is conditional
243 # and so that it is correct for both C and C++.
246 base=`basename $file`
247 if [ -r ${LIB}/$file ]; then
248 file_to_fix=${LIB}/$file
250 if [ -r ${INPUT}/$file ]; then
251 file_to_fix=${INPUT}/$file
256 if [ \! -z "$file_to_fix" ]; then
257 echo Checking $file_to_fix
258 cp $file_to_fix /tmp/$base
261 /^#define[ ]*NULL[ ]*0$/c
265 #else /* !defined(__cplusplus) */
266 #define __NULL_TYPE (void *)
267 #endif /* !defined(__cplusplus) */
268 #define NULL (__NULL_TYPE 0)
269 #endif /* !defined(NULL) */
273 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
274 echo No change needed in $file_to_fix
276 echo Fixed $file_to_fix
278 cp /tmp/$base ${LIB}/$file
283 # Likewise fix the definition of NULL in <stdio.h> so that it is conditional
284 # and so that it is correct for both C and C++.
287 base=`basename $file`
288 if [ -r ${LIB}/$file ]; then
289 file_to_fix=${LIB}/$file
291 if [ -r ${INPUT}/$file ]; then
292 file_to_fix=${INPUT}/$file
297 if [ \! -z "$file_to_fix" ]; then
298 echo Checking $file_to_fix
299 cp $file_to_fix /tmp/$base
302 /^#define[ ]*NULL[ ]*0$/c
305 #else /* !defined(__cplusplus) */
306 #define __NULL_TYPE (void *)
307 #endif /* !defined(__cplusplus) */
308 #define NULL (__NULL_TYPE 0)
312 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
313 echo No change needed in $file_to_fix
315 echo Fixed $file_to_fix
317 cp /tmp/$base ${LIB}/$file
322 # Add some missing declarations to <sys/mman.h>.
325 base=`basename $file`
326 if [ -r ${LIB}/$file ]; then
327 file_to_fix=${LIB}/$file
329 if [ -r ${INPUT}/$file ]; then
330 file_to_fix=${INPUT}/$file
335 if [ \! -z "$file_to_fix" ]; then
336 echo Checking $file_to_fix
337 cp $file_to_fix /tmp/$base
340 /^extern caddr_t mmap();$/c
342 extern caddr_t mmap (caddr_t addr, size_t len, int prot, int flags,
344 #else /* !defined(__STDC__) */
345 extern caddr_t mmap ();
346 #endif /* !defined(__STDC__) */
350 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
351 echo No changed needed in $file_to_fix
353 echo Fixed $file_to_fix
355 cp /tmp/$base ${LIB}/$file
360 # Fix declarations of `ftw' and `nftw' in <ftw.h>.
363 base=`basename $file`
364 if [ -r ${LIB}/$file ]; then
365 file_to_fix=${LIB}/$file
367 if [ -r ${INPUT}/$file ]; then
368 file_to_fix=${INPUT}/$file
373 if [ \! -z "$file_to_fix" ]; then
374 echo Checking $file_to_fix
375 cp $file_to_fix /tmp/$base
378 /^extern int ftw(const/c
379 #if !defined(_STYPES)
384 int ftw(const char *, int (*)(const char *, const struct stat *, int), int);
392 int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *),int, int);
394 /^extern int ftw(),/c
395 #if !defined(_STYPES)
410 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
411 echo No change needed in $file_to_fix
413 echo Fixed $file_to_fix
415 cp /tmp/$base ${LIB}/$file
420 # Add a `static' declaration of `getrnge' into <regexp.h>.
423 base=`basename $file`
424 if [ -r ${LIB}/$file ]; then
425 file_to_fix=${LIB}/$file
427 if [ -r ${INPUT}/$file ]; then
428 file_to_fix=${INPUT}/$file
433 if [ \! -z "$file_to_fix" ]; then
434 echo Checking $file_to_fix
435 cp $file_to_fix /tmp/$base
438 /^static int[ ]*size;/c
441 static int getrnge ();
445 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
446 echo No change needed in $file_to_fix
448 echo Fixed $file_to_fix
450 cp /tmp/$base ${LIB}/$file
455 # Add a #define of _SIGACTION_ into <sys/signal.h>.
458 base=`basename $file`
459 if [ -r ${LIB}/$file ]; then
460 file_to_fix=${LIB}/$file
462 if [ -r ${INPUT}/$file ]; then
463 file_to_fix=${INPUT}/$file
468 if [ \! -z "$file_to_fix" ]; then
469 echo Checking $file_to_fix
470 cp $file_to_fix /tmp/$base
473 /^struct sigaction {/c
479 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
480 echo No change needed in $file_to_fix
482 echo Fixed $file_to_fix
484 cp /tmp/$base ${LIB}/$file
489 # Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
492 base=`basename $file`
493 if [ -r ${LIB}/$file ]; then
494 file_to_fix=${LIB}/$file
496 if [ -r ${INPUT}/$file ]; then
497 file_to_fix=${INPUT}/$file
502 if [ \! -z "$file_to_fix" ]; then
503 echo Checking $file_to_fix
504 cp $file_to_fix /tmp/$base
507 /^dev_t makedev(const/c
508 static dev_t makedev(const major_t, const minor_t);
511 static dev_t makedev();
513 /^major_t major(const/c
514 static major_t major(const dev_t);
517 static major_t major();
519 /^minor_t minor(const/c
520 static minor_t minor(const dev_t);
523 static minor_t minor();
527 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
528 echo No change needed in $file_to_fix
530 echo Fixed $file_to_fix
532 cp /tmp/$base ${LIB}/$file
537 # Fix reference to NMSZ in <sys/adv.h>.
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 sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp/$base
553 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
554 echo No change needed in $file_to_fix
556 echo Fixed $file_to_fix
558 cp /tmp/$base ${LIB}/$file
563 # Fix reference to NC_NPI_RAW in <sys/netcspace.h>. Also fix types of
564 # array initializers.
567 base=`basename $file`
568 if [ -r ${LIB}/$file ]; then
569 file_to_fix=${LIB}/$file
571 if [ -r ${INPUT}/$file ]; then
572 file_to_fix=${INPUT}/$file
577 if [ \! -z "$file_to_fix" ]; then
578 echo Checking $file_to_fix
579 sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
580 | sed 's/NC_/(unsigned long) NC_/' > /tmp/$base
581 if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
582 echo No change needed in $file_to_fix
584 echo Fixed $file_to_fix
586 cp /tmp/$base ${LIB}/$file
591 # Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
593 file=fs/rfs/rf_cache.h
594 base=`basename $file`
595 if [ -r ${LIB}/$file ]; then
596 file_to_fix=${LIB}/$file
598 if [ -r ${INPUT}/$file ]; then
599 file_to_fix=${INPUT}/$file
604 if [ \! -z "$file_to_fix" ]; then
605 echo Checking $file_to_fix
606 if grep _KERNEL $file_to_fix > /dev/null; then
607 echo No change needed in $file_to_fix
609 echo '#ifdef _KERNEL' > /tmp/$base
610 cat $file_to_fix >> /tmp/$base
611 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
612 echo Fixed $file_to_fix
614 cp /tmp/$base ${LIB}/$file
619 # Conditionalize all of <sys/erec.h> on _KERNEL being defined.
622 base=`basename $file`
623 if [ -r ${LIB}/$file ]; then
624 file_to_fix=${LIB}/$file
626 if [ -r ${INPUT}/$file ]; then
627 file_to_fix=${INPUT}/$file
632 if [ \! -z "$file_to_fix" ]; then
633 echo Checking $file_to_fix
634 if grep _KERNEL $file_to_fix > /dev/null; then
635 echo No change needed in $file_to_fix
637 echo '#ifdef _KERNEL' > /tmp/$base
638 cat $file_to_fix >> /tmp/$base
639 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
640 echo Fixed $file_to_fix
642 cp /tmp/$base ${LIB}/$file
647 # Conditionalize all of <sys/err.h> on _KERNEL being defined.
650 base=`basename $file`
651 if [ -r ${LIB}/$file ]; then
652 file_to_fix=${LIB}/$file
654 if [ -r ${INPUT}/$file ]; then
655 file_to_fix=${INPUT}/$file
660 if [ \! -z "$file_to_fix" ]; then
661 echo Checking $file_to_fix
662 if grep _KERNEL $file_to_fix > /dev/null; then
663 echo No change needed in $file_to_fix
665 echo '#ifdef _KERNEL' > /tmp/$base
666 cat $file_to_fix >> /tmp/$base
667 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
668 echo Fixed $file_to_fix
670 cp /tmp/$base ${LIB}/$file
675 # Conditionalize all of <sys/char.h> on _KERNEL being defined.
678 base=`basename $file`
679 if [ -r ${LIB}/$file ]; then
680 file_to_fix=${LIB}/$file
682 if [ -r ${INPUT}/$file ]; then
683 file_to_fix=${INPUT}/$file
688 if [ \! -z "$file_to_fix" ]; then
689 echo Checking $file_to_fix
690 if grep _KERNEL $file_to_fix > /dev/null; then
691 echo No change needed in $file_to_fix
693 echo '#ifdef _KERNEL' > /tmp/$base
694 cat $file_to_fix >> /tmp/$base
695 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
696 echo Fixed $file_to_fix
698 cp /tmp/$base ${LIB}/$file
703 # Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
706 base=`basename $file`
707 if [ -r ${LIB}/$file ]; then
708 file_to_fix=${LIB}/$file
710 if [ -r ${INPUT}/$file ]; then
711 file_to_fix=${INPUT}/$file
716 if [ \! -z "$file_to_fix" ]; then
717 echo Checking $file_to_fix
718 if grep _KERNEL $file_to_fix > /dev/null; then
719 echo No change needed in $file_to_fix
721 echo '#ifdef _KERNEL' > /tmp/$base
722 cat $file_to_fix >> /tmp/$base
723 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
724 echo Fixed $file_to_fix
726 cp /tmp/$base ${LIB}/$file
731 # Conditionalize all of <sys/map.h> on _KERNEL being defined.
734 base=`basename $file`
735 if [ -r ${LIB}/$file ]; then
736 file_to_fix=${LIB}/$file
738 if [ -r ${INPUT}/$file ]; then
739 file_to_fix=${INPUT}/$file
744 if [ \! -z "$file_to_fix" ]; then
745 echo Checking $file_to_fix
746 if grep _KERNEL $file_to_fix > /dev/null; then
747 echo No change needed in $file_to_fix
749 echo '#ifdef _KERNEL' > /tmp/$base
750 cat $file_to_fix >> /tmp/$base
751 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
752 echo Fixed $file_to_fix
754 cp /tmp/$base ${LIB}/$file
759 # Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
762 base=`basename $file`
763 if [ -r ${LIB}/$file ]; then
764 file_to_fix=${LIB}/$file
766 if [ -r ${INPUT}/$file ]; then
767 file_to_fix=${INPUT}/$file
772 if [ \! -z "$file_to_fix" ]; then
773 echo Checking $file_to_fix
774 if grep _KERNEL $file_to_fix > /dev/null; then
775 echo No change needed in $file_to_fix
777 echo '#ifdef _KERNEL' > /tmp/$base
778 cat $file_to_fix >> /tmp/$base
779 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
780 echo Fixed $file_to_fix
782 cp /tmp/$base ${LIB}/$file
787 # Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
790 base=`basename $file`
791 if [ -r ${LIB}/$file ]; then
792 file_to_fix=${LIB}/$file
794 if [ -r ${INPUT}/$file ]; then
795 file_to_fix=${INPUT}/$file
800 if [ \! -z "$file_to_fix" ]; then
801 echo Checking $file_to_fix
802 if grep _KERNEL $file_to_fix > /dev/null; then
803 echo No change needed in $file_to_fix
805 echo '#ifdef _KERNEL' > /tmp/$base
806 cat $file_to_fix >> /tmp/$base
807 echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
808 echo Fixed $file_to_fix
810 cp /tmp/$base ${LIB}/$file
815 echo 'Removing unneeded directories:'
817 files=`find . -type d -print | sort -r`
818 for file in $files; do
819 rmdir $LIB/$file > /dev/null 2>&1
823 echo 'Making internal symbolic non-directory links'
825 files=`find . -type l -print`
826 for file in $files; do
827 dest=`ls -ld $file | sed -n 's/.*-> //p'`
828 if expr "$dest" : '[^/].*' > /dev/null; then
829 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
830 if [ -f $target ]; then
831 ln -s $dest ${LIB}/$file >/dev/null 2>&1
839 echo 'Replacing <sys/byteorder.h>'
840 rm -f ${LIB}/sys/byteorder.h
841 cp byteorder.h ${LIB}/sys/byteorder.h