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 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
166 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
167 echo $file '->' $dots$y ': Making link'
168 rm -fr ${LIB}/$file > /dev/null 2>&1
169 ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
171 # If the link is to a dir $target outside ${INPUT},
172 # repoint the link at ${INPUT}/root$target
173 # and process $target into ${INPUT}/root$target
174 # treat this directory as if it actually contained the files.
175 echo $file '->' root$x ': Making link'
176 if [ -d $LIB/root$x ]
182 while [ x$dirname != x ]; do
183 component=`echo $dirname | sed -e 's|/.*$||'`
184 mkdir $component >/dev/null 2>&1
186 dirmade=$dirmade/$component
187 dirname=`echo $dirname | sed -e 's|[^/]*/||'`
190 # Duplicate directory structure created in ${LIB}/$file in new
192 for file2 in $files; do
195 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
196 echo "Duplicating ${file}'s ${dupdir}"
207 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
209 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
210 rm -fr ${LIB}/$file > /dev/null 2>&1
211 ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
212 treetops="$treetops $x ${LIB}/root$x"
222 while [ $# != 0 ]; do
223 # $1 is an old directory to copy, and $2 is the new directory to copy to.
226 # The same dir can appear more than once in treetops.
227 # There's no need to scan it more than once.
233 echo Fixing directory $1 into $2
234 # Check .h files which are symlinks as well as those which are files.
235 # A link to a header file will not be processed by anything but this.
237 files=`find . -name '*.h' \( -type f -o -type l \) -print`
239 files=`find . -name '*.h' -type f -print`
241 echo Checking header files
243 # Note that BSD43_* are used on recent MIPS systems.
244 for file in $files; do
245 # This call to egrep is essential, since checking a file with egrep
246 # is much faster than actually trying to fix it.
247 # It is also essential that most files *not* match!
248 # Thus, matching every #endif is unacceptable.
249 # But the argument to egrep must be kept small, or many versions of egrep
250 # won't be able to handle it.
252 # We use the pattern [!-.0-~] instead of [^/ ] to match a noncomment
253 # following #else or #endif because some buggy egreps think [^/] matches
254 # newline, and they thus think `#else ' matches `#e[ndiflse]*[ ]+[^/ ]'.
256 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
257 # following #if or #elif that is not surrounded by __. The `a-ce-km-z'
258 # in this pattern lacks `d' and `l'; this means we don't worry about
259 # identifiers starting with `d' or `l'. This is OK, since none of the
260 # identifiers below start with `d' or `l'. It also greatly improves
261 # performance, since many files contain lines of the form `#if ... defined ...'
263 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
264 if [ -r $file ]; then
265 cp $file $2/$file >/dev/null 2>&1 \
266 || echo "Can't copy $file"
269 # Here is how the sed commands in braces work.
270 # (It doesn't work to put the comments inside the sed commands.)
271 # Surround each word with spaces, to simplify matching below.
272 # ANSIfy each pre-ANSI machine-dependent symbol
273 # by surrounding it with __ __.
274 # Remove the spaces that we inserted around each word.
279 s%^\([ ]*#[ ]*else\)[ ]*/[^*].*%\1%
280 s%^\([ ]*#[ ]*else\)[ ]*[^/ ].*%\1%
281 s%^\([ ]*#[ ]*endif\)[ ]*/[^*].*%\1%
282 s%^\([ ]*#[ ]*endif\)[ ]*[^/ ].*%\1%
283 /\/\/[^*]/ s|//\(.*\)$|/*\1*/|
284 /[ ]_IO[A-Z]*[ ]*(/ s/\(_IO[A-Z]*[ ]*(\)\(.\),/\1'\''\2'\'',/
285 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
286 /#define._IO/ s/'\''\([cgx]\)'\''/\1/g
287 /#define.BSD43__IO/ s/'\''\([cgx]\)'\''/\1/g
288 /[^A-Z0-9_]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
289 /[^A-Z0-9]_CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
290 /#define.CTRL/ s/'\''\([cgx]\)'\''/\1/g
291 /#define._CTRL/ s/'\''\([cgx]\)'\''/\1/g
292 /#define.BSD43_CTRL/ s/'\''\([cgx]\)'\''/\1/g
294 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
296 s/ bsd4\([0-9]\) / __bsd4\1__ /g
297 s/ _*i386 / __i386__ /g
298 s/ is68k / __is68k__ /g
299 s/ m68k / __m68k__ /g
300 s/ mc680\([0-9]\)0 / __mc680\10__ /g
301 s/ news\([0-9]*\) / __news\1__ /g
302 s/ ns32000 / __ns32000__ /g
304 s/ sony_news / __sony_news__ /g
305 s/ sparc / __sparc__ /g
306 s/ sun\([a-z0-9]*\) / __sun\1__ /g
307 s/ unix / __unix__ /g
310 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
312 /^#define.NULL[ ]/ i\
314 ' $2/$file > $2/$file.
315 mv $2/$file. $2/$file
316 if cmp $file $2/$file >/dev/null 2>&1; then
329 # Install the proper definition of size_t in header files that it comes from.
330 for file in sys/types.h sys/stdtypes.h;
332 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
333 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
334 chmod +w ${LIB}/$file 2>/dev/null
335 chmod a+r ${LIB}/$file 2>/dev/null
338 if [ -r ${LIB}/$file ]; then
339 echo Fixing $file comment
340 # Extract the definition of SIZE_TYPE, if any.
341 # (This file must be called something.c).
342 echo "#include \"tm.h\"
343 gobblegobble SIZE_TYPE" > ${LIB}/types.c
344 foo=`cd ${LIB}; cc -E -I${ORIGDIR} -I${SRCDIR} -I${SRCDIR}/config types.c | grep gobblegobble | sed -e "s/gobblegobble[ ]*//"`
346 # Default to our preferred type.
347 if [ "$foo" = SIZE_TYPE ]; then foo="unsigned long int"; else foo=`echo $foo | sed -e 's/^.*"\(.*\)".*$/\1/'`; fi
348 sed -e "s/typedef[ a-z_]*[ ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
349 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
350 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
356 # Fix one other error in this file: a mismatched quote not inside a C comment.
357 file=sundev/vuid_event.h
358 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
359 mkdir ${LIB}/sundev 2>/dev/null
360 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
361 chmod +w ${LIB}/$file 2>/dev/null
362 chmod a+r ${LIB}/$file 2>/dev/null
365 if [ -r ${LIB}/$file ]; then
366 echo Fixing $file comment
367 sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
368 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
369 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
374 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
375 file=sunwindow/win_cursor.h
376 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
377 # mkdir ${LIB}/sunwindow 2>/dev/null
378 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
379 chmod +w ${LIB}/$file 2>/dev/null
381 if [ -r ${LIB}/$file ]; then
383 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
384 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
385 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
389 file=sunwindow/win_lock.h
390 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
391 # mkdir ${LIB}/sunwindow 2>/dev/null
392 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
393 chmod +w ${LIB}/$file 2>/dev/null
395 if [ -r ${LIB}/$file ]; then
397 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
398 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
399 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
404 # Fix this Sun file to avoid interfering with stddef.h.
406 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
407 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
408 chmod +w ${LIB}/$file 2>/dev/null
409 chmod a+r ${LIB}/$file 2>/dev/null
412 if [ -r ${LIB}/$file ]; then
414 sed -e '/[ ]size_t.*;/i\
416 #define _GCC_SIZE_T' \
419 -e '/[ ]ptrdiff_t.*;/i\
420 #ifndef _GCC_PTRDIFF_T\
421 #define _GCC_PTRDIFF_T' \
422 -e '/[ ]ptrdiff_t.*;/a\
424 -e '/[ ]wchar_t.*;/i\
425 #ifndef _GCC_WCHAR_T\
426 #define _GCC_WCHAR_T' \
427 -e '/[ ]wchar_t.*;/a\
428 #endif' ${LIB}/$file > ${LIB}/${file}.sed
429 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
430 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
435 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
436 # match e.g. ssize_t present in AIX for the ps/2.
438 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
439 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
440 chmod +w ${LIB}/$file 2>/dev/null
441 chmod a+r ${LIB}/$file 2>/dev/null
444 if [ -r ${LIB}/$file ]; then
446 sed -e '/[ ]size_t.*;/i\
448 #define _GCC_SIZE_T' \
450 #endif' ${LIB}/$file > ${LIB}/${file}.sed
451 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
452 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
457 # Fix an error in this file: the #if says _cplusplus, not the double
458 # underscore __cplusplus that it should be
460 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
461 mkdir ${LIB}/rpcsvc 2>/dev/null
462 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
463 chmod +w ${LIB}/$file 2>/dev/null
464 chmod a+r ${LIB}/$file 2>/dev/null
467 if [ -r ${LIB}/$file ]; then
468 echo Fixing $file, __cplusplus macro
469 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
470 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
471 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
476 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
477 # structure definition.
479 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
480 mkdir ${LIB}/rpcsvc 2>/dev/null
481 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
482 chmod +w ${LIB}/$file 2>/dev/null
483 chmod a+r ${LIB}/$file 2>/dev/null
486 if [ -r ${LIB}/$file ]; then
487 echo Fixing $file, definition of statsswtch
488 sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
489 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
490 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
495 # Fix an error in this file: a missing semi-colon at the end of the nodeent
496 # structure definition.
497 file=netdnet/dnetdb.h
498 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
499 mkdir ${LIB}/netdnet 2>/dev/null
500 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
501 chmod +w ${LIB}/$file 2>/dev/null
502 chmod a+r ${LIB}/$file 2>/dev/null
505 if [ -r ${LIB}/$file ]; then
506 echo Fixing $file, definition of nodeent
507 sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
508 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
509 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
514 # Check for bad #ifdef line (in Ultrix 4.1)
516 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
517 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
518 chmod +w ${LIB}/$file 2>/dev/null
519 chmod a+r ${LIB}/$file 2>/dev/null
522 if [ -r ${LIB}/$file ]; then
523 echo Fixing $file, bad \#ifdef line
524 sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
525 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
526 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
531 # Check for superfluous `static' (in Ultrix 4.2)
533 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
534 mkdir ${LIB}/machine 2>/dev/null
535 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
536 chmod +w ${LIB}/$file 2>/dev/null
537 chmod a+r ${LIB}/$file 2>/dev/null
540 if [ -r ${LIB}/$file ]; then
541 echo Fixing $file, superfluous static
542 sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
543 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
544 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
547 # This file has an alternative name, mips/cpu.h. Fix that name, too.
548 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
549 mkdir ${LIB}/mips 2>&-
550 ln ${LIB}/$file ${LIB}/mips/cpu.h
555 # Incorrect sprintf declaration in X11/Xmu.h
557 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
558 mkdir ${LIB}/X11 2>/dev/null
559 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
560 chmod +w ${LIB}/$file 2>/dev/null
561 chmod a+r ${LIB}/$file 2>/dev/null
564 if [ -r ${LIB}/$file ]; then
565 echo Fixing $file sprintf declaration
566 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
567 extern char * sprintf();\
568 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
569 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
570 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
575 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
576 # (It's not clear whether the right file name is this or X11/Xmu.h.)
578 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
579 mkdir ${LIB}/X11/Xmu 2>/dev/null
580 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
581 chmod +w ${LIB}/$file 2>/dev/null
582 chmod a+r ${LIB}/$file 2>/dev/null
585 if [ -r ${LIB}/$file ]; then
586 echo Fixing $file sprintf declaration
587 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
588 extern char * sprintf();\
589 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
590 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
591 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
596 # Check for missing ';' in struct
598 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
599 mkdir ${LIB}/netinet 2>/dev/null
600 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
601 chmod +w ${LIB}/$file 2>/dev/null
602 chmod a+r ${LIB}/$file 2>/dev/null
605 if [ -r ${LIB}/$file ]; then
607 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
608 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
609 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
614 # Fix the CAT macro in SunOS memvar.h.
615 file=pixrect/memvar.h
616 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
617 mkdir ${LIB}/pixrect 2>/dev/null
618 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
619 chmod +w ${LIB}/$file 2>/dev/null
620 chmod a+r ${LIB}/$file 2>/dev/null
623 if [ -r ${LIB}/$file ]; then
625 sed -e '/^#define.CAT(a,b)/ i\
627 #define CAT(a,b) a##b\
629 /^#define.CAT(a,b)/ a\
631 ' ${LIB}/$file > ${LIB}/${file}.sed
632 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
633 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
638 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
640 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
641 mkdir ${LIB}/rpcsvc 2>/dev/null
642 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
643 chmod +w ${LIB}/$file 2>/dev/null
644 chmod a+r ${LIB}/$file 2>/dev/null
647 if [ -r ${LIB}/$file ]; then
649 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
650 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
651 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
656 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
658 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
659 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
660 chmod +w ${LIB}/$file 2>/dev/null
661 chmod a+r ${LIB}/$file 2>/dev/null
664 if [ -r ${LIB}/$file ]; then
666 sed -e 's/int abort/void abort/g' \
667 -e 's/int free/void free/g' \
668 -e 's/char \* calloc/void \* calloc/g' \
669 -e 's/char \* malloc/void \* malloc/g' \
670 -e 's/char \* realloc/void \* realloc/g' \
671 -e 's/int exit/void exit/g' ${LIB}/$file > ${LIB}/${file}.sed
672 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
673 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
678 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
680 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
681 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
682 chmod +w ${LIB}/$file 2>/dev/null
683 chmod a+r ${LIB}/$file 2>/dev/null
686 if [ -r ${LIB}/$file ]; then
688 sed -e 's/typedef[ ]char \* malloc_t/typedef void \* malloc_t/g' \
689 -e 's/int[ ][ ]*free/void free/g' \
690 ${LIB}/$file > ${LIB}/${file}.sed
691 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
692 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
697 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
698 file=hsfs/hsfs_spec.h
699 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
700 mkdir ${LIB}/hsfs 2>/dev/null
701 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
702 chmod +w ${LIB}/$file 2>/dev/null
703 chmod a+r ${LIB}/$file 2>/dev/null
706 if [ -r ${LIB}/$file ]; then
708 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
709 ${LIB}/$file > ${LIB}/${file}.
710 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
711 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
716 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
718 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
719 mkdir ${LIB}/hsfs 2>/dev/null
720 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
721 chmod +w ${LIB}/$file 2>/dev/null
722 chmod a+r ${LIB}/$file 2>/dev/null
725 if [ -r ${LIB}/$file ]; then
727 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
728 ${LIB}/$file > ${LIB}/${file}.sed
729 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
730 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
735 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
737 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
738 mkdir ${LIB}/hsfs 2>/dev/null
739 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
740 chmod +w ${LIB}/$file 2>/dev/null
741 chmod a+r ${LIB}/$file 2>/dev/null
744 if [ -r ${LIB}/$file ]; then
746 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
747 ${LIB}/$file > ${LIB}/${file}.sed
748 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
749 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
754 # Incorrect #include in Sony News-OS 3.2.
755 file=machine/machparam.h
756 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
757 mkdir ${LIB}/machine 2>/dev/null
758 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
759 chmod +w ${LIB}/$file 2>/dev/null
760 chmod a+r ${LIB}/$file 2>/dev/null
763 if [ -r ${LIB}/$file ]; then
764 echo Fixing $file, incorrect \#include
765 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
766 ${LIB}/$file > ${LIB}/${file}.
767 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
768 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
773 # Multiline comment after typedef on IRIX 4.0.1.
775 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
776 mkdir ${LIB}/sys 2>/dev/null
777 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
778 chmod +w ${LIB}/$file 2>/dev/null
779 chmod a+r ${LIB}/$file 2>/dev/null
782 if [ -r ${LIB}/$file ]; then
783 echo Fixing $file, comment in the middle of \#ifdef
784 sed -e 's@type of the result@type of the result */@' \
785 -e 's@of the sizeof@/* of the sizeof@' \
786 ${LIB}/$file > ${LIB}/${file}.sed
787 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
788 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
793 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
794 # header file, which embeds // comments inside multi-line /* */
795 # comments. If this looks like the IRIX header file, we refix it by
796 # just throwing away the // comments.
798 if [ -r ${LIB}/$file ]; then
799 if egrep indigo.esd ${LIB}/$file > /dev/null; then
800 echo Fixing $file, overeager sed script
802 sed -e 's|//.*$||g' $file > ${LIB}/$file
803 chmod +w ${LIB}/$file 2>/dev/null
804 chmod a+r ${LIB}/$file 2>/dev/null
808 # Another IRIX 4.0.1 header file contains the string "//"
810 if [ -r ${LIB}/$file ]; then
811 echo Fixing $file, overeager sed script
812 sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
813 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
814 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
819 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
820 # declaration on Sun OS 4.x. We must only fix this on Sun OS 4.x, because
821 # many other systems have similar text but correct versions of the file.
822 # To ensure only Sun's is fixed, we grep for a likely unique string.
824 if [ -r $file ] && egrep '/\* @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2 \*/' $file > /dev/null; then
825 if [ ! -r ${LIB}/$file ]; then
826 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
827 chmod +w ${LIB}/$file 2>/dev/null
828 chmod a+r ${LIB}/$file 2>/dev/null
830 if [ -r ${LIB}/$file ]; then
832 cat > ${LIB}/$file << EOF
833 /* This file was generated by fixincludes */
838 extern void *memccpy();
839 extern void *memchr();
840 extern void *memcpy();
841 extern void *memset();
843 extern char *memccpy();
844 extern char *memchr();
845 extern char *memcpy();
846 extern char *memset();
847 #endif /* __STDC__ */
851 #endif /* __memory_h__ */
856 # parameters not const on DECstation Ultrix V4.0.
858 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
859 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
860 chmod +w ${LIB}/$file 2>/dev/null
861 chmod a+r ${LIB}/$file 2>/dev/null
864 if [ -r ${LIB}/$file ]; then
865 echo Fixing $file, non-const arg
866 sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
867 -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
868 -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
869 -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
870 -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
871 -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
872 -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
873 ${LIB}/$file > ${LIB}/${file}.sed
874 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
875 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
880 # parameters conflict with C++ new on rs/6000
882 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
883 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
884 chmod +w ${LIB}/$file 2>/dev/null
887 if [ -r ${LIB}/$file ]; then
888 echo Fixing $file, parameter name conflicts
889 sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
890 ${LIB}/$file > ${LIB}/${file}.sed
891 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
892 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
897 # Don't use or define the name va_list in stdio.h.
898 # This is for ANSI and also to interoperate properly with gvarargs.h.
900 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
901 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
902 chmod +w ${LIB}/$file 2>/dev/null
903 chmod a+r ${LIB}/$file 2>/dev/null
906 if [ -r ${LIB}/$file ]; then
907 echo Fixing $file, use of va_list
908 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
909 (echo "#define __need___va_list"
910 echo "#include <stdarg.h>") > ${LIB}/${file}.sed
911 # Use __gnuc_va_list in arg types in place of va_list.
912 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
913 # trailing parentheses and semicolon save all other systems from this.
914 # Define __va_list__ (something harmless and unused) instead of va_list.
915 # Don't claim to have defined va_list.
916 sed -e 's@ va_list @ __gnuc_va_list @' \
917 -e 's@ va_list)@ __gnuc_va_list)@' \
918 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
919 -e 's@ va_list@ __va_list__@' \
920 -e 's@\*va_list@*__va_list__@' \
921 -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
922 -e 's@VA_LIST@DUMMY_VA_LIST@' \
923 -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
924 ${LIB}/$file >> ${LIB}/${file}.sed
926 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
927 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
932 # Cancel out ansi_compat.h on Ultrix. Replace it with empty file.
934 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
935 if grep -s ULTRIX $file; then
936 echo "/* This file intentionally left blank. */" > $LIB/$file
940 # parameter to atof not const on DECstation Ultrix V4.0.
941 # also get rid of bogus inline definitions in HP-UX 8.0
943 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
944 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
945 chmod +w ${LIB}/$file 2>/dev/null
946 chmod a+r ${LIB}/$file 2>/dev/null
949 if [ -r ${LIB}/$file ]; then
950 echo Fixing $file, non-const arg
951 sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
952 -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
953 -e 's@inline double abs(double d) { return fabs(d); }@@' \
954 ${LIB}/$file > ${LIB}/${file}.sed
955 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
956 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
961 # In limits.h, put #ifndefs around things that are supposed to be defined
962 # in float.h to avoid redefinition errors if float.h is included first.
963 # On HP/UX this patch does not work, because on HP/UX limits.h uses
964 # multi line comments and the inserted #endif winds up inside the
965 # comment. Fortunately, HP/UX already uses #ifndefs in limits.h; if
966 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
967 # are there, and we do not add them ourselves.
969 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
970 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
971 chmod +w ${LIB}/$file 2>/dev/null
972 chmod a+r ${LIB}/$file 2>/dev/null
975 if [ -r ${LIB}/$file ]; then
976 if egrep 'ifndef[ ]+FLT_MIN' ${LIB}/$file >/dev/null; then
980 sed -e '/[ ]FLT_MIN[ ]/i\
982 -e '/[ ]FLT_MIN[ ]/a\
984 -e '/[ ]FLT_MAX[ ]/i\
986 -e '/[ ]FLT_MAX[ ]/a\
988 -e '/[ ]FLT_DIG[ ]/i\
990 -e '/[ ]FLT_DIG[ ]/a\
992 -e '/[ ]DBL_MIN[ ]/i\
994 -e '/[ ]DBL_MIN[ ]/a\
996 -e '/[ ]DBL_MAX[ ]/i\
998 -e '/[ ]DBL_MAX[ ]/a\
1000 -e '/[ ]DBL_DIG[ ]/i\
1002 -e '/[ ]DBL_DIG[ ]/a\
1004 ${LIB}/$file > ${LIB}/${file}.sed
1005 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1007 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1008 echo Deleting ${LIB}/$file\; no fixes were needed.
1013 # These two files on SunOS 4 are included by other files
1014 # in the same directory, using "...". So we must make sure they exist
1015 # in the same directory as the other fixed files.
1016 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1018 ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1020 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1022 ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1025 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1026 # need to fix some additional files. This is the same test for ISC that
1028 if test -d /etc/conf/kconfig.d \
1029 && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1030 echo "Fixing ISC __STDC__ goof in several files..."
1031 for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1033 if test -r ${LIB}/$name; then
1038 # On Interactive 2.2, certain traditional Unix definitions
1039 # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1040 # defined, not just if _POSIX_SOURCE is defined. This makes it
1041 # impossible to compile any nontrivial program except with -posix.
1043 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1044 < $file > ${LIB}/$name.
1045 mv ${LIB}/$name. ${LIB}/$name
1048 echo "Fixing ISC fmod declaration"
1049 # This one's already been fixed for other things.
1051 sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1054 echo "Fixing nested comments in ISC <sys/limits.h>"
1056 sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1057 sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1060 echo 'Removing unneeded directories:'
1062 files=`find . -type d -print | sort -r`
1063 for file in $files; do
1064 rmdir $LIB/$file > /dev/null 2>&1
1068 echo 'Making internal symbolic non-directory links'
1070 files=`find . -type l -print`
1071 for file in $files; do
1072 dest=`ls -ld $file | sed -n 's/.*-> //p'`
1073 if expr "$dest" : '[^/].*' > /dev/null; then
1074 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1075 if [ -f $target ]; then
1076 ln -s $dest ${LIB}/$file >/dev/null 2>&1
1082 echo 'Cleaning up DONE files.'
1084 find . -name DONE -exec rm -f {} ';'