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"
263 # Here is how the sed commands in braces work.
264 # (It doesn't work to put the comments inside the sed commands.)
265 # Surround each word with spaces, to simplify matching below.
266 # ANSIfy each pre-ANSI machine-dependent symbol
267 # by surrounding it with __ __.
268 # Remove the spaces that we inserted around each word.
273 s%^\([ ]*#[ ]*else\)[ ]*/[^*].*%\1%
274 s%^\([ ]*#[ ]*else\)[ ]*[^/ ].*%\1%
275 s%^\([ ]*#[ ]*endif\)[ ]*/[^*].*%\1%
276 s%^\([ ]*#[ ]*endif\)[ ]*[^/ ].*%\1%
277 /\/\/[^*]/ s|//\(.*\)$|/*\1*/|
278 /[ ]_IO[A-Z]*[ ]*(/ s/\(_IO[A-Z]*[ ]*(\)\(.\),/\1'\''\2'\'',/
279 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
280 /#define._IO/ s/'\''\([cgx]\)'\''/\1/g
281 /#define.BSD43__IO/ s/'\''\([cgx]\)'\''/\1/g
282 /[^A-Z0-9_]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
283 /[^A-Z0-9]_CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
284 /#define.CTRL/ s/'\''\([cgx]\)'\''/\1/g
285 /#define._CTRL/ s/'\''\([cgx]\)'\''/\1/g
286 /#define.BSD43_CTRL/ s/'\''\([cgx]\)'\''/\1/g
288 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
290 s/ bsd4\([0-9]\) / __bsd4\1__ /g
291 s/ _*i386 / __i386__ /g
292 s/ is68k / __is68k__ /g
293 s/ m68k / __m68k__ /g
294 s/ mc680\([0-9]\)0 / __mc680\10__ /g
295 s/ news\([0-9]*\) / __news\1__ /g
296 s/ ns32000 / __ns32000__ /g
298 s/ sony_news / __sony_news__ /g
299 s/ sparc / __sparc__ /g
300 s/ sun\([a-z0-9]*\) / __sun\1__ /g
301 s/ unix / __unix__ /g
304 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
306 /^#define.NULL[ ]/ i\
308 ' $2/$file > $2/$file.
309 mv $2/$file. $2/$file
310 if cmp $file $2/$file >/dev/null 2>&1; then
323 # Install the proper definition of size_t in header files that it comes from.
324 for file in sys/types.h sys/stdtypes.h;
326 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
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 # Extract the definition of SIZE_TYPE, if any.
335 # (This file must be called something.c).
336 echo "#include \"tm.h\"
337 gobblegobble SIZE_TYPE" > ${LIB}/types.c
338 foo=`cd ${LIB}; cc -E -I${ORIGDIR} -I${SRCDIR} -I${SRCDIR}/config types.c | grep gobblegobble | sed -e "s/gobblegobble[ ]*//"`
340 # Default to our preferred type.
341 if [ "$foo" = SIZE_TYPE ]; then foo="unsigned long int"; else foo=`echo $foo | sed -e 's/^.*"\(.*\)".*$/\1/'`; fi
342 sed -e "s/typedef[ a-z_]*[ ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
343 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
344 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
350 # Fix one other error in this file: a mismatched quote not inside a C comment.
351 file=sundev/vuid_event.h
352 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
353 mkdir ${LIB}/sundev 2>/dev/null
354 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
355 chmod +w ${LIB}/$file 2>/dev/null
356 chmod a+r ${LIB}/$file 2>/dev/null
359 if [ -r ${LIB}/$file ]; then
360 echo Fixing $file comment
361 sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
362 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
363 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
368 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
369 file=sunwindow/win_cursor.h
370 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
371 # mkdir ${LIB}/sunwindow 2>/dev/null
372 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
373 chmod +w ${LIB}/$file 2>/dev/null
375 if [ -r ${LIB}/$file ]; then
377 sed -e "s/ecd.cursor/ecd_cursor/" ${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
383 file=sunwindow/win_lock.h
384 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
385 # mkdir ${LIB}/sunwindow 2>/dev/null
386 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
387 chmod +w ${LIB}/$file 2>/dev/null
389 if [ -r ${LIB}/$file ]; then
391 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
392 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
393 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
398 # Fix this Sun file to avoid interfering with stddef.h.
400 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
401 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
402 chmod +w ${LIB}/$file 2>/dev/null
403 chmod a+r ${LIB}/$file 2>/dev/null
406 if [ -r ${LIB}/$file ]; then
408 sed -e '/[ ]size_t.*;/i\
410 #define _GCC_SIZE_T' \
413 -e '/[ ]ptrdiff_t.*;/i\
414 #ifndef _GCC_PTRDIFF_T\
415 #define _GCC_PTRDIFF_T' \
416 -e '/[ ]ptrdiff_t.*;/a\
418 -e '/[ ]wchar_t.*;/i\
419 #ifndef _GCC_WCHAR_T\
420 #define _GCC_WCHAR_T' \
421 -e '/[ ]wchar_t.*;/a\
422 #endif' ${LIB}/$file > ${LIB}/${file}.sed
423 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
424 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
429 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
430 # match e.g. ssize_t present in AIX for the ps/2.
432 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
433 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
434 chmod +w ${LIB}/$file 2>/dev/null
435 chmod a+r ${LIB}/$file 2>/dev/null
438 if [ -r ${LIB}/$file ]; then
440 sed -e '/[ ]size_t.*;/i\
442 #define _GCC_SIZE_T' \
444 #endif' ${LIB}/$file > ${LIB}/${file}.sed
445 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
446 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
451 # Fix an error in this file: the #if says _cplusplus, not the double
452 # underscore __cplusplus that it should be
454 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
455 mkdir ${LIB}/rpcsvc 2>/dev/null
456 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
457 chmod +w ${LIB}/$file 2>/dev/null
458 chmod a+r ${LIB}/$file 2>/dev/null
461 if [ -r ${LIB}/$file ]; then
462 echo Fixing $file, __cplusplus macro
463 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
464 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
465 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
470 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
471 # structure definition.
473 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
474 mkdir ${LIB}/rpcsvc 2>/dev/null
475 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
476 chmod +w ${LIB}/$file 2>/dev/null
477 chmod a+r ${LIB}/$file 2>/dev/null
480 if [ -r ${LIB}/$file ]; then
481 echo Fixing $file, definition of statsswtch
482 sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
483 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
484 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
489 # Fix an error in this file: a missing semi-colon at the end of the nodeent
490 # structure definition.
491 file=netdnet/dnetdb.h
492 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
493 mkdir ${LIB}/netdnet 2>/dev/null
494 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
495 chmod +w ${LIB}/$file 2>/dev/null
496 chmod a+r ${LIB}/$file 2>/dev/null
499 if [ -r ${LIB}/$file ]; then
500 echo Fixing $file, definition of nodeent
501 sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
502 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
503 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
508 # Check for bad #ifdef line (in Ultrix 4.1)
510 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
511 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
512 chmod +w ${LIB}/$file 2>/dev/null
513 chmod a+r ${LIB}/$file 2>/dev/null
516 if [ -r ${LIB}/$file ]; then
517 echo Fixing $file, bad \#ifdef line
518 sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
519 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
520 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
525 # Check for superfluous `static' (in Ultrix 4.2)
527 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
528 mkdir ${LIB}/machine 2>/dev/null
529 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
530 chmod +w ${LIB}/$file 2>/dev/null
531 chmod a+r ${LIB}/$file 2>/dev/null
534 if [ -r ${LIB}/$file ]; then
535 echo Fixing $file, superfluous static
536 sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
537 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
538 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
541 # This file has an alternative name, mips/cpu.h. Fix that name, too.
542 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
543 mkdir ${LIB}/mips 2>&-
544 ln ${LIB}/$file ${LIB}/mips/cpu.h
549 # Incorrect sprintf declaration in X11/Xmu.h
551 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
552 mkdir ${LIB}/X11 2>/dev/null
553 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
554 chmod +w ${LIB}/$file 2>/dev/null
555 chmod a+r ${LIB}/$file 2>/dev/null
558 if [ -r ${LIB}/$file ]; then
559 echo Fixing $file sprintf declaration
560 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
561 extern char * sprintf();\
562 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
563 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
564 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
569 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
570 # (It's not clear whether the right file name is this or X11/Xmu.h.)
572 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
573 mkdir ${LIB}/X11/Xmu 2>/dev/null
574 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
575 chmod +w ${LIB}/$file 2>/dev/null
576 chmod a+r ${LIB}/$file 2>/dev/null
579 if [ -r ${LIB}/$file ]; then
580 echo Fixing $file sprintf declaration
581 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
582 extern char * sprintf();\
583 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
584 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
585 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
590 # Check for missing ';' in struct
592 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
593 mkdir ${LIB}/netinet 2>/dev/null
594 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
595 chmod +w ${LIB}/$file 2>/dev/null
596 chmod a+r ${LIB}/$file 2>/dev/null
599 if [ -r ${LIB}/$file ]; then
601 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
602 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
603 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
608 # Fix the CAT macro in SunOS memvar.h.
609 file=pixrect/memvar.h
610 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
611 mkdir ${LIB}/pixrect 2>/dev/null
612 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
613 chmod +w ${LIB}/$file 2>/dev/null
614 chmod a+r ${LIB}/$file 2>/dev/null
617 if [ -r ${LIB}/$file ]; then
619 sed -e '/^#define.CAT(a,b)/ i\
621 #define CAT(a,b) a##b\
623 /^#define.CAT(a,b)/ a\
625 ' ${LIB}/$file > ${LIB}/${file}.sed
626 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
627 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
632 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
634 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
635 mkdir ${LIB}/rpcsvc 2>/dev/null
636 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
637 chmod +w ${LIB}/$file 2>/dev/null
638 chmod a+r ${LIB}/$file 2>/dev/null
641 if [ -r ${LIB}/$file ]; then
643 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${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 exit and abort in <stdlib.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/int abort/void abort/g' \
661 -e 's/int free/void free/g' \
662 -e 's/char \* calloc/void \* calloc/g' \
663 -e 's/char \* malloc/void \* malloc/g' \
664 -e 's/char \* realloc/void \* realloc/g' \
665 -e 's/int exit/void exit/g' ${LIB}/$file > ${LIB}/${file}.sed
666 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
667 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
672 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
674 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
675 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
676 chmod +w ${LIB}/$file 2>/dev/null
677 chmod a+r ${LIB}/$file 2>/dev/null
680 if [ -r ${LIB}/$file ]; then
682 sed -e 's/typedef[ ]char \* malloc_t/typedef void \* malloc_t/g' \
683 -e 's/int[ ][ ]*free/void free/g' \
684 ${LIB}/$file > ${LIB}/${file}.sed
685 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
686 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
691 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
692 file=hsfs/hsfs_spec.h
693 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
694 mkdir ${LIB}/hsfs 2>/dev/null
695 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
696 chmod +w ${LIB}/$file 2>/dev/null
697 chmod a+r ${LIB}/$file 2>/dev/null
700 if [ -r ${LIB}/$file ]; then
702 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
703 ${LIB}/$file > ${LIB}/${file}.
704 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
705 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
710 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
712 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
713 mkdir ${LIB}/hsfs 2>/dev/null
714 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
715 chmod +w ${LIB}/$file 2>/dev/null
716 chmod a+r ${LIB}/$file 2>/dev/null
719 if [ -r ${LIB}/$file ]; then
721 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
722 ${LIB}/$file > ${LIB}/${file}.sed
723 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
724 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
729 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
731 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
732 mkdir ${LIB}/hsfs 2>/dev/null
733 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
734 chmod +w ${LIB}/$file 2>/dev/null
735 chmod a+r ${LIB}/$file 2>/dev/null
738 if [ -r ${LIB}/$file ]; then
740 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
741 ${LIB}/$file > ${LIB}/${file}.sed
742 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
743 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
748 # Incorrect #include in Sony News-OS 3.2.
749 file=machine/machparam.h
750 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
751 mkdir ${LIB}/machine 2>/dev/null
752 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
753 chmod +w ${LIB}/$file 2>/dev/null
754 chmod a+r ${LIB}/$file 2>/dev/null
757 if [ -r ${LIB}/$file ]; then
758 echo Fixing $file, incorrect \#include
759 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
760 ${LIB}/$file > ${LIB}/${file}.
761 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
762 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
767 # Multiline comment after typedef on IRIX 4.0.1.
769 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
770 mkdir ${LIB}/sys 2>/dev/null
771 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
772 chmod +w ${LIB}/$file 2>/dev/null
773 chmod a+r ${LIB}/$file 2>/dev/null
776 if [ -r ${LIB}/$file ]; then
777 echo Fixing $file, comment in the middle of \#ifdef
778 sed -e 's@type of the result@type of the result */@' \
779 -e 's@of the sizeof@/* of the sizeof@' \
780 ${LIB}/$file > ${LIB}/${file}.sed
781 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
782 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
787 # Fix line in IRIX 4.0.1 header file. The sed script turns
788 # #define EM_CTRL (CUTIOC|0x1)
790 # #define EM_CTRL (CUTIOC|0x'1')
792 if [ -r ${LIB}/$file ]; then
793 echo Fixing $file, overeager sed script
794 sed -e "s/0x'1'/0x1/" ${LIB}/$file > ${LIB}/${file}.sed
795 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
796 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
801 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
802 # header file, which embeds // comments inside multi-line /* */
803 # comments. If this looks like the IRIX header file, we refix it by
804 # just throwing away the // comments.
806 if [ -r ${LIB}/$file ]; then
807 if egrep indigo.esd ${LIB}/$file > /dev/null; then
808 echo Fixing $file, overeager sed script
810 sed -e 's|//.*$||g' $file > ${LIB}/$file
811 chmod +w ${LIB}/$file 2>/dev/null
812 chmod a+r ${LIB}/$file 2>/dev/null
816 # Another IRIX 4.0.1 header file contains the string "//"
818 if [ -r ${LIB}/$file ]; then
819 echo Fixing $file, overeager sed script
820 sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
821 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
822 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
827 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
828 # declaration on Sun OS 4.x. We must only fix this on Sun OS 4.x, because
829 # many other systems have similar text but correct versions of the file.
830 # To ensure only Sun's is fixed, we grep for a likely unique string.
832 if [ -r $file ] && egrep '/\* @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2 \*/' $file > /dev/null; then
833 if [ ! -r ${LIB}/$file ]; then
834 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
835 chmod +w ${LIB}/$file 2>/dev/null
836 chmod a+r ${LIB}/$file 2>/dev/null
838 if [ -r ${LIB}/$file ]; then
840 cat > ${LIB}/$file << EOF
841 /* This file was generated by fixincludes */
846 extern void *memccpy();
847 extern void *memchr();
848 extern void *memcpy();
849 extern void *memset();
851 extern char *memccpy();
852 extern char *memchr();
853 extern char *memcpy();
854 extern char *memset();
855 #endif /* __STDC__ */
859 #endif /* __memory_h__ */
864 # parameters not const on DECstation Ultrix V4.0.
866 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
867 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
868 chmod +w ${LIB}/$file 2>/dev/null
869 chmod a+r ${LIB}/$file 2>/dev/null
872 if [ -r ${LIB}/$file ]; then
873 echo Fixing $file, non-const arg
874 sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
875 -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
876 -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
877 -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
878 -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
879 -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
880 -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
881 ${LIB}/$file > ${LIB}/${file}.sed
882 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
883 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
888 # parameters conflict with C++ new on rs/6000
890 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
891 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
892 chmod +w ${LIB}/$file 2>/dev/null
895 if [ -r ${LIB}/$file ]; then
896 echo Fixing $file, parameter name conflicts
897 sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
898 ${LIB}/$file > ${LIB}/${file}.sed
899 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
900 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
905 # Don't use or define the name va_list in stdio.h.
906 # This is for ANSI and also to interoperate properly with gvarargs.h.
908 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
909 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
910 chmod +w ${LIB}/$file 2>/dev/null
911 chmod a+r ${LIB}/$file 2>/dev/null
914 if [ -r ${LIB}/$file ]; then
915 echo Fixing $file, use of va_list
916 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
917 (echo "#define __need___va_list"
918 echo "#include <stdarg.h>") > ${LIB}/${file}.sed
919 # Use __gnuc_va_list in arg types in place of va_list.
920 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
921 # trailing parentheses and semicolon save all other systems from this.
922 # Define __va_list__ (something harmless and unused) instead of va_list.
923 # Don't claim to have defined va_list.
924 sed -e 's@ va_list @ __gnuc_va_list @' \
925 -e 's@ va_list)@ __gnuc_va_list)@' \
926 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
927 -e 's@ va_list@ __va_list__@' \
928 -e 's@\*va_list@*__va_list__@' \
929 -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
930 -e 's@VA_LIST@DUMMY_VA_LIST@' \
931 -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
932 ${LIB}/$file >> ${LIB}/${file}.sed
934 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
935 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
940 # Cancel out ansi_compat.h on Ultrix. Replace it with empty file.
942 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
943 if grep -s ULTRIX $file; then
944 echo "/* This file intentionally left blank. */" > $LIB/$file
948 # parameter to atof not const on DECstation Ultrix V4.0.
949 # also get rid of bogus inline definitions in HP-UX 8.0
951 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
952 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
953 chmod +w ${LIB}/$file 2>/dev/null
954 chmod a+r ${LIB}/$file 2>/dev/null
957 if [ -r ${LIB}/$file ]; then
958 echo Fixing $file, non-const arg
959 sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
960 -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
961 -e 's@inline double abs(double d) { return fabs(d); }@@' \
962 ${LIB}/$file > ${LIB}/${file}.sed
963 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
964 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
969 # In limits.h, put #ifndefs around things that are supposed to be defined
970 # in float.h to avoid redefinition errors if float.h is included first.
971 # On HP/UX this patch does not work, because on HP/UX limits.h uses
972 # multi line comments and the inserted #endif winds up inside the
973 # comment. Fortunately, HP/UX already uses #ifndefs in limits.h; if
974 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
975 # are there, and we do not add them ourselves.
977 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
978 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
979 chmod +w ${LIB}/$file 2>/dev/null
980 chmod a+r ${LIB}/$file 2>/dev/null
983 if [ -r ${LIB}/$file ]; then
984 if egrep 'ifndef[ ]+FLT_MIN' ${LIB}/$file >/dev/null; then
988 sed -e '/[ ]FLT_MIN[ ]/i\
990 -e '/[ ]FLT_MIN[ ]/a\
992 -e '/[ ]FLT_MAX[ ]/i\
994 -e '/[ ]FLT_MAX[ ]/a\
996 -e '/[ ]FLT_DIG[ ]/i\
998 -e '/[ ]FLT_DIG[ ]/a\
1000 -e '/[ ]DBL_MIN[ ]/i\
1002 -e '/[ ]DBL_MIN[ ]/a\
1004 -e '/[ ]DBL_MAX[ ]/i\
1006 -e '/[ ]DBL_MAX[ ]/a\
1008 -e '/[ ]DBL_DIG[ ]/i\
1010 -e '/[ ]DBL_DIG[ ]/a\
1012 ${LIB}/$file > ${LIB}/${file}.sed
1013 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1015 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1016 echo Deleting ${LIB}/$file\; no fixes were needed.
1021 # These two files on SunOS 4 are included by other files
1022 # in the same directory, using "...". So we must make sure they exist
1023 # in the same directory as the other fixed files.
1024 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1026 ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1028 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1030 ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1033 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1034 # need to fix some additional files. This is the same test for ISC that
1036 if test -d /etc/conf/kconfig.d \
1037 && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1038 echo "Fixing ISC __STDC__ goof in several files..."
1039 for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1041 if test -r ${LIB}/$name; then
1046 # On Interactive 2.2, certain traditional Unix definitions
1047 # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1048 # defined, not just if _POSIX_SOURCE is defined. This makes it
1049 # impossible to compile any nontrivial program except with -posix.
1051 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1052 < $file > ${LIB}/$name.
1053 mv ${LIB}/$name. ${LIB}/$name
1056 echo "Fixing ISC fmod declaration"
1057 # This one's already been fixed for other things.
1059 sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1062 echo "Fixing nested comments in ISC <sys/limits.h>"
1064 sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1065 sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1068 echo 'Removing unneeded directories:'
1070 files=`find . -type d -print | sort -r`
1071 for file in $files; do
1072 rmdir $LIB/$file > /dev/null 2>&1
1076 echo 'Making internal symbolic non-directory links'
1078 files=`find . -type l -print`
1079 for file in $files; do
1080 dest=`ls -ld $file | sed -n 's/.*-> //p'`
1081 if expr "$dest" : '[^/].*' > /dev/null; then
1082 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1083 if [ -f $target ]; then
1084 ln -s $dest ${LIB}/$file >/dev/null 2>&1
1090 echo 'Cleaning up DONE files.'
1092 find . -name DONE -exec rm -f {} ';'