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
69 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
70 rm -f /tmp/ShouldNotExist
76 echo Finding directories and links to directories
78 # Find all directories and all symlinks that point to directories.
79 # Put the list in $files.
80 # Each time we find a symlink, add it to newdirs
81 # so that we do another find within the dir the link points to.
82 # Note that $files may have duplicates in it;
83 # later parts of this file are supposed to ignore them.
86 while [ -n "$dirs" ] && [ $levels -gt 0 ]
88 levels=`expr $levels - 1`
92 echo " Searching $INPUT/$d"
98 # Find all directories under $d, relative to $d, excluding $d itself.
99 files="$files `find $d -type d -print | \
100 sed -e '/\/\.$/d' -e '/^\.$/d'`"
101 # Find all links to directories.
102 # Using `-exec test -d' in find fails on some systems,
103 # and trying to run test via sh fails on others,
104 # so this is the simplest alternative left.
105 # First find all the links, then test each one.
108 theselinks=`find $d -type l -print`
109 for d1 in $theselinks --dummy--
111 # If the link points to a directory,
112 # add that dir to $newdirs
115 newdirs="$newdirs $d1"
120 files="$files $newdirs"
125 echo "All directories (including links to directories):"
128 for file in $files; do
130 if [ ! -d $LIB/$file ]
131 then mkdir $LIB/$file
136 # treetops gets an alternating list
137 # of old directories to copy
138 # and the new directories to copy to.
139 treetops="${INPUT} ${LIB}"
142 echo 'Making symbolic directory links'
143 for file in $files; do
144 dest=`ls -ld $file | sed -n 's/.*-> //p'`
147 # In case $dest is relative, get to $file's dir first.
149 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
150 # Check that the target directory exists.
151 # Redirections changed to avoid bug in sh on Ultrix.
152 (cd $dest) > /dev/null 2>&1
155 # X gets the dir that the link actually leads to.
157 # If a link points to ., make a similar link to .
158 if [ $x = $INPUT ]; then
159 echo $file '->' . ': Making link'
160 rm -fr ${LIB}/$file > /dev/null 2>&1
161 ln -s . ${LIB}/$file > /dev/null 2>&1
162 # If link leads back into ${INPUT},
163 # make a similar link here.
164 elif expr $x : "${INPUT}/.*" > /dev/null; then
165 # Y gets the actual target dir name, relative to ${INPUT}.
166 y=`echo $x | sed -n "s&${INPUT}/&&p"`
167 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
169 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
170 echo $file '->' $dots$y ': Making link'
171 rm -fr ${LIB}/$file > /dev/null 2>&1
172 ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
174 # If the link is to a dir $target outside ${INPUT},
175 # repoint the link at ${INPUT}/root$target
176 # and process $target into ${INPUT}/root$target
177 # treat this directory as if it actually contained the files.
178 echo $file '->' root$x ': Making link'
179 if [ -d $LIB/root$x ]
185 while [ x$dirname != x ]; do
186 component=`echo $dirname | sed -e 's|/.*$||'`
187 mkdir $component >/dev/null 2>&1
189 dirmade=$dirmade/$component
190 dirname=`echo $dirname | sed -e 's|[^/]*/||'`
193 # Duplicate directory structure created in ${LIB}/$file in new
195 for file2 in $files; do
198 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
199 echo "Duplicating ${file}'s ${dupdir}"
210 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
212 sed -e 's@^./@@' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
213 rm -fr ${LIB}/$file > /dev/null 2>&1
214 ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
215 treetops="$treetops $x ${LIB}/root$x"
225 while [ $# != 0 ]; do
226 # $1 is an old directory to copy, and $2 is the new directory to copy to.
229 # The same dir can appear more than once in treetops.
230 # There's no need to scan it more than once.
236 echo Fixing directory $1 into $2
237 # Check .h files which are symlinks as well as those which are files.
238 # A link to a header file will not be processed by anything but this.
240 files=`find . -name '*.h' \( -type f -o -type l \) -print`
242 files=`find . -name '*.h' -type f -print`
244 echo Checking header files
246 # Note that BSD43_* are used on recent MIPS systems.
247 for file in $files; do
248 # This call to egrep is essential, since checking a file with egrep
249 # is much faster than actually trying to fix it.
250 # It is also essential that most files *not* match!
251 # Thus, matching every #endif is unacceptable.
252 # But the argument to egrep must be kept small, or many versions of egrep
253 # won't be able to handle it.
255 # We use the pattern [!-.0-~] instead of [^/ ] to match a noncomment
256 # following #else or #endif because some buggy egreps think [^/] matches
257 # newline, and they thus think `#else ' matches `#e[ndiflse]*[ ]+[^/ ]'.
259 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
260 # following #if or #elif that is not surrounded by __. The `a-ce-km-z'
261 # in this pattern lacks `d' and `l'; this means we don't worry about
262 # identifiers starting with `d' or `l'. This is OK, since none of the
263 # identifiers below start with `d' or `l'. It also greatly improves
264 # performance, since many files contain lines of the form `#if ... defined ...'
266 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
267 if [ -r $file ]; then
268 cp $file $2/$file >/dev/null 2>&1 \
269 || echo "Can't copy $file"
272 # Here is how the sed commands in braces work.
273 # (It doesn't work to put the comments inside the sed commands.)
274 # Surround each word with spaces, to simplify matching below.
275 # ANSIfy each pre-ANSI machine-dependent symbol
276 # by surrounding it with __ __.
277 # Remove the spaces that we inserted around each word.
282 s%^\([ ]*#[ ]*else\)[ ]*/[^*].*%\1%
283 s%^\([ ]*#[ ]*else\)[ ]*[^/ ].*%\1%
284 s%^\([ ]*#[ ]*endif\)[ ]*/[^*].*%\1%
285 s%^\([ ]*#[ ]*endif\)[ ]*\*[^/].*%\1%
286 s%^\([ ]*#[ ]*endif\)[ ]*[^/* ].*%\1%
287 /\/\/[^*]/ s|//\(.*\)$|/*\1*/|
288 /[ ]_IO[A-Z]*[ ]*(/ s/\(_IO[A-Z]*[ ]*(\)\(.\),/\1'\''\2'\'',/
289 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
290 /#define._IO/ s/'\''\([cgx]\)'\''/\1/g
291 /#define.BSD43__IO/ s/'\''\([cgx]\)'\''/\1/g
292 /[^A-Z0-9_]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
293 /[^A-Z0-9]_CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
294 /#define[ ]*[ ]CTRL/ s/'\''\([cgx]\)'\''/\1/g
295 /#define[ ]*[ ]_CTRL/ s/'\''\([cgx]\)'\''/\1/g
296 /#define.BSD43_CTRL/ s/'\''\([cgx]\)'\''/\1/g
298 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
300 s/ bsd4\([0-9]\) / __bsd4\1__ /g
301 s/ _*i386 / __i386__ /g
302 s/ is68k / __is68k__ /g
303 s/ m68k / __m68k__ /g
304 s/ mc680\([0-9]\)0 / __mc680\10__ /g
305 s/ news\([0-9]*\) / __news\1__ /g
306 s/ ns32000 / __ns32000__ /g
308 s/ sony_news / __sony_news__ /g
309 s/ sparc / __sparc__ /g
310 s/ sun\([a-z0-9]*\) / __sun\1__ /g
311 s/ unix / __unix__ /g
314 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
316 /^#define.NULL[ ]/ i\
318 ' $2/$file > $2/$file.
319 mv $2/$file. $2/$file
320 if cmp $file $2/$file >/dev/null 2>&1; then
333 # Install the proper definition of size_t in header files that it comes from.
334 for file in sys/types.h stdlib.h sys/stdtypes.h; do
335 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
336 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
337 chmod +w ${LIB}/$file 2>/dev/null
338 chmod a+r ${LIB}/$file 2>/dev/null
341 if [ -r ${LIB}/$file ]; then
342 echo Fixing $file comment
343 # Extract the definition of SIZE_TYPE, if any.
344 # (This file must be called something.c).
345 echo "#include \"tm.h\"
346 gobblegobble SIZE_TYPE" > ${LIB}/types.c
347 foo=`cd ${LIB}; cc -E -I${ORIGDIR} -I${SRCDIR} -I${SRCDIR}/config types.c | grep gobblegobble | sed -e "s/gobblegobble[ ]*//"`
349 # Default to our preferred type.
350 if [ "$foo" = SIZE_TYPE ]; then foo="unsigned long int"; else foo=`echo $foo | sed -e 's/^.*"\(.*\)".*$/\1/'`; fi
351 sed -e "s/typedef[ a-z_]*[ ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
352 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
353 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
359 # Fix one other error in this file: a mismatched quote not inside a C comment.
360 file=sundev/vuid_event.h
361 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
362 mkdir ${LIB}/sundev 2>/dev/null
363 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
364 chmod +w ${LIB}/$file 2>/dev/null
365 chmod a+r ${LIB}/$file 2>/dev/null
368 if [ -r ${LIB}/$file ]; then
369 echo Fixing $file comment
370 sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
371 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
372 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
377 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
378 file=sunwindow/win_cursor.h
379 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
380 # mkdir ${LIB}/sunwindow 2>/dev/null
381 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
382 chmod +w ${LIB}/$file 2>/dev/null
384 if [ -r ${LIB}/$file ]; then
386 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
387 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
388 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
392 file=sunwindow/win_lock.h
393 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
394 # mkdir ${LIB}/sunwindow 2>/dev/null
395 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
396 chmod +w ${LIB}/$file 2>/dev/null
398 if [ -r ${LIB}/$file ]; then
400 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
401 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
402 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
407 # Fix this Sun file to avoid interfering with stddef.h.
409 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
410 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
411 chmod +w ${LIB}/$file 2>/dev/null
412 chmod a+r ${LIB}/$file 2>/dev/null
415 if [ -r ${LIB}/$file ]; then
417 sed -e '/[ ]size_t.*;/i\
419 #define _GCC_SIZE_T' \
422 -e '/[ ]ptrdiff_t.*;/i\
423 #ifndef _GCC_PTRDIFF_T\
424 #define _GCC_PTRDIFF_T' \
425 -e '/[ ]ptrdiff_t.*;/a\
427 -e '/[ ]wchar_t.*;/i\
428 #ifndef _GCC_WCHAR_T\
429 #define _GCC_WCHAR_T' \
430 -e '/[ ]wchar_t.*;/a\
431 #endif' ${LIB}/$file > ${LIB}/${file}.sed
432 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
433 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
438 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
439 # match e.g. ssize_t present in AIX for the ps/2.
441 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
442 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
443 chmod +w ${LIB}/$file 2>/dev/null
444 chmod a+r ${LIB}/$file 2>/dev/null
447 if [ -r ${LIB}/$file ]; then
449 sed -e '/[ ]size_t.*;/i\
451 #define _GCC_SIZE_T' \
453 #endif' ${LIB}/$file > ${LIB}/${file}.sed
454 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
455 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
460 # Fix an error in this file: the #if says _cplusplus, not the double
461 # underscore __cplusplus that it should be
463 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
464 mkdir ${LIB}/rpcsvc 2>/dev/null
465 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
466 chmod +w ${LIB}/$file 2>/dev/null
467 chmod a+r ${LIB}/$file 2>/dev/null
470 if [ -r ${LIB}/$file ]; then
471 echo Fixing $file, __cplusplus macro
472 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
473 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
474 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
479 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
480 # structure definition.
482 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
483 mkdir ${LIB}/rpcsvc 2>/dev/null
484 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
485 chmod +w ${LIB}/$file 2>/dev/null
486 chmod a+r ${LIB}/$file 2>/dev/null
489 if [ -r ${LIB}/$file ]; then
490 echo Fixing $file, definition of statsswtch
491 sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
492 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
493 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
498 # Fix an error in this file: a missing semi-colon at the end of the nodeent
499 # structure definition.
500 file=netdnet/dnetdb.h
501 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
502 mkdir ${LIB}/netdnet 2>/dev/null
503 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
504 chmod +w ${LIB}/$file 2>/dev/null
505 chmod a+r ${LIB}/$file 2>/dev/null
508 if [ -r ${LIB}/$file ]; then
509 echo Fixing $file, definition of nodeent
510 sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
511 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
512 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
517 # Check for bad #ifdef line (in Ultrix 4.1)
519 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
520 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
521 chmod +w ${LIB}/$file 2>/dev/null
522 chmod a+r ${LIB}/$file 2>/dev/null
525 if [ -r ${LIB}/$file ]; then
526 echo Fixing $file, bad \#ifdef line
527 sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
528 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
529 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
534 # Check for superfluous `static' (in Ultrix 4.2)
536 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
537 mkdir ${LIB}/machine 2>/dev/null
538 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
539 chmod +w ${LIB}/$file 2>/dev/null
540 chmod a+r ${LIB}/$file 2>/dev/null
543 if [ -r ${LIB}/$file ]; then
544 echo Fixing $file, superfluous static
545 sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
546 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
547 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
550 # This file has an alternative name, mips/cpu.h. Fix that name, too.
551 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
552 mkdir ${LIB}/mips 2>&-
553 ln ${LIB}/$file ${LIB}/mips/cpu.h
558 # Incorrect sprintf declaration in X11/Xmu.h
560 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
561 mkdir ${LIB}/X11 2>/dev/null
562 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
563 chmod +w ${LIB}/$file 2>/dev/null
564 chmod a+r ${LIB}/$file 2>/dev/null
567 if [ -r ${LIB}/$file ]; then
568 echo Fixing $file sprintf declaration
569 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
570 extern char * sprintf();\
571 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
572 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
573 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
578 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
579 # (It's not clear whether the right file name is this or X11/Xmu.h.)
581 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
582 mkdir ${LIB}/X11/Xmu 2>/dev/null
583 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
584 chmod +w ${LIB}/$file 2>/dev/null
585 chmod a+r ${LIB}/$file 2>/dev/null
588 if [ -r ${LIB}/$file ]; then
589 echo Fixing $file sprintf declaration
590 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
591 extern char * sprintf();\
592 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
593 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
594 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
599 # Check for missing ';' in struct
601 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
602 mkdir ${LIB}/netinet 2>/dev/null
603 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
604 chmod +w ${LIB}/$file 2>/dev/null
605 chmod a+r ${LIB}/$file 2>/dev/null
608 if [ -r ${LIB}/$file ]; then
610 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
611 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
612 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
617 # Fix the CAT macro in SunOS memvar.h.
618 file=pixrect/memvar.h
619 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
620 mkdir ${LIB}/pixrect 2>/dev/null
621 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
622 chmod +w ${LIB}/$file 2>/dev/null
623 chmod a+r ${LIB}/$file 2>/dev/null
626 if [ -r ${LIB}/$file ]; then
628 sed -e '/^#define.CAT(a,b)/ i\
630 #define CAT(a,b) a##b\
632 /^#define.CAT(a,b)/ a\
634 ' ${LIB}/$file > ${LIB}/${file}.sed
635 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
636 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
641 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
643 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
644 mkdir ${LIB}/rpcsvc 2>/dev/null
645 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
646 chmod +w ${LIB}/$file 2>/dev/null
647 chmod a+r ${LIB}/$file 2>/dev/null
650 if [ -r ${LIB}/$file ]; then
652 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
653 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
654 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
659 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
660 # Also wrap protection around size_t for m88k-sysv3 systems.
662 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
663 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
664 chmod +w ${LIB}/$file 2>/dev/null
665 chmod a+r ${LIB}/$file 2>/dev/null
668 if [ -r ${LIB}/$file ]; then
670 sed -e 's/int abort/void abort/g' \
671 -e 's/int free/void free/g' \
672 -e 's/char \* calloc/void \* calloc/g' \
673 -e 's/char \* malloc/void \* malloc/g' \
674 -e 's/char \* realloc/void \* realloc/g' \
675 -e 's/int exit/void exit/g' \
676 -e '/typedef[ a-zA-Z_]*[ ]size_t[ ]*;/i\
678 #define _GCC_SIZE_T' \
679 -e '/typedef[ a-zA-Z_]*[ ]size_t[ ]*;/a\
681 ${LIB}/$file > ${LIB}/${file}.sed
682 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
683 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
688 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
690 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
691 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
692 chmod +w ${LIB}/$file 2>/dev/null
693 chmod a+r ${LIB}/$file 2>/dev/null
696 if [ -r ${LIB}/$file ]; then
698 sed -e 's/typedef[ ]char \* malloc_t/typedef void \* malloc_t/g' \
699 -e 's/int[ ][ ]*free/void free/g' \
700 ${LIB}/$file > ${LIB}/${file}.sed
701 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
702 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
707 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
708 file=hsfs/hsfs_spec.h
709 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
710 mkdir ${LIB}/hsfs 2>/dev/null
711 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
712 chmod +w ${LIB}/$file 2>/dev/null
713 chmod a+r ${LIB}/$file 2>/dev/null
716 if [ -r ${LIB}/$file ]; then
718 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
719 ${LIB}/$file > ${LIB}/${file}.
720 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
721 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
726 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
728 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
729 mkdir ${LIB}/hsfs 2>/dev/null
730 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
731 chmod +w ${LIB}/$file 2>/dev/null
732 chmod a+r ${LIB}/$file 2>/dev/null
735 if [ -r ${LIB}/$file ]; then
737 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
738 ${LIB}/$file > ${LIB}/${file}.sed
739 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
740 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
745 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
747 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
748 mkdir ${LIB}/hsfs 2>/dev/null
749 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
750 chmod +w ${LIB}/$file 2>/dev/null
751 chmod a+r ${LIB}/$file 2>/dev/null
754 if [ -r ${LIB}/$file ]; then
756 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
757 ${LIB}/$file > ${LIB}/${file}.sed
758 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
759 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
764 # Incorrect #include in Sony News-OS 3.2.
765 file=machine/machparam.h
766 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
767 mkdir ${LIB}/machine 2>/dev/null
768 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
769 chmod +w ${LIB}/$file 2>/dev/null
770 chmod a+r ${LIB}/$file 2>/dev/null
773 if [ -r ${LIB}/$file ]; then
774 echo Fixing $file, incorrect \#include
775 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
776 ${LIB}/$file > ${LIB}/${file}.
777 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
778 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
783 # Multiline comment after typedef on IRIX 4.0.1.
785 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
786 mkdir ${LIB}/sys 2>/dev/null
787 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
788 chmod +w ${LIB}/$file 2>/dev/null
789 chmod a+r ${LIB}/$file 2>/dev/null
792 if [ -r ${LIB}/$file ]; then
793 echo Fixing $file, comment in the middle of \#ifdef
794 sed -e 's@type of the result@type of the result */@' \
795 -e 's@of the sizeof@/* of the sizeof@' \
796 ${LIB}/$file > ${LIB}/${file}.sed
797 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
798 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
803 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
804 # header file, which embeds // comments inside multi-line /* */
805 # comments. If this looks like the IRIX header file, we refix it by
806 # just throwing away the // comments.
808 if [ -r ${LIB}/$file ]; then
809 if egrep indigo.esd ${LIB}/$file > /dev/null; then
810 echo Fixing $file, overeager sed script
812 sed -e 's|//.*$||g' $file > ${LIB}/$file
813 chmod +w ${LIB}/$file 2>/dev/null
814 chmod a+r ${LIB}/$file 2>/dev/null
818 # Another IRIX 4.0.1 header file contains the string "//"
820 if [ -r ${LIB}/$file ]; then
821 echo Fixing $file, overeager sed script
822 sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
823 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
824 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
829 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
830 # declaration on Sun OS 4.x. We must only fix this on Sun OS 4.x, because
831 # many other systems have similar text but correct versions of the file.
832 # To ensure only Sun's is fixed, we grep for a likely unique string.
834 if [ -r $file ] && egrep '/\* @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2 \*/' $file > /dev/null; then
835 if [ ! -r ${LIB}/$file ]; then
836 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
837 chmod +w ${LIB}/$file 2>/dev/null
838 chmod a+r ${LIB}/$file 2>/dev/null
840 if [ -r ${LIB}/$file ]; then
842 cat > ${LIB}/$file << EOF
843 /* This file was generated by fixincludes */
848 extern void *memccpy();
849 extern void *memchr();
850 extern void *memcpy();
851 extern void *memset();
853 extern char *memccpy();
854 extern char *memchr();
855 extern char *memcpy();
856 extern char *memset();
857 #endif /* __STDC__ */
861 #endif /* __memory_h__ */
866 # parameters not const on DECstation Ultrix V4.0.
868 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
869 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
870 chmod +w ${LIB}/$file 2>/dev/null
871 chmod a+r ${LIB}/$file 2>/dev/null
874 if [ -r ${LIB}/$file ]; then
875 echo Fixing $file, non-const arg
876 sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
877 -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
878 -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
879 -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
880 -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
881 -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
882 -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
883 ${LIB}/$file > ${LIB}/${file}.sed
884 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
885 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
890 # parameters conflict with C++ new on rs/6000
891 for file in stdio.h unistd.h ; do
892 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
893 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
894 chmod +w ${LIB}/$file 2>/dev/null
897 if [ -r ${LIB}/$file ]; then
898 echo Fixing $file, parameter name conflicts
899 sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
900 ${LIB}/$file > ${LIB}/${file}.sed
901 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
902 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
908 # function class(double x) conflicts with C++ keyword on rs/6000
910 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
911 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
912 chmod +w ${LIB}/$file 2>/dev/null
913 chmod a+r ${LIB}/$file 2>/dev/null
916 if [ -r ${LIB}/$file ]; then
917 if grep 'class[(]' ${LIB}/$file >/dev/null; then
920 #ifndef __cplusplus' \
922 #endif' ${LIB}/$file > ${LIB}/${file}.sed
923 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
924 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
930 # NeXT defines 'int wait(union wait*)', which conflicts with Posix.1.
932 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
933 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
934 chmod +w ${LIB}/$file 2>/dev/null
937 if [ -r ${LIB}/$file ] \
938 && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
939 echo Fixing $file, bad wait formal
940 sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
941 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
942 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
947 # Don't use or define the name va_list in stdio.h.
948 # This is for ANSI and also to interoperate properly with gvarargs.h.
950 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
951 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
952 chmod +w ${LIB}/$file 2>/dev/null
953 chmod a+r ${LIB}/$file 2>/dev/null
956 if [ -r ${LIB}/$file ]; then
957 echo Fixing $file, use of va_list
958 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
959 (echo "#define __need___va_list"
960 echo "#include <stdarg.h>") > ${LIB}/${file}.sed
961 # Use __gnuc_va_list in arg types in place of va_list.
962 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
963 # trailing parentheses and semicolon save all other systems from this.
964 # Define __va_list__ (something harmless and unused) instead of va_list.
965 # Don't claim to have defined va_list.
966 sed -e 's@ va_list @ __gnuc_va_list @' \
967 -e 's@ va_list)@ __gnuc_va_list)@' \
968 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
969 -e 's@ va_list@ __va_list__@' \
970 -e 's@\*va_list@*__va_list__@' \
971 -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
972 -e 's@VA_LIST@DUMMY_VA_LIST@' \
973 -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
974 ${LIB}/$file >> ${LIB}/${file}.sed
976 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
977 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
982 # Cancel out ansi_compat.h on Ultrix. Replace it with empty file.
984 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
985 if grep -s ULTRIX $file; then
986 echo "/* This file intentionally left blank. */" > $LIB/$file
990 # parameter to atof not const on DECstation Ultrix V4.0.
991 # also get rid of bogus inline definitions in HP-UX 8.0
993 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
994 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
995 chmod +w ${LIB}/$file 2>/dev/null
996 chmod a+r ${LIB}/$file 2>/dev/null
999 if [ -r ${LIB}/$file ]; then
1000 echo Fixing $file, non-const arg
1001 sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
1002 -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
1003 -e 's@inline double abs(double d) { return fabs(d); }@@' \
1004 ${LIB}/$file > ${LIB}/${file}.sed
1005 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1006 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1011 # In limits.h, put #ifndefs around things that are supposed to be defined
1012 # in float.h to avoid redefinition errors if float.h is included first.
1013 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1014 # multi line comments and the inserted #endif winds up inside the
1015 # comment. Fortunately, HP/UX already uses #ifndefs in limits.h; if
1016 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1017 # are there, and we do not add them ourselves.
1019 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1020 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1021 chmod +w ${LIB}/$file 2>/dev/null
1022 chmod a+r ${LIB}/$file 2>/dev/null
1025 if [ -r ${LIB}/$file ]; then
1026 if egrep 'ifndef[ ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1030 sed -e '/[ ]FLT_MIN[ ]/i\
1032 -e '/[ ]FLT_MIN[ ]/a\
1034 -e '/[ ]FLT_MAX[ ]/i\
1036 -e '/[ ]FLT_MAX[ ]/a\
1038 -e '/[ ]FLT_DIG[ ]/i\
1040 -e '/[ ]FLT_DIG[ ]/a\
1042 -e '/[ ]DBL_MIN[ ]/i\
1044 -e '/[ ]DBL_MIN[ ]/a\
1046 -e '/[ ]DBL_MAX[ ]/i\
1048 -e '/[ ]DBL_MAX[ ]/a\
1050 -e '/[ ]DBL_DIG[ ]/i\
1052 -e '/[ ]DBL_DIG[ ]/a\
1054 ${LIB}/$file > ${LIB}/${file}.sed
1055 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1057 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1058 echo Deleting ${LIB}/$file\; no fixes were needed.
1063 # These two files on SunOS 4 are included by other files
1064 # in the same directory, using "...". So we must make sure they exist
1065 # in the same directory as the other fixed files.
1066 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1068 ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1070 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1072 ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1075 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1076 # need to fix some additional files. This is the same test for ISC that
1078 if test -d /etc/conf/kconfig.d \
1079 && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1080 echo "Fixing ISC __STDC__ goof in several files..."
1081 for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1083 if test -r ${LIB}/$name; then
1088 # On Interactive 2.2, certain traditional Unix definitions
1089 # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1090 # defined, not just if _POSIX_SOURCE is defined. This makes it
1091 # impossible to compile any nontrivial program except with -posix.
1093 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1094 < $file > ${LIB}/$name.
1095 mv ${LIB}/$name. ${LIB}/$name
1098 echo "Fixing ISC fmod declaration"
1099 # This one's already been fixed for other things.
1101 sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1104 echo "Fixing nested comments in ISC <sys/limits.h>"
1106 sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1107 sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1110 echo 'Removing unneeded directories:'
1112 files=`find . -type d -print | sort -r`
1113 for file in $files; do
1114 rmdir $LIB/$file > /dev/null 2>&1
1118 echo 'Making internal symbolic non-directory links'
1120 files=`find . -type l -print`
1121 for file in $files; do
1122 dest=`ls -ld $file | sed -n 's/.*-> //p'`
1123 if expr "$dest" : '[^/].*' > /dev/null; then
1124 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1125 if [ -f $target ]; then
1126 ln -s $dest ${LIB}/$file >/dev/null 2>&1
1132 echo 'Cleaning up DONE files.'
1134 find . -name DONE -exec rm -f {} ';'