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"
216 while [ $# != 0 ]; do
217 # $1 is an old directory to copy, and $2 is the new directory to copy to.
220 # The same dir can appear more than once in treetops.
221 # There's no need to scan it more than once.
227 echo Fixing directory $1 into $2
228 # Check .h files which are symlinks as well as those which are files.
229 # A link to a header file will not be processed by anything but this.
231 files=`find . -name '*.h' \( -type f -o -type l \) -print`
233 files=`find . -name '*.h' -type f -print`
235 echo Checking header files
237 # Note that BSD43_* are used on recent MIPS systems.
238 for file in $files; do
239 # This call to egrep is essential, since checking a file with egrep
240 # is much faster than actually trying to fix it.
241 # It is also essential that most files *not* match!
242 # Thus, matching every #endif is unacceptable.
243 # But the argument to egrep must be kept small, or many versions of egrep
244 # won't be able to handle it.
246 # We use the pattern [!-.0-~] instead of [^/ ] to match a noncomment
247 # following #else or #endif because some buggy egreps think [^/] matches
248 # newline, and they thus think `#else ' matches `#e[ndiflse]*[ ]+[^/ ]'.
250 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
251 # following #if or #elif that is not surrounded by __. The `a-ce-km-z'
252 # in this pattern lacks `d' and `l'; this means we don't worry about
253 # identifiers starting with `d' or `l'. This is OK, since none of the
254 # identifiers below start with `d' or `l'. It also greatly improves
255 # performance, since many files contain lines of the form `#if ... defined ...'
257 if egrep '//|[ _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[ ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-z][a-z0-9]' $file >/dev/null; then
258 if [ -r $file ]; then
259 cp $file $2/$file >/dev/null 2>&1 \
260 || echo "Can't copy $file"
267 s%^\([ ]*#[ ]*endif[ ]*\)\([^/ ].*\)$%\1/* \2 */%
268 s%^\([ ]*#[ ]*else[ ]*\)\([^/ ].*\)$%\1/* \2 */%
269 /\/\/[^*]/ s|//\(.*\)$|/*\1*/|
270 /[ ]_IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
271 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
272 /#define._IO/ s/'\''\([cgx]\)'\''/\1/g
273 /#define.BSD43__IO/ s/'\''\([cgx]\)'\''/\1/g
274 /[^A-Z]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
275 /#define.CTRL/ s/'\''\([cgx]\)'\''/\1/g
276 /#define._CTRL/ s/'\''\([cgx]\)'\''/\1/g
277 /#define.BSD43_CTRL/ s/'\''\([cgx]\)'\''/\1/g
279 # Surround each word with spaces, to simplify matching below.
280 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
282 # ANSIfy each pre-ANSI machine-dependent symbol
283 # by surrounding it with __ __.
284 s/ bsd4\([0-9]\) / __bsd4\1__ /g
285 s/ _*i386 / __i386__ /g
286 s/ is68k / __is68k__ /g
287 s/ m68k / __m68k__ /g
288 s/ mc680\([0-9]\)0 / __mc680\10__ /g
289 s/ news\([0-9]*\) / __news\1__ /g
290 s/ ns32000 / __ns32000__ /g
292 s/ sony_news / __sony_news__ /g
293 s/ sparc / __sparc__ /g
294 s/ sun\([a-z0-9]*\) / __sun\1__ /g
295 s/ unix / __unix__ /g
298 # Remove the spaces that we inserted around each word.
299 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
301 /^#define.NULL[ ]/ i\
303 ' $2/$file > $2/$file.sed
304 mv $2/$file.sed $2/$file
305 if cmp $file $2/$file >/dev/null 2>&1; then
318 # Install the proper definition of size_t in header files that it comes from.
319 for file in sys/types.h sys/stdtypes.h;
321 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
322 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
323 chmod +w ${LIB}/$file 2>/dev/null
324 chmod a+r ${LIB}/$file 2>/dev/null
327 if [ -r ${LIB}/$file ]; then
328 echo Fixing $file comment
329 # Extract the definition of SIZE_TYPE, if any.
330 # (This file must be called something.c).
331 echo "#include \"tm.h\"
332 gobblegobble SIZE_TYPE" > ${LIB}/types.c
333 foo=`cc -E -I${ORIGDIR} -I${SRCDIR} -I${SRCDIR}/config ${LIB}/types.c | grep gobblegobble | sed -e "s/gobblegobble[ ]*//"`
335 # Default to our preferred type.
336 if [ "$foo" = SIZE_TYPE ]; then foo="unsigned long int"; else foo=`echo $foo | sed -e 's/^.*"\(.*\)".*$/\1/'`; fi
337 sed -e "s/typedef[ a-z_]*[ ]size_t/typedef $foo size_t/" ${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
345 # Fix one other error in this file: a mismatched quote not inside a C comment.
346 file=sundev/vuid_event.h
347 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
348 mkdir ${LIB}/sundev 2>/dev/null
349 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
350 chmod +w ${LIB}/$file 2>/dev/null
351 chmod a+r ${LIB}/$file 2>/dev/null
354 if [ -r ${LIB}/$file ]; then
355 echo Fixing $file comment
356 sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
357 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
358 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
363 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
364 file=sunwindow/win_cursor.h
365 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
366 # mkdir ${LIB}/sunwindow 2>/dev/null
367 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
368 chmod +w ${LIB}/$file 2>/dev/null
370 if [ -r ${LIB}/$file ]; then
372 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
373 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
374 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
378 file=sunwindow/win_lock.h
379 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
380 # mkdir ${LIB}/sunwindow 2>/dev/null
381 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
382 chmod +w ${LIB}/$file 2>/dev/null
384 if [ -r ${LIB}/$file ]; then
386 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
387 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
388 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
393 # Fix this Sun file to avoid interfering with stddef.h.
395 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
396 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
397 chmod +w ${LIB}/$file 2>/dev/null
398 chmod a+r ${LIB}/$file 2>/dev/null
401 if [ -r ${LIB}/$file ]; then
403 sed -e '/size_t.*;/i\
405 #define _GCC_SIZE_T' \
409 #ifndef _GCC_PTRDIFF_T\
410 #define _GCC_PTRDIFF_T' \
414 #ifndef _GCC_WCHAR_T\
415 #define _GCC_WCHAR_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 this file to avoid interfering with stddef.h, but don't mistakenly
425 # match e.g. ssize_t present in AIX for the ps/2.
427 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
428 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
429 chmod +w ${LIB}/$file 2>/dev/null
430 chmod a+r ${LIB}/$file 2>/dev/null
433 if [ -r ${LIB}/$file ]; then
435 sed -e '/[ ]size_t.*;/i\
437 #define _GCC_SIZE_T' \
439 #endif' ${LIB}/$file > ${LIB}/${file}.sed
440 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
441 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
446 # Fix an error in this file: the #if says _cplusplus, not the double
447 # underscore __cplusplus that it should be
449 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
450 mkdir ${LIB}/rpcsvc 2>/dev/null
451 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
452 chmod +w ${LIB}/$file 2>/dev/null
453 chmod a+r ${LIB}/$file 2>/dev/null
456 if [ -r ${LIB}/$file ]; then
457 echo Fixing $file, __cplusplus macro
458 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
459 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
460 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
465 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
466 # structure definition.
468 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
469 mkdir ${LIB}/rpcsvc 2>/dev/null
470 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
471 chmod +w ${LIB}/$file 2>/dev/null
472 chmod a+r ${LIB}/$file 2>/dev/null
475 if [ -r ${LIB}/$file ]; then
476 echo Fixing $file, definition of statsswtch
477 sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
478 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
479 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
484 # Fix an error in this file: a missing semi-colon at the end of the nodeent
485 # structure definition.
486 file=netdnet/dnetdb.h
487 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
488 mkdir ${LIB}/netdnet 2>/dev/null
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, definition of nodeent
496 sed -e 's/char.*na_addr *$/char *na_addr;/' ${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 bad #ifdef line (in Ultrix 4.1)
505 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
506 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
507 chmod +w ${LIB}/$file 2>/dev/null
508 chmod a+r ${LIB}/$file 2>/dev/null
511 if [ -r ${LIB}/$file ]; then
512 echo Fixing $file, bad \#ifdef line
513 sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
514 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
515 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
520 # Remove nested comments created by #endifs in a comment (Ultrix 4.1)
521 # Only needed if commenting out junk after #endif.
523 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
524 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
525 chmod +w ${LIB}/$file 2>/dev/null
526 chmod a+r ${LIB}/$file 2>/dev/null
529 if [ -r ${LIB}/$file ]; then
530 echo Fixing $file, nested comments
531 sed -e 's/#endif.*/#endif/' ${LIB}/$file > ${LIB}/${file}.sed
532 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
533 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
538 # Check for superfluous `static' (in Ultrix 4.2)
540 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
541 mkdir ${LIB}/machine 2>/dev/null
542 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
543 chmod +w ${LIB}/$file 2>/dev/null
544 chmod a+r ${LIB}/$file 2>/dev/null
547 if [ -r ${LIB}/$file ]; then
548 echo Fixing $file, superfluous static
549 sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
550 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
551 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
554 # This file has an alternative name, mips/cpu.h. Fix that name, too.
555 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
556 mkdir ${LIB}/mips 2>&-
557 ln ${LIB}/$file ${LIB}/mips/cpu.h
562 # Incorrect sprintf declaration in X11/Xmu.h
564 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
565 mkdir ${LIB}/X11 2>/dev/null
566 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
567 chmod +w ${LIB}/$file 2>/dev/null
568 chmod a+r ${LIB}/$file 2>/dev/null
571 if [ -r ${LIB}/$file ]; then
572 echo Fixing $file sprintf declaration
573 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
574 extern char * sprintf();\
575 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
576 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
577 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
582 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
583 # (It's not clear whether the right file name is this or X11/Xmu.h.)
585 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
586 mkdir ${LIB}/X11/Xmu 2>/dev/null
587 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
588 chmod +w ${LIB}/$file 2>/dev/null
589 chmod a+r ${LIB}/$file 2>/dev/null
592 if [ -r ${LIB}/$file ]; then
593 echo Fixing $file sprintf declaration
594 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
595 extern char * sprintf();\
596 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
597 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
598 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
603 # Check for missing ';' in struct
605 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
606 mkdir ${LIB}/netinet 2>/dev/null
607 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
608 chmod +w ${LIB}/$file 2>/dev/null
609 chmod a+r ${LIB}/$file 2>/dev/null
612 if [ -r ${LIB}/$file ]; then
614 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
615 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
616 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
621 # Fix the CAT macro in SunOS memvar.h.
622 file=pixrect/memvar.h
623 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
624 mkdir ${LIB}/pixrect 2>/dev/null
625 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
626 chmod +w ${LIB}/$file 2>/dev/null
627 chmod a+r ${LIB}/$file 2>/dev/null
630 if [ -r ${LIB}/$file ]; then
632 sed -e '/^#define.CAT(a,b)/ i\
634 #define CAT(a,b) a##b\
636 /^#define.CAT(a,b)/ a\
638 ' ${LIB}/$file > ${LIB}/${file}.sed
639 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
640 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
645 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
647 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
648 mkdir ${LIB}/rpcsvc 2>/dev/null
649 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
650 chmod +w ${LIB}/$file 2>/dev/null
651 chmod a+r ${LIB}/$file 2>/dev/null
654 if [ -r ${LIB}/$file ]; then
656 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${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 exit and abort in <stdlib.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/int abort/void abort/g' \
674 -e 's/int free/void free/g' \
675 -e 's/char \* calloc/void \* calloc/g' \
676 -e 's/char \* malloc/void \* malloc/g' \
677 -e 's/char \* realloc/void \* realloc/g' \
678 -e 's/int exit/void exit/g' ${LIB}/$file > ${LIB}/${file}.sed
679 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
680 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
685 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
687 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
688 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
689 chmod +w ${LIB}/$file 2>/dev/null
690 chmod a+r ${LIB}/$file 2>/dev/null
693 if [ -r ${LIB}/$file ]; then
695 sed -e 's/typedef[ ]char \* malloc_t/typedef void \* malloc_t/g' \
696 -e 's/int[ ][ ]*free/void free/g' \
697 ${LIB}/$file > ${LIB}/${file}.sed
698 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
699 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
705 # Fix bogus comment in <locale.h> on SunOS 4.1.
707 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
708 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
709 chmod +w ${LIB}/$file 2>/dev/null
710 chmod a+r ${LIB}/$file 2>/dev/null
713 if [ -r ${LIB}/$file ]; then
715 sed -e 's%#endif / \*%#endif /\* %g' ${LIB}/$file > ${LIB}/${file}.sed
716 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
717 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
722 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
723 file=hsfs/hsfs_spec.h
724 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
725 mkdir ${LIB}/hsfs 2>/dev/null
726 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
727 chmod +w ${LIB}/$file 2>/dev/null
728 chmod a+r ${LIB}/$file 2>/dev/null
731 if [ -r ${LIB}/$file ]; then
733 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
734 ${LIB}/$file > ${LIB}/${file}.sed
735 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
736 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
741 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
743 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
744 mkdir ${LIB}/hsfs 2>/dev/null
745 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
746 chmod +w ${LIB}/$file 2>/dev/null
747 chmod a+r ${LIB}/$file 2>/dev/null
750 if [ -r ${LIB}/$file ]; then
752 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
753 ${LIB}/$file > ${LIB}/${file}.sed
754 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
755 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
760 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
762 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
763 mkdir ${LIB}/hsfs 2>/dev/null
764 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
765 chmod +w ${LIB}/$file 2>/dev/null
766 chmod a+r ${LIB}/$file 2>/dev/null
769 if [ -r ${LIB}/$file ]; then
771 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
772 ${LIB}/$file > ${LIB}/${file}.sed
773 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
774 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
779 # Incorrect #include in Sony News-OS 3.2.
780 file=machine/machparam.h
781 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
782 mkdir ${LIB}/machine 2>/dev/null
783 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
784 chmod +w ${LIB}/$file 2>/dev/null
785 chmod a+r ${LIB}/$file 2>/dev/null
788 if [ -r ${LIB}/$file ]; then
789 echo Fixing $file, incorrect \#include
790 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
791 ${LIB}/$file > ${LIB}/${file}.sed
792 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
793 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
798 # Multiline comment after typedef on IRIX 4.0.1.
800 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
801 mkdir ${LIB}/sys 2>/dev/null
802 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
803 chmod +w ${LIB}/$file 2>/dev/null
804 chmod a+r ${LIB}/$file 2>/dev/null
807 if [ -r ${LIB}/$file ]; then
808 echo Fixing $file, comment in the middle of \#ifdef
809 sed -e 's@type of the result@type of the result */@' \
810 -e 's@of the sizeof@/* of the sizeof@' \
811 ${LIB}/$file > ${LIB}/${file}.sed
812 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
813 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
818 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
819 # declaration on Sun OS 4.x. We must only fix this on Sun OS 4.x, because
820 # many other systems have similar text but correct versions of the file.
821 # To ensure only Sun's is fixed, we grep for a likely unique string.
823 if egrep '/\* @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2 \*/' $file > /dev/null; then
824 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
825 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
826 chmod +w ${LIB}/$file 2>/dev/null
827 chmod a+r ${LIB}/$file 2>/dev/null
829 if [ -r ${LIB}/$file ]; then
831 cat > ${LIB}/$file << EOF
832 /* This file was generated by fixincludes */
837 extern void *memccpy();
838 extern void *memchr();
839 extern void *memcpy();
840 extern void *memset();
842 extern char *memccpy();
843 extern char *memchr();
844 extern char *memcpy();
845 extern char *memset();
846 #endif /* __STDC__ */
855 # parameters not const on DECstation Ultrix V4.0.
857 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
858 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
859 chmod +w ${LIB}/$file 2>/dev/null
860 chmod a+r ${LIB}/$file 2>/dev/null
863 if [ -r ${LIB}/$file ]; then
864 echo Fixing $file, non-const arg
865 sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
866 -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
867 -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
868 -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
869 -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
870 -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
871 -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
872 ${LIB}/$file > ${LIB}/${file}.sed
873 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
874 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
879 # parameters conflict with C++ new on rs/6000
881 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
882 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
883 chmod +w ${LIB}/$file 2>/dev/null
886 if [ -r ${LIB}/$file ]; then
887 echo Fixing $file, parameter name conflicts
888 sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
889 ${LIB}/$file > ${LIB}/${file}.sed
890 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
891 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
896 # Don't use or define the name va_list in stdio.h.
897 # This is for ANSI and also to interoperate properly with gvarargs.h.
899 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
900 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
901 chmod +w ${LIB}/$file 2>/dev/null
902 chmod a+r ${LIB}/$file 2>/dev/null
905 if [ -r ${LIB}/$file ]; then
906 echo Fixing $file, use of va_list
907 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
908 (echo "#define __need___va_list"
909 echo "#include <stdarg.h>") > ${LIB}/${file}.sed
910 # Use __gnuc_va_list in arg types in place of va_list.
911 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
912 # trailing parentheses and semicolon save all other systems from this.
913 # Define __va_list__ (something harmless and unused) instead of va_list.
914 # Don't claim to have defined va_list.
915 sed -e 's@ va_list @ __gnuc_va_list @' \
916 -e 's@ va_list)@ __gnuc_va_list)@' \
917 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
918 -e 's@ va_list@ __va_list__@' \
919 -e 's@\*va_list@*__va_list__@' \
920 -e 's@VA_LIST@DUMMY_VA_LIST@' \
921 ${LIB}/$file >> ${LIB}/${file}.sed
923 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
924 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
929 # Cancel out ansi_compat.h on Ultrix. Replace it with empty file.
931 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
932 if grep -s ULTRIX $file; then
933 echo "/* This file intentionally left blank. */" > $LIB/$file
937 # parameter to atof not const on DECstation Ultrix V4.0.
938 # also get rid of bogus inline definitions in HP-UX 8.0
940 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
941 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
942 chmod +w ${LIB}/$file 2>/dev/null
943 chmod a+r ${LIB}/$file 2>/dev/null
946 if [ -r ${LIB}/$file ]; then
947 echo Fixing $file, non-const arg
948 sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
949 -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
950 -e 's@inline double abs(double d) { return fabs(d); }@@' \
951 ${LIB}/$file > ${LIB}/${file}.sed
952 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
953 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
958 # In limits.h, put #ifndefs around things that are supposed to be defined
959 # in float.h to avoid redefinition errors if float.h is included first.
961 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
962 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
963 chmod +w ${LIB}/$file 2>/dev/null
964 chmod a+r ${LIB}/$file 2>/dev/null
967 if [ -r ${LIB}/$file ]; then
969 sed -e '/[ ]FLT_MIN[ ]/i\
971 -e '/[ ]FLT_MIN[ ]/a\
973 -e '/[ ]FLT_MAX[ ]/i\
975 -e '/[ ]FLT_MAX[ ]/a\
977 -e '/[ ]FLT_DIG[ ]/i\
979 -e '/[ ]FLT_DIG[ ]/a\
981 -e '/[ ]DBL_MIN[ ]/i\
983 -e '/[ ]DBL_MIN[ ]/a\
985 -e '/[ ]DBL_MAX[ ]/i\
987 -e '/[ ]DBL_MAX[ ]/a\
989 -e '/[ ]DBL_DIG[ ]/i\
991 -e '/[ ]DBL_DIG[ ]/a\
993 ${LIB}/$file > ${LIB}/${file}.sed
994 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
995 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
996 echo Deleting ${LIB}/$file\; no fixes were needed.
1001 # These two files on SunOS 4 are included by other files
1002 # in the same directory, using "...". So we must make sure they exist
1003 # in the same directory as the other fixed files.
1004 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1006 ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1008 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1010 ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1013 echo 'Removing unneeded directories:'
1015 files=`find . -type d -print | sort -r`
1016 for file in $files; do
1017 rmdir $LIB/$file > /dev/null 2>&1
1021 echo 'Making internal symbolic non-directory links'
1023 files=`find . -type l -print`
1024 for file in $files; do
1025 dest=`ls -ld $file | sed -n 's/.*-> //p'`
1026 if expr "$dest" : '[^/].*' > /dev/null; then
1027 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1028 if [ -f $target ]; then
1029 ln -s $dest ${LIB}/$file >/dev/null 2>&1
1035 echo 'Cleaning up DONE files.'
1037 find . -name DONE -exec rm -f {} ';'