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 where gcc sources (and sometimes special include files) live.
9 # fixincludes doesn't use this, but fixinc.svr4 does, and I want to make
10 # sure somebody doesn't try to use arg3 for something incompatible. -- gumby
11 SRCDIR=${3-${SRCDIR-.}}
13 # Directory containing the original header files.
14 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
15 INPUT=${2-${INPUT-/usr/include}}
17 # Directory in which to store the results.
18 LIB=${1?"fixincludes: output directory not specified"}
20 # Define PWDCMD as a command to use to get the working dir
21 # in the form that we want.
25 # On an Apollo, discard everything before `/usr'.
26 PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
33 # Make sure it exists.
34 if [ ! -d $LIB ]; then
38 # Make LIB absolute only if needed to avoid problems with the amd.
43 cd $LIB; LIB=`${PWDCMD}`
47 # Make SRCDIR absolute only if needed to avoid problems with the amd.
53 cd $SRCDIR; SRCDIR=`${PWDCMD}`
57 # Fail if no arg to specify a directory for the output.
59 then echo fixincludes: no output directory specified
63 echo Building fixed headers in ${LIB}
65 # Determine whether this system has symbolic links.
66 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
67 rm -f $LIB/ShouldNotExist
73 echo Finding directories and links to directories
75 # Find all directories and all symlinks that point to directories.
76 # Put the list in $files.
77 # Each time we find a symlink, add it to newdirs
78 # so that we do another find within the dir the link points to.
79 # Note that $files may have duplicates in it;
80 # later parts of this file are supposed to ignore them.
83 while [ -n "$dirs" ] && [ $levels -gt 0 ]
85 levels=`expr $levels - 1`
89 echo " Searching $INPUT/$d"
95 # Find all directories under $d, relative to $d, excluding $d itself.
96 files="$files `find $d -type d -print | \
97 sed -e '/\/\.$/d' -e '/^\.$/d'`"
98 # Find all links to directories.
99 # Using `-exec test -d' in find fails on some systems,
100 # and trying to run test via sh fails on others,
101 # so this is the simplest alternative left.
102 # First find all the links, then test each one.
105 theselinks=`find $d -type l -print`
106 for d1 in $theselinks --dummy--
108 # If the link points to a directory,
109 # add that dir to $newdirs
112 newdirs="$newdirs $d1"
117 files="$files $newdirs"
122 echo "All directories (including links to directories):"
125 for file in $files; do
127 if [ ! -d $LIB/$file ]
128 then mkdir $LIB/$file
133 # treetops gets an alternating list
134 # of old directories to copy
135 # and the new directories to copy to.
136 treetops="${INPUT} ${LIB}"
139 echo 'Making symbolic directory links'
140 for file in $files; do
141 dest=`ls -ld $file | sed -n 's/.*-> //p'`
144 # In case $dest is relative, get to $file's dir first.
146 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
147 # Check that the target directory exists.
148 # Redirections changed to avoid bug in sh on Ultrix.
149 (cd $dest) > /dev/null 2>&1
152 # X gets the dir that the link actually leads to.
154 # If a link points to ., make a similar link to .
155 if [ $x = $INPUT ]; then
156 echo $file '->' . ': Making link'
157 rm -fr ${LIB}/$file > /dev/null 2>&1
158 ln -s . ${LIB}/$file > /dev/null 2>&1
159 # If link leads back into ${INPUT},
160 # make a similar link here.
161 elif expr $x : "${INPUT}/.*" > /dev/null; then
162 # Y gets the actual target dir name, relative to ${INPUT}.
163 y=`echo $x | sed -n "s&${INPUT}/&&p"`
164 echo $file '->' $y ': Making link'
165 rm -fr ${LIB}/$file > /dev/null 2>&1
166 ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
168 # If the link is to a dir $target outside ${INPUT},
169 # repoint the link at ${INPUT}/root$target
170 # and process $target into ${INPUT}/root$target
171 # treat this directory as if it actually contained the files.
172 echo $file '->' root$x ': Making link'
173 if [ -d $LIB/root$x ]
179 while [ x$dirname != x ]; do
180 component=`echo $dirname | sed -e 's|/.*$||'`
181 mkdir $component >/dev/null 2>&1
183 dirmade=$dirmade/$component
184 dirname=`echo $dirname | sed -e 's|[^/]*/||'`
187 # Duplicate directory structure created in ${LIB}/$file in new
189 for file2 in $files; do
192 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
193 echo "Duplicating ${file}'s ${dupdir}"
204 rm -fr ${LIB}/$file > /dev/null 2>&1
205 ln -s ${LIB}/root$x ${LIB}/$file > /dev/null 2>&1
206 treetops="$treetops $x ${LIB}/root$x"
215 while [ $# != 0 ]; do
216 # $1 is an old directory to copy, and $2 is the new directory to copy to.
219 # The same dir can appear more than once in treetops.
220 # There's no need to scan it more than once.
226 echo Fixing directory $1 into $2
227 # Check .h files which are symlinks as well as those which are files.
228 # A link to a header file will not be processed by anything but this.
230 files=`find . -name '*.h' \( -type f -o -type l \) -print`
232 files=`find . -name '*.h' -type f -print`
234 echo Checking header files
236 # Note that BSD43_* are used on recent MIPS systems.
237 for file in $files; do
238 # This call to egrep is essential, since checking a file with egrep
239 # is much faster than actually trying to fix it.
240 # It is also essential that most files *not* match!
241 # Thus, matching every #endif is unacceptable.
242 # But the argument to egrep must be kept small, or many versions of egrep
243 # won't be able to handle it.
244 # rms: I removed `|#[el].*if.*[^/ ]' because it made egrep fail.
245 if egrep '//|[ _]_IO|CTRL|#define.NULL|#[el]*if.*([0-9]|sparc|vax|sun|pyr)' $file > /dev/null; then
246 if [ -r $file ]; then
247 cp $file $2/$file >/dev/null 2>&1 \
248 || echo "Can't copy $file"
251 # Following two lines removed.
252 # s%^\([ ]*#[ ]*endif[ ]*\)\([^/ ].*\)$%\1/* \2 */%
253 # s%^\([ ]*#[ ]*else[ ]*\)\([^/ ].*\)$%\1/* \2 */%
259 /\/\/[^*]/ s|//\(.*\)$|/*\1*/|
260 /[ ]_IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
261 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
262 /#define._IO/ s/'\''\([cgx]\)'\''/\1/g
263 /#define.BSD43__IO/ s/'\''\(]cgx]\)'\''/\1/g
264 /[^A-Z]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
265 /#define.CTRL/ s/'\''\([cgx]\)'\''/\1/g
266 /#define._CTRL/ s/'\''\([cgx]\)'\''/\1/g
267 /#define.BSD43_CTRL/ s/'\''\([cgx]\)'\''/\1/g
268 /#[a-z]*if.*[ (]m68k/ s/\([^_]\)m68k/\1__m68k__/g
269 /#[a-z]*if.*[ (]__i386/ s/__i386/__i386__/g
270 /#[a-z]*if.*[ (]i386/ s/\([^_]\)i386/\1__i386__/g
271 /#[a-z]*if.*[ (]sparc/ s/\([^_]\)sparc/\1__sparc__/g
272 /#[a-z]*if.*[ (]mc68000/ s/\([^_]\)mc68000/\1__mc68000__/g
273 /#[a-z]*if.*[ (]vax/ s/\([^_]\)vax/\1__vax__/g
274 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
275 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
276 /#[a-z]*if.*[ (]ns32000/ s/\([^_]\)ns32000/\1__ns32000__/g
277 /#[a-z]*if.*[ (]pyr/ s/\([^_]\)pyr/\1__pyr__/g
278 /#[a-z]*if.*[ (]is68k/ s/\([^_]\)is68k/\1__is68k__/g
279 /^#define.NULL[ ]/ i\
281 ' $2/$file > $2/$file.sed
282 mv $2/$file.sed $2/$file
283 if cmp $file $2/$file >/dev/null 2>&1; then
296 # Install the proper definition of size_t in header files that it comes from.
297 for file in sys/types.h sys/stdtypes.h;
299 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
300 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
301 chmod +w ${LIB}/$file 2>/dev/null
302 chmod a+r ${LIB}/$file 2>/dev/null
305 if [ -r ${LIB}/$file ]; then
306 echo Fixing $file comment
307 # Extract the definition of SIZE_TYPE, if any.
308 # (This file must be called something.c).
309 echo "#include \"tm.h\"
310 gobblegobble SIZE_TYPE" > ${LIB}/types.c
311 foo=`cc -E -I${ORIGDIR} -I${SRCDIR} -I${SRCDIR}/config ${LIB}/types.c | grep gobblegobble | sed -e "s/gobblegobble[ ]*//"`
313 # Default to our preferred type.
314 if [ "$foo" = SIZE_TYPE ]; then foo="unsigned long int"; else foo=`echo $foo | sed -e 's/^.*"\(.*\)".*$/\1/'`; fi
315 sed -e "s/typedef[ a-z_]*[ ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
316 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
317 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
323 # Fix one other error in this file: a mismatched quote not inside a C comment.
324 file=sundev/vuid_event.h
325 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
326 mkdir ${LIB}/sundev 2>/dev/null
327 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
328 chmod +w ${LIB}/$file 2>/dev/null
329 chmod a+r ${LIB}/$file 2>/dev/null
332 if [ -r ${LIB}/$file ]; then
333 echo Fixing $file comment
334 sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
335 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
336 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
341 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
342 file=sunwindow/win_cursor.h
343 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
344 # mkdir ${LIB}/sunwindow 2>/dev/null
345 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
346 chmod +w ${LIB}/$file 2>/dev/null
348 if [ -r ${LIB}/$file ]; then
350 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
351 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
352 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
356 file=sunwindow/win_lock.h
357 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
358 # mkdir ${LIB}/sunwindow 2>/dev/null
359 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
360 chmod +w ${LIB}/$file 2>/dev/null
362 if [ -r ${LIB}/$file ]; then
364 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
365 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
366 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
371 # Fix this Sun file to avoid interfering with stddef.h.
373 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
374 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
375 chmod +w ${LIB}/$file 2>/dev/null
376 chmod a+r ${LIB}/$file 2>/dev/null
379 if [ -r ${LIB}/$file ]; then
381 sed -e '/size_t.*;/i\
383 #define _GCC_SIZE_T' \
387 #ifndef _GCC_PTRDIFF_T\
388 #define _GCC_PTRDIFF_T' \
392 #ifndef _GCC_WCHAR_T\
393 #define _GCC_WCHAR_T' \
395 #endif' ${LIB}/$file > ${LIB}/${file}.sed
396 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
397 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
402 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
403 # match e.g. ssize_t present in AIX for the ps/2.
405 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
406 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
407 chmod +w ${LIB}/$file 2>/dev/null
408 chmod a+r ${LIB}/$file 2>/dev/null
411 if [ -r ${LIB}/$file ]; then
413 sed -e '/[ ]size_t.*;/i\
415 #define _GCC_SIZE_T' \
417 #endif' ${LIB}/$file > ${LIB}/${file}.sed
418 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
419 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
424 # Fix an error in this file: the #if says _cplusplus, not the double
425 # underscore __cplusplus that it should be
427 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
428 mkdir ${LIB}/rpcsvc 2>/dev/null
429 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
430 chmod +w ${LIB}/$file 2>/dev/null
431 chmod a+r ${LIB}/$file 2>/dev/null
434 if [ -r ${LIB}/$file ]; then
435 echo Fixing $file, __cplusplus macro
436 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
437 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
438 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
443 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
444 # structure definition.
446 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
447 mkdir ${LIB}/rpcsvc 2>/dev/null
448 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
449 chmod +w ${LIB}/$file 2>/dev/null
450 chmod a+r ${LIB}/$file 2>/dev/null
453 if [ -r ${LIB}/$file ]; then
454 echo Fixing $file, definition of statsswtch
455 sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
456 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
457 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
462 # Fix an error in this file: a missing semi-colon at the end of the nodeent
463 # structure definition.
464 file=netdnet/dnetdb.h
465 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
466 mkdir ${LIB}/netdnet 2>/dev/null
467 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
468 chmod +w ${LIB}/$file 2>/dev/null
469 chmod a+r ${LIB}/$file 2>/dev/null
472 if [ -r ${LIB}/$file ]; then
473 echo Fixing $file, definition of nodeent
474 sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
475 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
476 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
481 # Check for bad #ifdef line (in Ultrix 4.1)
483 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
484 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
485 chmod +w ${LIB}/$file 2>/dev/null
486 chmod a+r ${LIB}/$file 2>/dev/null
489 if [ -r ${LIB}/$file ]; then
490 echo Fixing $file, bad \#ifdef line
491 sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
492 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
493 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
498 # Remove nested comments created by #endifs in a comment (Ultrix 4.1)
499 # Only needed if commenting out junk after #endif.
501 #if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
502 # cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
503 # chmod +w ${LIB}/$file 2>/dev/null
504 # chmod a+r ${LIB}/$file 2>/dev/null
507 #if [ -r ${LIB}/$file ]; then
508 # echo Fixing $file, nested comments
509 # sed -e 's/#endif.*/#endif/' ${LIB}/$file > ${LIB}/${file}.sed
510 # rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
511 # if cmp $file ${LIB}/$file >/dev/null 2>&1; then
516 # Check for superfluous `static' (in Ultrix 4.2)
518 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
519 mkdir ${LIB}/machine 2>/dev/null
520 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
521 chmod +w ${LIB}/$file 2>/dev/null
522 chmod a+r ${LIB}/$file 2>/dev/null
525 if [ -r ${LIB}/$file ]; then
526 echo Fixing $file, superfluous static
527 sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
528 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
529 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
532 # This file has an alternative name, mips/cpu.h. Fix that name, too.
533 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
534 mkdir ${LIB}/mips 2>&-
535 ln ${LIB}/$file ${LIB}/mips/cpu.h
540 # Incorrect sprintf declaration in X11/Xmu.h
542 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
543 mkdir ${LIB}/X11 2>/dev/null
544 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
545 chmod +w ${LIB}/$file 2>/dev/null
546 chmod a+r ${LIB}/$file 2>/dev/null
549 if [ -r ${LIB}/$file ]; then
550 echo Fixing $file sprintf declaration
551 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
552 extern char * sprintf();\
553 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
554 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
555 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
560 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
561 # (It's not clear whether the right file name is this or X11/Xmu.h.)
563 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
564 mkdir ${LIB}/X11/Xmu 2>/dev/null
565 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
566 chmod +w ${LIB}/$file 2>/dev/null
567 chmod a+r ${LIB}/$file 2>/dev/null
570 if [ -r ${LIB}/$file ]; then
571 echo Fixing $file sprintf declaration
572 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
573 extern char * sprintf();\
574 #endif /* !defined __STDC__ */,' ${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
581 # Check for missing ';' in struct
583 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
584 mkdir ${LIB}/netinet 2>/dev/null
585 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
586 chmod +w ${LIB}/$file 2>/dev/null
587 chmod a+r ${LIB}/$file 2>/dev/null
590 if [ -r ${LIB}/$file ]; then
592 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
593 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
594 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
599 # Fix the CAT macro in SunOS memvar.h.
600 file=pixrect/memvar.h
601 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
602 mkdir ${LIB}/pixrect 2>/dev/null
603 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
604 chmod +w ${LIB}/$file 2>/dev/null
605 chmod a+r ${LIB}/$file 2>/dev/null
608 if [ -r ${LIB}/$file ]; then
610 sed -e '/^#define.CAT(a,b)/ i\
612 #define CAT(a,b) a##b\
614 /^#define.CAT(a,b)/ a\
616 ' ${LIB}/$file > ${LIB}/${file}.sed
617 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
618 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
623 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
625 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
626 mkdir ${LIB}/rpcsvc 2>/dev/null
627 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
628 chmod +w ${LIB}/$file 2>/dev/null
629 chmod a+r ${LIB}/$file 2>/dev/null
632 if [ -r ${LIB}/$file ]; then
634 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
635 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
636 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
641 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
643 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
644 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
645 chmod +w ${LIB}/$file 2>/dev/null
646 chmod a+r ${LIB}/$file 2>/dev/null
649 if [ -r ${LIB}/$file ]; then
651 sed -e 's/int abort/void abort/g' \
652 -e 's/int free/void free/g' \
653 -e 's/char \* calloc/void \* calloc/g' \
654 -e 's/char \* malloc/void \* malloc/g' \
655 -e 's/char \* realloc/void \* realloc/g' \
656 -e 's/int exit/void exit/g' ${LIB}/$file > ${LIB}/${file}.sed
657 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
658 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
663 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
665 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
666 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
667 chmod +w ${LIB}/$file 2>/dev/null
668 chmod a+r ${LIB}/$file 2>/dev/null
671 if [ -r ${LIB}/$file ]; then
673 sed -e 's/typedef[ ]char \* malloc_t/typedef void \* malloc_t/g' \
674 -e 's/int[ ][ ]*free/void free/g' \
675 ${LIB}/$file > ${LIB}/${file}.sed
676 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
677 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
683 # Fix bogus comment in <locale.h> on SunOS 4.1.
685 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
686 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
687 chmod +w ${LIB}/$file 2>/dev/null
688 chmod a+r ${LIB}/$file 2>/dev/null
691 if [ -r ${LIB}/$file ]; then
693 sed -e 's%#endif / \*%#endif /\* %g' ${LIB}/$file > ${LIB}/${file}.sed
694 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
695 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
700 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
701 file=hsfs/hsfs_spec.h
702 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
703 mkdir ${LIB}/hsfs 2>/dev/null
704 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
705 chmod +w ${LIB}/$file 2>/dev/null
706 chmod a+r ${LIB}/$file 2>/dev/null
709 if [ -r ${LIB}/$file ]; then
711 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
712 ${LIB}/$file > ${LIB}/${file}.sed
713 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
714 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
719 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
721 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
722 mkdir ${LIB}/hsfs 2>/dev/null
723 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
724 chmod +w ${LIB}/$file 2>/dev/null
725 chmod a+r ${LIB}/$file 2>/dev/null
728 if [ -r ${LIB}/$file ]; then
730 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
731 ${LIB}/$file > ${LIB}/${file}.sed
732 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
733 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
738 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
740 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
741 mkdir ${LIB}/hsfs 2>/dev/null
742 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
743 chmod +w ${LIB}/$file 2>/dev/null
744 chmod a+r ${LIB}/$file 2>/dev/null
747 if [ -r ${LIB}/$file ]; then
749 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
750 ${LIB}/$file > ${LIB}/${file}.sed
751 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
752 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
757 # Incorrect #include in Sony News-OS 3.2.
758 file=machine/machparam.h
759 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
760 mkdir ${LIB}/machine 2>/dev/null
761 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
762 chmod +w ${LIB}/$file 2>/dev/null
763 chmod a+r ${LIB}/$file 2>/dev/null
766 if [ -r ${LIB}/$file ]; then
767 echo Fixing $file, incorrect \#include
768 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
769 ${LIB}/$file > ${LIB}/${file}.sed
770 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
771 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
776 # Multiline comment after typedef on IRIX 4.0.1.
778 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
779 mkdir ${LIB}/sys 2>/dev/null
780 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
781 chmod +w ${LIB}/$file 2>/dev/null
782 chmod a+r ${LIB}/$file 2>/dev/null
785 if [ -r ${LIB}/$file ]; then
786 echo Fixing $file, comment in the middle of \#ifdef
787 sed -e 's@type of the result@type of the result */@' \
788 -e 's@of the sizeof@/* of the sizeof@' \
789 ${LIB}/$file > ${LIB}/${file}.sed
790 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
791 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
796 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
797 # declaration on Sun OS 4.x. We must only fix this on Sun OS 4.x, because
798 # many other systems have similar text but correct versions of the file.
799 # To ensure only Sun's is fixed, we grep for a likely unique string.
801 if egrep '/\* @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2 \*/' $file > /dev/null; then
802 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
803 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
804 chmod +w ${LIB}/$file 2>/dev/null
805 chmod a+r ${LIB}/$file 2>/dev/null
807 if [ -r ${LIB}/$file ]; then
809 cat > ${LIB}/$file << EOF
810 /* This file was generated by fixincludes */
815 extern void *memccpy();
816 extern void *memchr();
817 extern void *memcpy();
818 extern void *memset();
820 extern char *memccpy();
821 extern char *memchr();
822 extern char *memcpy();
823 extern char *memset();
824 #endif /* __STDC__ */
833 # parameters not const on DECstation Ultrix V4.0.
835 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
836 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
837 chmod +w ${LIB}/$file 2>/dev/null
838 chmod a+r ${LIB}/$file 2>/dev/null
841 if [ -r ${LIB}/$file ]; then
842 echo Fixing $file, non-const arg
843 sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
844 -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
845 -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
846 -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
847 -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
848 -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
849 -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
850 ${LIB}/$file > ${LIB}/${file}.sed
851 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
852 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
857 # parameters conflict with C++ new on rs/6000
859 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
860 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
861 chmod +w ${LIB}/$file 2>/dev/null
864 if [ -r ${LIB}/$file ]; then
865 echo Fixing $file, parameter name conflicts
866 sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
867 ${LIB}/$file > ${LIB}/${file}.sed
868 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
869 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
874 # Don't use or define the name va_list in stdio.h.
875 # This is for ANSI and also to interoperate properly with gvarargs.h.
877 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
878 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
879 chmod +w ${LIB}/$file 2>/dev/null
880 chmod a+r ${LIB}/$file 2>/dev/null
883 if [ -r ${LIB}/$file ]; then
884 echo Fixing $file, use of va_list
885 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
886 (echo "#define __need___va_list"
887 echo "#include <stdarg.h>") > ${LIB}/${file}.sed
888 # Use __gnuc_va_list in arg types in place of va_list.
889 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
890 # trailing parentheses and semicolon save all other systems from this.
891 # Define __va_list__ (something harmless and unused) instead of va_list.
892 # Don't claim to have defined va_list.
893 sed -e 's@ va_list @ __gnuc_va_list @' \
894 -e 's@ va_list)@ __gnuc_va_list)@' \
895 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
896 -e 's@ va_list@ __va_list__@' \
897 -e 's@\*va_list@*__va_list__@' \
898 -e 's@VA_LIST@DUMMY_VA_LIST@' \
899 ${LIB}/$file >> ${LIB}/${file}.sed
901 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
902 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
907 # Cancel out ansi_compat.h on Ultrix. Replace it with empty file.
909 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
910 if grep -s ULTRIX $file; then
911 echo "/* This file intentionally left blank. */" > $LIB/$file
915 # parameter to atof not const on DECstation Ultrix V4.0.
916 # also get rid of bogus inline definitions in HP-UX 8.0
918 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
919 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
920 chmod +w ${LIB}/$file 2>/dev/null
921 chmod a+r ${LIB}/$file 2>/dev/null
924 if [ -r ${LIB}/$file ]; then
925 echo Fixing $file, non-const arg
926 sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
927 -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
928 -e 's@inline double abs(double d) { return fabs(d); }@@' \
929 ${LIB}/$file > ${LIB}/${file}.sed
930 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
931 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
936 # In limits.h, put #ifndefs around things that are supposed to be defined
937 # in float.h to avoid redefinition errors if float.h is included first.
939 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
940 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
941 chmod +w ${LIB}/$file 2>/dev/null
942 chmod a+r ${LIB}/$file 2>/dev/null
945 if [ -r ${LIB}/$file ]; then
947 sed -e '/[ ]FLT_MIN[ ]/i\
949 -e '/[ ]FLT_MIN[ ]/a\
951 -e '/[ ]FLT_MAX[ ]/i\
953 -e '/[ ]FLT_MAX[ ]/a\
955 -e '/[ ]FLT_DIG[ ]/i\
957 -e '/[ ]FLT_DIG[ ]/a\
959 -e '/[ ]DBL_MIN[ ]/i\
961 -e '/[ ]DBL_MIN[ ]/a\
963 -e '/[ ]DBL_MAX[ ]/i\
965 -e '/[ ]DBL_MAX[ ]/a\
967 -e '/[ ]DBL_DIG[ ]/i\
969 -e '/[ ]DBL_DIG[ ]/a\
971 ${LIB}/$file > ${LIB}/${file}.sed
972 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
973 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
974 echo Deleting ${LIB}/$file\; no fixes were needed.
979 # These two files on SunOS 4 are included by other files
980 # in the same directory, using "...". So we must make sure they exist
981 # in the same directory as the other fixed files.
982 if [ -r ${INPUT}/multimedia/audio_errno.h ]
984 ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
986 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
988 ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
991 echo 'Removing unneeded directories:'
993 files=`find . -type d -print | sort -r`
994 for file in $files; do
995 rmdir $LIB/$file > /dev/null 2>&1
999 echo 'Making internal symbolic non-directory links'
1001 files=`find . -type l -print`
1002 for file in $files; do
1003 dest=`ls -ld $file | sed -n 's/.*-> //p'`
1004 if expr "$dest" : '[^/].*' > /dev/null; then
1005 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1006 if [ -f $target ]; then
1007 ln -s $dest ${LIB}/$file >/dev/null 2>&1
1013 # Prevent premature exit when subsequently processing OTHER_FIXINCLUDES_DIRS.