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.
9 GCCCMD=${4-${GCCCMD-gcc}}
11 # Directory where gcc sources (and sometimes special include files) live.
12 # fixincludes doesn't use this, but fixinc.svr4 does, and I want to make
13 # sure somebody doesn't try to use arg3 for something incompatible. -- gumby
14 SRCDIR=${3-${SRCDIR-.}}
16 # Directory containing the original header files.
17 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
18 INPUT=${2-${INPUT-/usr/include}}
20 # Directory in which to store the results.
21 LIB=${1?"fixincludes: output directory not specified"}
23 # Define PWDCMD as a command to use to get the working dir
24 # in the form that we want.
28 # On an Apollo, discard everything before `/usr'.
29 PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
36 # Make sure it exists.
37 if [ ! -d $LIB ]; then
41 # Make LIB absolute only if needed to avoid problems with the amd.
46 cd $LIB; LIB=`${PWDCMD}`
50 # Make SRCDIR absolute only if needed to avoid problems with the amd.
56 cd $SRCDIR; SRCDIR=`${PWDCMD}`
60 # Fail if no arg to specify a directory for the output.
62 then echo fixincludes: no output directory specified
66 echo Building fixed headers in ${LIB}
68 # Determine whether this system has symbolic links.
69 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
70 rm -f $LIB/ShouldNotExist
72 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
73 rm -f /tmp/ShouldNotExist
79 echo Finding directories and links to directories
81 # Find all directories and all symlinks that point to directories.
82 # Put the list in $files.
83 # Each time we find a symlink, add it to newdirs
84 # so that we do another find within the dir the link points to.
85 # Note that $files may have duplicates in it;
86 # later parts of this file are supposed to ignore them.
89 while [ -n "$dirs" ] && [ $levels -gt 0 ]
91 levels=`expr $levels - 1`
95 echo " Searching $INPUT/$d"
101 # Find all directories under $d, relative to $d, excluding $d itself.
102 files="$files `find $d -type d -print | \
103 sed -e '/\/\.$/d' -e '/^\.$/d'`"
104 # Find all links to directories.
105 # Using `-exec test -d' in find fails on some systems,
106 # and trying to run test via sh fails on others,
107 # so this is the simplest alternative left.
108 # First find all the links, then test each one.
111 theselinks=`find $d -type l -print`
112 for d1 in $theselinks --dummy--
114 # If the link points to a directory,
115 # add that dir to $newdirs
118 newdirs="$newdirs $d1"
123 files="$files $newdirs"
128 echo "All directories (including links to directories):"
131 for file in $files; do
133 if [ ! -d $LIB/$file ]
134 then mkdir $LIB/$file
139 # treetops gets an alternating list
140 # of old directories to copy
141 # and the new directories to copy to.
142 treetops="${INPUT} ${LIB}"
145 echo 'Making symbolic directory links'
146 for file in $files; do
147 dest=`ls -ld $file | sed -n 's/.*-> //p'`
150 # In case $dest is relative, get to $file's dir first.
152 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
153 # Check that the target directory exists.
154 # Redirections changed to avoid bug in sh on Ultrix.
155 (cd $dest) > /dev/null 2>&1
158 # X gets the dir that the link actually leads to.
160 # If a link points to ., make a similar link to .
161 if [ $x = $INPUT ]; then
162 echo $file '->' . ': Making link'
163 rm -fr ${LIB}/$file > /dev/null 2>&1
164 ln -s . ${LIB}/$file > /dev/null 2>&1
165 # If link leads back into ${INPUT},
166 # make a similar link here.
167 elif expr $x : "${INPUT}/.*" > /dev/null; then
168 # Y gets the actual target dir name, relative to ${INPUT}.
169 y=`echo $x | sed -n "s&${INPUT}/&&p"`
170 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
172 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
173 echo $file '->' $dots$y ': Making link'
174 rm -fr ${LIB}/$file > /dev/null 2>&1
175 ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
177 # If the link is to a dir $target outside ${INPUT},
178 # repoint the link at ${INPUT}/root$target
179 # and process $target into ${INPUT}/root$target
180 # treat this directory as if it actually contained the files.
181 echo $file '->' root$x ': Making link'
182 if [ -d $LIB/root$x ]
188 while [ x$dirname != x ]; do
189 component=`echo $dirname | sed -e 's|/.*$||'`
190 mkdir $component >/dev/null 2>&1
192 dirmade=$dirmade/$component
193 dirname=`echo $dirname | sed -e 's|[^/]*/||'`
196 # Duplicate directory structure created in ${LIB}/$file in new
198 for file2 in $files; do
201 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
202 echo "Duplicating ${file}'s ${dupdir}"
213 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
215 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
216 rm -fr ${LIB}/$file > /dev/null 2>&1
217 ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
218 treetops="$treetops $x ${LIB}/root$x"
228 while [ $# != 0 ]; do
229 # $1 is an old directory to copy, and $2 is the new directory to copy to.
232 # The same dir can appear more than once in treetops.
233 # There's no need to scan it more than once.
239 echo Fixing directory $1 into $2
240 # Check .h files which are symlinks as well as those which are files.
241 # A link to a header file will not be processed by anything but this.
243 files=`find . -name '*.h' \( -type f -o -type l \) -print`
245 files=`find . -name '*.h' -type f -print`
247 echo Checking header files
249 # Note that BSD43_* are used on recent MIPS systems.
250 for file in $files; do
251 # This call to egrep is essential, since checking a file with egrep
252 # is much faster than actually trying to fix it.
253 # It is also essential that most files *not* match!
254 # Thus, matching every #endif is unacceptable.
255 # But the argument to egrep must be kept small, or many versions of egrep
256 # won't be able to handle it.
258 # We use the pattern [!-.0-~] instead of [^/ ] to match a noncomment
259 # following #else or #endif because some buggy egreps think [^/] matches
260 # newline, and they thus think `#else ' matches `#e[ndiflse]*[ ]+[^/ ]'.
262 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
263 # following #if or #elif that is not surrounded by __. The `a-ce-km-z'
264 # in this pattern lacks `d' and `l'; this means we don't worry about
265 # identifiers starting with `d' or `l'. This is OK, since none of the
266 # identifiers below start with `d' or `l'. It also greatly improves
267 # performance, since many files contain lines of the form `#if ... defined ...'
269 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
270 if [ -r $file ]; then
271 cp $file $2/$file >/dev/null 2>&1 \
272 || echo "Can't copy $file"
275 # Here is how the sed commands in braces work.
276 # (It doesn't work to put the comments inside the sed commands.)
277 # Surround each word with spaces, to simplify matching below.
278 # ANSIfy each pre-ANSI machine-dependent symbol
279 # by surrounding it with __ __.
280 # Remove the spaces that we inserted around each word.
285 s%^\([ ]*#[ ]*else\)[ ]*/[^*].*%\1%
286 s%^\([ ]*#[ ]*else\)[ ]*[^/ ].*%\1%
287 s%^\([ ]*#[ ]*endif\)[ ]*/[^*].*%\1%
288 s%^\([ ]*#[ ]*endif\)[ ]*\*[^/].*%\1%
289 s%^\([ ]*#[ ]*endif\)[ ]*[^/* ].*%\1%
290 /\/\/[^*]/ s|//\(.*\)$|/*\1*/|
291 /[ ]_IO[A-Z]*[ ]*(/ s/\(_IO[A-Z]*[ ]*(\)\(.\),/\1'\''\2'\'',/
292 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
293 /#define._IO/ s/'\''\([cgx]\)'\''/\1/g
294 /#define.BSD43__IO/ s/'\''\([cgx]\)'\''/\1/g
295 /[^A-Z0-9_]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
296 /[^A-Z0-9]_CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
297 /#define[ ]*[ ]CTRL/ s/'\''\([cgx]\)'\''/\1/g
298 /#define[ ]*[ ]_CTRL/ s/'\''\([cgx]\)'\''/\1/g
299 /#define.BSD43_CTRL/ s/'\''\([cgx]\)'\''/\1/g
301 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
303 s/ bsd4\([0-9]\) / __bsd4\1__ /g
304 s/ _*i386 / __i386__ /g
305 s/ is68k / __is68k__ /g
306 s/ m68k / __m68k__ /g
307 s/ mc680\([0-9]\)0 / __mc680\10__ /g
308 s/ news\([0-9]*\) / __news\1__ /g
309 s/ ns32000 / __ns32000__ /g
311 s/ sony_news / __sony_news__ /g
312 s/ sparc / __sparc__ /g
313 s/ sun\([a-z0-9]*\) / __sun\1__ /g
314 s/ unix / __unix__ /g
317 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
319 /^#define.NULL[ ]/ i\
321 ' $2/$file > $2/$file.
322 mv $2/$file. $2/$file
323 if cmp $file $2/$file >/dev/null 2>&1; then
336 # Install the proper definition of size_t in header files that it comes from.
337 for file in sys/types.h stdlib.h sys/stdtypes.h; do
338 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
339 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
340 chmod +w ${LIB}/$file 2>/dev/null
341 chmod a+r ${LIB}/$file 2>/dev/null
344 if [ -r ${LIB}/$file ]; then
345 echo Fixing $file comment
346 # Get the definition of __SIZE_TYPE__, if any.
347 # (This file must be called something.c).
348 echo "__SIZE_TYPE__" > ${LIB}/types.c
349 foo=`${GCCCMD} -E -P ${LIB}/types.c`
351 # Default to our preferred type.
352 if [ "$foo" = __SIZE_TYPE__ ]; then foo="unsigned long int"; fi
353 sed -e "s/typedef[ a-z_]*[ ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
354 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
355 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
361 # Fix one other error in this file: a mismatched quote not inside a C comment.
362 file=sundev/vuid_event.h
363 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
364 mkdir ${LIB}/sundev 2>/dev/null
365 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
366 chmod +w ${LIB}/$file 2>/dev/null
367 chmod a+r ${LIB}/$file 2>/dev/null
370 if [ -r ${LIB}/$file ]; then
371 echo Fixing $file comment
372 sed -e "s/doesn't/does not/" ${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
379 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
380 file=sunwindow/win_cursor.h
381 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
382 # mkdir ${LIB}/sunwindow 2>/dev/null
383 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
384 chmod +w ${LIB}/$file 2>/dev/null
386 if [ -r ${LIB}/$file ]; then
388 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
389 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
390 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
394 file=sunwindow/win_lock.h
395 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
396 # mkdir ${LIB}/sunwindow 2>/dev/null
397 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
398 chmod +w ${LIB}/$file 2>/dev/null
400 if [ -r ${LIB}/$file ]; then
402 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
403 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
404 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
409 # Fix this Sun file to avoid interfering with stddef.h.
411 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
412 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
413 chmod +w ${LIB}/$file 2>/dev/null
414 chmod a+r ${LIB}/$file 2>/dev/null
417 if [ -r ${LIB}/$file ]; then
419 sed -e '/[ ]size_t.*;/i\
421 #define _GCC_SIZE_T' \
424 -e '/[ ]ptrdiff_t.*;/i\
425 #ifndef _GCC_PTRDIFF_T\
426 #define _GCC_PTRDIFF_T' \
427 -e '/[ ]ptrdiff_t.*;/a\
429 -e '/[ ]wchar_t.*;/i\
430 #ifndef _GCC_WCHAR_T\
431 #define _GCC_WCHAR_T' \
432 -e '/[ ]wchar_t.*;/a\
433 #endif' ${LIB}/$file > ${LIB}/${file}.sed
434 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
435 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
440 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
441 # match e.g. ssize_t present in AIX for the ps/2.
443 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
444 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
445 chmod +w ${LIB}/$file 2>/dev/null
446 chmod a+r ${LIB}/$file 2>/dev/null
449 if [ -r ${LIB}/$file ]; then
451 sed -e '/[ ]size_t.*;/i\
453 #define _GCC_SIZE_T' \
455 #endif' ${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: the #if says _cplusplus, not the double
463 # underscore __cplusplus that it should be
465 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
466 mkdir ${LIB}/rpcsvc 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, __cplusplus macro
474 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${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 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
482 # structure definition.
484 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
485 mkdir ${LIB}/rpcsvc 2>/dev/null
486 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
487 chmod +w ${LIB}/$file 2>/dev/null
488 chmod a+r ${LIB}/$file 2>/dev/null
491 if [ -r ${LIB}/$file ]; then
492 echo Fixing $file, definition of statsswtch
493 sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
494 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
495 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
500 # Fix an error in this file: a missing semi-colon at the end of the nodeent
501 # structure definition.
502 file=netdnet/dnetdb.h
503 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
504 mkdir ${LIB}/netdnet 2>/dev/null
505 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
506 chmod +w ${LIB}/$file 2>/dev/null
507 chmod a+r ${LIB}/$file 2>/dev/null
510 if [ -r ${LIB}/$file ]; then
511 echo Fixing $file, definition of nodeent
512 sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
513 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
514 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
519 # Check for bad #ifdef line (in Ultrix 4.1)
521 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
522 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
523 chmod +w ${LIB}/$file 2>/dev/null
524 chmod a+r ${LIB}/$file 2>/dev/null
527 if [ -r ${LIB}/$file ]; then
528 echo Fixing $file, bad \#ifdef line
529 sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
530 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
531 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
536 # Check for superfluous `static' (in Ultrix 4.2)
538 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
539 mkdir ${LIB}/machine 2>/dev/null
540 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
541 chmod +w ${LIB}/$file 2>/dev/null
542 chmod a+r ${LIB}/$file 2>/dev/null
545 if [ -r ${LIB}/$file ]; then
546 echo Fixing $file, superfluous static
547 sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
548 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
549 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
552 # This file has an alternative name, mips/cpu.h. Fix that name, too.
553 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
554 mkdir ${LIB}/mips 2>&-
555 ln ${LIB}/$file ${LIB}/mips/cpu.h
560 # Incorrect sprintf declaration in X11/Xmu.h
562 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
563 mkdir ${LIB}/X11 2>/dev/null
564 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
565 chmod +w ${LIB}/$file 2>/dev/null
566 chmod a+r ${LIB}/$file 2>/dev/null
569 if [ -r ${LIB}/$file ]; then
570 echo Fixing $file sprintf declaration
571 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
572 extern char * sprintf();\
573 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
574 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
575 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
580 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
581 # (It's not clear whether the right file name is this or X11/Xmu.h.)
583 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
584 mkdir ${LIB}/X11/Xmu 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
591 echo Fixing $file sprintf declaration
592 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
593 extern char * sprintf();\
594 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
595 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
596 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
601 # Check for missing ';' in struct
603 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
604 mkdir ${LIB}/netinet 2>/dev/null
605 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
606 chmod +w ${LIB}/$file 2>/dev/null
607 chmod a+r ${LIB}/$file 2>/dev/null
610 if [ -r ${LIB}/$file ]; then
612 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
613 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
614 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
619 # Fix the CAT macro in SunOS memvar.h.
620 file=pixrect/memvar.h
621 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
622 mkdir ${LIB}/pixrect 2>/dev/null
623 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
624 chmod +w ${LIB}/$file 2>/dev/null
625 chmod a+r ${LIB}/$file 2>/dev/null
628 if [ -r ${LIB}/$file ]; then
630 sed -e '/^#define.CAT(a,b)/ i\
632 #define CAT(a,b) a##b\
634 /^#define.CAT(a,b)/ a\
636 ' ${LIB}/$file > ${LIB}/${file}.sed
637 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
638 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
643 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
645 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
646 mkdir ${LIB}/rpcsvc 2>/dev/null
647 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
648 chmod +w ${LIB}/$file 2>/dev/null
649 chmod a+r ${LIB}/$file 2>/dev/null
652 if [ -r ${LIB}/$file ]; then
654 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
655 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
656 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
661 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
662 # Also wrap protection around size_t for m88k-sysv3 systems.
664 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
665 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
666 chmod +w ${LIB}/$file 2>/dev/null
667 chmod a+r ${LIB}/$file 2>/dev/null
670 if [ -r ${LIB}/$file ]; then
672 sed -e 's/int abort/void abort/g' \
673 -e 's/int free/void free/g' \
674 -e 's/char \* calloc/void \* calloc/g' \
675 -e 's/char \* malloc/void \* malloc/g' \
676 -e 's/char \* realloc/void \* realloc/g' \
677 -e 's/int exit/void exit/g' \
678 -e '/typedef[ a-zA-Z_]*[ ]size_t[ ]*;/i\
680 #define _GCC_SIZE_T' \
681 -e '/typedef[ a-zA-Z_]*[ ]size_t[ ]*;/a\
683 ${LIB}/$file > ${LIB}/${file}.sed
684 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
685 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
690 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
692 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
693 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
694 chmod +w ${LIB}/$file 2>/dev/null
695 chmod a+r ${LIB}/$file 2>/dev/null
698 if [ -r ${LIB}/$file ]; then
700 sed -e 's/typedef[ ]char \* malloc_t/typedef void \* malloc_t/g' \
701 -e 's/int[ ][ ]*free/void free/g' \
702 ${LIB}/$file > ${LIB}/${file}.sed
703 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
704 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
709 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
710 file=hsfs/hsfs_spec.h
711 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
712 mkdir ${LIB}/hsfs 2>/dev/null
713 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
714 chmod +w ${LIB}/$file 2>/dev/null
715 chmod a+r ${LIB}/$file 2>/dev/null
718 if [ -r ${LIB}/$file ]; then
720 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
721 ${LIB}/$file > ${LIB}/${file}.
722 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
723 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
728 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
730 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
731 mkdir ${LIB}/hsfs 2>/dev/null
732 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
733 chmod +w ${LIB}/$file 2>/dev/null
734 chmod a+r ${LIB}/$file 2>/dev/null
737 if [ -r ${LIB}/$file ]; then
739 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
740 ${LIB}/$file > ${LIB}/${file}.sed
741 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
742 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
747 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
749 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
750 mkdir ${LIB}/hsfs 2>/dev/null
751 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
752 chmod +w ${LIB}/$file 2>/dev/null
753 chmod a+r ${LIB}/$file 2>/dev/null
756 if [ -r ${LIB}/$file ]; then
758 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
759 ${LIB}/$file > ${LIB}/${file}.sed
760 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
761 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
766 # Incorrect #include in Sony News-OS 3.2.
767 file=machine/machparam.h
768 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
769 mkdir ${LIB}/machine 2>/dev/null
770 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
771 chmod +w ${LIB}/$file 2>/dev/null
772 chmod a+r ${LIB}/$file 2>/dev/null
775 if [ -r ${LIB}/$file ]; then
776 echo Fixing $file, incorrect \#include
777 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
778 ${LIB}/$file > ${LIB}/${file}.
779 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
780 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
785 # Multiline comment after typedef on IRIX 4.0.1.
787 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
788 mkdir ${LIB}/sys 2>/dev/null
789 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
790 chmod +w ${LIB}/$file 2>/dev/null
791 chmod a+r ${LIB}/$file 2>/dev/null
794 if [ -r ${LIB}/$file ]; then
795 echo Fixing $file, comment in the middle of \#ifdef
796 sed -e 's@type of the result@type of the result */@' \
797 -e 's@of the sizeof@/* of the sizeof@' \
798 ${LIB}/$file > ${LIB}/${file}.sed
799 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
800 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
805 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
806 # header file, which embeds // comments inside multi-line /* */
807 # comments. If this looks like the IRIX header file, we refix it by
808 # just throwing away the // comments.
810 if [ -r ${LIB}/$file ]; then
811 if egrep indigo.esd ${LIB}/$file > /dev/null; then
812 echo Fixing $file, overeager sed script
814 sed -e 's|//.*$||g' $file > ${LIB}/$file
815 chmod +w ${LIB}/$file 2>/dev/null
816 chmod a+r ${LIB}/$file 2>/dev/null
820 # Another IRIX 4.0.1 header file contains the string "//"
822 if [ -r ${LIB}/$file ]; then
823 echo Fixing $file, overeager sed script
824 sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
825 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
826 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
831 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
832 # declaration on Sun OS 4.x. We must only fix this on Sun OS 4.x, because
833 # many other systems have similar text but correct versions of the file.
834 # To ensure only Sun's is fixed, we grep for a likely unique string.
836 if [ -r $file ] && egrep '/\* @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2 \*/' $file > /dev/null; then
837 if [ ! -r ${LIB}/$file ]; then
838 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
839 chmod +w ${LIB}/$file 2>/dev/null
840 chmod a+r ${LIB}/$file 2>/dev/null
842 if [ -r ${LIB}/$file ]; then
844 cat > ${LIB}/$file << EOF
845 /* This file was generated by fixincludes */
850 extern void *memccpy();
851 extern void *memchr();
852 extern void *memcpy();
853 extern void *memset();
855 extern char *memccpy();
856 extern char *memchr();
857 extern char *memcpy();
858 extern char *memset();
859 #endif /* __STDC__ */
863 #endif /* __memory_h__ */
868 # parameters not const on DECstation Ultrix V4.0.
870 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
871 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
872 chmod +w ${LIB}/$file 2>/dev/null
873 chmod a+r ${LIB}/$file 2>/dev/null
876 if [ -r ${LIB}/$file ]; then
877 echo Fixing $file, non-const arg
878 sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
879 -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
880 -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
881 -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
882 -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
883 -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
884 -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
885 ${LIB}/$file > ${LIB}/${file}.sed
886 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
887 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
892 # parameters conflict with C++ new on rs/6000
893 for file in stdio.h unistd.h ; do
894 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
895 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
896 chmod +w ${LIB}/$file 2>/dev/null
899 if [ -r ${LIB}/$file ]; then
900 echo Fixing $file, parameter name conflicts
901 sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
902 ${LIB}/$file > ${LIB}/${file}.sed
903 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
904 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
910 # function class(double x) conflicts with C++ keyword on rs/6000
912 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
913 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
914 chmod +w ${LIB}/$file 2>/dev/null
915 chmod a+r ${LIB}/$file 2>/dev/null
918 if [ -r ${LIB}/$file ]; then
919 if grep 'class[(]' ${LIB}/$file >/dev/null; then
922 #ifndef __cplusplus' \
924 #endif' ${LIB}/$file > ${LIB}/${file}.sed
925 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
926 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
932 # NeXT defines 'int wait(union wait*)', which conflicts with Posix.1.
934 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
935 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
936 chmod +w ${LIB}/$file 2>/dev/null
939 if [ -r ${LIB}/$file ] \
940 && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
941 echo Fixing $file, bad wait formal
942 sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
943 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
944 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
949 # Don't use or define the name va_list in stdio.h.
950 # This is for ANSI and also to interoperate properly with gvarargs.h.
952 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
953 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
954 chmod +w ${LIB}/$file 2>/dev/null
955 chmod a+r ${LIB}/$file 2>/dev/null
958 if [ -r ${LIB}/$file ]; then
959 echo Fixing $file, use of va_list
960 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
961 (echo "#define __need___va_list"
962 echo "#include <stdarg.h>") > ${LIB}/${file}.sed
963 # Use __gnuc_va_list in arg types in place of va_list.
964 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
965 # trailing parentheses and semicolon save all other systems from this.
966 # Define __va_list__ (something harmless and unused) instead of va_list.
967 # Don't claim to have defined va_list.
968 sed -e 's@ va_list @ __gnuc_va_list @' \
969 -e 's@ va_list)@ __gnuc_va_list)@' \
970 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
971 -e 's@ va_list@ __va_list__@' \
972 -e 's@\*va_list@*__va_list__@' \
973 -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
974 -e 's@VA_LIST@DUMMY_VA_LIST@' \
975 -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
976 ${LIB}/$file >> ${LIB}/${file}.sed
978 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
979 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
984 # Cancel out ansi_compat.h on Ultrix. Replace it with empty file.
986 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
987 if grep -s ULTRIX $file; then
988 echo "/* This file intentionally left blank. */" > $LIB/$file
992 # parameter to atof not const on DECstation Ultrix V4.0.
993 # also get rid of bogus inline definitions in HP-UX 8.0
995 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
996 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
997 chmod +w ${LIB}/$file 2>/dev/null
998 chmod a+r ${LIB}/$file 2>/dev/null
1001 if [ -r ${LIB}/$file ]; then
1002 echo Fixing $file, non-const arg
1003 sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
1004 -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
1005 -e 's@inline double abs(double d) { return fabs(d); }@@' \
1006 ${LIB}/$file > ${LIB}/${file}.sed
1007 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1008 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1013 # In limits.h, put #ifndefs around things that are supposed to be defined
1014 # in float.h to avoid redefinition errors if float.h is included first.
1015 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1016 # multi line comments and the inserted #endif winds up inside the
1017 # comment. Fortunately, HP/UX already uses #ifndefs in limits.h; if
1018 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1019 # are there, and we do not add them ourselves.
1021 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1022 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1023 chmod +w ${LIB}/$file 2>/dev/null
1024 chmod a+r ${LIB}/$file 2>/dev/null
1027 if [ -r ${LIB}/$file ]; then
1028 if egrep 'ifndef[ ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1032 sed -e '/[ ]FLT_MIN[ ]/i\
1034 -e '/[ ]FLT_MIN[ ]/a\
1036 -e '/[ ]FLT_MAX[ ]/i\
1038 -e '/[ ]FLT_MAX[ ]/a\
1040 -e '/[ ]FLT_DIG[ ]/i\
1042 -e '/[ ]FLT_DIG[ ]/a\
1044 -e '/[ ]DBL_MIN[ ]/i\
1046 -e '/[ ]DBL_MIN[ ]/a\
1048 -e '/[ ]DBL_MAX[ ]/i\
1050 -e '/[ ]DBL_MAX[ ]/a\
1052 -e '/[ ]DBL_DIG[ ]/i\
1054 -e '/[ ]DBL_DIG[ ]/a\
1056 ${LIB}/$file > ${LIB}/${file}.sed
1057 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1059 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1060 echo Deleting ${LIB}/$file\; no fixes were needed.
1065 # These two files on SunOS 4 are included by other files
1066 # in the same directory, using "...". So we must make sure they exist
1067 # in the same directory as the other fixed files.
1068 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1070 ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1072 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1074 ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1077 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1078 # need to fix some additional files. This is the same test for ISC that
1080 if test -d /etc/conf/kconfig.d \
1081 && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1082 echo "Fixing ISC __STDC__ goof in several files..."
1083 for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1085 if test -r ${LIB}/$name; then
1090 # On Interactive 2.2, certain traditional Unix definitions
1091 # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1092 # defined, not just if _POSIX_SOURCE is defined. This makes it
1093 # impossible to compile any nontrivial program except with -posix.
1095 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1096 < $file > ${LIB}/$name.
1097 mv ${LIB}/$name. ${LIB}/$name
1100 echo "Fixing ISC fmod declaration"
1101 # This one's already been fixed for other things.
1103 sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1106 echo "Fixing nested comments in ISC <sys/limits.h>"
1108 sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1109 sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1112 echo 'Removing unneeded directories:'
1114 files=`find . -type d -print | sort -r`
1115 for file in $files; do
1116 rmdir $LIB/$file > /dev/null 2>&1
1120 echo 'Making internal symbolic non-directory links'
1122 files=`find . -type l -print`
1123 for file in $files; do
1124 dest=`ls -ld $file | sed -n 's/.*-> //p'`
1125 if expr "$dest" : '[^/].*' > /dev/null; then
1126 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1127 if [ -f $target ]; then
1128 ln -s $dest ${LIB}/$file >/dev/null 2>&1
1134 echo 'Cleaning up DONE files.'
1136 find . -name DONE -exec rm -f {} ';'