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;
336 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
337 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
338 chmod +w ${LIB}/$file 2>/dev/null
339 chmod a+r ${LIB}/$file 2>/dev/null
342 if [ -r ${LIB}/$file ]; then
343 echo Fixing $file comment
344 # Extract the definition of SIZE_TYPE, if any.
345 # (This file must be called something.c).
346 echo "#include \"tm.h\"
347 gobblegobble SIZE_TYPE" > ${LIB}/types.c
348 foo=`cd ${LIB}; cc -E -I${ORIGDIR} -I${SRCDIR} -I${SRCDIR}/config types.c | grep gobblegobble | sed -e "s/gobblegobble[ ]*//"`
350 # Default to our preferred type.
351 if [ "$foo" = SIZE_TYPE ]; then foo="unsigned long int"; else foo=`echo $foo | sed -e 's/^.*"\(.*\)".*$/\1/'`; fi
352 sed -e "s/typedef[ a-z_]*[ ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
353 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
354 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
360 # Fix one other error in this file: a mismatched quote not inside a C comment.
361 file=sundev/vuid_event.h
362 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
363 mkdir ${LIB}/sundev 2>/dev/null
364 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
365 chmod +w ${LIB}/$file 2>/dev/null
366 chmod a+r ${LIB}/$file 2>/dev/null
369 if [ -r ${LIB}/$file ]; then
370 echo Fixing $file comment
371 sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
372 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
373 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
378 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
379 file=sunwindow/win_cursor.h
380 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
381 # mkdir ${LIB}/sunwindow 2>/dev/null
382 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
383 chmod +w ${LIB}/$file 2>/dev/null
385 if [ -r ${LIB}/$file ]; then
387 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
388 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
389 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
393 file=sunwindow/win_lock.h
394 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
395 # mkdir ${LIB}/sunwindow 2>/dev/null
396 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
397 chmod +w ${LIB}/$file 2>/dev/null
399 if [ -r ${LIB}/$file ]; then
401 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
402 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
403 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
408 # Fix this Sun file to avoid interfering with stddef.h.
410 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
411 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
412 chmod +w ${LIB}/$file 2>/dev/null
413 chmod a+r ${LIB}/$file 2>/dev/null
416 if [ -r ${LIB}/$file ]; then
418 sed -e '/[ ]size_t.*;/i\
420 #define _GCC_SIZE_T' \
423 -e '/[ ]ptrdiff_t.*;/i\
424 #ifndef _GCC_PTRDIFF_T\
425 #define _GCC_PTRDIFF_T' \
426 -e '/[ ]ptrdiff_t.*;/a\
428 -e '/[ ]wchar_t.*;/i\
429 #ifndef _GCC_WCHAR_T\
430 #define _GCC_WCHAR_T' \
431 -e '/[ ]wchar_t.*;/a\
432 #endif' ${LIB}/$file > ${LIB}/${file}.sed
433 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
434 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
439 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
440 # match e.g. ssize_t present in AIX for the ps/2.
442 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
443 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
444 chmod +w ${LIB}/$file 2>/dev/null
445 chmod a+r ${LIB}/$file 2>/dev/null
448 if [ -r ${LIB}/$file ]; then
450 sed -e '/[ ]size_t.*;/i\
452 #define _GCC_SIZE_T' \
454 #endif' ${LIB}/$file > ${LIB}/${file}.sed
455 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
456 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
461 # Fix an error in this file: the #if says _cplusplus, not the double
462 # underscore __cplusplus that it should be
464 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
465 mkdir ${LIB}/rpcsvc 2>/dev/null
466 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
467 chmod +w ${LIB}/$file 2>/dev/null
468 chmod a+r ${LIB}/$file 2>/dev/null
471 if [ -r ${LIB}/$file ]; then
472 echo Fixing $file, __cplusplus macro
473 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
474 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
475 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
480 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
481 # structure definition.
483 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
484 mkdir ${LIB}/rpcsvc 2>/dev/null
485 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
486 chmod +w ${LIB}/$file 2>/dev/null
487 chmod a+r ${LIB}/$file 2>/dev/null
490 if [ -r ${LIB}/$file ]; then
491 echo Fixing $file, definition of statsswtch
492 sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
493 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
494 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
499 # Fix an error in this file: a missing semi-colon at the end of the nodeent
500 # structure definition.
501 file=netdnet/dnetdb.h
502 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
503 mkdir ${LIB}/netdnet 2>/dev/null
504 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
505 chmod +w ${LIB}/$file 2>/dev/null
506 chmod a+r ${LIB}/$file 2>/dev/null
509 if [ -r ${LIB}/$file ]; then
510 echo Fixing $file, definition of nodeent
511 sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
512 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
513 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
518 # Check for bad #ifdef line (in Ultrix 4.1)
520 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
521 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
522 chmod +w ${LIB}/$file 2>/dev/null
523 chmod a+r ${LIB}/$file 2>/dev/null
526 if [ -r ${LIB}/$file ]; then
527 echo Fixing $file, bad \#ifdef line
528 sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
529 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
530 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
535 # Check for superfluous `static' (in Ultrix 4.2)
537 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
538 mkdir ${LIB}/machine 2>/dev/null
539 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
540 chmod +w ${LIB}/$file 2>/dev/null
541 chmod a+r ${LIB}/$file 2>/dev/null
544 if [ -r ${LIB}/$file ]; then
545 echo Fixing $file, superfluous static
546 sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
547 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
548 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
551 # This file has an alternative name, mips/cpu.h. Fix that name, too.
552 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
553 mkdir ${LIB}/mips 2>&-
554 ln ${LIB}/$file ${LIB}/mips/cpu.h
559 # Incorrect sprintf declaration in X11/Xmu.h
561 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
562 mkdir ${LIB}/X11 2>/dev/null
563 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
564 chmod +w ${LIB}/$file 2>/dev/null
565 chmod a+r ${LIB}/$file 2>/dev/null
568 if [ -r ${LIB}/$file ]; then
569 echo Fixing $file sprintf declaration
570 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
571 extern char * sprintf();\
572 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
573 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
574 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
579 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
580 # (It's not clear whether the right file name is this or X11/Xmu.h.)
582 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
583 mkdir ${LIB}/X11/Xmu 2>/dev/null
584 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
585 chmod +w ${LIB}/$file 2>/dev/null
586 chmod a+r ${LIB}/$file 2>/dev/null
589 if [ -r ${LIB}/$file ]; then
590 echo Fixing $file sprintf declaration
591 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
592 extern char * sprintf();\
593 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
594 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
595 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
600 # Check for missing ';' in struct
602 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
603 mkdir ${LIB}/netinet 2>/dev/null
604 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
605 chmod +w ${LIB}/$file 2>/dev/null
606 chmod a+r ${LIB}/$file 2>/dev/null
609 if [ -r ${LIB}/$file ]; then
611 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
612 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
613 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
618 # Fix the CAT macro in SunOS memvar.h.
619 file=pixrect/memvar.h
620 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
621 mkdir ${LIB}/pixrect 2>/dev/null
622 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
623 chmod +w ${LIB}/$file 2>/dev/null
624 chmod a+r ${LIB}/$file 2>/dev/null
627 if [ -r ${LIB}/$file ]; then
629 sed -e '/^#define.CAT(a,b)/ i\
631 #define CAT(a,b) a##b\
633 /^#define.CAT(a,b)/ a\
635 ' ${LIB}/$file > ${LIB}/${file}.sed
636 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
637 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
642 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
644 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
645 mkdir ${LIB}/rpcsvc 2>/dev/null
646 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
647 chmod +w ${LIB}/$file 2>/dev/null
648 chmod a+r ${LIB}/$file 2>/dev/null
651 if [ -r ${LIB}/$file ]; then
653 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
654 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
655 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
660 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
661 # Also wrap protection around size_t for m88k-sysv3 systems.
663 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
664 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
665 chmod +w ${LIB}/$file 2>/dev/null
666 chmod a+r ${LIB}/$file 2>/dev/null
669 if [ -r ${LIB}/$file ]; then
671 sed -e 's/int abort/void abort/g' \
672 -e 's/int free/void free/g' \
673 -e 's/char \* calloc/void \* calloc/g' \
674 -e 's/char \* malloc/void \* malloc/g' \
675 -e 's/char \* realloc/void \* realloc/g' \
676 -e 's/int exit/void exit/g' \
677 -e '/typedef[ a-zA-Z_]*[ ]size_t[ ]*;/i\
679 #define _GCC_SIZE_T' \
680 -e '/typedef[ a-zA-Z_]*[ ]size_t[ ]*;/a\
682 ${LIB}/$file > ${LIB}/${file}.sed
683 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
684 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
689 # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
691 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
692 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
693 chmod +w ${LIB}/$file 2>/dev/null
694 chmod a+r ${LIB}/$file 2>/dev/null
697 if [ -r ${LIB}/$file ]; then
699 sed -e 's/typedef[ ]char \* malloc_t/typedef void \* malloc_t/g' \
700 -e 's/int[ ][ ]*free/void free/g' \
701 ${LIB}/$file > ${LIB}/${file}.sed
702 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
703 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
708 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
709 file=hsfs/hsfs_spec.h
710 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
711 mkdir ${LIB}/hsfs 2>/dev/null
712 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
713 chmod +w ${LIB}/$file 2>/dev/null
714 chmod a+r ${LIB}/$file 2>/dev/null
717 if [ -r ${LIB}/$file ]; then
719 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
720 ${LIB}/$file > ${LIB}/${file}.
721 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
722 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
727 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
729 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
730 mkdir ${LIB}/hsfs 2>/dev/null
731 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
732 chmod +w ${LIB}/$file 2>/dev/null
733 chmod a+r ${LIB}/$file 2>/dev/null
736 if [ -r ${LIB}/$file ]; then
738 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
739 ${LIB}/$file > ${LIB}/${file}.sed
740 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
741 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
746 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
748 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
749 mkdir ${LIB}/hsfs 2>/dev/null
750 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
751 chmod +w ${LIB}/$file 2>/dev/null
752 chmod a+r ${LIB}/$file 2>/dev/null
755 if [ -r ${LIB}/$file ]; then
757 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
758 ${LIB}/$file > ${LIB}/${file}.sed
759 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
760 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
765 # Incorrect #include in Sony News-OS 3.2.
766 file=machine/machparam.h
767 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
768 mkdir ${LIB}/machine 2>/dev/null
769 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
770 chmod +w ${LIB}/$file 2>/dev/null
771 chmod a+r ${LIB}/$file 2>/dev/null
774 if [ -r ${LIB}/$file ]; then
775 echo Fixing $file, incorrect \#include
776 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
777 ${LIB}/$file > ${LIB}/${file}.
778 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
779 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
784 # Multiline comment after typedef on IRIX 4.0.1.
786 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
787 mkdir ${LIB}/sys 2>/dev/null
788 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
789 chmod +w ${LIB}/$file 2>/dev/null
790 chmod a+r ${LIB}/$file 2>/dev/null
793 if [ -r ${LIB}/$file ]; then
794 echo Fixing $file, comment in the middle of \#ifdef
795 sed -e 's@type of the result@type of the result */@' \
796 -e 's@of the sizeof@/* of the sizeof@' \
797 ${LIB}/$file > ${LIB}/${file}.sed
798 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
799 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
804 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
805 # header file, which embeds // comments inside multi-line /* */
806 # comments. If this looks like the IRIX header file, we refix it by
807 # just throwing away the // comments.
809 if [ -r ${LIB}/$file ]; then
810 if egrep indigo.esd ${LIB}/$file > /dev/null; then
811 echo Fixing $file, overeager sed script
813 sed -e 's|//.*$||g' $file > ${LIB}/$file
814 chmod +w ${LIB}/$file 2>/dev/null
815 chmod a+r ${LIB}/$file 2>/dev/null
819 # Another IRIX 4.0.1 header file contains the string "//"
821 if [ -r ${LIB}/$file ]; then
822 echo Fixing $file, overeager sed script
823 sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
824 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
825 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
830 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
831 # declaration on Sun OS 4.x. We must only fix this on Sun OS 4.x, because
832 # many other systems have similar text but correct versions of the file.
833 # To ensure only Sun's is fixed, we grep for a likely unique string.
835 if [ -r $file ] && egrep '/\* @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2 \*/' $file > /dev/null; then
836 if [ ! -r ${LIB}/$file ]; then
837 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
838 chmod +w ${LIB}/$file 2>/dev/null
839 chmod a+r ${LIB}/$file 2>/dev/null
841 if [ -r ${LIB}/$file ]; then
843 cat > ${LIB}/$file << EOF
844 /* This file was generated by fixincludes */
849 extern void *memccpy();
850 extern void *memchr();
851 extern void *memcpy();
852 extern void *memset();
854 extern char *memccpy();
855 extern char *memchr();
856 extern char *memcpy();
857 extern char *memset();
858 #endif /* __STDC__ */
862 #endif /* __memory_h__ */
867 # parameters not const on DECstation Ultrix V4.0.
869 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
870 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
871 chmod +w ${LIB}/$file 2>/dev/null
872 chmod a+r ${LIB}/$file 2>/dev/null
875 if [ -r ${LIB}/$file ]; then
876 echo Fixing $file, non-const arg
877 sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
878 -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
879 -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
880 -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
881 -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
882 -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
883 -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
884 ${LIB}/$file > ${LIB}/${file}.sed
885 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
886 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
891 # parameters conflict with C++ new on rs/6000
893 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
894 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
895 chmod +w ${LIB}/$file 2>/dev/null
898 if [ -r ${LIB}/$file ]; then
899 echo Fixing $file, parameter name conflicts
900 sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
901 ${LIB}/$file > ${LIB}/${file}.sed
902 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
903 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
908 # Don't use or define the name va_list in stdio.h.
909 # This is for ANSI and also to interoperate properly with gvarargs.h.
911 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
912 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
913 chmod +w ${LIB}/$file 2>/dev/null
914 chmod a+r ${LIB}/$file 2>/dev/null
917 if [ -r ${LIB}/$file ]; then
918 echo Fixing $file, use of va_list
919 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
920 (echo "#define __need___va_list"
921 echo "#include <stdarg.h>") > ${LIB}/${file}.sed
922 # Use __gnuc_va_list in arg types in place of va_list.
923 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
924 # trailing parentheses and semicolon save all other systems from this.
925 # Define __va_list__ (something harmless and unused) instead of va_list.
926 # Don't claim to have defined va_list.
927 sed -e 's@ va_list @ __gnuc_va_list @' \
928 -e 's@ va_list)@ __gnuc_va_list)@' \
929 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
930 -e 's@ va_list@ __va_list__@' \
931 -e 's@\*va_list@*__va_list__@' \
932 -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
933 -e 's@VA_LIST@DUMMY_VA_LIST@' \
934 -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
935 ${LIB}/$file >> ${LIB}/${file}.sed
937 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
938 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
943 # Cancel out ansi_compat.h on Ultrix. Replace it with empty file.
945 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
946 if grep -s ULTRIX $file; then
947 echo "/* This file intentionally left blank. */" > $LIB/$file
951 # parameter to atof not const on DECstation Ultrix V4.0.
952 # also get rid of bogus inline definitions in HP-UX 8.0
954 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
955 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
956 chmod +w ${LIB}/$file 2>/dev/null
957 chmod a+r ${LIB}/$file 2>/dev/null
960 if [ -r ${LIB}/$file ]; then
961 echo Fixing $file, non-const arg
962 sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
963 -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
964 -e 's@inline double abs(double d) { return fabs(d); }@@' \
965 ${LIB}/$file > ${LIB}/${file}.sed
966 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
967 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
972 # In limits.h, put #ifndefs around things that are supposed to be defined
973 # in float.h to avoid redefinition errors if float.h is included first.
974 # On HP/UX this patch does not work, because on HP/UX limits.h uses
975 # multi line comments and the inserted #endif winds up inside the
976 # comment. Fortunately, HP/UX already uses #ifndefs in limits.h; if
977 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
978 # are there, and we do not add them ourselves.
980 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
981 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
982 chmod +w ${LIB}/$file 2>/dev/null
983 chmod a+r ${LIB}/$file 2>/dev/null
986 if [ -r ${LIB}/$file ]; then
987 if egrep 'ifndef[ ]+FLT_MIN' ${LIB}/$file >/dev/null; then
991 sed -e '/[ ]FLT_MIN[ ]/i\
993 -e '/[ ]FLT_MIN[ ]/a\
995 -e '/[ ]FLT_MAX[ ]/i\
997 -e '/[ ]FLT_MAX[ ]/a\
999 -e '/[ ]FLT_DIG[ ]/i\
1001 -e '/[ ]FLT_DIG[ ]/a\
1003 -e '/[ ]DBL_MIN[ ]/i\
1005 -e '/[ ]DBL_MIN[ ]/a\
1007 -e '/[ ]DBL_MAX[ ]/i\
1009 -e '/[ ]DBL_MAX[ ]/a\
1011 -e '/[ ]DBL_DIG[ ]/i\
1013 -e '/[ ]DBL_DIG[ ]/a\
1015 ${LIB}/$file > ${LIB}/${file}.sed
1016 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1018 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1019 echo Deleting ${LIB}/$file\; no fixes were needed.
1024 # These two files on SunOS 4 are included by other files
1025 # in the same directory, using "...". So we must make sure they exist
1026 # in the same directory as the other fixed files.
1027 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1029 ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1031 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1033 ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1036 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1037 # need to fix some additional files. This is the same test for ISC that
1039 if test -d /etc/conf/kconfig.d \
1040 && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1041 echo "Fixing ISC __STDC__ goof in several files..."
1042 for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1044 if test -r ${LIB}/$name; then
1049 # On Interactive 2.2, certain traditional Unix definitions
1050 # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1051 # defined, not just if _POSIX_SOURCE is defined. This makes it
1052 # impossible to compile any nontrivial program except with -posix.
1054 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1055 < $file > ${LIB}/$name.
1056 mv ${LIB}/$name. ${LIB}/$name
1059 echo "Fixing ISC fmod declaration"
1060 # This one's already been fixed for other things.
1062 sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1065 echo "Fixing nested comments in ISC <sys/limits.h>"
1067 sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1068 sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1071 echo 'Removing unneeded directories:'
1073 files=`find . -type d -print | sort -r`
1074 for file in $files; do
1075 rmdir $LIB/$file > /dev/null 2>&1
1079 echo 'Making internal symbolic non-directory links'
1081 files=`find . -type l -print`
1082 for file in $files; do
1083 dest=`ls -ld $file | sed -n 's/.*-> //p'`
1084 if expr "$dest" : '[^/].*' > /dev/null; then
1085 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1086 if [ -f $target ]; then
1087 ln -s $dest ${LIB}/$file >/dev/null 2>&1
1093 echo 'Cleaning up DONE files.'
1095 find . -name DONE -exec rm -f {} ';'