home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gcc-2.7.2.1-base.tgz / gcc-2.7.2.1-base.tar / fsf / gcc / fixincludes < prev    next >
Text File  |  1996-06-29  |  91KB  |  2,556 lines

  1. #! /bin/sh
  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.
  5.  
  6. # See README-fixinc for more information.
  7.  
  8. # Directory containing the original header files.
  9. # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
  10. INPUT=${2-${INPUT-/usr/include}}
  11.  
  12. # Directory in which to store the results.
  13. LIB=${1?"fixincludes: output directory not specified"}
  14.  
  15. # Define PWDCMD as a command to use to get the working dir
  16. # in the form that we want.
  17. PWDCMD=pwd
  18. case "`pwd`" in
  19. //*)
  20.     # On an Apollo, discard everything before `/usr'.
  21.     PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
  22.     ;;
  23. esac
  24.  
  25. # Original directory.
  26. ORIGDIR=`${PWDCMD}`
  27.  
  28. # Make sure it exists.
  29. if [ ! -d $LIB ]; then
  30.   mkdir $LIB || exit 1
  31. fi
  32.  
  33. # Make LIB absolute only if needed to avoid problems with the amd.
  34. case $LIB in
  35. /*)
  36.     ;;
  37. *)
  38.     cd $LIB; LIB=`${PWDCMD}`
  39.     ;;
  40. esac
  41.  
  42. # Fail if no arg to specify a directory for the output.
  43. if [ x$1 = x ]
  44. then echo fixincludes: no output directory specified
  45. exit 1
  46. fi
  47.  
  48. echo Building fixed headers in ${LIB}
  49.  
  50. # Determine whether this system has symbolic links.
  51. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  52.   rm -f $LIB/ShouldNotExist
  53.   LINKS=true
  54. elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
  55.   rm -f /tmp/ShouldNotExist
  56.   LINKS=true
  57. else
  58.   LINKS=false
  59. fi
  60.  
  61. echo Finding directories and links to directories
  62. cd ${INPUT}
  63. # Find all directories and all symlinks that point to directories.
  64. # Put the list in $files.
  65. # Each time we find a symlink, add it to newdirs
  66. # so that we do another find within the dir the link points to.
  67. # Note that $files may have duplicates in it;
  68. # later parts of this file are supposed to ignore them.
  69. dirs="."
  70. levels=2
  71. while [ -n "$dirs" ] && [ $levels -gt 0 ]
  72. do
  73.     levels=`expr $levels - 1`
  74.     newdirs=
  75.     for d in $dirs
  76.     do
  77.     echo " Searching $INPUT/$d"
  78.     if [ "$d" != . ]
  79.     then
  80.         d=$d/.
  81.     fi
  82.  
  83.     # Find all directories under $d, relative to $d, excluding $d itself.
  84.         files="$files `find $d -type d -print | \
  85.                sed -e '/\/\.$/d' -e '/^\.$/d'`"
  86.     # Find all links to directories.
  87.     # Using `-exec test -d' in find fails on some systems,
  88.     # and trying to run test via sh fails on others,
  89.     # so this is the simplest alternative left.
  90.     # First find all the links, then test each one.
  91.     theselinks=
  92.     $LINKS && \
  93.       theselinks=`find $d -type l -print`
  94.     for d1 in $theselinks --dummy--
  95.     do
  96.         # If the link points to a directory,
  97.         # add that dir to $newdirs
  98.         if [ -d $d1 ]
  99.         then
  100.         files="$files $d1"
  101.         if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
  102.         then
  103.             newdirs="$newdirs $d1"
  104.         fi
  105.         fi
  106.     done
  107.     done
  108.  
  109.     dirs="$newdirs"
  110. done
  111.  
  112. dirs=
  113. echo "All directories (including links to directories):"
  114. echo $files
  115.  
  116. for file in $files; do
  117.   rm -rf $LIB/$file
  118.   if [ ! -d $LIB/$file ]
  119.   then mkdir $LIB/$file
  120.   fi
  121. done
  122. mkdir $LIB/root
  123.  
  124. # treetops gets an alternating list
  125. # of old directories to copy
  126. # and the new directories to copy to.
  127. treetops="${INPUT} ${LIB}"
  128.  
  129. if $LINKS; then
  130.   echo 'Making symbolic directory links'
  131.   for file in $files; do
  132.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  133.     if [ "$dest" ]; then    
  134.       cwd=`${PWDCMD}`
  135.       # In case $dest is relative, get to $file's dir first.
  136.       cd ${INPUT}
  137.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  138.       # Check that the target directory exists.
  139.       # Redirections changed to avoid bug in sh on Ultrix.
  140.       (cd $dest) > /dev/null 2>&1
  141.       if [ $? = 0 ]; then
  142.     cd $dest
  143.     # X gets the dir that the link actually leads to.
  144.     x=`${PWDCMD}`
  145.     # Canonicalize ${INPUT} now to minimize the time an
  146.     # automounter has to change the result of ${PWDCMD}.
  147.     cinput=`cd ${INPUT}; ${PWDCMD}`
  148.     # If a link points to ., make a similar link to .
  149.     if [ $x = ${cinput} ]; then
  150.       echo $file '->' . ': Making link'
  151.       rm -fr ${LIB}/$file > /dev/null 2>&1
  152.       ln -s . ${LIB}/$file > /dev/null 2>&1
  153.     # If link leads back into ${INPUT},
  154.     # make a similar link here.
  155.     elif expr $x : "${cinput}/.*" > /dev/null; then
  156.       # Y gets the actual target dir name, relative to ${INPUT}.
  157.       y=`echo $x | sed -n "s&${cinput}/&&p"`
  158.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  159.       dots=`echo "$file" |
  160.         sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
  161.       echo $file '->' $dots$y ': Making link'
  162.       rm -fr ${LIB}/$file > /dev/null 2>&1
  163.       ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
  164.     else
  165.       # If the link is to a dir $target outside ${INPUT},
  166.       # repoint the link at ${INPUT}/root$target
  167.       # and process $target into ${INPUT}/root$target
  168.       # treat this directory as if it actually contained the files.
  169.       echo $file '->' root$x ': Making link'
  170.       if [ -d $LIB/root$x ]
  171.       then true
  172.       else
  173.         dirname=root$x/
  174.         dirmade=.
  175.         cd $LIB
  176.         while [ x$dirname != x ]; do
  177.           component=`echo $dirname | sed -e 's|/.*$||'`
  178.           mkdir $component >/dev/null 2>&1
  179.           cd $component
  180.           dirmade=$dirmade/$component
  181.           dirname=`echo $dirname | sed -e 's|[^/]*/||'`
  182.         done
  183.       fi
  184.       # Duplicate directory structure created in ${LIB}/$file in new
  185.       # root area.
  186.       for file2 in $files; do
  187.         case $file2 in
  188.           $file/./*)
  189.         dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
  190.         echo "Duplicating ${file}'s ${dupdir}"
  191.         if [ -d ${dupdir} ]
  192.         then true
  193.         else
  194.           mkdir ${dupdir}
  195.         fi
  196.         ;;
  197.           *)
  198.         ;;
  199.         esac
  200.           done
  201.       # Get the path from ${LIB} to $file, accounting for symlinks.
  202.       parent=`echo "$file" | sed -e 's@/[^/]*$@@'`
  203.       libabs=`cd ${LIB}; ${PWDCMD}`
  204.       file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"`
  205.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  206.       dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'`
  207.       rm -fr ${LIB}/$file > /dev/null 2>&1
  208.       ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
  209.       treetops="$treetops $x ${LIB}/root$x"
  210.     fi
  211.       fi
  212.       cd $cwd
  213.     fi
  214.   done
  215. fi
  216.  
  217. required=
  218. set x $treetops
  219. shift
  220. while [ $# != 0 ]; do
  221.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  222.   cd ${INPUT}
  223.   cd $1
  224. # The same dir can appear more than once in treetops.
  225. # There's no need to scan it more than once.
  226.   if [ -f $2/DONE ]
  227.   then
  228.     files=
  229.   else
  230.     touch $2/DONE
  231.     echo Fixing directory $1 into $2
  232. # Check .h files which are symlinks as well as those which are files.
  233. # A link to a header file will not be processed by anything but this.
  234.     if $LINKS; then
  235.       files=`find . -name '*.h' \( -type f -o -type l \) -print`
  236.     else
  237.       files=`find . -name '*.h' -type f -print`
  238.     fi
  239.     echo Checking header files
  240.   fi
  241. # Note that BSD43_* are used on recent MIPS systems.
  242.   for file in $files; do
  243. # This call to egrep is essential, since checking a file with egrep
  244. # is much faster than actually trying to fix it.
  245. # It is also essential that most files *not* match!
  246. # Thus, matching every #endif is unacceptable.
  247. # But the argument to egrep must be kept small, or many versions of egrep
  248. # won't be able to handle it.
  249. #
  250. # We use the pattern [!-.0-~] instead of [^/     ] to match a noncomment
  251. # following #else or #endif because some buggy egreps think [^/] matches
  252. # newline, and they thus think `#else ' matches `#e[ndiflse]*[     ]+[^/     ]'.
  253. #
  254. # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
  255. # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
  256. # in this pattern lacks `d' and `l'; this means we don't worry about
  257. # identifiers starting with `d' or `l'.  This is OK, since none of the
  258. # identifiers below start with `d' or `l'.  It also greatly improves
  259. # performance, since many files contain lines of the form `#if ... defined ...'
  260. # or `#if lint'.
  261.     if egrep '//|[     _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[     ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-zA-Z][a-zA-Z0-9]' $file >/dev/null; then
  262.       if [ -r $file ]; then
  263.     cp $file $2/$file >/dev/null 2>&1    \
  264.     || echo "Can't copy $file"
  265.     chmod +w $2/$file
  266.     chmod a+r $2/$file
  267.     # Here is how the sed commands in braces work.
  268.     # (It doesn't work to put the comments inside the sed commands.)
  269.         # Surround each word with spaces, to simplify matching below.
  270.         # ANSIfy each pre-ANSI machine-dependent symbol
  271.         # by surrounding it with __ __.
  272.         # Remove the spaces that we inserted around each word.
  273.     sed -e '
  274.                    :loop
  275.       /\\$/            N
  276.       /\\$/            b loop
  277.       s%^\([     ]*#[     ]*else\)[     ]*/[^*].*%\1%
  278.       s%^\([     ]*#[     ]*else\)[     ]*[^/     ].*%\1%
  279.       s%^\([     ]*#[     ]*endif\)[     ]*/[^*].*%\1%
  280.       s%^\([     ]*#[     ]*endif\)[     ]*\*[^/].*%\1%
  281.       s%^\([     ]*#[     ]*endif\)[     ]*[^/*     ].*%\1%
  282.       /\/\/[^*]/            s|//\(.*\)$|/*\1*/|
  283.       /[     ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[     ]*(\)\(.\),/\1'\''\2'\'',/
  284.       /[     ]BSD43__IO[A-Z]*[     ]*(/    s/(\(.\),/('\''\1'\'',/
  285.       /#define._IO/            s/'\''\([cgxtf]\)'\''/\1/g
  286.       /#define.BSD43__IO/        s/'\''\([cgx]\)'\''/\1/g
  287.       /[^A-Z0-9_]CTRL[     ]*(/        s/\([^'\'']\))/'\''\1'\'')/
  288.       /[^A-Z0-9]_CTRL[     ]*(/        s/\([^'\'']\))/'\''\1'\'')/
  289.       /#define[     ]*[     ]CTRL/        s/'\''\([cgx]\)'\''/\1/g
  290.       /#define[     ]*[     ]_CTRL/        s/'\''\([cgx]\)'\''/\1/g
  291.       /#define.BSD43_CTRL/        s/'\''\([cgx]\)'\''/\1/g
  292.       /#[     ]*[el]*if/{
  293.         s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
  294.  
  295.         s/ bsd4\([0-9]\) / __bsd4\1__ /g
  296.         s/ _*host_mips / __host_mips__ /g
  297.         s/ _*i386 / __i386__ /g
  298.         s/ M32 / __M32__ /g
  299.         s/ is68k / __is68k__ /g
  300.         s/ m68k / __m68k__ /g
  301.         s/ mc680\([0-9]\)0 / __mc680\10__ /g
  302.         s/ m88k / __m88k__ /g
  303.         s/ _*mips / __mips__ /g
  304.         s/ news\([0-9]*\) / __news\1__ /g
  305.         s/ ns32000 / __ns32000__ /g
  306.         s/ pdp11 / __pdp11__ /g
  307.         s/ pyr / __pyr__ /g
  308.         s/ sel / __sel__ /g
  309.         s/ sony_news / __sony_news__ /g
  310.         s/ sparc / __sparc__ /g
  311.         s/ sun\([a-z0-9]*\) / __sun\1__ /g
  312.         s/ tahoe / __tahoe__ /g
  313.         s/ tower\([_0-9]*\) / __tower\1__ /g
  314.         s/ u370 / __u370__ /g
  315.         s/ u3b\([0-9]*\) / __u3b\1__ /g
  316.         s/ unix / __unix__ /g
  317.         s/ vax / __vax__ /g
  318.         s/ _*MIPSE\([LB]\) / __MIPSE\1__ /g
  319.         s/ _*\([Rr][34]\)000 / __\1000__ /g
  320.         s/ _*SYSTYPE_\([A-Z0-9]*\) / __SYSTYPE_\1__ /g
  321.  
  322.         s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
  323.       }
  324.       /^#define.NULL[     ]/    i\
  325.         #undef NULL
  326.     ' $2/$file > $2/$file.
  327.     mv $2/$file. $2/$file
  328.     if cmp $file $2/$file >/dev/null 2>&1 \
  329.         || egrep 'This file is part of the GNU C Library' $2/$file >/dev/null 2>&1; then
  330.        rm $2/$file
  331.     else
  332.        echo Fixed $file
  333.        # Find any include directives that use "file".
  334.        for include in `egrep '^[     ]*#[     ]*include[     ]*"[^/]' $2/$file | sed -e 's/^[     ]*#[     ]*include[     ]*"\([^"]*\)".*$/\1/'`; do
  335.           dir=`echo $file | sed -e s'|/[^/]*$||'`
  336.           required="$required $1 $dir/$include $2/$dir/$include"
  337.        done
  338.     fi
  339.       fi
  340.     fi
  341.   done
  342.   shift; shift
  343. done
  344.  
  345. cd ${INPUT}
  346.  
  347. # Install the proper definition of the three standard types in header files
  348. # that they come from.
  349. for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
  350.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  351.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  352.     chmod +w ${LIB}/$file 2>/dev/null
  353.     chmod a+r ${LIB}/$file 2>/dev/null
  354.   fi
  355.  
  356.   if [ -r ${LIB}/$file ]; then
  357.     echo Fixing size_t, ptrdiff_t and wchar_t in $file
  358.     sed \
  359.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]size_t/i\
  360. #ifndef __SIZE_TYPE__\
  361. #define __SIZE_TYPE__ long unsigned int\
  362. #endif
  363. ' \
  364.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]size_t/typedef __SIZE_TYPE__ size_t/' \
  365.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]ptrdiff_t/i\
  366. #ifndef __PTRDIFF_TYPE__\
  367. #define __PTRDIFF_TYPE__ long int\
  368. #endif
  369. ' \
  370.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
  371.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]wchar_t/i\
  372. #ifndef __WCHAR_TYPE__\
  373. #define __WCHAR_TYPE__ int\
  374. #endif\
  375. #ifndef __cplusplus
  376. ' \
  377.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]wchar_t/a\
  378. #endif
  379. ' \
  380.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
  381.       ${LIB}/$file > ${LIB}/${file}.sed
  382.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  383.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  384.       rm ${LIB}/$file
  385.     else
  386.       # Find any include directives that use "file".
  387.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  388.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  389.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  390.       done
  391.     fi
  392.   fi
  393. done
  394.  
  395. # Fix one other error in this file: a mismatched quote not inside a C comment.
  396. file=sundev/vuid_event.h
  397. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  398.   mkdir ${LIB}/sundev 2>/dev/null
  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
  402. fi
  403.  
  404. if [ -r ${LIB}/$file ]; then
  405.   echo Fixing $file comment
  406.   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
  407.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  408.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  409.     rm ${LIB}/$file
  410.   else
  411.     # Find any include directives that use "file".
  412.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  413.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  414.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  415.     done
  416.   fi
  417. fi
  418.  
  419. # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
  420. file=sunwindow/win_cursor.h
  421. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  422. #  mkdir ${LIB}/sunwindow 2>/dev/null
  423.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  424.   chmod +w ${LIB}/$file 2>/dev/null
  425. fi
  426. if [ -r ${LIB}/$file ]; then
  427.   echo Fixing $file
  428.   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
  429.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  430.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  431.     rm ${LIB}/$file
  432.   else
  433.     # Find any include directives that use "file".
  434.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  435.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  436.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  437.     done
  438.   fi
  439. fi
  440. file=sunwindow/win_lock.h
  441. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  442. #  mkdir ${LIB}/sunwindow 2>/dev/null
  443.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  444.   chmod +w ${LIB}/$file 2>/dev/null
  445. fi
  446. if [ -r ${LIB}/$file ]; then
  447.   echo Fixing $file
  448.   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
  449.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  450.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  451.     rm ${LIB}/$file
  452.   else
  453.     # Find any include directives that use "file".
  454.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  455.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  456.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  457.     done
  458.   fi
  459. fi
  460.  
  461. # Fix this Sun file to avoid interfering with stddef.h.
  462. file=sys/stdtypes.h
  463. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  464.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  465.   chmod +w ${LIB}/$file 2>/dev/null
  466.   chmod a+r ${LIB}/$file 2>/dev/null
  467. fi
  468.  
  469. if [ -r ${LIB}/$file ]; then
  470.   echo Fixing $file
  471. sed -e '/[     ]size_t.*;/i\
  472. #ifndef _GCC_SIZE_T\
  473. #define _GCC_SIZE_T
  474. ' \
  475.     -e '/[     ]size_t.*;/a\
  476. #endif
  477. ' \
  478.     -e '/[     ]ptrdiff_t.*;/i\
  479. #ifndef _GCC_PTRDIFF_T\
  480. #define _GCC_PTRDIFF_T
  481. ' \
  482.     -e '/[     ]ptrdiff_t.*;/a\
  483. #endif
  484. ' \
  485.     -e '/[     ]wchar_t.*;/i\
  486. #ifndef _GCC_WCHAR_T\
  487. #define _GCC_WCHAR_T
  488. ' \
  489.     -e '/[     ]wchar_t.*;/a\
  490. #endif
  491. ' ${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
  494.     rm ${LIB}/$file
  495.   else
  496.     # Find any include directives that use "file".
  497.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  498.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  499.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  500.     done
  501.   fi
  502. fi
  503.  
  504. # Fix this ARM/RISCiX file to avoid interfering with the use of __wchar_t
  505. # in cc1plus.
  506. file=stdlib.h
  507. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  508.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  509.   chmod +w ${LIB}/$file 2>/dev/null
  510.   chmod a+r ${LIB}/$file 2>/dev/null
  511. fi
  512.  
  513. if [ -r ${LIB}/$file ]; then
  514.   echo Fixing $file
  515.   sed -e "s/\(#[     ]*ifndef[     ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
  516.       -e "s/\(#[     ]*define[     ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
  517.      ${LIB}/$file > ${LIB}/${file}.sed
  518.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  519.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  520.     rm ${LIB}/$file
  521.   else
  522.     # Find any include directives that use "file".
  523.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  524.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  525.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  526.     done
  527.   fi
  528. fi
  529.  
  530. # Fix this ARM/RISCiX file where ___type is a Compiler hint that is specific to
  531. # the Norcroft compiler.
  532. file=X11/Intrinsic.h
  533. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  534.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  535.   chmod +w ${LIB}/$file 2>/dev/null
  536.   chmod a+r ${LIB}/$file 2>/dev/null
  537. fi
  538.  
  539. if [ -r ${LIB}/$file ]; then
  540.   echo Fixing $file
  541.   sed -e "s/___type p_type/p_type/" \
  542.      ${LIB}/$file > ${LIB}/${file}.sed
  543.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  544.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  545.     rm ${LIB}/$file
  546.   else
  547.     # Find any include directives that use "file".
  548.     for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  549.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  550.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  551.     done
  552.   fi
  553. fi
  554.  
  555. # Fix this file to avoid interfering with stddef.h, but don't mistakenly
  556. # match ssize_t present in AIX for the ps/2, or typedefs which use (but do not
  557. # set) size_t.
  558. file=sys/types.h
  559. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  560.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  561.   chmod +w ${LIB}/$file 2>/dev/null
  562.   chmod a+r ${LIB}/$file 2>/dev/null
  563. fi
  564.  
  565. if [ -r ${LIB}/$file ]; then
  566.   echo Fixing $file
  567. sed -e '/typedef[     ][     ]*[A-Za-z_][     A-Za-z_]*[     ]size_t/i\
  568. #ifndef _GCC_SIZE_T\
  569. #define _GCC_SIZE_T
  570. ' \
  571.     -e '/typedef[     ][     ]*[A-Za-z_][     A-Za-z_]*[     ]size_t/a\
  572. #endif
  573. ' ${LIB}/$file > ${LIB}/${file}.sed
  574.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  575.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  576.     rm ${LIB}/$file
  577.   else
  578.     # Find any include directives that use "file".
  579.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  580.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  581.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  582.     done
  583.   fi
  584. fi
  585.  
  586. # Fix HP's use of ../machine/inline.h to refer to
  587. # /usr/include/machine/inline.h
  588. file=sys/spinlock.h
  589. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  590.   cp $file ${LIB}/$file
  591. fi
  592. if [ -r ${LIB}/$file ] ; then
  593.   echo Fixing $file
  594.   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
  595.     -e 's,"../machine/psl.h",<machine/psl.h>,' \
  596.   ${LIB}/$file > ${LIB}/${file}.sed
  597.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  598.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  599.     rm ${LIB}/$file
  600.   else
  601.     # Find any include directives that use "file".
  602.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  603.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  604.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  605.     done
  606.   fi
  607. fi
  608.  
  609. # Fix an error in this file: the #if says _cplusplus, not the double
  610. # underscore __cplusplus that it should be
  611. file=tinfo.h
  612. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  613.   mkdir ${LIB}/rpcsvc 2>/dev/null
  614.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  615.   chmod +w ${LIB}/$file 2>/dev/null
  616.   chmod a+r ${LIB}/$file 2>/dev/null
  617. fi
  618.  
  619. if [ -r ${LIB}/$file ]; then
  620.   echo Fixing $file, __cplusplus macro
  621.   sed -e 's/[     ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
  622.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  623.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  624.     rm ${LIB}/$file
  625.   else
  626.     # Find any include directives that use "file".
  627.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  628.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  629.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  630.     done
  631.   fi
  632. fi
  633.  
  634. # Fix an error in this file: a missing semi-colon at the end of the statsswtch
  635. # structure definition.
  636. file=rpcsvc/rstat.h
  637. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  638.   mkdir ${LIB}/rpcsvc 2>/dev/null
  639.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  640.   chmod +w ${LIB}/$file 2>/dev/null
  641.   chmod a+r ${LIB}/$file 2>/dev/null
  642. fi
  643.  
  644. if [ -r ${LIB}/$file ]; then
  645.   echo Fixing $file, definition of statsswtch
  646.   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
  647.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  648.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  649.     rm ${LIB}/$file
  650.   else
  651.     # Find any include directives that use "file".
  652.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  653.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  654.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  655.     done
  656.   fi
  657. fi
  658.  
  659. # Fix an error in this file: a missing semi-colon at the end of the nodeent
  660. # structure definition.
  661. file=netdnet/dnetdb.h
  662. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  663.   mkdir ${LIB}/netdnet 2>/dev/null
  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
  667. fi
  668.  
  669. if [ -r ${LIB}/$file ]; then
  670.   echo Fixing $file, definition of nodeent
  671.   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
  672.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  673.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  674.     rm ${LIB}/$file
  675.   else
  676.     # Find any include directives that use "file".
  677.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  678.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  679.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  680.     done
  681.   fi
  682. fi
  683.  
  684. # Check for bad #ifdef line (in Ultrix 4.1)
  685. file=sys/file.h
  686. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  687.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  688.   chmod +w ${LIB}/$file 2>/dev/null
  689.   chmod a+r ${LIB}/$file 2>/dev/null
  690. fi
  691.  
  692. if [ -r ${LIB}/$file ]; then
  693.   echo Fixing $file, bad \#ifdef line
  694.   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
  695.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  696.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  697.     rm ${LIB}/$file
  698.   else
  699.     # Find any include directives that use "file".
  700.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  701.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  702.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  703.     done
  704.   fi
  705. fi
  706.  
  707. # Check for (...) in C++ code in HP/UX sys/file.h.
  708. file=sys/file.h
  709. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  710.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  711.   chmod +w ${LIB}/$file 2>/dev/null
  712.   chmod a+r ${LIB}/$file 2>/dev/null
  713. fi
  714.  
  715. if [ -r ${LIB}/$file ]; then
  716.   if egrep HPUX_SOURCE ${LIB}/$file > /dev/null; then
  717.     echo Fixing $file, use of '(...)'
  718.     sed -e 's/(\.\.\.)/(struct file * ...)/' ${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
  721.       rm ${LIB}/$file
  722.     else
  723.       # Find any include directives that use "file".
  724.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  725.     dir=`echo $file | sed -e s'|/[^/]*$||'`
  726.     required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  727.       done
  728.     fi
  729.   fi
  730. fi
  731.  
  732. # Check for superfluous `static' (in Ultrix 4.2)
  733. # On Ultrix 4.3, includes of other files (r3_cpu.h,r4_cpu.h) is broken.
  734. file=machine/cpu.h
  735. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  736.   mkdir ${LIB}/machine 2>/dev/null
  737.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  738.   chmod +w ${LIB}/$file 2>/dev/null
  739.   chmod a+r ${LIB}/$file 2>/dev/null
  740. fi
  741.  
  742. if [ -r ${LIB}/$file ]; then
  743.   echo Fixing $file, superfluous static and broken includes of other files.
  744.   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' \
  745.       -e 's/^#include "r3_cpu\.h"$/#include <machine\/r3_cpu\.h>/' \
  746.       -e 's/^#include "r4_cpu\.h"$/#include <machine\/r4_cpu\.h>/' \
  747.       ${LIB}/$file > ${LIB}/${file}.sed
  748.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  749.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  750.     rm ${LIB}/$file
  751.   else
  752.     # Find any include directives that use "file".
  753.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  754.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  755.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  756.     done
  757. # This file has an alternative name, mips/cpu.h.  Fix that name, too.
  758.     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
  759.       mkdir ${LIB}/mips 2>&-
  760. # Don't remove the file first, they may be the same file!
  761.       ln ${LIB}/$file ${LIB}/mips/cpu.h > /dev/null 2>&1
  762.     fi
  763.   fi
  764. fi
  765.  
  766. # Incorrect sprintf declaration in X11/Xmu.h
  767. file=X11/Xmu.h
  768. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  769.   mkdir ${LIB}/X11 2>/dev/null
  770.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  771.   chmod +w ${LIB}/$file 2>/dev/null
  772.   chmod a+r ${LIB}/$file 2>/dev/null
  773. fi
  774.  
  775. if [ -r ${LIB}/$file ]; then
  776.   echo Fixing $file sprintf declaration
  777.   sed -e 's,^extern char \*    sprintf();$,#ifndef __STDC__\
  778. extern char *    sprintf();\
  779. #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
  780.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  781.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  782.     rm ${LIB}/$file
  783.   else
  784.     # Find any include directives that use "file".
  785.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  786.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  787.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  788.     done
  789.   fi
  790. fi
  791.  
  792. # Incorrect sprintf declaration in X11/Xmu/Xmu.h
  793. # (It's not clear whether the right file name is this or X11/Xmu.h.)
  794. file=X11/Xmu/Xmu.h
  795. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  796.   mkdir ${LIB}/X11/Xmu 2>/dev/null
  797.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  798.   chmod +w ${LIB}/$file 2>/dev/null
  799.   chmod a+r ${LIB}/$file 2>/dev/null
  800. fi
  801.  
  802. if [ -r ${LIB}/$file ]; then
  803.   echo Fixing $file sprintf declaration
  804.   sed -e 's,^extern char \*    sprintf();$,#ifndef __STDC__\
  805. extern char *    sprintf();\
  806. #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
  807.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  808.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  809.     rm ${LIB}/$file
  810.   else
  811.     # Find any include directives that use "file".
  812.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  813.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  814.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  815.     done
  816.   fi
  817. fi
  818.  
  819. # Check for missing ';' in struct
  820. file=netinet/ip.h
  821. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  822.   mkdir ${LIB}/netinet 2>/dev/null
  823.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  824.   chmod +w ${LIB}/$file 2>/dev/null
  825.   chmod a+r ${LIB}/$file 2>/dev/null
  826. fi
  827.  
  828. if [ -r ${LIB}/$file ]; then
  829.   echo Fixing $file
  830.   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
  831.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  832.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  833.     rm -f ${LIB}/$file
  834.   else
  835.     # Find any include directives that use "file".
  836.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  837.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  838.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  839.     done
  840.   fi
  841. fi
  842.  
  843. # Fix the CAT macro in SunOS memvar.h.
  844. file=pixrect/memvar.h
  845. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  846.   mkdir ${LIB}/pixrect 2>/dev/null
  847.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  848.   chmod +w ${LIB}/$file 2>/dev/null
  849.   chmod a+r ${LIB}/$file 2>/dev/null
  850. fi
  851.  
  852. if [ -r ${LIB}/$file ]; then
  853.   echo Fixing $file
  854.   sed -e '/^#define.CAT(a,b)/ i\
  855. #ifdef __STDC__ \
  856. #define CAT(a,b) a##b\
  857. #else
  858. /^#define.CAT(a,b)/ a\
  859. #endif
  860. ' ${LIB}/$file > ${LIB}/${file}.sed
  861.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  862.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  863.     rm -f ${LIB}/$file
  864.   else
  865.     # Find any include directives that use "file".
  866.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  867.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  868.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  869.     done
  870.   fi
  871. fi
  872.  
  873. # Check for yet more missing ';' in struct (in SunOS 4.0.x)
  874. file=rpcsvc/rusers.h
  875. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  876.   mkdir ${LIB}/rpcsvc 2>/dev/null
  877.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  878.   chmod +w ${LIB}/$file 2>/dev/null
  879.   chmod a+r ${LIB}/$file 2>/dev/null
  880. fi
  881.  
  882. if [ -r ${LIB}/$file ]; then
  883.   echo Fixing $file
  884.   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${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
  887.     rm -f ${LIB}/$file
  888.   else
  889.     # Find any include directives that use "file".
  890.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  891.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  892.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  893.     done
  894.   fi
  895. fi
  896.  
  897. # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
  898. # Also wrap protection around size_t for m88k-sysv3 systems.
  899. file=stdlib.h
  900. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  901.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  902.   chmod +w ${LIB}/$file 2>/dev/null
  903.   chmod a+r ${LIB}/$file 2>/dev/null
  904. fi
  905.  
  906. if [ -r ${LIB}/$file ]; then
  907.   echo Fixing $file
  908.   sed -e 's/int    abort/void    abort/g' \
  909.   -e 's/int    free/void    free/g' \
  910.   -e 's/char[     ]*\*[     ]*calloc/void \*    calloc/g' \
  911.   -e 's/char[     ]*\*[     ]*malloc/void \*    malloc/g' \
  912.   -e 's/char[     ]*\*[     ]*realloc/void \*    realloc/g' \
  913.   -e 's/int[     ][     ]*exit/void    exit/g' \
  914.   -e '/typedef[     a-zA-Z_]*[     ]size_t[     ]*;/i\
  915. #ifndef _GCC_SIZE_T\
  916. #define _GCC_SIZE_T
  917. ' \
  918.   -e '/typedef[     a-zA-Z_]*[     ]size_t[     ]*;/a\
  919. #endif
  920. ' \
  921.       ${LIB}/$file > ${LIB}/${file}.sed
  922.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  923.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  924.     rm -f ${LIB}/$file
  925.   else
  926.     # Find any include directives that use "file".
  927.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  928.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  929.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  930.     done
  931.   fi
  932. fi
  933.  
  934. # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
  935. # Also fix return type of {m,re}alloc in <malloc.h> on sysV68
  936. file=malloc.h
  937. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  938.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  939.   chmod +w ${LIB}/$file 2>/dev/null
  940.   chmod a+r ${LIB}/$file 2>/dev/null
  941. fi
  942.  
  943. if [ -r ${LIB}/$file ]; then
  944.   echo Fixing $file
  945.   sed -e 's/typedef[     ]char \*    malloc_t/typedef void \*    malloc_t/g' \
  946.   -e 's/int[     ][     ]*free/void    free/g' \
  947.   -e 's/char\([     ]*\*[     ]*malloc\)/void\1/g' \
  948.   -e 's/char\([     ]*\*[     ]*realloc\)/void\1/g' \
  949.   ${LIB}/$file > ${LIB}/${file}.sed
  950.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  951.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  952.     rm -f ${LIB}/$file
  953.   else
  954.     # Find any include directives that use "file".
  955.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  956.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  957.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  958.     done
  959.   fi
  960. fi
  961.  
  962. # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
  963. file=hsfs/hsfs_spec.h
  964. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  965.   mkdir ${LIB}/hsfs 2>/dev/null
  966.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  967.   chmod +w ${LIB}/$file 2>/dev/null
  968.   chmod a+r ${LIB}/$file 2>/dev/null
  969. fi
  970.  
  971. if [ -r ${LIB}/$file ]; then
  972.   echo Fixing $file
  973.   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
  974.     ${LIB}/$file > ${LIB}/${file}.
  975.   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
  976.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  977.     rm -f ${LIB}/$file
  978.   else
  979.     # Find any include directives that use "file".
  980.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  981.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  982.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  983.     done
  984.   fi
  985. fi
  986.  
  987. # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
  988. file=hsfs/hsnode.h
  989. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  990.   mkdir ${LIB}/hsfs 2>/dev/null
  991.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  992.   chmod +w ${LIB}/$file 2>/dev/null
  993.   chmod a+r ${LIB}/$file 2>/dev/null
  994. fi
  995.  
  996. if [ -r ${LIB}/$file ]; then
  997.   echo Fixing $file
  998.   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
  999.     ${LIB}/$file > ${LIB}/${file}.sed
  1000.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1001.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1002.     rm -f ${LIB}/$file
  1003.   else
  1004.     # Find any include directives that use "file".
  1005.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1006.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1007.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1008.     done
  1009.   fi
  1010. fi
  1011.  
  1012. # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
  1013. file=hsfs/iso_spec.h
  1014. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1015.   mkdir ${LIB}/hsfs 2>/dev/null
  1016.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1017.   chmod +w ${LIB}/$file 2>/dev/null
  1018.   chmod a+r ${LIB}/$file 2>/dev/null
  1019. fi
  1020.  
  1021. if [ -r ${LIB}/$file ]; then
  1022.   echo Fixing $file
  1023.   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
  1024.     ${LIB}/$file > ${LIB}/${file}.sed
  1025.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1026.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1027.     rm -f ${LIB}/$file
  1028.   else
  1029.     # Find any include directives that use "file".
  1030.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1031.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1032.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1033.     done
  1034.   fi
  1035. fi
  1036.  
  1037. # Incorrect #include in Sony News-OS 3.2.
  1038. file=machine/machparam.h
  1039. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1040.   mkdir ${LIB}/machine 2>/dev/null
  1041.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1042.   chmod +w ${LIB}/$file 2>/dev/null
  1043.   chmod a+r ${LIB}/$file 2>/dev/null
  1044. fi
  1045.  
  1046. if [ -r ${LIB}/$file ]; then
  1047.   echo Fixing $file, incorrect \#include
  1048.   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
  1049.     ${LIB}/$file > ${LIB}/${file}.
  1050.   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
  1051.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1052.     rm -f ${LIB}/$file
  1053.   else
  1054.     # Find any include directives that use "file".
  1055.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1056.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1057.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1058.     done
  1059.   fi
  1060. fi
  1061.  
  1062. # Multiline comment after typedef on IRIX 4.0.1.
  1063. file=sys/types.h
  1064. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1065.   mkdir ${LIB}/sys 2>/dev/null
  1066.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1067.   chmod +w ${LIB}/$file 2>/dev/null
  1068.   chmod a+r ${LIB}/$file 2>/dev/null
  1069. fi
  1070.  
  1071. if [ -r ${LIB}/$file ]; then
  1072.   echo Fixing $file, comment in the middle of \#ifdef
  1073.   sed -e 's@type of the result@type of the result */@' \
  1074.     -e 's@of the sizeof@/* of the sizeof@' \
  1075.     ${LIB}/$file > ${LIB}/${file}.sed
  1076.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1077.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1078.     rm -f ${LIB}/$file
  1079.   else
  1080.     # Find any include directives that use "file".
  1081.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1082.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1083.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1084.     done
  1085.   fi
  1086. fi
  1087.  
  1088. # Turning // comments into /* */ comments trashes this IRIX 4.0.1
  1089. # header file, which embeds // comments inside multi-line /* */
  1090. # comments.  If this looks like the IRIX header file, we refix it by
  1091. # just throwing away the // comments.
  1092. file=fam.h
  1093. if [ -r ${LIB}/$file ]; then
  1094.   if egrep indigo.esd ${LIB}/$file > /dev/null; then
  1095.     echo Fixing $file, overeager sed script
  1096.     rm ${LIB}/$file
  1097.     sed -e 's|//.*$||g' $file > ${LIB}/$file
  1098.     chmod +w ${LIB}/$file 2>/dev/null
  1099.     chmod a+r ${LIB}/$file 2>/dev/null
  1100.   fi
  1101. fi
  1102.  
  1103. # There is a similar problem with the VxWorks drv/netif/if_med.h file.
  1104. file=drv/netif/if_med.h
  1105. if [ -r ${LIB}/$file ]; then
  1106.   if egrep 'Wind River' ${LIB}/$file > /dev/null; then
  1107.     echo Fixing $file, overeager sed script
  1108.     rm ${LIB}/$file
  1109.     sed -e 's|//.*$||g' $file > ${LIB}/$file
  1110.     chmod +w ${LIB}/$file 2>/dev/null
  1111.     chmod a+r ${LIB}/$file 2>/dev/null
  1112.   fi
  1113. fi
  1114.  
  1115. # Some IRIX header files contains the string "//"
  1116. for file in elf_abi.h elf.h; do
  1117.   if [ -r ${LIB}/$file ]; then
  1118.     echo Fixing $file, overeager sed script
  1119.     sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
  1120.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1121.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1122.       rm -f ${LIB}/$file
  1123.   else
  1124.     # Find any include directives that use "file".
  1125.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1126.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1127.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1128.     done
  1129.     fi
  1130.   fi
  1131. done
  1132.  
  1133. # IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr in prototype without
  1134. # previous definition.
  1135. file=rpc/auth.h
  1136. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1137.   mkdir ${LIB}/rpc 2>/dev/null
  1138.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1139.   chmod +w ${LIB}/$file 2>/dev/null
  1140.   chmod a+r ${LIB}/$file 2>/dev/null
  1141. fi
  1142.  
  1143. if [ -r ${LIB}/$file ]; then
  1144.   echo Fixing $file, undefined type
  1145.   sed -e '/authdes_create.*struct sockaddr/i\
  1146. struct sockaddr;
  1147. ' \
  1148.     ${LIB}/$file > ${LIB}/$file.sed
  1149.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1150.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1151.     rm -f ${LIB}/$file
  1152.   else
  1153.     # Find any include directives that use "file".
  1154.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1155.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1156.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1157.     done
  1158.   fi
  1159. fi
  1160.  
  1161. # IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s in prototype without previous
  1162. # definition.
  1163. file=rpc/xdr.h
  1164. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1165.   mkdir ${LIB}/rpc 2>/dev/null
  1166.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1167.   chmod +w ${LIB}/$file 2>/dev/null
  1168.   chmod a+r ${LIB}/$file 2>/dev/null
  1169. fi
  1170.  
  1171. if [ -r ${LIB}/$file ]; then
  1172.   echo Fixing $file, undefined type
  1173.   sed -e '/xdrstdio_create.*struct __file_s/i\
  1174. struct __file_s;
  1175. ' \
  1176.     ${LIB}/$file > ${LIB}/$file.sed
  1177.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1178.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1179.     rm -f ${LIB}/$file
  1180.   else
  1181.     # Find any include directives that use "file".
  1182.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1183.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1184.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1185.     done
  1186.   fi
  1187. fi
  1188.  
  1189. # Same problem with a file from SunOS 4.1.3 : a header file containing
  1190. # the string "//" embedded in "/**/"
  1191. file=sbusdev/audiovar.h
  1192. if [ -r ${LIB}/$file ]; then
  1193.   echo Fixing $file, overeager sed script
  1194.   rm ${LIB}/$file
  1195.   sed -e 's|//.*$||g' $file > ${LIB}/$file
  1196.   chmod +w ${LIB}/$file 2>/dev/null
  1197.   chmod a+r ${LIB}/$file 2>/dev/null
  1198. fi
  1199.  
  1200. # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
  1201. # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
  1202. # many other systems have similar text but correct versions of the file.
  1203. # To ensure only Sun's is fixed, we grep for a likely unique string.
  1204. file=memory.h
  1205. if [ -r $file ] && egrep '/\*    @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2    \*/' $file > /dev/null; then
  1206.   if [ ! -r ${LIB}/$file ]; then
  1207.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1208.     chmod +w ${LIB}/$file 2>/dev/null
  1209.     chmod a+r ${LIB}/$file 2>/dev/null
  1210.   fi
  1211.   if [ -r ${LIB}/$file ]; then
  1212.     echo Replacing $file
  1213.     cat > ${LIB}/$file << EOF
  1214. /* This file was generated by fixincludes */
  1215. #ifndef __memory_h__
  1216. #define __memory_h__
  1217.  
  1218. #ifdef __STDC__
  1219. extern void *memccpy();
  1220. extern void *memchr();
  1221. extern void *memcpy();
  1222. extern void *memset();
  1223. #else
  1224. extern char *memccpy();
  1225. extern char *memchr();
  1226. extern char *memcpy();
  1227. extern char *memset();
  1228. #endif /* __STDC__ */
  1229.  
  1230. extern int memcmp();
  1231.  
  1232. #endif /* __memory_h__ */
  1233. EOF
  1234.   fi
  1235. fi
  1236.  
  1237. # parameters not const on DECstation Ultrix V4.0 and OSF/1.
  1238. file=stdio.h
  1239. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1240.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1241.   chmod +w ${LIB}/$file 2>/dev/null
  1242.   chmod a+r ${LIB}/$file 2>/dev/null
  1243. fi
  1244.  
  1245. if [ -r ${LIB}/$file ]; then
  1246.   echo Fixing $file, non-const arg
  1247.   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
  1248.       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
  1249.       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
  1250.       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
  1251.       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
  1252.       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
  1253.       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
  1254.       -e 's@popen(char \*, char \*);@popen(const char *, const char *);@' \
  1255.       -e 's@tempnam(char\*,char\*);@tempnam(const char*,const char*);@' \
  1256.     ${LIB}/$file > ${LIB}/${file}.sed
  1257.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1258.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1259.     rm -f ${LIB}/$file
  1260.   else
  1261.     # Find any include directives that use "file".
  1262.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1263.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1264.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1265.     done
  1266.   fi
  1267. fi
  1268.  
  1269. # parameters conflict with C++ new on rs/6000 
  1270. for file in stdio.h unistd.h ; do
  1271.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1272.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1273.     chmod +w ${LIB}/$file 2>/dev/null
  1274.   fi
  1275.  
  1276.   if [ -r ${LIB}/$file ]; then
  1277.     echo Fixing $file, parameter name conflicts
  1278.     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
  1279.       ${LIB}/$file > ${LIB}/${file}.sed
  1280.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1281.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1282.       rm -f ${LIB}/$file
  1283.     else
  1284.       # Find any include directives that use "file".
  1285.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1286.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  1287.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1288.       done
  1289.     fi
  1290.   fi
  1291. done
  1292.  
  1293. # function class(double x) conflicts with C++ keyword on rs/6000 
  1294. file=math.h
  1295. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1296.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1297.   chmod +w ${LIB}/$file 2>/dev/null
  1298.   chmod a+r ${LIB}/$file 2>/dev/null
  1299. fi
  1300.  
  1301. if [ -r ${LIB}/$file ]; then
  1302.   if grep 'class[(]' ${LIB}/$file >/dev/null; then
  1303.     echo Fixing $file
  1304.     sed -e '/class[(]/i\
  1305. #ifndef __cplusplus
  1306. ' \
  1307.         -e '/class[(]/a\
  1308. #endif
  1309. ' ${LIB}/$file > ${LIB}/${file}.sed
  1310.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1311.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1312.       rm ${LIB}/$file
  1313.     else
  1314.       # Find any include directives that use "file".
  1315.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1316.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  1317.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1318.       done
  1319.     fi
  1320.   fi
  1321. fi
  1322.  
  1323. # Wrong fchmod prototype on RS/6000.
  1324. file=sys/stat.h
  1325. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1326.   mkdir ${LIB}/sys 2>/dev/null
  1327.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1328.   chmod +w ${LIB}/$file 2>/dev/null
  1329.   chmod a+r ${LIB}/$file 2>/dev/null
  1330. fi
  1331.  
  1332. if [ -r ${LIB}/$file ]; then
  1333.   echo Fixing $file, fchmod prototype
  1334.   sed -e 's/fchmod(char \*/fchmod(int/' \
  1335.     ${LIB}/$file > ${LIB}/$file.sed
  1336.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1337.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1338.     rm -f ${LIB}/$file
  1339.   else
  1340.     # Find any include directives that use "file".
  1341.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1342.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1343.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1344.     done
  1345.   fi
  1346. fi
  1347.  
  1348. # There are several name conflicts with C++ reserved words in X11
  1349. # header files.  These are fixed in some versions, so don't do the
  1350. # fixes if we find __cplusplus in the file.  These were found on the
  1351. # RS/6000.
  1352.  
  1353. # class in X11/ShellP.h
  1354. file=X11/ShellP.h
  1355. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1356.   mkdir ${LIB}/sys 2>/dev/null
  1357.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1358.   chmod +w ${LIB}/$file 2>/dev/null
  1359.   chmod a+r ${LIB}/$file 2>/dev/null
  1360. fi
  1361.  
  1362. if [ -r ${LIB}/$file ]; then
  1363.   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
  1364.     true;
  1365.   else
  1366.     echo Fixing $file, field class
  1367.     sed -e '/char [*]class;/i\
  1368. #ifdef __cplusplus\
  1369.     char *c_class;\
  1370. #else
  1371. ' \
  1372.         -e '/char [*]class;/a\
  1373. #endif
  1374. ' ${LIB}/$file > ${LIB}/${file}.sed
  1375.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1376.   fi
  1377.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1378.     rm -f ${LIB}/$file
  1379.   else
  1380.     # Find any include directives that use "file".
  1381.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1382.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1383.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1384.     done
  1385.   fi
  1386. fi
  1387. # new in Xm/Traversal.h
  1388. file=Xm/Traversal.h
  1389. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1390.   mkdir ${LIB}/sys 2>/dev/null
  1391.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1392.   chmod +w ${LIB}/$file 2>/dev/null
  1393.   chmod a+r ${LIB}/$file 2>/dev/null
  1394. fi
  1395.  
  1396. if [ -r ${LIB}/$file ]; then
  1397.   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
  1398.     true;
  1399.   else
  1400.     echo Fixing $file, uses of new
  1401.     sed -e '/Widget    old, new;/i\
  1402. #ifdef __cplusplus\
  1403.     Widget    old, c_new;\
  1404. #else
  1405. ' \
  1406.         -e '/Widget    old, new;/a\
  1407. #endif
  1408. ' \
  1409.     -e 's/Widget new,/Widget c_new,/g' ${LIB}/$file > ${LIB}/${file}.sed
  1410.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1411.   fi
  1412.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1413.     rm -f ${LIB}/$file
  1414.   else
  1415.     # Find any include directives that use "file".
  1416.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1417.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1418.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1419.     done
  1420.   fi
  1421. fi
  1422. # class in Xm/BaseClassI.h
  1423. file=Xm/BaseClassI.h
  1424. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1425.   mkdir ${LIB}/sys 2>/dev/null
  1426.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1427.   chmod +w ${LIB}/$file 2>/dev/null
  1428.   chmod a+r ${LIB}/$file 2>/dev/null
  1429. fi
  1430.  
  1431. if [ -r ${LIB}/$file ]; then
  1432.   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
  1433.     true;
  1434.   else
  1435.     echo Fixing $file, prototype parameter name
  1436.     sed -e 's/ class[)]/ c_class)/g' ${LIB}/$file > ${LIB}/${file}.sed
  1437.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1438.   fi
  1439.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1440.     rm -f ${LIB}/$file
  1441.   else
  1442.     # Find any include directives that use "file".
  1443.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1444.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1445.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1446.     done
  1447.   fi
  1448. fi
  1449.  
  1450. # NeXT 3.2 adds const prefix to some math functions. These conflict
  1451. # with the built-in functions.
  1452. file=ansi/math.h
  1453. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1454.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1455.   chmod +w ${LIB}/$file 2>/dev/null
  1456. fi
  1457. if [ -r ${LIB}/$file ]; then
  1458.   echo Fixing $file
  1459.   sed -e '/^extern.*double.*__const__.*cos(/s/__const__//' \
  1460.       -e '/^extern.*double.*__const__.*sin(/s/__const__//' ${LIB}/$file > ${LIB}/${file}.sed
  1461.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1462.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1463.     rm -f ${LIB}/$file
  1464.   else
  1465.     # Find any include directives that use "file".
  1466.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1467.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1468.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1469.     done
  1470.   fi
  1471. fi
  1472.  
  1473. # NeXT 3.2 uses the word "template" as a parameter for some 
  1474. # functions. GCC reports an invalid use of a reserved key word
  1475. # with the built-in functions. NeXT 3.2 includes the keyword
  1476. # volatile in the prototype for abort(). This conflicts with
  1477. # the built-in definition.
  1478. file=bsd/libc.h
  1479. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1480.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1481.   chmod +w ${LIB}/$file 2>/dev/null
  1482. fi
  1483. if [ -r ${LIB}/$file ]; then
  1484.   echo Fixing $file
  1485.   sed -e '/\(.*template\)/s/template//' \
  1486.       -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
  1487.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1488.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1489.     rm -f ${LIB}/$file
  1490.   else
  1491.     # Find any include directives that use "file".
  1492.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1493.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1494.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1495.     done
  1496.   fi
  1497. fi
  1498.  
  1499. # NeXT 3.2 includes the keyword volatile in the abort() and 
  1500. # exit() function prototypes. That conflicts with the 
  1501. # built-in functions.
  1502. file=ansi/stdlib.h
  1503. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1504.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1505.   chmod +w ${LIB}/$file 2>/dev/null
  1506. fi
  1507. if [ -r ${LIB}/$file ]; then
  1508.   echo Fixing $file
  1509.   sed -e '/extern.*volatile.*void.*exit/s/volatile//' \
  1510.       -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
  1511.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1512.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1513.     rm -f ${LIB}/$file
  1514.   else
  1515.     # Find any include directives that use "file".
  1516.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1517.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1518.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1519.     done
  1520.   fi
  1521. fi
  1522.  
  1523. # sys/wait.h on AIX 3.2.5 puts the declaration of wait3 before the definition
  1524. # of struct rusage, so the prototype (added by fixproto) causes havoc.
  1525. file=sys/wait.h
  1526. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1527.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1528.   chmod +w ${LIB}/$file 2>/dev/null
  1529. fi
  1530.  
  1531. if [ -r ${LIB}/$file ] \
  1532.   && grep 'bos325,' ${LIB}/$file >/dev/null; then
  1533.   echo Fixing $file, wait3 declaration
  1534.   sed -e '/^extern pid_t wait3();$/i\
  1535. struct rusage;
  1536. '\
  1537.     ${LIB}/$file > ${LIB}/${file}.sed
  1538.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1539.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1540.     rm -f ${LIB}/$file
  1541.   else
  1542.     # Find any include directives that use "file".
  1543.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1544.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1545.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1546.     done
  1547.   fi
  1548. fi
  1549.  
  1550. # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
  1551. # Note that version 3 of the NeXT system has wait.h in a different directory,
  1552. # so that this code won't do anything.  But wait.h in version 3 has a
  1553. # conditional, so it doesn't need this fix.  So everything is okay.
  1554. file=sys/wait.h
  1555. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1556.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1557.   chmod +w ${LIB}/$file 2>/dev/null
  1558. fi
  1559.  
  1560. if [ -r ${LIB}/$file ] \
  1561.   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
  1562.   echo Fixing $file, bad wait formal
  1563.   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
  1564.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1565.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1566.     rm -f ${LIB}/$file
  1567.   else
  1568.     # Find any include directives that use "file".
  1569.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1570.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1571.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1572.     done
  1573.   fi
  1574. fi
  1575.  
  1576. # Don't use or define the name va_list in stdio.h.
  1577. # This is for ANSI and also to interoperate properly with gcc's varargs.h.
  1578. file=stdio.h
  1579. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1580.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1581.   chmod +w ${LIB}/$file 2>/dev/null
  1582.   chmod a+r ${LIB}/$file 2>/dev/null
  1583. fi
  1584.  
  1585. if [ -r ${LIB}/$file ]; then
  1586.   echo Fixing $file, use of va_list
  1587.   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
  1588.   if egrep "__need___va_list" ${LIB}/$file >/dev/null 2>&1; then
  1589.     touch ${LIB}/${file}.sed
  1590.   else
  1591.     (echo "#define __need___va_list"
  1592.      echo "#include <stdarg.h>") > ${LIB}/${file}.sed
  1593.   fi
  1594.   # Use __gnuc_va_list in arg types in place of va_list.
  1595.   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
  1596.   # trailing parentheses and semicolon save all other systems from this.
  1597.   # Define __va_list__ (something harmless and unused) instead of va_list.
  1598.   # Don't claim to have defined va_list.
  1599.   sed -e 's@ va_list @ __gnuc_va_list @' \
  1600.       -e 's@ va_list)@ __gnuc_va_list)@' \
  1601.       -e 's@ _BSD_VA_LIST_));@ __gnuc_va_list));@' \
  1602.       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
  1603.       -e 's@ va_list@ __va_list__@' \
  1604.       -e 's@\*va_list@*__va_list__@' \
  1605.       -e 's@ __va_list)@ __gnuc_va_list)@' \
  1606.       -e 's@GNUC_VA_LIST@GNUC_Va_LIST@' \
  1607.       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
  1608.       -e 's@VA_LIST@DUMMY_VA_LIST@' \
  1609.       -e 's@_Va_LIST@_VA_LIST@' \
  1610.     ${LIB}/$file >> ${LIB}/${file}.sed
  1611.   
  1612.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1613.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1614.     rm -f ${LIB}/$file
  1615.   else
  1616.     # Find any include directives that use "file".
  1617.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1618.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1619.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1620.     done
  1621.   fi
  1622. fi
  1623.  
  1624. # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
  1625. file=ansi_compat.h
  1626. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1627.   if grep -s ULTRIX $file; then
  1628.     echo "/* This file intentionally left blank.  */" > $LIB/$file
  1629.   fi
  1630. fi
  1631.  
  1632. # parameter to atof not const on DECstation Ultrix V4.0 and NEWS-OS 4.2R.
  1633. # also get rid of bogus inline definitions in HP-UX 8.0
  1634. file=math.h
  1635. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1636.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1637.   chmod +w ${LIB}/$file 2>/dev/null
  1638.   chmod a+r ${LIB}/$file 2>/dev/null
  1639. fi
  1640.  
  1641. if [ -r ${LIB}/$file ]; then
  1642.   echo Fixing $file, non-const arg
  1643.   sed -e 's@atof(\([     ]*char[     ]*\*[^)]*\))@atof(const \1)@' \
  1644.       -e 's@inline int abs(int [a-z][a-z]*) {.*}@extern "C" int abs(int);@' \
  1645.       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
  1646.       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
  1647.       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
  1648.     ${LIB}/$file > ${LIB}/${file}.sed
  1649.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1650.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1651.     rm -f ${LIB}/$file
  1652.   else
  1653.     # Find any include directives that use "file".
  1654.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1655.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1656.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1657.     done
  1658.   fi
  1659. fi
  1660.  
  1661. # fix bogus recursive stdlib.h in NEWS-OS 4.0C
  1662. file=stdlib.h
  1663. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1664.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1665.   chmod +w ${LIB}/$file 2>/dev/null
  1666.   chmod a+r ${LIB}/$file 2>/dev/null
  1667. fi
  1668.  
  1669. if [ -r ${LIB}/$file ]; then
  1670.   echo Fixing $file, recursive inclusion
  1671.   sed -e '/^#include <stdlib.h>/i\
  1672. #if 0
  1673. ' \
  1674.       -e '/^#include <stdlib.h>/a\
  1675. #endif
  1676. ' \
  1677.     ${LIB}/$file > ${LIB}/${file}.sed
  1678.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1679.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1680.     rm -f ${LIB}/$file
  1681.   else
  1682.     # Find any include directives that use "file".
  1683.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1684.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1685.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1686.     done
  1687.   fi
  1688. fi
  1689.  
  1690. # Avoid nested comments on Ultrix 4.3.
  1691. file=rpc/svc.h
  1692. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1693.   mkdir ${LIB}/rpc 2>/dev/null
  1694.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1695.   chmod +w ${LIB}/$file 2>/dev/null
  1696.   chmod a+r ${LIB}/$file 2>/dev/null
  1697. fi
  1698.  
  1699. if [ -r ${LIB}/$file ]; then
  1700.   echo Fixing $file, nested comment
  1701.   sed -e 's@^\( \*    int protocol;  \)/\*@\1*/ /*@' \
  1702.     ${LIB}/$file > ${LIB}/$file.sed
  1703.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1704.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1705.     rm -f ${LIB}/$file
  1706.   else
  1707.     # Find any include directives that use "file".
  1708.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1709.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1710.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1711.     done
  1712.   fi
  1713. fi
  1714.  
  1715. # This file in RISC/os uses /**/ to concatenate two tokens.
  1716. file=bsd43/bsd43_.h
  1717. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1718.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1719.   chmod +w ${LIB}/$file 2>/dev/null
  1720.   chmod a+r ${LIB}/$file 2>/dev/null
  1721. fi
  1722. if [ -r ${LIB}/$file ]; then
  1723.   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
  1724.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1725.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1726.     rm -f ${LIB}/$file
  1727.   else
  1728.     # Find any include directives that use "file".
  1729.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1730.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1731.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1732.     done
  1733.   fi
  1734. fi
  1735.  
  1736. file=rpc/rpc.h
  1737. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1738.   mkdir ${LIB}/rpc 2>/dev/null
  1739.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1740.   chmod +w ${LIB}/$file 2>/dev/null
  1741.   chmod a+r ${LIB}/$file 2>/dev/null
  1742. fi
  1743.  
  1744. if [ -r ${LIB}/$file ]; then
  1745.   echo Fixing $file, nested comment
  1746.   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
  1747.     ${LIB}/$file > ${LIB}/$file.sed
  1748.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1749.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1750.     rm -f ${LIB}/$file
  1751.   else
  1752.     # Find any include directives that use "file".
  1753.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1754.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1755.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1756.     done
  1757.   fi
  1758. fi
  1759.  
  1760. # In limits.h, put #ifndefs around things that are supposed to be defined
  1761. # in float.h to avoid redefinition errors if float.h is included first.
  1762. # On HP/UX this patch does not work, because on HP/UX limits.h uses
  1763. # multi line comments and the inserted #endif winds up inside the
  1764. # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
  1765. # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
  1766. # are there, and we do not add them ourselves.
  1767. for file in limits.h sys/limits.h; do
  1768.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1769.     mkdir ${LIB}/sys 2>/dev/null
  1770.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1771.     chmod +w ${LIB}/$file 2>/dev/null
  1772.     chmod a+r ${LIB}/$file 2>/dev/null
  1773.   fi
  1774.  
  1775.   if [ -r ${LIB}/$file ]; then
  1776.     if egrep 'ifndef[     ]+FLT_MIN' ${LIB}/$file >/dev/null; then
  1777.       true
  1778.     else
  1779.       echo Fixing $file
  1780.       sed -e '/[     ]FLT_MIN[     ]/i\
  1781. #ifndef FLT_MIN
  1782. '\
  1783.       -e '/[     ]FLT_MIN[     ]/a\
  1784. #endif
  1785. '\
  1786.       -e '/[     ]FLT_MAX[     ]/i\
  1787. #ifndef FLT_MAX
  1788. '\
  1789.       -e '/[     ]FLT_MAX[     ]/a\
  1790. #endif
  1791. '\
  1792.       -e '/[     ]FLT_DIG[     ]/i\
  1793. #ifndef FLT_DIG
  1794. '\
  1795.       -e '/[     ]FLT_DIG[     ]/a\
  1796. #endif
  1797. '\
  1798.       -e '/[     ]DBL_MIN[     ]/i\
  1799. #ifndef DBL_MIN
  1800. '\
  1801.       -e '/[     ]DBL_MIN[     ]/a\
  1802. #endif
  1803. '\
  1804.       -e '/[     ]DBL_MAX[     ]/i\
  1805. #ifndef DBL_MAX
  1806. '\
  1807.       -e '/[     ]DBL_MAX[     ]/a\
  1808. #endif
  1809. '\
  1810.       -e '/[     ]DBL_DIG[     ]/i\
  1811. #ifndef DBL_DIG
  1812. '\
  1813.       -e '/[     ]DBL_DIG[     ]/a\
  1814. #endif
  1815. '\
  1816.     ${LIB}/$file > ${LIB}/${file}.sed
  1817.       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1818.     fi
  1819.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1820.       echo Deleting ${LIB}/$file\; no fixes were needed.
  1821.       rm -f ${LIB}/$file
  1822.     else
  1823.       # Find any include directives that use "file".
  1824.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1825.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  1826.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1827.       done
  1828.     fi
  1829.   fi
  1830. done
  1831.  
  1832. # In math.h, put #ifndefs around things that might be defined in a gcc
  1833. # specific math-*.h file.
  1834. file=math.h
  1835. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1836.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1837.   chmod +w ${LIB}/$file 2>/dev/null
  1838.   chmod a+r ${LIB}/$file 2>/dev/null
  1839. fi
  1840.  
  1841. if [ -r ${LIB}/$file ]; then
  1842.   echo Fixing $file
  1843.   sed -e '/define[     ]HUGE_VAL[     ]/i\
  1844. #ifndef HUGE_VAL
  1845. '\
  1846.       -e '/define[     ]HUGE_VAL[     ]/a\
  1847. #endif
  1848. '\
  1849.     ${LIB}/$file > ${LIB}/${file}.sed
  1850.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1851.  
  1852.   # In addition, copy the definition of DBL_MAX from float.h
  1853.   # if math.h requires one.  The Lynx math.h requires it.
  1854.   if egrep '#define[     ]*HUGE_VAL[     ]+DBL_MAX' $file >/dev/null 2>&1; then
  1855.     if egrep '#define[     ]+DBL_MAX[     ]+' $file >/dev/null 2>&1; then
  1856.       true;
  1857.     else
  1858.       dbl_max_def=`egrep 'define[     ]+DBL_MAX[     ]+.*' float.h 2>/dev/null`
  1859.       if [ "$dbl_max_def" != "" ]; then
  1860.         dbl_max_def=`echo $dbl_max_def | sed 's/.*define[     ]*DBL_MAX[     ]*//'`
  1861.         sed -e "/define[     ]HUGE_VAL[     ]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
  1862.           ${LIB}/$file > ${LIB}/${file}.sed
  1863.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1864.       fi
  1865.     fi
  1866.   fi
  1867.  
  1868.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1869.     echo Deleting ${LIB}/$file\; no fixes were needed.
  1870.     rm -f ${LIB}/$file
  1871.   else
  1872.     # Find any include directives that use "file".
  1873.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1874.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1875.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1876.     done
  1877.   fi
  1878. fi
  1879.  
  1880. # Remove erroneous parentheses in sym.h on Alpha OSF/1.
  1881. file=sym.h
  1882. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1883.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1884.   chmod +w ${LIB}/$file 2>/dev/null
  1885.   chmod a+r ${LIB}/$file 2>/dev/null
  1886. fi
  1887.  
  1888. if [ -r ${LIB}/$file ]; then
  1889.   echo Fixing $file
  1890.   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
  1891.     ${LIB}/$file > ${LIB}/${file}.sed
  1892.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1893.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1894.     rm -f ${LIB}/$file
  1895.   else
  1896.     # Find any include directives that use "file".
  1897.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1898.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1899.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1900.     done
  1901.   fi
  1902. fi
  1903.  
  1904. # Fix return value of mem{ccpy,chr,cpy,set} and str{len,spn,cspn}
  1905. # in string.h on sysV68
  1906. # Correct the return type for strlen in string.h on Lynx.
  1907. # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
  1908. # Add missing const for strdup on OSF/1 V3.0.
  1909. file=string.h
  1910. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1911.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1912.   chmod +w ${LIB}/$file 2>/dev/null
  1913.   chmod a+r ${LIB}/$file 2>/dev/null
  1914. fi
  1915.  
  1916. if [ -r ${LIB}/$file ]; then
  1917.   echo Fixing $file, mem{ccpy,chr,cpy,set} and str{len,spn,cspn} return value
  1918.   sed -e 's/extern[     ]*int[     ]*strlen();/extern unsigned int strlen();/' \
  1919.       -e 's/extern[     ]*int[     ]*ffs[     ]*(long);/extern int ffs(int);/' \
  1920.       -e 's/strdup(char \*s1);/strdup(const char *s1);/' \
  1921.       -e '/^extern char$/N' \
  1922.       -e 's/^extern char\(\n    \*memccpy(),\)$/extern void\1/'\
  1923.       -e '/^    strncmp(),$/N'\
  1924.       -e 's/^\(    strncmp()\),\n\(    strlen(),\)$/\1;\
  1925. extern unsigned int\
  1926. \2/'\
  1927.     ${LIB}/$file > ${LIB}/${file}.sed
  1928.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1929.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1930.     rm -f ${LIB}/$file
  1931.   else
  1932.     # Find any include directives that use "file".
  1933.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1934.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1935.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1936.     done
  1937.   fi
  1938. fi
  1939.  
  1940. # Correct the return type for strlen in strings.h in SunOS 4.
  1941. file=strings.h
  1942. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1943.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1944.   chmod +w ${LIB}/$file 2>/dev/null
  1945.   chmod a+r ${LIB}/$file 2>/dev/null
  1946. fi
  1947.  
  1948. if [ -r ${LIB}/$file ]; then
  1949.   echo Fixing $file
  1950.   sed -e 's/int[     ]*strlen();/__SIZE_TYPE__ strlen();/' \
  1951.     ${LIB}/$file > ${LIB}/${file}.sed
  1952.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1953.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1954.     rm -f ${LIB}/$file
  1955.   else
  1956.     # Find any include directives that use "file".
  1957.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1958.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1959.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1960.     done
  1961.   fi
  1962. fi
  1963.  
  1964. # Delete the '#define void int' line from curses.h on Lynx
  1965. file=curses.h
  1966. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1967.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1968.   chmod +w ${LIB}/$file 2>/dev/null
  1969.   chmod a+r ${LIB}/$file 2>/dev/null
  1970. fi
  1971.  
  1972. if [ -r ${LIB}/$file ]; then
  1973.   echo Fixing $file
  1974.   sed -e '/#[     ]*define[     ][     ]*void[     ]int/d' \
  1975.      ${LIB}/$file > ${LIB}/${file}.sed
  1976.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1977.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1978.     rm -f ${LIB}/$file
  1979.   else
  1980.     # Find any include directives that use "file".
  1981.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1982.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1983.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1984.     done
  1985.   fi
  1986. fi
  1987.  
  1988. # Fix `typedef struct term;' on hppa1.1-hp-hpux9.
  1989. file=curses.h
  1990. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1991.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1992.   chmod +w ${LIB}/$file 2>/dev/null
  1993.   chmod a+r ${LIB}/$file 2>/dev/null
  1994. fi
  1995.  
  1996. if [ -r ${LIB}/$file ]; then
  1997.   echo Fixing $file
  1998.   sed -e 's/^[     ]*typedef[     ][     ]*\(struct[     ][     ]*term[     ]*;[     ]*\)$/\1/' \
  1999.      ${LIB}/$file > ${LIB}/${file}.sed
  2000.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2001.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2002.     rm -f ${LIB}/$file
  2003.   else
  2004.     # Find any include directives that use "file".
  2005.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2006.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2007.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2008.     done
  2009.   fi
  2010. fi
  2011.  
  2012. # For C++, avoid any typedef or macro definition of bool, and use the
  2013. # built in type instead.
  2014. for files in curses.h; do
  2015.   if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then
  2016.     if [ ! -r ${LIB}/$file ]; then
  2017.       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2018.       chmod +w ${LIB}/$file 2>/dev/null
  2019.       chmod a+r ${LIB}/$file 2>/dev/null
  2020.     fi
  2021.  
  2022.     echo Fixing $file
  2023.     sed -e '/^#[     ]*define[     ][     ]*bool[     ][     ]*char[     ]*$/i\
  2024. #ifndef __cplusplus'\
  2025.     -e '/^#[     ]*define[     ][     ]*bool[     ][     ]*char[     ]*$/a\
  2026. #endif'\
  2027.     -e '/^typedef[     ][     ]*char[     ][     ]*bool[     ]*;/i\
  2028. #ifndef __cplusplus'\
  2029.     -e '/^typedef[     ][     ]*char[     ][     ]*bool[     ]*;/a\
  2030. #endif'\
  2031.     ${LIB}/$file > ${LIB}/${file}.sed
  2032.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2033.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2034.       rm -f ${LIB}/$file
  2035.     else
  2036.       # Find any include directives that use "file".
  2037.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2038.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  2039.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2040.       done
  2041.     fi
  2042.   fi
  2043. done
  2044.  
  2045. # Fix incorrect S_IF* definitions on m88k-sysv3.
  2046. file=sys/stat.h
  2047. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2048.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2049.   chmod +w ${LIB}/$file 2>/dev/null
  2050.   chmod a+r ${LIB}/$file 2>/dev/null
  2051. fi
  2052.  
  2053. if [ -r ${LIB}/$file ]; then
  2054.   echo Fixing $file
  2055.   sed -e 's/^\(#define[     ]*S_IS[A-Z]*(m)\)[     ]*(m[     ]*&[     ]*\(S_IF[A-Z][A-Z][A-Z][A-Z]*\)[     ]*)/\1 (((m)\&S_IFMT)==\2)/' \
  2056.       -e 's/^\(#define[     ]*S_IS[A-Z]*(m)\)[     ]*(m[     ]*&[     ]*\(0[0-9]*\)[     ]*)/\1 (((m)\&S_IFMT)==\2)/' \
  2057.     ${LIB}/$file > ${LIB}/${file}.sed
  2058.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2059.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2060.     rm -f ${LIB}/$file
  2061.   else
  2062.     # Find any include directives that use "file".
  2063.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2064.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2065.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2066.     done
  2067.   fi
  2068. fi
  2069.  
  2070. # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
  2071. for file in stdio.h stdlib.h; do
  2072.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2073.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2074.     chmod +w ${LIB}/$file 2>/dev/null
  2075.     chmod a+r ${LIB}/$file 2>/dev/null
  2076.   fi
  2077.  
  2078.   if [ -r ${LIB}/$file ]; then
  2079.     echo Fixing $file, getopt declaration
  2080.     sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
  2081.       ${LIB}/$file > ${LIB}/${file}.sed
  2082.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2083.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2084.       rm -f ${LIB}/$file
  2085.     else
  2086.       # Find any include directives that use "file".
  2087.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2088.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  2089.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2090.       done
  2091.     fi
  2092.   fi
  2093. done
  2094.  
  2095. # Determine if we're on Interactive Unix 2.2 or later, in which case we
  2096. # need to fix some additional files.  This is the same test for ISC that
  2097. # Autoconf uses.
  2098. if test -d /etc/conf/kconfig.d \
  2099.     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
  2100.   echo "Fixing ISC __STDC__ goof in several files..."
  2101.   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
  2102.     echo $name
  2103.     if test -r ${LIB}/$name; then
  2104.       file=${LIB}/$name
  2105.     else
  2106.       file=${INPUT}/$name
  2107.     fi
  2108.     # On Interactive 2.2, certain traditional Unix definitions
  2109.     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
  2110.     # defined, not just if _POSIX_SOURCE is defined.  This makes it
  2111.     # impossible to compile any nontrivial program except with -posix.
  2112.     sed \
  2113. 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
  2114.         < $file > ${LIB}/$name.
  2115.     mv ${LIB}/$name. ${LIB}/$name
  2116.   done
  2117.   
  2118.   echo "Fixing ISC fmod declaration"
  2119.   # This one's already been fixed for other things.
  2120.   file=${LIB}/math.h
  2121.   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
  2122.   mv $file. $file
  2123.   
  2124.   echo "Fixing nested comments in ISC <sys/limits.h>"
  2125.   file=sys/limits.h
  2126.   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
  2127.   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
  2128. fi
  2129.  
  2130. # These files in Sun OS 4.x use /**/ to concatenate tokens.
  2131. for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h    \
  2132.     sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h    \
  2133.     sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
  2134. do
  2135.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2136.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2137.     chmod +w ${LIB}/$file 2>/dev/null
  2138.     chmod a+r ${LIB}/$file 2>/dev/null
  2139.   fi
  2140.  
  2141.   if [ -r ${LIB}/$file ]; then
  2142.     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
  2143.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2144.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2145.       rm -f ${LIB}/$file
  2146.     else
  2147.       # Find any include directives that use "file".
  2148.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2149.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  2150.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2151.       done
  2152.     fi
  2153.   fi
  2154. done
  2155.  
  2156. # These files in ARM/RISCiX use /**/ to concatenate tokens.
  2157. for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
  2158.     dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
  2159. do
  2160.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2161.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2162.     chmod +w ${LIB}/$file 2>/dev/null
  2163.     chmod a+r ${LIB}/$file 2>/dev/null
  2164.   fi
  2165.  
  2166.   if [ -r ${LIB}/$file ]; then
  2167.     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
  2168.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2169.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2170.       rm -f ${LIB}/$file
  2171.   else
  2172.     # Find any include directives that use "file".
  2173.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2174.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2175.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2176.     done
  2177.     fi
  2178.   fi
  2179. done
  2180.  
  2181. # math.h on SunOS 4 puts the declaration of matherr before the definition
  2182. # of struct exception, so the prototype (added by fixproto) causes havoc.
  2183. file=math.h
  2184. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2185.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2186.   chmod +w ${LIB}/$file 2>/dev/null
  2187.   chmod a+r ${LIB}/$file 2>/dev/null
  2188. fi
  2189.  
  2190. if [ -r ${LIB}/$file ]; then
  2191.   echo Fixing $file, matherr declaration
  2192.   sed -e '/^struct exception/,$b' \
  2193.       -e '/matherr/i\
  2194. struct exception;
  2195. '\
  2196.     ${LIB}/$file > ${LIB}/${file}.sed
  2197.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2198.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2199.     rm -f ${LIB}/$file
  2200.   else
  2201.     # Find any include directives that use "file".
  2202.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2203.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2204.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2205.     done
  2206.   fi
  2207. fi
  2208.  
  2209. # assert.h on HP/UX is not C++ ready, even though NO_IMPLICIT_EXTERN_C
  2210. # is defined on HP/UX.
  2211. file=assert.h
  2212. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2213.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2214.   chmod +w ${LIB}/$file 2>/dev/null
  2215.   chmod a+r ${LIB}/$file 2>/dev/null
  2216. fi
  2217.  
  2218. if [ -r ${LIB}/$file ]; then
  2219.   if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
  2220.      || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
  2221.     true
  2222.   else
  2223.     echo Fixing $file
  2224.     echo '#ifdef __cplusplus
  2225. extern "C" {
  2226. #endif' > ${LIB}/${file}.sed
  2227.     cat ${LIB}/${file} >> ${LIB}/${file}.sed
  2228.     echo '#ifdef __cplusplus
  2229. }
  2230. #endif' >> ${LIB}/${file}.sed 
  2231.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2232.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2233.       rm -f ${LIB}/$file
  2234.     else
  2235.       # Find any include directives that use "file".
  2236.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2237.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  2238.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2239.       done
  2240.     fi
  2241.   fi
  2242. fi
  2243.  
  2244. # check for broken assert.h that needs stdio.h or stdlib.h
  2245. file=assert.h
  2246. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2247.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2248.   chmod +w ${LIB}/$file 2>/dev/null
  2249.   chmod a+r ${LIB}/$file 2>/dev/null
  2250. fi
  2251.  
  2252. if [ -r ${LIB}/$file ]; then
  2253.   if grep 'stderr' ${LIB}/$file >/dev/null 2>/dev/null; then
  2254.     if grep 'include.*stdio.h' ${LIB}/$file >/dev/null 2>/dev/null; then
  2255.       true
  2256.     else
  2257.       echo "Fixing $file (needs stdio.h)"
  2258.       echo '#ifdef __cplusplus
  2259. #include <stdio.h>
  2260. #endif' >>${LIB}/$file
  2261.     fi
  2262.   fi
  2263.   if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
  2264.      grep 'abort *(' ${LIB}/$file >/dev/null 2>/dev/null; then
  2265.     if grep 'include.*stdlib.h' ${LIB}/$file >/dev/null 2>/dev/null; then
  2266.       true
  2267.     else
  2268.       echo "Fixing $file (needs stdlib.h)"
  2269.       echo '#ifdef __cplusplus
  2270. #include <stdlib.h>
  2271. #endif' >>${LIB}/$file
  2272.     fi
  2273.   fi
  2274.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2275.     rm -f ${LIB}/$file
  2276.   else
  2277.     # Find any include directives that use "file".
  2278.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2279.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2280.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2281.     done
  2282.   fi
  2283. fi
  2284.  
  2285. # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
  2286. file=unistd.h
  2287. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2288.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2289.   chmod +w ${LIB}/$file 2>/dev/null
  2290.   chmod a+r ${LIB}/$file 2>/dev/null
  2291. fi
  2292.  
  2293. if [ -r ${LIB}/$file ]; then
  2294.   echo Fixing $file, sbrk declaration
  2295.   sed -e 's/char\([     ]*\*[     ]*sbrk[     ]*(\)/void\1/' \
  2296.     ${LIB}/$file > ${LIB}/${file}.sed
  2297.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2298.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2299.     rm -f ${LIB}/$file
  2300.   else
  2301.     # Find any include directives that use "file".
  2302.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2303.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2304.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2305.     done
  2306.   fi
  2307. fi
  2308.  
  2309. # This file on SunOS 4 has a very large macro.  When the sed loop
  2310. # tries pull it in, it overflows the pattern space size of the SunOS
  2311. # sed (GNU sed does not have this problem).  Since the file does not
  2312. # require fixing, we remove it from the fixed directory.
  2313. file=sundev/ipi_error.h
  2314. if [ -r ${LIB}/$file ]; then
  2315.   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
  2316.   rm -f ${LIB}/$file
  2317. fi
  2318.  
  2319. # Put cpp wrappers around these include files to avoid redeclaration
  2320. # errors during multiple inclusion on m88k-tektronix-sysv3.
  2321. for file in time.h sys/time.h ; do
  2322.   if egrep '#ifndef' $file >/dev/null 2>&1; then
  2323.     true
  2324.   else
  2325.     if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2326.       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2327.       chmod +w ${LIB}/$file 2>/dev/null
  2328.     fi
  2329.     if [ -r ${LIB}/$file ]; then
  2330.       echo Fixing $file, to protect against multiple inclusion.
  2331.       cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
  2332.       (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
  2333.       echo "#define __GCC_GOT_${cpp_wrapper}_"
  2334.       cat ${LIB}/${file}
  2335.       echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
  2336.       rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
  2337.     fi
  2338.   fi
  2339. done
  2340.  
  2341. # Fix fcntl prototype in fcntl.h on LynxOS.
  2342. file=fcntl.h
  2343. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2344.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2345.   chmod +w ${LIB}/$file 2>/dev/null
  2346.   chmod a+r ${LIB}/$file 2>/dev/null
  2347. fi
  2348.  
  2349. if [ -r ${LIB}/$file ]; then
  2350.   echo Fixing $file, fcntl declaration
  2351.   sed -e 's/\(fcntl.*(int, int, \)int)/\1...)/' \
  2352.     ${LIB}/$file > ${LIB}/${file}.sed
  2353.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2354.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2355.     rm -f ${LIB}/$file
  2356.   else
  2357.     # Find any include directives that use "file".
  2358.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2359.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2360.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2361.     done
  2362.   fi
  2363. fi
  2364.  
  2365. # Fix definitions of macros used by va-i960.h in VxWorks header file.
  2366. file=arch/i960/archI960.h
  2367. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2368.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2369.   chmod +w ${LIB}/$file 2>/dev/null
  2370.   chmod a+r ${LIB}/$file 2>/dev/null
  2371. fi
  2372.  
  2373. if [ -r ${LIB}/$file ]; then
  2374.   echo Fixing $file
  2375.   sed -e 's/__vsiz/__vxvsiz/' -e 's/__vali/__vxvali/' \
  2376.       -e s'/__vpad/__vxvpad/' -e 's/__alignof__/__vxalignof__/' \
  2377.     ${LIB}/$file > ${LIB}/${file}.sed
  2378.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2379.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2380.     rm -f ${LIB}/$file
  2381.   else
  2382.     # Find any include directives that use "file".
  2383.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2384.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2385.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2386.     done
  2387.   fi
  2388. fi
  2389.  
  2390. # Make VxWorks header which is almost gcc ready fully gcc ready.
  2391. file=types/vxTypesBase.h
  2392. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2393.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2394.   chmod +w ${LIB}/$file 2>/dev/null
  2395.   chmod a+r ${LIB}/$file 2>/dev/null
  2396. fi
  2397.  
  2398. if [ -r ${LIB}/$file ]; then
  2399.   echo Fixing $file
  2400.   sed -e 's/#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__/#if 1/' \
  2401.       -e '/[     ]size_t/i\
  2402. #ifndef _GCC_SIZE_T\
  2403. #define _GCC_SIZE_T
  2404. ' \
  2405.       -e '/[     ]size_t/a\
  2406. #endif
  2407. ' \
  2408.       -e '/[     ]ptrdiff_t/i\
  2409. #ifndef _GCC_PTRDIFF_T\
  2410. #define _GCC_PTRDIFF_T
  2411. ' \
  2412.       -e '/[     ]ptrdiff_t/a\
  2413. #endif
  2414. ' \
  2415.       -e '/[     ]wchar_t/i\
  2416. #ifndef _GCC_WCHAR_T\
  2417. #define _GCC_WCHAR_T
  2418. ' \
  2419.       -e '/[     ]wchar_t/a\
  2420. #endif
  2421. ' \
  2422.     ${LIB}/$file > ${LIB}/${file}.sed
  2423.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2424.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2425.     rm -f ${LIB}/$file
  2426.   else
  2427.     # Find any include directives that use "file".
  2428.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2429.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2430.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2431.     done
  2432.   fi
  2433. fi
  2434.  
  2435. # Fix VxWorks <sys/stat.h> to not require including <vxWorks.h>.
  2436. file=sys/stat.h
  2437. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2438.   mkdir ${LIB}/sys 2>/dev/null
  2439.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2440.   chmod +w ${LIB}/$file 2>/dev/null
  2441.   chmod a+r ${LIB}/$file 2>/dev/null
  2442. fi
  2443.  
  2444. if [ -r ${LIB}/$file ]; then
  2445.   if egrep '#include' ${LIB}/$file >/dev/null 2>&1; then
  2446.     :
  2447.   else
  2448.     if egrep 'ULONG' ${LIB}/$file >/dev/null 2>&1 \
  2449.        && [ -r types/vxTypesOld.h ]; then
  2450.       echo Fixing $file
  2451.       sed -e '/#define[     ][     ]*__INCstath/a\
  2452. #include <types/vxTypesOld.h>
  2453. ' \
  2454.     ${LIB}/$file > ${LIB}/${file}.sed
  2455.       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2456.     fi
  2457.   fi
  2458.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2459.     rm -f ${LIB}/$file
  2460.   else
  2461.     # Find any include directives that use "file".
  2462.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2463.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2464.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2465.     done
  2466.   fi
  2467. fi
  2468.  
  2469. # Fix VxWorks <time.h> to not require including <vxTypes.h>.
  2470. file=time.h
  2471. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2472.   mkdir ${LIB}/sys 2>/dev/null
  2473.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2474.   chmod +w ${LIB}/$file 2>/dev/null
  2475.   chmod a+r ${LIB}/$file 2>/dev/null
  2476. fi
  2477.  
  2478. if [ -r ${LIB}/$file ]; then
  2479.   if egrep 'uint_t[     ][     ]*_clocks_per_sec' ${LIB}/$file >/dev/null 2>&1; then
  2480.     echo Fixing $file
  2481.     sed -e 's/uint_t/unsigned int/' ${LIB}/$file > ${LIB}/${file}.sed
  2482.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2483.   fi
  2484.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2485.     rm -f ${LIB}/$file
  2486.   else
  2487.     # Find any include directives that use "file".
  2488.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2489.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2490.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2491.     done
  2492.   fi
  2493. fi
  2494.     
  2495.  
  2496. # This loop does not appear to do anything, because it uses file
  2497. # rather than $file when setting target.  It also appears to be
  2498. # unnecessary, since the main loop processes symbolic links.
  2499. #if $LINKS; then
  2500. #  echo 'Making internal symbolic non-directory links'
  2501. #  cd ${INPUT}
  2502. #  files=`find . -type l -print`
  2503. #  for file in $files; do
  2504. #    dest=`ls -ld $file | sed -n 's/.*-> //p'`
  2505. #    if expr "$dest" : '[^/].*' > /dev/null; then    
  2506. #      target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  2507. #      if [ -f $target ]; then
  2508. #        ln -s $dest ${LIB}/$file >/dev/null 2>&1
  2509. #      fi
  2510. #    fi
  2511. #  done
  2512. #fi
  2513.  
  2514. # Make sure that any include files referenced using double quotes
  2515. # exist in the fixed directory.  This comes last since otherwise
  2516. # we might end up deleting some of these files "because they don't
  2517. # need any change."
  2518. set x $required
  2519. shift
  2520. while [ $# != 0 ]; do
  2521.   newreq=
  2522.   while [ $# != 0 ]; do
  2523.     # $1 is the directory to copy from, $2 is the unfixed file,
  2524.     # $3 is the fixed file name.
  2525.     cd ${INPUT}
  2526.     cd $1
  2527.     if [ -r $2 ] && [ ! -r $3 ]; then
  2528.       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
  2529.       chmod +w $3 2>/dev/null
  2530.       chmod a+r $3 2>/dev/null
  2531.       echo Copied $2
  2532.       for include in `egrep '^[     ]*#[     ]*include[     ]*"[^/]' $3 | sed -e 's/^[     ]*#[     ]*include[     ]*"\([^"]*\)".*$/\1/'`; do
  2533.     dir=`echo $2 | sed -e s'|/[^/]*$||'`
  2534.     dir2=`echo $3 | sed -e s'|/[^/]*$||'`
  2535.     newreq="$newreq $1 $dir/$include $dir2/$include"
  2536.       done
  2537.     fi
  2538.     shift; shift; shift
  2539.   done
  2540.   set x $newreq
  2541.   shift
  2542. done
  2543.  
  2544. echo 'Cleaning up DONE files.'
  2545. cd $LIB
  2546. find . -name DONE -exec rm -f '{}' ';'
  2547.  
  2548. echo 'Removing unneeded directories:'
  2549. cd $LIB
  2550. files=`find . -type d -print | sort -r`
  2551. for file in $files; do
  2552.   rmdir $LIB/$file > /dev/null 2>&1
  2553. done
  2554.  
  2555. exit 0
  2556.