2 # Install modified versions of certain ANSI-incompatible system header files
3 # which are fixed to work correctly with ANSI C
4 # and placed in a directory that GNU C will search.
6 # See README-fixinc for more information.
8 # Directory containing the original header files.
9 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
10 INPUT=${2-${INPUT-/usr/include}}
12 # This prevents /bin/ex from failing if the current terminal type is
17 # Directory in which to store the results.
18 LIB=${1-${LIB-/usr/local/lib/gcc-include}}
20 # Make sure it exists.
21 if [ ! -d $LIB ]; then
28 # Fail if no arg to specify a directory for the output.
30 then echo fixincludes: no output directory specified
34 echo 'Building fixincludes in ' ${LIB}
36 # Determine whether this system has symbolic links.
37 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
38 rm -f $LIB/ShouldNotExist
44 echo 'Making directories:'
46 # Find all directories and all symlinks that point to directories.
47 files=` find . -type d -print | sed '/^.$/d'
48 $LINKS && find . -type l -exec test -d '{}' \; -print`
49 for file in $files; do
51 if [ ! -d $LIB/$file ]
56 # treetops gets an alternating list
57 # of old directories to copy
58 # and the new directories to copy to.
59 treetops="${INPUT} ${LIB}"
62 echo 'Making internal symbolic directory links'
63 for file in $files; do
64 dest=`ls -ld $file | sed -n 's/.*-> //p'`
67 # In case $dest is relative, get to $file's dir first.
69 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
70 # Check that the target directory exists.
71 # Redirections changed to avoid bug in sh on Ultrix.
72 (cd $dest) > /dev/null 2>&1
75 # X gets the dir that the link actually leads to.
77 # If link leads back into ${INPUT},
78 # make a similar link here.
79 if expr $x : "${INPUT}/.*" > /dev/null; then
80 # Y gets the actual target dir name, relative to ${INPUT}.
81 y=`echo $x | sed -n "s&${INPUT}/&&p"`
82 echo $file '->' $y ': Making link'
83 rm -fr ${LIB}/$file > /dev/null 2>&1
84 ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
86 # If the link is to outside ${INPUT},
87 # treat this directory as if it actually contained the files.
88 # This line used to have $dest instead of $x.
89 # $dest seemed to be wrong for links found in subdirectories
90 # of ${INPUT}. Does this change break anything?
91 treetops="$treetops $x ${LIB}/$file"
100 while [ $# != 0 ]; do
101 # $1 is an old directory to copy, and $2 is the new directory to copy to.
102 echo "Finding header files in $1:"
105 files=`find . -name '*.h' -type f -print`
106 echo 'Checking header files:'
107 # Note that BSD43_* are used on recent MIPS systems.
108 for file in $files; do
109 # This call to egrep is essential, since checking a file with egrep
110 # is much faster than actually trying to fix it.
111 # It is also essential that most files *not* match!
112 # Thus, matching every #endif is unacceptable.
113 # But the argument to egrep must be kept small, or many versions of egrep
114 # won't be able to handle it.
115 # rms: I removed `|#[el].*if.*[^/ ]' because it made egrep fail.
116 if egrep '[ _]_IO|CTRL|#define.NULL|#[el]*if.*([0-9]|sparc|vax|sun|pyr)' $file > /dev/null; then
118 if [ -r $file ]; then
119 cp $file $2/$file >/dev/null 2>&1 \
120 || echo "Can't copy $file"
122 # Following two lines removed.
123 # s%^\([ ]*#[ ]*endif[ ]*\)\([^/ ].*\)$%\1/* \2 */%
124 # s%^\([ ]*#[ ]*else[ ]*\)\([^/ ].*\)$%\1/* \2 */%
130 /[ ]_IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
131 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
132 /#define._IO/ s/'\''x'\''/x/g
133 /#define.BSD43__IO/ s/'\''x'\''/x/g
134 /[^A-Z]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
135 /#define.CTRL/ s/'\''c'\''/c/g
136 /#define._CTRL/ s/'\''c'\''/c/g
137 /#define.BSD43_CTRL/ s/'\''c'\''/c/g
138 /#[a-z]*if.*[ (]m68k/ s/\([^_]\)m68k/\1__m68k__/g
139 /#[a-z]*if.*[ (]__i386/ s/__i386/__i386__/g
140 /#[a-z]*if.*[ (]i386/ s/\([^_]\)i386/\1__i386__/g
141 /#[a-z]*if.*[ (]sparc/ s/\([^_]\)sparc/\1__sparc__/g
142 /#[a-z]*if.*[ (]mc68000/ s/\([^_]\)mc68000/\1__mc68000__/g
143 /#[a-z]*if.*[ (]vax/ s/\([^_]\)vax/\1__vax__/g
144 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
145 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
146 /#[a-z]*if.*[ (]ns32000/ s/\([^_]\)ns32000/\1__ns32000__/g
147 /#[a-z]*if.*[ (]pyr/ s/\([^_]\)pyr/\1__pyr__/g
148 /#[a-z]*if.*[ (]is68k/ s/\([^_]\)is68k/\1__is68k__/g
151 ' $2/$file > $2/$file.sed
152 mv $2/$file.sed $2/$file
153 if cmp $file $2/$file >/dev/null 2>&1; then
154 echo Deleting $2/$file\; no fixes were needed.
165 # Fix one other error in this file: a mismatched quote not inside a C comment.
166 file=sundev/vuid_event.h
167 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
168 mkdir ${LIB}/sundev 2>/dev/null
169 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
170 chmod +w ${LIB}/$file 2>/dev/null
173 if [ -r ${LIB}/$file ]; then
174 echo Fixing $file comment
175 ex ${LIB}/$file <<EOF
176 g/doesn't/s/doesn't/does not/
179 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
180 echo Deleting ${LIB}/$file\; no fixes were needed.
185 # Fix this Sun file to avoid interfering with stddef.h.
187 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
188 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
189 chmod +w ${LIB}/$file 2>/dev/null
192 if [ -r ${LIB}/$file ]; then
194 ex ${LIB}/$file <<EOF
206 #ifndef _GCC_PTRDIFF_T
207 #define _GCC_PTRDIFF_T
224 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
225 echo Deleting ${LIB}/$file\; no fixes were needed.
230 # Fix this file to avoid interfering with stddef.h.
232 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
233 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
234 chmod +w ${LIB}/$file 2>/dev/null
237 if [ -r ${LIB}/$file ]; then
239 ex ${LIB}/$file <<EOF
251 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
252 echo Deleting ${LIB}/$file\; no fixes were needed.
257 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
258 # structure definition.
260 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
261 mkdir ${LIB}/rpcsvc 2>/dev/null
262 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
263 chmod +w ${LIB}/$file 2>/dev/null
266 if [ -r ${LIB}/$file ]; then
267 echo Fixing $file, definition of statsswtch
268 ex ${LIB}/$file <<EOF
272 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
273 echo Deleting ${LIB}/$file\; no fixes were needed.
278 # Fix an error in this file: a missing semi-colon at the end of the nodeent
279 # structure definition.
280 file=netdnet/dnetdb.h
281 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
282 mkdir ${LIB}/netdnet 2>/dev/null
283 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
284 chmod +w ${LIB}/$file 2>/dev/null
287 if [ -r ${LIB}/$file ]; then
288 echo Fixing $file, definition of nodeent
289 ex ${LIB}/$file <<EOF
293 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
294 echo Deleting ${LIB}/$file\; no fixes were needed.
299 # Check for bad #ifdef line (in Ultrix 4.1)
301 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
302 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
303 chmod +w ${LIB}/$file 2>/dev/null
306 if [ -r ${LIB}/$file ]; then
307 echo Fixing $file, bad \#ifdef line
308 ex ${LIB}/$file <<EOF
309 g/^#ifdef KERNEL && !defined/
310 s/#ifdef KERNEL && !defined/#if defined(KERNEL) \&\& !defined/
313 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
314 echo Deleting ${LIB}/$file\; no fixes were needed.
319 # Remove nested comments created by #endifs in a comment (Ultrix 4.1)
320 # Only needed if commenting out junk after #endif.
322 #if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
323 # cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
324 # chmod +w ${LIB}/$file 2>/dev/null
327 #if [ -r ${LIB}/$file ]; then
328 # echo Fixing $file, nested comments
329 # sed -e 's/#endif.*/#endif/' ${LIB}/$file > ${LIB}/${file}.sed
330 # rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
331 # if cmp $file ${LIB}/$file >/dev/null 2>&1; then
332 # echo Deleting ${LIB}/$file\; no fixes were needed.
337 # Check for superfluous `static' (in Ultrix 4.2)
339 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
340 mkdir ${LIB}/machine 2>/dev/null
341 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
342 chmod +w ${LIB}/$file 2>/dev/null
345 if [ -r ${LIB}/$file ]; then
346 echo Fixing $file, superfluous static
347 ex ${LIB}/$file <<EOF
348 g/^static struct tlb_pid_state/
352 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
353 echo Deleting ${LIB}/$file\; no fixes were needed.
356 # This file has an alternative name, mips/cpu.h. Fix that name, too.
357 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
358 mkdir ${LIB}/mips 2>&-
359 ln ${LIB}/$file ${LIB}/mips/cpu.h
364 # Incorrect sprintf declaration in X11/Xmu.h
366 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
367 mkdir ${LIB}/X11 2>/dev/null
368 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
369 chmod +w ${LIB}/$file 2>/dev/null
372 if [ -r ${LIB}/$file ]; then
373 echo Fixing $file sprintf declaration
374 ex ${LIB}/$file <<EOF
375 /^extern char \* sprintf();$/c
377 extern char * sprintf();
378 #endif /* !defined __STDC__ */
382 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
383 echo Deleting ${LIB}/$file\; no fixes were needed.
388 # Check for missing ';' in struct
390 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
391 mkdir ${LIB}/netinet 2>/dev/null
392 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
393 chmod +w ${LIB}/$file 2>/dev/null
396 if [ -r ${LIB}/$file ]; then
398 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
399 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
400 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
401 echo Deleting ${LIB}/$file\; no fixes were needed.
406 # Fix the CAT macro in SunOS memvar.h.
407 file=pixrect/memvar.h
408 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
409 mkdir ${LIB}/pixrect 2>/dev/null
410 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
411 chmod +w ${LIB}/$file 2>/dev/null
414 if [ -r ${LIB}/$file ]; then
416 sed -e '/^#define.CAT(a,b)/ i\
418 #define CAT(a,b) a##b\
420 /^#define.CAT(a,b)/ a\
422 ' ${LIB}/$file > ${LIB}/${file}.sed
423 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
424 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
425 echo Deleting ${LIB}/$file\; no fixes were needed.
430 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
432 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
433 mkdir ${LIB}/rpcsvc 2>/dev/null
434 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
435 chmod +w ${LIB}/$file 2>/dev/null
438 if [ -r ${LIB}/$file ]; then
440 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
441 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
442 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
443 echo Deleting ${LIB}/$file\; no fixes were needed.
448 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
450 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
451 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
452 chmod +w ${LIB}/$file 2>/dev/null
455 if [ -r ${LIB}/$file ]; then
457 sed -e 's/int abort/void abort/g' \
458 -e 's/int free/void free/g' \
459 -e 's/char \* calloc/void \* calloc/g' \
460 -e 's/char \* malloc/void \* malloc/g' \
461 -e 's/char \* realloc/void \* realloc/g' \
462 -e 's/int exit/void exit/g' ${LIB}/$file > ${LIB}/${file}.sed
463 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
464 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
465 echo Deleting ${LIB}/$file\; no fixes were needed.
470 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
472 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
473 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
474 chmod +w ${LIB}/$file 2>/dev/null
477 if [ -r ${LIB}/$file ]; then
479 sed -e 's/typedef char \* malloc_t/typedef void \* malloc_t/g' \
480 ${LIB}/$file > ${LIB}/${file}.sed
481 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
482 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
483 echo Deleting ${LIB}/$file\; no fixes were needed.
489 # Fix bogus comment in <locale.h> on SunOS 4.1.
491 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
492 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
493 chmod +w ${LIB}/$file 2>/dev/null
496 if [ -r ${LIB}/$file ]; then
498 sed -e 's%#endif / \*%#endif /\* %g' ${LIB}/$file > ${LIB}/${file}.sed
499 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
500 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
501 echo Deleting ${LIB}/$file\; no fixes were needed.
506 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
507 file=hsfs/hsfs_spec.h
508 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
509 mkdir ${LIB}/hsfs 2>/dev/null
510 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
511 chmod +w ${LIB}/$file 2>/dev/null
514 if [ -r ${LIB}/$file ]; then
516 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
517 ${LIB}/$file > ${LIB}/${file}.sed
518 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
519 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
520 echo Deleting ${LIB}/$file\; no fixes were needed.
525 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
527 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
528 mkdir ${LIB}/hsfs 2>/dev/null
529 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
530 chmod +w ${LIB}/$file 2>/dev/null
533 if [ -r ${LIB}/$file ]; then
535 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
536 ${LIB}/$file > ${LIB}/${file}.sed
537 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
538 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
539 echo Deleting ${LIB}/$file\; no fixes were needed.
544 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
546 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
547 mkdir ${LIB}/hsfs 2>/dev/null
548 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
549 chmod +w ${LIB}/$file 2>/dev/null
552 if [ -r ${LIB}/$file ]; then
554 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
555 ${LIB}/$file > ${LIB}/${file}.sed
556 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
557 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
558 echo Deleting ${LIB}/$file\; no fixes were needed.
563 # Incorrect #include in Sony News-OS 3.2.
564 file=machine/machparam.h
565 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
566 mkdir ${LIB}/machine 2>/dev/null
567 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
568 chmod +w ${LIB}/$file 2>/dev/null
571 if [ -r ${LIB}/$file ]; then
572 echo Fixing $file, incorrect \#include
573 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
574 ${LIB}/$file > ${LIB}/${file}.sed
575 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
576 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
577 echo Deleting ${LIB}/$file\; no fixes were needed.
582 # Multiline comment after typedef on IRIX 4.0.1.
584 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
585 mkdir ${LIB}/sys 2>/dev/null
586 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
587 chmod +w ${LIB}/$file 2>/dev/null
590 if [ -r ${LIB}/$file ]; then
591 echo Fixing $file, comment in the middle of \#ifdef
592 sed -e 's@type of the result@type of the result */@' \
593 -e 's@of the sizeof@/* of the sizeof@' \
594 ${LIB}/$file > ${LIB}/${file}.sed
595 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
596 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
597 echo Deleting ${LIB}/$file\; no fixes were needed.
602 echo 'Removing unneeded directories:'
604 files=`find . -type d -print | sort -r`
605 for file in $files; do
606 rmdir $LIB/$file > /dev/null 2>&1
610 echo 'Making internal symbolic non-directory links'
612 files=`find . -type l -print`
613 for file in $files; do
614 dest=`ls -ld $file | sed -n 's/.*-> //p'`
615 if expr "$dest" : '[^/].*' > /dev/null; then
616 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
617 if [ -f $target ]; then
618 ln -s $dest ${LIB}/$file >/dev/null 2>&1