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:'
47 files
=`ls -LR | sed -n s/:$//p`
49 files
=`find . -type d -print | sed '/^.$/d'`
51 for file in $files; do
53 if [ ! -d $LIB/$file ]
58 # treetops gets an alternating list
59 # of old directories to copy
60 # and the new directories to copy to.
61 treetops
="${INPUT} ${LIB}"
64 echo 'Making internal symbolic directory links'
65 for file in $files; do
66 dest
=`ls -ld $file | sed -n 's/.*-> //p'`
69 # In case $dest is relative, get to $file's dir first.
71 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
72 # Check that the target directory exists.
73 # Redirections changed to avoid bug in sh on Ultrix.
74 (cd $dest) > /dev
/null
2>&1
77 # X gets the dir that the link actually leads to.
79 # If link leads back into ${INPUT},
80 # make a similar link here.
81 if expr $x : "${INPUT}/.*" > /dev
/null
; then
82 # Y gets the actual target dir name, relative to ${INPUT}.
83 y
=`echo $x | sed -n "s&${INPUT}/&&p"`
84 echo $file '->' $y ': Making link'
85 rm -fr ${LIB}/$file > /dev
/null
2>&1
86 ln -s ${LIB}/$y ${LIB}/$file > /dev
/null
2>&1
88 # If the link is to outside ${INPUT},
89 # treat this directory as if it actually contained the files.
90 # This line used to have $dest instead of $x.
91 # $dest seemed to be wrong for links found in subdirectories
92 # of ${INPUT}. Does this change break anything?
93 treetops
="$treetops $x ${LIB}/$file"
102 while [ $# != 0 ]; do
103 # $1 is an old directory to copy, and $2 is the new directory to copy to.
104 echo "Finding header files in $1:"
107 files
=`find . -name '*.h' -type f -print`
108 echo 'Checking header files:'
109 # Note that BSD43_* are used on recent MIPS systems.
110 for file in $files; do
111 # This call to egrep is essential, since checking a file with egrep
112 # is much faster than actually trying to fix it.
113 # But the argument to egrep must be kept small, or many versions of egrep
114 # won't be able to handle it.
115 if egrep '[ _]_IO|CTRL|#define.NULL|#[el]*if.*([0-9]|#e[nl]|sparc|vax|sun|pyr)' $file > /dev
/null
; then
117 if [ -r $file ]; then
118 cp $file $2/$file >/dev
/null
2>&1 \
119 ||
echo "Can't copy $file"
125 s%\(#[ ]*endif[ ]*\)\([^/ ].*\)$%\1/* \2 */%
126 s%\(#[ ]*else[ ]*\)\([^/ ].*\)$%\1/* \2 */%
127 /[ ]_IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
128 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
129 /#define._IO/ s/'\''x'\''/x/g
130 /#define.BSD43__IO/ s/'\''x'\''/x/g
131 /[^A-Z]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
132 /#define.CTRL/ s/'\''c'\''/c/g
133 /#define._CTRL/ s/'\''c'\''/c/g
134 /#define.BSD43_CTRL/ s/'\''c'\''/c/g
135 /#[a-z]*if.*[ (]m68k/ s/\([^_]\)m68k/\1__m68k__/g
136 /#[a-z]*if.*[ (]__i386/ s/__i386/__i386__/g
137 /#[a-z]*if.*[ (]i386/ s/\([^_]\)i386/\1__i386__/g
138 /#[a-z]*if.*[ (]sparc/ s/\([^_]\)sparc/\1__sparc__/g
139 /#[a-z]*if.*[ (]mc68000/ s/\([^_]\)mc68000/\1__mc68000__/g
140 /#[a-z]*if.*[ (]vax/ s/\([^_]\)vax/\1__vax__/g
141 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
142 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
143 /#[a-z]*if.*[ (]ns32000/ s/\([^_]\)ns32000/\1__ns32000__/g
144 /#[a-z]*if.*[ (]pyr/ s/\([^_]\)pyr/\1__pyr__/g
145 /#[a-z]*if.*[ (]is68k/ s/\([^_]\)is68k/\1__is68k__/g
148 ' $2/$file > $2/$file.
sed
149 mv $2/$file.
sed $2/$file
150 if cmp $file $2/$file >/dev
/null
2>&1; then
151 echo Deleting
$2/$file\
; no fixes were needed.
162 # Fix one other error in this file: a mismatched quote not inside a C comment.
163 file=sundev
/vuid_event.h
164 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
165 mkdir
${LIB}/sundev
2>/dev
/null
166 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
167 chmod +w
${LIB}/$file 2>/dev
/null
170 if [ -r ${LIB}/$file ]; then
171 echo Fixing
$file comment
172 ex
${LIB}/$file <<EOF
173 g/doesn't/s/doesn't/does not/
176 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
177 echo Deleting
${LIB}/$file\
; no fixes were needed.
182 # Fix this Sun file to avoid intefering with stddef.h.
184 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
185 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
186 chmod +w
${LIB}/$file 2>/dev
/null
189 if [ -r ${LIB}/$file ]; then
191 ex
${LIB}/$file <<EOF
221 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
222 echo Deleting
${LIB}/$file\
; no fixes were needed.
227 # Fix this file to avoid intefering with stddef.h.
229 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
230 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
231 chmod +w
${LIB}/$file 2>/dev
/null
234 if [ -r ${LIB}/$file ]; then
236 ex
${LIB}/$file <<EOF
248 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
249 echo Deleting
${LIB}/$file\
; no fixes were needed.
254 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
255 # structure definition.
257 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
258 mkdir
${LIB}/rpcsvc
2>/dev
/null
259 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
260 chmod +w
${LIB}/$file 2>/dev
/null
263 if [ -r ${LIB}/$file ]; then
264 echo Fixing
$file, definition of statsswtch
265 ex
${LIB}/$file <<EOF
269 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
270 echo Deleting
${LIB}/$file\
; no fixes were needed.
275 # Fix an error in this file: a missing semi-colon at the end of the nodeent
276 # structure definition.
277 file=netdnet
/dnetdb.h
278 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
279 mkdir
${LIB}/netdnet
2>/dev
/null
280 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
281 chmod +w
${LIB}/$file 2>/dev
/null
284 if [ -r ${LIB}/$file ]; then
285 echo Fixing
$file, definition of nodeent
286 ex
${LIB}/$file <<EOF
290 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
291 echo Deleting
${LIB}/$file\
; no fixes were needed.
296 # Check for bad #ifdef line (in Ultrix 4.1)
298 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
299 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
300 chmod +w
${LIB}/$file 2>/dev
/null
303 if [ -r ${LIB}/$file ]; then
304 echo Fixing
$file, bad \
#ifdef line
305 ex
${LIB}/$file <<EOF
306 g/^#ifdef KERNEL && !defined/
307 s/#ifdef KERNEL && !defined/#if defined(KERNEL) \&\& !defined/
310 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
311 echo Deleting
${LIB}/$file\
; no fixes were needed.
316 # Check for superfluous `static' (in Ultrix 4.2)
318 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
319 mkdir
${LIB}/machine
2>/dev
/null
320 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
321 chmod +w
${LIB}/$file 2>/dev
/null
324 if [ -r ${LIB}/$file ]; then
325 echo Fixing
$file, superfluous static
326 ex
${LIB}/$file <<EOF
327 g/^static struct tlb_pid_state/
331 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
332 echo Deleting
${LIB}/$file\
; no fixes were needed.
335 # This file has an alternative name, mips/cpu.h. Fix that name, too.
336 if cmp machine
/cpu.h mips
/cpu.h
> /dev
/null
2>& 1; then
337 mkdir
${LIB}/mips
2>&-
338 ln ${LIB}/$file ${LIB}/mips
/cpu.h
343 # Deal with yet another challenge, this in X11/Xmu.h
345 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
346 mkdir
${LIB}/X11
2>/dev
/null
347 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
348 chmod +w
${LIB}/$file 2>/dev
/null
351 if [ -r ${LIB}/$file ]; then
352 echo Fixing
$file sprintf declaration
353 ex
${LIB}/$file <<EOF
354 /^extern char \* sprintf();$/c
356 extern char * sprintf();
357 #endif /* !defined __STDC__ */
361 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
362 echo Deleting
${LIB}/$file\
; no fixes were needed.
367 # Check for missing ';' in struct
369 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
370 mkdir
${LIB}/netinet
2>/dev
/null
371 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
372 chmod +w
${LIB}/$file 2>/dev
/null
375 if [ -r ${LIB}/$file ]; then
377 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.
sed
378 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
379 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
380 echo Deleting
${LIB}/$file\
; no fixes were needed.
385 # Fix the CAT macro in memvar.h.
386 file=pixrect
/memvar.h
387 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
388 mkdir
${LIB}/pixrect
2>/dev
/null
389 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
390 chmod +w
${LIB}/$file 2>/dev
/null
393 if [ -r ${LIB}/$file ]; then
395 sed -e '/^#define.CAT(a,b)/ i\
397 #define CAT(a,b) a##b\
399 /^#define.CAT(a,b)/ a\
401 ' ${LIB}/$file > ${LIB}/${file}.
sed
402 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
403 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
404 echo Deleting
${LIB}/$file\
; no fixes were needed.
409 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
411 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
412 mkdir
${LIB}/rpcsvc
2>/dev
/null
413 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
414 chmod +w
${LIB}/$file 2>/dev
/null
417 if [ -r ${LIB}/$file ]; then
419 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.
sed
420 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
421 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
422 echo Deleting
${LIB}/$file\
; no fixes were needed.
427 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
429 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
430 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
431 chmod +w
${LIB}/$file 2>/dev
/null
434 if [ -r ${LIB}/$file ]; then
436 sed -e 's/int abort/void abort/g' \
437 -e 's/int exit/void exit/g' ${LIB}/$file > ${LIB}/${file}.
sed
438 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
439 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
440 echo Deleting
${LIB}/$file\
; no fixes were needed.
445 # Fix bogus comment in <locale.h> on SunOS 4.1.
447 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
448 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
449 chmod +w
${LIB}/$file 2>/dev
/null
452 if [ -r ${LIB}/$file ]; then
454 sed -e 's%#endif / \*%#endif /\* %g' ${LIB}/$file > ${LIB}/${file}.
sed
455 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
456 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
457 echo Deleting
${LIB}/$file\
; no fixes were needed.
462 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
463 file=hsfs
/hsfs_spec.h
464 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
465 mkdir
${LIB}/hsfs
2>/dev
/null
466 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
467 chmod +w
${LIB}/$file 2>/dev
/null
470 if [ -r ${LIB}/$file ]; then
472 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
473 ${LIB}/$file > ${LIB}/${file}.
sed
474 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
475 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
476 echo Deleting
${LIB}/$file\
; no fixes were needed.
481 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
483 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
484 mkdir
${LIB}/hsfs
2>/dev
/null
485 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
486 chmod +w
${LIB}/$file 2>/dev
/null
489 if [ -r ${LIB}/$file ]; then
491 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
492 ${LIB}/$file > ${LIB}/${file}.
sed
493 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
494 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
495 echo Deleting
${LIB}/$file\
; no fixes were needed.
500 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
502 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
503 mkdir
${LIB}/hsfs
2>/dev
/null
504 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
505 chmod +w
${LIB}/$file 2>/dev
/null
508 if [ -r ${LIB}/$file ]; then
510 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
511 ${LIB}/$file > ${LIB}/${file}.
sed
512 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
513 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
514 echo Deleting
${LIB}/$file\
; no fixes were needed.
519 echo 'Removing unneeded directories:'
521 files
=`find . -type d -print | sort -r`
522 for file in $files; do
523 rmdir $LIB/$file > /dev
/null
2>&1
527 echo 'Making internal symbolic non-directory links'
529 files
=`find . -type l -print`
530 for file in $files; do
531 dest
=`ls -ld $file | sed -n 's/.*-> //p'`
532 if expr "$dest" : '[^/].*' > /dev
/null
; then
533 target
=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
534 if [ -f $target ]; then
535 ln -s $dest ${LIB}/$file >/dev
/null
2>&1