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/,'"
30 # Make sure it exists.
31 if [ ! -d $LIB ]; then
35 # Make LIB absolute only if needed to avoid problems with the amd.
40 cd $LIB; LIB=`${PWDCMD}`
44 # Fail if no arg to specify a directory for the output.
46 then echo fixincludes: no output directory specified
50 echo Building fixed headers in ${LIB}
52 # Determine whether this system has symbolic links.
53 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
54 rm -f $LIB/ShouldNotExist
60 echo Finding directories and links to directories
62 # Find all directories and all symlinks that point to directories.
63 # Put the list in $files.
64 # Each time we find a symlink, add it to newdirs
65 # so that we do another find within the dir the link points to.
66 # Note that $files may have duplicates in it;
67 # later parts of this file are supposed to ignore them.
70 while [ -n "$dirs" ] && [ $levels -gt 0 ]
72 levels=`expr $levels - 1`
76 echo " Searching $INPUT/$d"
82 # Find all directories under $d, relative to $d, excluding $d itself.
83 files="$files `find $d -type d -print | \
84 sed -e '/\/\.$/d' -e '/^\.$/d'`"
85 # Find all links to directories.
86 # Using `-exec test -d' in find fails on some systems,
87 # and trying to run test via sh fails on others,
88 # so this is the simplest alternative left.
89 # First find all the links, then test each one.
92 theselinks=`find $d -type l -print`
93 for d1 in $theselinks --dummy--
95 # If the link points to a directory,
96 # add that dir to $newdirs
99 newdirs="$newdirs $d1"
104 files="$files $newdirs"
109 echo "All directories (including links to directories):"
112 for file in $files; do
114 if [ ! -d $LIB/$file ]
115 then mkdir $LIB/$file
120 # treetops gets an alternating list
121 # of old directories to copy
122 # and the new directories to copy to.
123 treetops="${INPUT} ${LIB}"
126 echo 'Making symbolic directory links'
127 for file in $files; do
128 dest=`ls -ld $file | sed -n 's/.*-> //p'`
131 # In case $dest is relative, get to $file's dir first.
133 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
134 # Check that the target directory exists.
135 # Redirections changed to avoid bug in sh on Ultrix.
136 (cd $dest) > /dev/null 2>&1
139 # X gets the dir that the link actually leads to.
141 # If a link points to ., make a similar link to .
142 if [ $x = $INPUT ]; then
143 echo $file '->' . ': Making link'
144 rm -fr ${LIB}/$file > /dev/null 2>&1
145 ln -s . ${LIB}/$file > /dev/null 2>&1
146 # If link leads back into ${INPUT},
147 # make a similar link here.
148 elif expr $x : "${INPUT}/.*" > /dev/null; then
149 # Y gets the actual target dir name, relative to ${INPUT}.
150 y=`echo $x | sed -n "s&${INPUT}/&&p"`
151 echo $file '->' $y ': Making link'
152 rm -fr ${LIB}/$file > /dev/null 2>&1
153 ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
155 # If the link is to a dir $target outside ${INPUT},
156 # repoint the link at ${INPUT}/root$target
157 # and process $target into ${INPUT}/root$target
158 # treat this directory as if it actually contained the files.
159 echo $file '->' root$x ': Making link'
160 if [ -d $LIB/root$x ]
166 while [ x$dirname != x ]; do
167 component=`echo $dirname | sed -e 's|/.*$||'`
168 mkdir $component >/dev/null 2>&1
170 dirmade=$dirmade/$component
171 dirname=`echo $dirname | sed -e 's|[^/]*/||'`
174 # Duplicate directory structure created in ${LIB}/$file in new
176 for file2 in $files; do
179 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
180 echo "Duplicating ${file}'s ${dupdir}"
191 rm -fr ${LIB}/$file > /dev/null 2>&1
192 ln -s ${LIB}/root$x ${LIB}/$file > /dev/null 2>&1
193 treetops="$treetops $x ${LIB}/root$x"
202 while [ $# != 0 ]; do
203 # $1 is an old directory to copy, and $2 is the new directory to copy to.
206 # The same dir can appear more than once in treetops.
207 # There's no need to scan it more than once.
213 echo Fixing directory $1 into $2
214 # Check .h files which are symlinks as well as those which are files.
215 # A link to a header file will not be processed by anything but this.
217 files=`find . -name '*.h' \( -type f -o -type l \) -print`
219 files=`find . -name '*.h' -type f -print`
221 echo Checking header files
223 # Note that BSD43_* are used on recent MIPS systems.
224 for file in $files; do
225 # This call to egrep is essential, since checking a file with egrep
226 # is much faster than actually trying to fix it.
227 # It is also essential that most files *not* match!
228 # Thus, matching every #endif is unacceptable.
229 # But the argument to egrep must be kept small, or many versions of egrep
230 # won't be able to handle it.
231 # rms: I removed `|#[el].*if.*[^/ ]' because it made egrep fail.
232 if egrep '//|[ _]_IO|CTRL|#define.NULL|#[el]*if.*([0-9]|sparc|vax|sun|pyr)' $file > /dev/null; then
233 if [ -r $file ]; then
234 cp $file $2/$file >/dev/null 2>&1 \
235 || echo "Can't copy $file"
238 # Following two lines removed.
239 # s%^\([ ]*#[ ]*endif[ ]*\)\([^/ ].*\)$%\1/* \2 */%
240 # s%^\([ ]*#[ ]*else[ ]*\)\([^/ ].*\)$%\1/* \2 */%
246 /\/\/[^*]/ s|//\(.*\)$|/*\1*/|
247 /[ ]_IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
248 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
249 /#define._IO/ s/'\''\([cgx]\)'\''/\1/g
250 /#define.BSD43__IO/ s/'\''\(]cgx]\)'\''/\1/g
251 /[^A-Z]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
252 /#define.CTRL/ s/'\''\([cgx]\)'\''/\1/g
253 /#define._CTRL/ s/'\''\([cgx]\)'\''/\1/g
254 /#define.BSD43_CTRL/ s/'\''\([cgx]\)'\''/\1/g
255 /#[a-z]*if.*[ (]m68k/ s/\([^_]\)m68k/\1__m68k__/g
256 /#[a-z]*if.*[ (]__i386/ s/__i386/__i386__/g
257 /#[a-z]*if.*[ (]i386/ s/\([^_]\)i386/\1__i386__/g
258 /#[a-z]*if.*[ (]sparc/ s/\([^_]\)sparc/\1__sparc__/g
259 /#[a-z]*if.*[ (]mc68000/ s/\([^_]\)mc68000/\1__mc68000__/g
260 /#[a-z]*if.*[ (]vax/ s/\([^_]\)vax/\1__vax__/g
261 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
262 /#[a-z]*if.*[ (]sun/ s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
263 /#[a-z]*if.*[ (]ns32000/ s/\([^_]\)ns32000/\1__ns32000__/g
264 /#[a-z]*if.*[ (]pyr/ s/\([^_]\)pyr/\1__pyr__/g
265 /#[a-z]*if.*[ (]is68k/ s/\([^_]\)is68k/\1__is68k__/g
266 /^#define.NULL[ ]/ i\
268 ' $2/$file > $2/$file.sed
269 mv $2/$file.sed $2/$file
270 if cmp $file $2/$file >/dev/null 2>&1; then
283 # Install the proper definition of size_t in header files that it comes from.
284 for file in sys/types.h sys/stdtypes.h;
286 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
287 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
288 chmod +w ${LIB}/$file 2>/dev/null
289 chmod a+r ${LIB}/$file 2>/dev/null
292 if [ -r ${LIB}/$file ]; then
293 echo Fixing $file comment
294 # Extract the definition of SIZE_TYPE, if any.
295 # (This file must be called something.c).
296 echo "#include \"tm.h\"
297 gobblegobble SIZE_TYPE" > types.c
298 foo=`cc -E -I. -I$SRCDIR -I$SRCDIR/config types.c | grep gobblegobble | sed -e "s/gobblegobble[ ]*//"`
300 # Default to our preferred type.
301 if [ $foo = SIZE_TYPE ]; then foo="unsigned long int"; else true; fi
302 sed -e "s/typedef[ a-z_]*[ ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
303 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
304 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
310 # Fix one other error in this file: a mismatched quote not inside a C comment.
311 file=sundev/vuid_event.h
312 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
313 mkdir ${LIB}/sundev 2>/dev/null
314 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
315 chmod +w ${LIB}/$file 2>/dev/null
316 chmod a+r ${LIB}/$file 2>/dev/null
319 if [ -r ${LIB}/$file ]; then
320 echo Fixing $file comment
321 sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
322 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
323 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
328 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
329 file=sunwindow/win_cursor.h
330 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
331 # mkdir ${LIB}/sunwindow 2>/dev/null
332 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
333 chmod +w ${LIB}/$file 2>/dev/null
335 if [ -r ${LIB}/$file ]; then
337 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
338 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
339 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
343 file=sunwindow/win_lock.h
344 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
345 # mkdir ${LIB}/sunwindow 2>/dev/null
346 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
347 chmod +w ${LIB}/$file 2>/dev/null
349 if [ -r ${LIB}/$file ]; then
351 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
352 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
353 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
358 # Fix this Sun file to avoid interfering with stddef.h.
360 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
361 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
362 chmod +w ${LIB}/$file 2>/dev/null
363 chmod a+r ${LIB}/$file 2>/dev/null
366 if [ -r ${LIB}/$file ]; then
368 sed -e '/size_t.*;/i\
370 #define _GCC_SIZE_T' \
374 #ifndef _GCC_PTRDIFF_T\
375 #define _GCC_PTRDIFF_T' \
379 #ifndef _GCC_WCHAR_T\
380 #define _GCC_WCHAR_T' \
382 #endif' ${LIB}/$file > ${LIB}/${file}.sed
383 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
384 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
389 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
390 # match e.g. ssize_t present in AIX for the ps/2.
392 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
393 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
394 chmod +w ${LIB}/$file 2>/dev/null
395 chmod a+r ${LIB}/$file 2>/dev/null
398 if [ -r ${LIB}/$file ]; then
400 sed -e '/[ ]size_t.*;/i\
402 #define _GCC_SIZE_T' \
404 #endif' ${LIB}/$file > ${LIB}/${file}.sed
405 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
406 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
411 # Fix an error in this file: the #if says _cplusplus, not the double
412 # underscore __cplusplus that it should be
414 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
415 mkdir ${LIB}/rpcsvc 2>/dev/null
416 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
417 chmod +w ${LIB}/$file 2>/dev/null
418 chmod a+r ${LIB}/$file 2>/dev/null
421 if [ -r ${LIB}/$file ]; then
422 echo Fixing $file, __cplusplus macro
423 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
424 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
425 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
430 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
431 # structure definition.
433 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
434 mkdir ${LIB}/rpcsvc 2>/dev/null
435 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
436 chmod +w ${LIB}/$file 2>/dev/null
437 chmod a+r ${LIB}/$file 2>/dev/null
440 if [ -r ${LIB}/$file ]; then
441 echo Fixing $file, definition of statsswtch
442 sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
443 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
444 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
449 # Fix an error in this file: a missing semi-colon at the end of the nodeent
450 # structure definition.
451 file=netdnet/dnetdb.h
452 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
453 mkdir ${LIB}/netdnet 2>/dev/null
454 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
455 chmod +w ${LIB}/$file 2>/dev/null
456 chmod a+r ${LIB}/$file 2>/dev/null
459 if [ -r ${LIB}/$file ]; then
460 echo Fixing $file, definition of nodeent
461 sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
462 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
463 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
468 # Check for bad #ifdef line (in Ultrix 4.1)
470 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
471 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
472 chmod +w ${LIB}/$file 2>/dev/null
473 chmod a+r ${LIB}/$file 2>/dev/null
476 if [ -r ${LIB}/$file ]; then
477 echo Fixing $file, bad \#ifdef line
478 sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
479 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
480 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
485 # Remove nested comments created by #endifs in a comment (Ultrix 4.1)
486 # Only needed if commenting out junk after #endif.
488 #if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
489 # cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
490 # chmod +w ${LIB}/$file 2>/dev/null
491 # chmod a+r ${LIB}/$file 2>/dev/null
494 #if [ -r ${LIB}/$file ]; then
495 # echo Fixing $file, nested comments
496 # sed -e 's/#endif.*/#endif/' ${LIB}/$file > ${LIB}/${file}.sed
497 # rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
498 # if cmp $file ${LIB}/$file >/dev/null 2>&1; then
503 # Check for superfluous `static' (in Ultrix 4.2)
505 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
506 mkdir ${LIB}/machine 2>/dev/null
507 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
508 chmod +w ${LIB}/$file 2>/dev/null
509 chmod a+r ${LIB}/$file 2>/dev/null
512 if [ -r ${LIB}/$file ]; then
513 echo Fixing $file, superfluous static
514 sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
515 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
516 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
519 # This file has an alternative name, mips/cpu.h. Fix that name, too.
520 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
521 mkdir ${LIB}/mips 2>&-
522 ln ${LIB}/$file ${LIB}/mips/cpu.h
527 # Incorrect sprintf declaration in X11/Xmu.h
529 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
530 mkdir ${LIB}/X11 2>/dev/null
531 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
532 chmod +w ${LIB}/$file 2>/dev/null
533 chmod a+r ${LIB}/$file 2>/dev/null
536 if [ -r ${LIB}/$file ]; then
537 echo Fixing $file sprintf declaration
538 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
539 extern char * sprintf();\
540 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
541 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
542 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
547 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
548 # (It's not clear whether the right file name is this or X11/Xmu.h.)
550 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
551 mkdir ${LIB}/X11/Xmu 2>/dev/null
552 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
553 chmod +w ${LIB}/$file 2>/dev/null
554 chmod a+r ${LIB}/$file 2>/dev/null
557 if [ -r ${LIB}/$file ]; then
558 echo Fixing $file sprintf declaration
559 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
560 extern char * sprintf();\
561 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
562 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
563 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
568 # Check for missing ';' in struct
570 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
571 mkdir ${LIB}/netinet 2>/dev/null
572 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
573 chmod +w ${LIB}/$file 2>/dev/null
574 chmod a+r ${LIB}/$file 2>/dev/null
577 if [ -r ${LIB}/$file ]; then
579 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
580 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
581 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
586 # Fix the CAT macro in SunOS memvar.h.
587 file=pixrect/memvar.h
588 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
589 mkdir ${LIB}/pixrect 2>/dev/null
590 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
591 chmod +w ${LIB}/$file 2>/dev/null
592 chmod a+r ${LIB}/$file 2>/dev/null
595 if [ -r ${LIB}/$file ]; then
597 sed -e '/^#define.CAT(a,b)/ i\
599 #define CAT(a,b) a##b\
601 /^#define.CAT(a,b)/ a\
603 ' ${LIB}/$file > ${LIB}/${file}.sed
604 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
605 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
610 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
612 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
613 mkdir ${LIB}/rpcsvc 2>/dev/null
614 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
615 chmod +w ${LIB}/$file 2>/dev/null
616 chmod a+r ${LIB}/$file 2>/dev/null
619 if [ -r ${LIB}/$file ]; then
621 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
622 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
623 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
628 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
630 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
631 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
632 chmod +w ${LIB}/$file 2>/dev/null
633 chmod a+r ${LIB}/$file 2>/dev/null
636 if [ -r ${LIB}/$file ]; then
638 sed -e 's/int abort/void abort/g' \
639 -e 's/int free/void free/g' \
640 -e 's/char \* calloc/void \* calloc/g' \
641 -e 's/char \* malloc/void \* malloc/g' \
642 -e 's/char \* realloc/void \* realloc/g' \
643 -e 's/int exit/void exit/g' ${LIB}/$file > ${LIB}/${file}.sed
644 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
645 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
650 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
652 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
653 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
654 chmod +w ${LIB}/$file 2>/dev/null
655 chmod a+r ${LIB}/$file 2>/dev/null
658 if [ -r ${LIB}/$file ]; then
660 sed -e 's/typedef[ ]char \* malloc_t/typedef void \* malloc_t/g' \
661 -e 's/int[ ][ ]*free/void free/g' \
662 ${LIB}/$file > ${LIB}/${file}.sed
663 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
664 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
670 # Fix bogus comment in <locale.h> on SunOS 4.1.
672 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
673 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
674 chmod +w ${LIB}/$file 2>/dev/null
675 chmod a+r ${LIB}/$file 2>/dev/null
678 if [ -r ${LIB}/$file ]; then
680 sed -e 's%#endif / \*%#endif /\* %g' ${LIB}/$file > ${LIB}/${file}.sed
681 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
682 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
687 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
688 file=hsfs/hsfs_spec.h
689 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
690 mkdir ${LIB}/hsfs 2>/dev/null
691 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
692 chmod +w ${LIB}/$file 2>/dev/null
693 chmod a+r ${LIB}/$file 2>/dev/null
696 if [ -r ${LIB}/$file ]; then
698 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
699 ${LIB}/$file > ${LIB}/${file}.sed
700 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
701 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
706 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
708 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
709 mkdir ${LIB}/hsfs 2>/dev/null
710 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
711 chmod +w ${LIB}/$file 2>/dev/null
712 chmod a+r ${LIB}/$file 2>/dev/null
715 if [ -r ${LIB}/$file ]; then
717 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
718 ${LIB}/$file > ${LIB}/${file}.sed
719 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
720 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
725 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
727 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
728 mkdir ${LIB}/hsfs 2>/dev/null
729 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
730 chmod +w ${LIB}/$file 2>/dev/null
731 chmod a+r ${LIB}/$file 2>/dev/null
734 if [ -r ${LIB}/$file ]; then
736 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
737 ${LIB}/$file > ${LIB}/${file}.sed
738 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
739 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
744 # Incorrect #include in Sony News-OS 3.2.
745 file=machine/machparam.h
746 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
747 mkdir ${LIB}/machine 2>/dev/null
748 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
749 chmod +w ${LIB}/$file 2>/dev/null
750 chmod a+r ${LIB}/$file 2>/dev/null
753 if [ -r ${LIB}/$file ]; then
754 echo Fixing $file, incorrect \#include
755 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
756 ${LIB}/$file > ${LIB}/${file}.sed
757 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
758 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
763 # Multiline comment after typedef on IRIX 4.0.1.
765 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
766 mkdir ${LIB}/sys 2>/dev/null
767 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
768 chmod +w ${LIB}/$file 2>/dev/null
769 chmod a+r ${LIB}/$file 2>/dev/null
772 if [ -r ${LIB}/$file ]; then
773 echo Fixing $file, comment in the middle of \#ifdef
774 sed -e 's@type of the result@type of the result */@' \
775 -e 's@of the sizeof@/* of the sizeof@' \
776 ${LIB}/$file > ${LIB}/${file}.sed
777 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
778 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
783 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
784 # declaration on Sun OS 4.x. We must only fix this on Sun OS 4.x, because
785 # many other systems have similar text but correct versions of the file.
786 # To ensure only Sun's is fixed, we grep for a likely unique string.
788 if egrep '/\* @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2 \*/' $file > /dev/null; then
789 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
790 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
791 chmod +w ${LIB}/$file 2>/dev/null
792 chmod a+r ${LIB}/$file 2>/dev/null
794 if [ -r ${LIB}/$file ]; then
796 cat > ${LIB}/$file << EOF
797 /* This file was generated by fixincludes */
802 extern void *memccpy();
803 extern void *memchr();
804 extern void *memcpy();
805 extern void *memset();
807 extern char *memccpy();
808 extern char *memchr();
809 extern char *memcpy();
810 extern char *memset();
811 #endif /* __STDC__ */
820 # parameters not const on DECstation Ultrix V4.0.
822 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
823 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
824 chmod +w ${LIB}/$file 2>/dev/null
825 chmod a+r ${LIB}/$file 2>/dev/null
828 if [ -r ${LIB}/$file ]; then
829 echo Fixing $file, non-const arg
830 sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
831 -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
832 -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
833 -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
834 -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
835 -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
836 -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
837 ${LIB}/$file > ${LIB}/${file}.sed
838 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
839 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
844 # parameters conflict with C++ new on rs/6000
846 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
847 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
848 chmod +w ${LIB}/$file 2>/dev/null
851 if [ -r ${LIB}/$file ]; then
852 echo Fixing $file, parameter name conflicts
853 sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
854 ${LIB}/$file > ${LIB}/${file}.sed
855 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
856 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
861 # Don't use or define the name va_list in stdio.h.
862 # This is for ANSI and also to interoperate properly with gvarargs.h.
864 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
865 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
866 chmod +w ${LIB}/$file 2>/dev/null
867 chmod a+r ${LIB}/$file 2>/dev/null
870 if [ -r ${LIB}/$file ]; then
871 echo Fixing $file, use of va_list
872 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
873 (echo "#define __need___va_list"
874 echo "#include <stdarg.h>") > ${LIB}/${file}.sed
875 # Use __gnuc_va_list in arg types in place of va_list.
876 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
877 # trailing parentheses and semicolon save all other systems from this.
878 # Define __va_list__ (something harmless and unused) instead of va_list.
879 # Don't claim to have defined va_list.
880 sed -e 's@ va_list @ __gnuc_va_list @' \
881 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
882 -e 's@ va_list@ __va_list__@' \
883 -e 's@\*va_list@*__va_list__@' \
884 -e 's@VA_LIST@DUMMY_VA_LIST@' \
885 ${LIB}/$file >> ${LIB}/${file}.sed
887 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
888 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
893 # Cancel out ansi_compat.h on Ultrix. Replace it with empty file.
895 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
896 if grep -s ULTRIX $file; then
897 echo "/* This file intentionally left blank. */" > $LIB/$file
901 # parameter to atof not const on DECstation Ultrix V4.0.
902 # also get rid of bogus inline definitions in HP-UX 8.0
904 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
905 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
906 chmod +w ${LIB}/$file 2>/dev/null
907 chmod a+r ${LIB}/$file 2>/dev/null
910 if [ -r ${LIB}/$file ]; then
911 echo Fixing $file, non-const arg
912 sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
913 -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
914 -e 's@inline double abs(double d) { return fabs(d); }@@' \
915 ${LIB}/$file > ${LIB}/${file}.sed
916 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
917 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
922 # In limits.h, put #ifndefs around things that are supposed to be defined
923 # in float.h to avoid redefinition errors if float.h is included first.
925 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
926 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
927 chmod +w ${LIB}/$file 2>/dev/null
928 chmod a+r ${LIB}/$file 2>/dev/null
931 if [ -r ${LIB}/$file ]; then
933 sed -e '/[ ]FLT_MIN[ ]/i\
935 -e '/[ ]FLT_MIN[ ]/a\
937 -e '/[ ]FLT_MAX[ ]/i\
939 -e '/[ ]FLT_MAX[ ]/a\
941 -e '/[ ]FLT_DIG[ ]/i\
943 -e '/[ ]FLT_DIG[ ]/a\
945 -e '/[ ]DBL_MIN[ ]/i\
947 -e '/[ ]DBL_MIN[ ]/a\
949 -e '/[ ]DBL_MAX[ ]/i\
951 -e '/[ ]DBL_MAX[ ]/a\
953 -e '/[ ]DBL_DIG[ ]/i\
955 -e '/[ ]DBL_DIG[ ]/a\
957 ${LIB}/$file > ${LIB}/${file}.sed
958 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
959 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
960 echo Deleting ${LIB}/$file\; no fixes were needed.
965 # These two files on SunOS 4 are included by other files
966 # in the same directory, using "...". So we must make sure they exist
967 # in the same directory as the other fixed files.
968 if [ -r ${INPUT}/multimedia/audio_errno.h ]
970 ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
972 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
974 ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
977 echo 'Removing unneeded directories:'
979 files=`find . -type d -print | sort -r`
980 for file in $files; do
981 rmdir $LIB/$file > /dev/null 2>&1
985 echo 'Making internal symbolic non-directory links'
987 files=`find . -type l -print`
988 for file in $files; do
989 dest=`ls -ld $file | sed -n 's/.*-> //p'`
990 if expr "$dest" : '[^/].*' > /dev/null; then
991 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
992 if [ -f $target ]; then
993 ln -s $dest ${LIB}/$file >/dev/null 2>&1