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