2 # Install modified versions of certain ANSI-incompatible system header files
3 # which are fixed to work correctly with ANSI C
4 # and placed in a directory that GNU C will search.
6 # See README-fixinc for more information.
8 # Directory where gcc sources (and sometimes special include files) live.
9 # fixincludes doesn't use this, but fixinc.svr4 does, and I want to make
10 # sure somebody doesn't try to use arg3 for something incompatible. -- gumby
11 SRCDIR=${3-${SRCDIR-.}}
13 # Directory containing the original header files.
14 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
15 INPUT=${2-${INPUT-/usr/include}}
17 # Directory in which to store the results.
18 LIB=${1?"fixincludes: output directory not specified"}
20 # Define PWDCMD as a command to use to get the working dir
21 # in the form that we want.
25 # On an Apollo, discard everything before `/usr'.
26 PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
33 # Make sure it exists.
34 if [ ! -d $LIB ]; then
38 # Make LIB absolute only if needed to avoid problems with the amd.
43 cd $LIB; LIB=`${PWDCMD}`
47 # Make SRCDIR absolute only if needed to avoid problems with the amd.
53 cd $SRCDIR; SRCDIR=`${PWDCMD}`
57 # Fail if no arg to specify a directory for the output.
59 then echo fixincludes: no output directory specified
63 echo Building fixed headers in ${LIB}
65 # Determine whether this system has symbolic links.
66 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
67 rm -f $LIB/ShouldNotExist
73 echo Finding directories and links to directories
75 # Find all directories and all symlinks that point to directories.
76 # Put the list in $files.
77 # Each time we find a symlink, add it to newdirs
78 # so that we do another find within the dir the link points to.
79 # Note that $files may have duplicates in it;
80 # later parts of this file are supposed to ignore them.
83 while [ -n "$dirs" ] && [ $levels -gt 0 ]
85 levels=`expr $levels - 1`
89 echo " Searching $INPUT/$d"
95 # Find all directories under $d, relative to $d, excluding $d itself.
96 files="$files `find $d -type d -print | \
97 sed -e '/\/\.$/d' -e '/^\.$/d'`"
98 # Find all links to directories.
99 # Using `-exec test -d' in find fails on some systems,
100 # and trying to run test via sh fails on others,
101 # so this is the simplest alternative left.
102 # First find all the links, then test each one.
105 theselinks=`find $d -type l -print`
106 for d1 in $theselinks --dummy--
108 # If the link points to a directory,
109 # add that dir to $newdirs
112 newdirs="$newdirs $d1"
117 files="$files $newdirs"
122 echo "All directories (including links to directories):"
125 for file in $files; do
127 if [ ! -d $LIB/$file ]
128 then mkdir $LIB/$file
133 # treetops gets an alternating list
134 # of old directories to copy
135 # and the new directories to copy to.
136 treetops="${INPUT} ${LIB}"
139 echo 'Making symbolic directory links'
140 for file in $files; do
141 dest=`ls -ld $file | sed -n 's/.*-> //p'`
144 # In case $dest is relative, get to $file's dir first.
146 cd `echo ./$file | sed -n 's&[^/]*$&&p'`
147 # Check that the target directory exists.
148 # Redirections changed to avoid bug in sh on Ultrix.
149 (cd $dest) > /dev/null 2>&1
152 # X gets the dir that the link actually leads to.
154 # If a link points to ., make a similar link to .
155 if [ $x = $INPUT ]; then
156 echo $file '->' . ': Making link'
157 rm -fr ${LIB}/$file > /dev/null 2>&1
158 ln -s . ${LIB}/$file > /dev/null 2>&1
159 # If link leads back into ${INPUT},
160 # make a similar link here.
161 elif expr $x : "${INPUT}/.*" > /dev/null; then
162 # Y gets the actual target dir name, relative to ${INPUT}.
163 y=`echo $x | sed -n "s&${INPUT}/&&p"`
164 echo $file '->' $y ': Making link'
165 rm -fr ${LIB}/$file > /dev/null 2>&1
166 ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
168 # If the link is to a dir $target outside ${INPUT},
169 # repoint the link at ${INPUT}/root$target
170 # and process $target into ${INPUT}/root$target
171 # treat this directory as if it actually contained the files.
172 echo $file '->' root$x ': Making link'
173 if [ -d $LIB/root$x ]
179 while [ x$dirname != x ]; do
180 component=`echo $dirname | sed -e 's|/.*$||'`
181 mkdir $component >/dev/null 2>&1
183 dirmade=$dirmade/$component
184 dirname=`echo $dirname | sed -e 's|[^/]*/||'`
187 # Duplicate directory structure created in ${LIB}/$file in new
189 for file2 in $files; do
192 dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
193 echo "Duplicating ${file}'s ${dupdir}"
204 rm -fr ${LIB}/$file > /dev/null 2>&1
205 ln -s ${LIB}/root$x ${LIB}/$file > /dev/null 2>&1
206 treetops="$treetops $x ${LIB}/root$x"
216 while [ $# != 0 ]; do
217 # $1 is an old directory to copy, and $2 is the new directory to copy to.
220 # The same dir can appear more than once in treetops.
221 # There's no need to scan it more than once.
227 echo Fixing directory $1 into $2
228 # Check .h files which are symlinks as well as those which are files.
229 # A link to a header file will not be processed by anything but this.
231 files=`find . -name '*.h' \( -type f -o -type l \) -print`
233 files=`find . -name '*.h' -type f -print`
235 echo Checking header files
237 # Note that BSD43_* are used on recent MIPS systems.
238 for file in $files; do
239 # This call to egrep is essential, since checking a file with egrep
240 # is much faster than actually trying to fix it.
241 # It is also essential that most files *not* match!
242 # Thus, matching every #endif is unacceptable.
243 # But the argument to egrep must be kept small, or many versions of egrep
244 # won't be able to handle it.
246 # We use the pattern [!-.0-~] instead of [^/ ] to match a noncomment
247 # following #else or #endif because some buggy egreps think [^/] matches
248 # newline, and they thus think `#else ' matches `#e[ndiflse]*[ ]+[^/ ]'.
250 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
251 # following #if or #elif that is not surrounded by __. The `a-ce-km-z'
252 # in this pattern lacks `d' and `l'; this means we don't worry about
253 # identifiers starting with `d' or `l'. This is OK, since none of the
254 # identifiers below start with `d' or `l'. It also greatly improves
255 # performance, since many files contain lines of the form `#if ... defined ...'
257 if egrep '//|[ _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[ ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-z][a-z0-9]' $file >/dev/null; then
258 if [ -r $file ]; then
259 cp $file $2/$file >/dev/null 2>&1 \
260 || echo "Can't copy $file"
263 # Here is how the sed commands in braces work.
264 # (It doesn't work to put the comments inside the sed commands.)
265 # Surround each word with spaces, to simplify matching below.
266 # ANSIfy each pre-ANSI machine-dependent symbol
267 # by surrounding it with __ __.
268 # Remove the spaces that we inserted around each word.
273 s%^\([ ]*#[ ]*endif[ ]*\)\([^/ ].*\)$%\1/* \2 */%
274 s%^\([ ]*#[ ]*else[ ]*\)\([^/ ].*\)$%\1/* \2 */%
275 /\/\/[^*]/ s|//\(.*\)$|/*\1*/|
276 /[ ]_IO[A-Z]*[ ]*(/ s/\(_IO[A-Z]*[ ]*(\)\(.\),/\1'\''\2'\'',/
277 /[ ]BSD43__IO[A-Z]*[ ]*(/ s/(\(.\),/('\''\1'\'',/
278 /#define._IO/ s/'\''\([cgx]\)'\''/\1/g
279 /#define.BSD43__IO/ s/'\''\([cgx]\)'\''/\1/g
280 /[^A-Z0-9_]CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
281 /[^A-Z0-9]_CTRL[ ]*(/ s/\([^'\'']\))/'\''\1'\'')/
282 /#define.CTRL/ s/'\''\([cgx]\)'\''/\1/g
283 /#define._CTRL/ s/'\''\([cgx]\)'\''/\1/g
284 /#define.BSD43_CTRL/ s/'\''\([cgx]\)'\''/\1/g
286 s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
288 s/ bsd4\([0-9]\) / __bsd4\1__ /g
289 s/ _*i386 / __i386__ /g
290 s/ is68k / __is68k__ /g
291 s/ m68k / __m68k__ /g
292 s/ mc680\([0-9]\)0 / __mc680\10__ /g
293 s/ news\([0-9]*\) / __news\1__ /g
294 s/ ns32000 / __ns32000__ /g
296 s/ sony_news / __sony_news__ /g
297 s/ sparc / __sparc__ /g
298 s/ sun\([a-z0-9]*\) / __sun\1__ /g
299 s/ unix / __unix__ /g
302 s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
304 /^#define.NULL[ ]/ i\
306 ' $2/$file > $2/$file.
307 mv $2/$file. $2/$file
308 if cmp $file $2/$file >/dev/null 2>&1; then
321 # Install the proper definition of size_t in header files that it comes from.
322 for file in sys/types.h sys/stdtypes.h;
324 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
325 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
326 chmod +w ${LIB}/$file 2>/dev/null
327 chmod a+r ${LIB}/$file 2>/dev/null
330 if [ -r ${LIB}/$file ]; then
331 echo Fixing $file comment
332 # Extract the definition of SIZE_TYPE, if any.
333 # (This file must be called something.c).
334 echo "#include \"tm.h\"
335 gobblegobble SIZE_TYPE" > ${LIB}/types.c
336 foo=`cd ${LIB}; cc -E -I${ORIGDIR} -I${SRCDIR} -I${SRCDIR}/config types.c | grep gobblegobble | sed -e "s/gobblegobble[ ]*//"`
338 # Default to our preferred type.
339 if [ "$foo" = SIZE_TYPE ]; then foo="unsigned long int"; else foo=`echo $foo | sed -e 's/^.*"\(.*\)".*$/\1/'`; fi
340 sed -e "s/typedef[ a-z_]*[ ]size_t/typedef $foo size_t/" ${LIB}/$file > ${LIB}/${file}.sed
341 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
342 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
348 # Fix one other error in this file: a mismatched quote not inside a C comment.
349 file=sundev/vuid_event.h
350 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
351 mkdir ${LIB}/sundev 2>/dev/null
352 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
353 chmod +w ${LIB}/$file 2>/dev/null
354 chmod a+r ${LIB}/$file 2>/dev/null
357 if [ -r ${LIB}/$file ]; then
358 echo Fixing $file comment
359 sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
360 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
361 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
366 # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
367 file=sunwindow/win_cursor.h
368 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
369 # mkdir ${LIB}/sunwindow 2>/dev/null
370 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
371 chmod +w ${LIB}/$file 2>/dev/null
373 if [ -r ${LIB}/$file ]; then
375 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
376 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
377 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
381 file=sunwindow/win_lock.h
382 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
383 # mkdir ${LIB}/sunwindow 2>/dev/null
384 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
385 chmod +w ${LIB}/$file 2>/dev/null
387 if [ -r ${LIB}/$file ]; then
389 sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
390 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
391 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
396 # Fix this Sun file to avoid interfering with stddef.h.
398 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
399 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
400 chmod +w ${LIB}/$file 2>/dev/null
401 chmod a+r ${LIB}/$file 2>/dev/null
404 if [ -r ${LIB}/$file ]; then
406 sed -e '/size_t.*;/i\
408 #define _GCC_SIZE_T' \
412 #ifndef _GCC_PTRDIFF_T\
413 #define _GCC_PTRDIFF_T' \
417 #ifndef _GCC_WCHAR_T\
418 #define _GCC_WCHAR_T' \
420 #endif' ${LIB}/$file > ${LIB}/${file}.sed
421 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
422 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
427 # Fix this file to avoid interfering with stddef.h, but don't mistakenly
428 # match e.g. ssize_t present in AIX for the ps/2.
430 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
431 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
432 chmod +w ${LIB}/$file 2>/dev/null
433 chmod a+r ${LIB}/$file 2>/dev/null
436 if [ -r ${LIB}/$file ]; then
438 sed -e '/[ ]size_t.*;/i\
440 #define _GCC_SIZE_T' \
442 #endif' ${LIB}/$file > ${LIB}/${file}.sed
443 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
444 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
449 # Fix an error in this file: the #if says _cplusplus, not the double
450 # underscore __cplusplus that it should be
452 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
453 mkdir ${LIB}/rpcsvc 2>/dev/null
454 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
455 chmod +w ${LIB}/$file 2>/dev/null
456 chmod a+r ${LIB}/$file 2>/dev/null
459 if [ -r ${LIB}/$file ]; then
460 echo Fixing $file, __cplusplus macro
461 sed -e 's/[ ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
462 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
463 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
468 # Fix an error in this file: a missing semi-colon at the end of the statsswtch
469 # structure definition.
471 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
472 mkdir ${LIB}/rpcsvc 2>/dev/null
473 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
474 chmod +w ${LIB}/$file 2>/dev/null
475 chmod a+r ${LIB}/$file 2>/dev/null
478 if [ -r ${LIB}/$file ]; then
479 echo Fixing $file, definition of statsswtch
480 sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
481 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
482 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
487 # Fix an error in this file: a missing semi-colon at the end of the nodeent
488 # structure definition.
489 file=netdnet/dnetdb.h
490 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
491 mkdir ${LIB}/netdnet 2>/dev/null
492 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
493 chmod +w ${LIB}/$file 2>/dev/null
494 chmod a+r ${LIB}/$file 2>/dev/null
497 if [ -r ${LIB}/$file ]; then
498 echo Fixing $file, definition of nodeent
499 sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
500 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
501 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
506 # Check for bad #ifdef line (in Ultrix 4.1)
508 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
509 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
510 chmod +w ${LIB}/$file 2>/dev/null
511 chmod a+r ${LIB}/$file 2>/dev/null
514 if [ -r ${LIB}/$file ]; then
515 echo Fixing $file, bad \#ifdef line
516 sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
517 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
518 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
523 # Remove nested comments created by #endifs in a comment (Ultrix 4.1)
524 # Only needed if commenting out junk after #endif.
526 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
527 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
528 chmod +w ${LIB}/$file 2>/dev/null
529 chmod a+r ${LIB}/$file 2>/dev/null
532 if [ -r ${LIB}/$file ]; then
533 echo Fixing $file, nested comments
534 sed -e 's/^[ ]*#endif.*/#endif/' ${LIB}/$file > ${LIB}/${file}.sed
535 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
536 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
541 # Check for superfluous `static' (in Ultrix 4.2)
543 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
544 mkdir ${LIB}/machine 2>/dev/null
545 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
546 chmod +w ${LIB}/$file 2>/dev/null
547 chmod a+r ${LIB}/$file 2>/dev/null
550 if [ -r ${LIB}/$file ]; then
551 echo Fixing $file, superfluous static
552 sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' ${LIB}/$file > ${LIB}/${file}.sed
553 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
554 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
557 # This file has an alternative name, mips/cpu.h. Fix that name, too.
558 if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
559 mkdir ${LIB}/mips 2>&-
560 ln ${LIB}/$file ${LIB}/mips/cpu.h
565 # Incorrect sprintf declaration in X11/Xmu.h
567 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
568 mkdir ${LIB}/X11 2>/dev/null
569 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
570 chmod +w ${LIB}/$file 2>/dev/null
571 chmod a+r ${LIB}/$file 2>/dev/null
574 if [ -r ${LIB}/$file ]; then
575 echo Fixing $file sprintf declaration
576 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
577 extern char * sprintf();\
578 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
579 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
580 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
585 # Incorrect sprintf declaration in X11/Xmu/Xmu.h
586 # (It's not clear whether the right file name is this or X11/Xmu.h.)
588 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
589 mkdir ${LIB}/X11/Xmu 2>/dev/null
590 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
591 chmod +w ${LIB}/$file 2>/dev/null
592 chmod a+r ${LIB}/$file 2>/dev/null
595 if [ -r ${LIB}/$file ]; then
596 echo Fixing $file sprintf declaration
597 sed -e 's,^extern char \* sprintf();$,#ifndef __STDC__\
598 extern char * sprintf();\
599 #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
600 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
601 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
606 # Check for missing ';' in struct
608 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
609 mkdir ${LIB}/netinet 2>/dev/null
610 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
611 chmod +w ${LIB}/$file 2>/dev/null
612 chmod a+r ${LIB}/$file 2>/dev/null
615 if [ -r ${LIB}/$file ]; then
617 sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
618 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
619 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
624 # Fix the CAT macro in SunOS memvar.h.
625 file=pixrect/memvar.h
626 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
627 mkdir ${LIB}/pixrect 2>/dev/null
628 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
629 chmod +w ${LIB}/$file 2>/dev/null
630 chmod a+r ${LIB}/$file 2>/dev/null
633 if [ -r ${LIB}/$file ]; then
635 sed -e '/^#define.CAT(a,b)/ i\
637 #define CAT(a,b) a##b\
639 /^#define.CAT(a,b)/ a\
641 ' ${LIB}/$file > ${LIB}/${file}.sed
642 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
643 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
648 # Check for yet more missing ';' in struct (in SunOS 4.0.x)
650 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
651 mkdir ${LIB}/rpcsvc 2>/dev/null
652 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
653 chmod +w ${LIB}/$file 2>/dev/null
654 chmod a+r ${LIB}/$file 2>/dev/null
657 if [ -r ${LIB}/$file ]; then
659 sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
660 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
661 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
666 # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
668 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
669 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
670 chmod +w ${LIB}/$file 2>/dev/null
671 chmod a+r ${LIB}/$file 2>/dev/null
674 if [ -r ${LIB}/$file ]; then
676 sed -e 's/int abort/void abort/g' \
677 -e 's/int free/void free/g' \
678 -e 's/char \* calloc/void \* calloc/g' \
679 -e 's/char \* malloc/void \* malloc/g' \
680 -e 's/char \* realloc/void \* realloc/g' \
681 -e 's/int exit/void exit/g' ${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
708 # Fix bogus comment in <locale.h> on SunOS 4.1.
710 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
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%#endif / \*%#endif /\* %g' ${LIB}/$file > ${LIB}/${file}.sed
719 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
720 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
725 # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
726 file=hsfs/hsfs_spec.h
727 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
728 mkdir ${LIB}/hsfs 2>/dev/null
729 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
730 chmod +w ${LIB}/$file 2>/dev/null
731 chmod a+r ${LIB}/$file 2>/dev/null
734 if [ -r ${LIB}/$file ]; then
736 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
737 ${LIB}/$file > ${LIB}/${file}.
738 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
739 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
744 # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
746 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
747 mkdir ${LIB}/hsfs 2>/dev/null
748 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
749 chmod +w ${LIB}/$file 2>/dev/null
750 chmod a+r ${LIB}/$file 2>/dev/null
753 if [ -r ${LIB}/$file ]; then
755 sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
756 ${LIB}/$file > ${LIB}/${file}.sed
757 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
758 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
763 # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
765 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
766 mkdir ${LIB}/hsfs 2>/dev/null
767 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
768 chmod +w ${LIB}/$file 2>/dev/null
769 chmod a+r ${LIB}/$file 2>/dev/null
772 if [ -r ${LIB}/$file ]; then
774 sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
775 ${LIB}/$file > ${LIB}/${file}.sed
776 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
777 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
782 # Incorrect #include in Sony News-OS 3.2.
783 file=machine/machparam.h
784 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
785 mkdir ${LIB}/machine 2>/dev/null
786 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
787 chmod +w ${LIB}/$file 2>/dev/null
788 chmod a+r ${LIB}/$file 2>/dev/null
791 if [ -r ${LIB}/$file ]; then
792 echo Fixing $file, incorrect \#include
793 sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
794 ${LIB}/$file > ${LIB}/${file}.
795 rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
796 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
801 # Multiline comment after typedef on IRIX 4.0.1.
803 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
804 mkdir ${LIB}/sys 2>/dev/null
805 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
806 chmod +w ${LIB}/$file 2>/dev/null
807 chmod a+r ${LIB}/$file 2>/dev/null
810 if [ -r ${LIB}/$file ]; then
811 echo Fixing $file, comment in the middle of \#ifdef
812 sed -e 's@type of the result@type of the result */@' \
813 -e 's@of the sizeof@/* of the sizeof@' \
814 ${LIB}/$file > ${LIB}/${file}.sed
815 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
816 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
821 # Fix line in IRIX 4.0.1 header file. The sed script turns
822 # #define EM_CTRL (CUTIOC|0x1)
824 # #define EM_CTRL (CUTIOC|0x'1')
826 if [ -r ${LIB}/$file ]; then
827 echo Fixing $file, overeager sed script
828 sed -e "s/0x'1'/0x1/" ${LIB}/$file > ${LIB}/${file}.sed
829 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
830 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
835 # Turning // comments into /* */ comments trashes this IRIX 4.0.1
836 # header file, which embeds // comments inside multi-line /* */
837 # comments. If this looks like the IRIX header file, we refix it by
838 # just throwing away the // comments.
840 if [ -r ${LIB}/$file ]; then
841 if egrep indigo.esd ${LIB}/$file > /dev/null; then
842 echo Fixing $file, overeager sed script
844 sed -e 's|//.*$||g' $file > ${LIB}/$file
845 chmod +w ${LIB}/$file 2>/dev/null
846 chmod a+r ${LIB}/$file 2>/dev/null
850 # Another IRIX 4.0.1 header file contains the string "//"
852 if [ -r ${LIB}/$file ]; then
853 echo Fixing $file, overeager sed script
854 sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
855 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
856 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
861 # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
862 # declaration on Sun OS 4.x. We must only fix this on Sun OS 4.x, because
863 # many other systems have similar text but correct versions of the file.
864 # To ensure only Sun's is fixed, we grep for a likely unique string.
866 if [ -r $file ] && egrep '/\* @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2 \*/' $file > /dev/null; then
867 if [ ! -r ${LIB}/$file ]; then
868 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
869 chmod +w ${LIB}/$file 2>/dev/null
870 chmod a+r ${LIB}/$file 2>/dev/null
872 if [ -r ${LIB}/$file ]; then
874 cat > ${LIB}/$file << EOF
875 /* This file was generated by fixincludes */
880 extern void *memccpy();
881 extern void *memchr();
882 extern void *memcpy();
883 extern void *memset();
885 extern char *memccpy();
886 extern char *memchr();
887 extern char *memcpy();
888 extern char *memset();
889 #endif /* __STDC__ */
893 #endif /* __memory_h__ */
898 # parameters not const on DECstation Ultrix V4.0.
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, non-const arg
908 sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
909 -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
910 -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
911 -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
912 -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
913 -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
914 -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
915 ${LIB}/$file > ${LIB}/${file}.sed
916 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
917 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
922 # parameters conflict with C++ new on rs/6000
924 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
925 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
926 chmod +w ${LIB}/$file 2>/dev/null
929 if [ -r ${LIB}/$file ]; then
930 echo Fixing $file, parameter name conflicts
931 sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
932 ${LIB}/$file > ${LIB}/${file}.sed
933 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
934 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
939 # Don't use or define the name va_list in stdio.h.
940 # This is for ANSI and also to interoperate properly with gvarargs.h.
942 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
943 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
944 chmod +w ${LIB}/$file 2>/dev/null
945 chmod a+r ${LIB}/$file 2>/dev/null
948 if [ -r ${LIB}/$file ]; then
949 echo Fixing $file, use of va_list
950 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
951 (echo "#define __need___va_list"
952 echo "#include <stdarg.h>") > ${LIB}/${file}.sed
953 # Use __gnuc_va_list in arg types in place of va_list.
954 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
955 # trailing parentheses and semicolon save all other systems from this.
956 # Define __va_list__ (something harmless and unused) instead of va_list.
957 # Don't claim to have defined va_list.
958 sed -e 's@ va_list @ __gnuc_va_list @' \
959 -e 's@ va_list)@ __gnuc_va_list)@' \
960 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
961 -e 's@ va_list@ __va_list__@' \
962 -e 's@\*va_list@*__va_list__@' \
963 -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
964 -e 's@VA_LIST@DUMMY_VA_LIST@' \
965 -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
966 ${LIB}/$file >> ${LIB}/${file}.sed
968 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
969 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
974 # Cancel out ansi_compat.h on Ultrix. Replace it with empty file.
976 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
977 if grep -s ULTRIX $file; then
978 echo "/* This file intentionally left blank. */" > $LIB/$file
982 # parameter to atof not const on DECstation Ultrix V4.0.
983 # also get rid of bogus inline definitions in HP-UX 8.0
985 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
986 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
987 chmod +w ${LIB}/$file 2>/dev/null
988 chmod a+r ${LIB}/$file 2>/dev/null
991 if [ -r ${LIB}/$file ]; then
992 echo Fixing $file, non-const arg
993 sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
994 -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
995 -e 's@inline double abs(double d) { return fabs(d); }@@' \
996 ${LIB}/$file > ${LIB}/${file}.sed
997 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
998 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1003 # In limits.h, put #ifndefs around things that are supposed to be defined
1004 # in float.h to avoid redefinition errors if float.h is included first.
1005 # On HP/UX this patch does not work, because on HP/UX limits.h uses
1006 # multi line comments and the inserted #endif winds up inside the
1007 # comment. Fortunately, HP/UX already uses #ifndefs in limits.h; if
1008 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
1009 # are there, and we do not add them ourselves.
1011 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
1012 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
1013 chmod +w ${LIB}/$file 2>/dev/null
1014 chmod a+r ${LIB}/$file 2>/dev/null
1017 if [ -r ${LIB}/$file ]; then
1018 if egrep 'ifndef[ ]+FLT_MIN' ${LIB}/$file >/dev/null; then
1022 sed -e '/[ ]FLT_MIN[ ]/i\
1024 -e '/[ ]FLT_MIN[ ]/a\
1026 -e '/[ ]FLT_MAX[ ]/i\
1028 -e '/[ ]FLT_MAX[ ]/a\
1030 -e '/[ ]FLT_DIG[ ]/i\
1032 -e '/[ ]FLT_DIG[ ]/a\
1034 -e '/[ ]DBL_MIN[ ]/i\
1036 -e '/[ ]DBL_MIN[ ]/a\
1038 -e '/[ ]DBL_MAX[ ]/i\
1040 -e '/[ ]DBL_MAX[ ]/a\
1042 -e '/[ ]DBL_DIG[ ]/i\
1044 -e '/[ ]DBL_DIG[ ]/a\
1046 ${LIB}/$file > ${LIB}/${file}.sed
1047 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1049 if cmp $file ${LIB}/$file >/dev/null 2>&1; then
1050 echo Deleting ${LIB}/$file\; no fixes were needed.
1055 # These two files on SunOS 4 are included by other files
1056 # in the same directory, using "...". So we must make sure they exist
1057 # in the same directory as the other fixed files.
1058 if [ -r ${INPUT}/multimedia/audio_errno.h ]
1060 ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
1062 if [ -r ${INPUT}/multimedia/audio_hdr.h ]
1064 ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
1067 # Determine if we're on Interactive Unix 2.2 or later, in which case we
1068 # need to fix some additional files. This is the same test for ISC that
1070 if test -d /etc/conf/kconfig.d \
1071 && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
1072 echo "Fixing ISC __STDC__ goof in several files..."
1073 for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
1075 if test -r ${LIB}/$name; then
1080 # On Interactive 2.2, certain traditional Unix definitions
1081 # (notably getc and putc in stdio.h) are omitted if __STDC__ is
1082 # defined, not just if _POSIX_SOURCE is defined. This makes it
1083 # impossible to compile any nontrivial program except with -posix.
1085 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
1086 < $file > ${LIB}/$name.
1087 mv ${LIB}/$name. ${LIB}/$name
1090 echo "Fixing ISC fmod declaration"
1091 # This one's already been fixed for other things.
1093 sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
1096 echo "Fixing nested comments in ISC <sys/limits.h>"
1098 sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
1099 sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
1102 # These files on Ultrix 4.2 put comments around instances of #endif
1103 # __mips. When the sed expression turns that into #endif /* __mips */
1104 # the comment ends prematurely.
1105 for file in sys/audit.h sys/signal.h; do
1106 if [ -r ${LIB}/${file} ]; then
1107 echo Fixing $file, early comment termination
1108 sed -e 's|^#endif /\*.*\*/|#endif|g' ${LIB}/${file} > ${LIB}/${file}.sed
1109 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
1113 echo 'Removing unneeded directories:'
1115 files=`find . -type d -print | sort -r`
1116 for file in $files; do
1117 rmdir $LIB/$file > /dev/null 2>&1
1121 echo 'Making internal symbolic non-directory links'
1123 files=`find . -type l -print`
1124 for file in $files; do
1125 dest=`ls -ld $file | sed -n 's/.*-> //p'`
1126 if expr "$dest" : '[^/].*' > /dev/null; then
1127 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
1128 if [ -f $target ]; then
1129 ln -s $dest ${LIB}/$file >/dev/null 2>&1
1135 echo 'Cleaning up DONE files.'
1137 find . -name DONE -exec rm -f {} ';'