home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / gnu / gcc-2.3.3-src.lha / src / amiga / gcc-2.3.3 / fixincludes < prev    next >
Encoding:
Text File  |  1994-02-07  |  26.3 KB  |  906 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 where gcc sources (and sometimes special include files) live.
  9. # fixincludes doesn't use this, but fixinc.svr4 does, and I want to make
  10. # sure somebody doesn't try to use arg3 for something incompatible. -- gumby
  11. SRCDIR=${3-${SRCDIR-.}}
  12.  
  13. # Directory containing the original header files.
  14. # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
  15. INPUT=${2-${INPUT-/usr/include}}
  16.  
  17. # This prevents /bin/ex from failing if the current terminal type is
  18. # unrecognizable.
  19. TERM=unknown
  20. export TERM
  21. # This prevents two problems:
  22. # Either ex might find a .exrc file and get confused,
  23. # or ex might complain if the EXINIT variable is invalid. 
  24. # We know there is no .exrc in the GCC source.
  25. # `set' is a no-op ex command.
  26. EXINIT=set
  27. export EXINIT
  28.  
  29. # Define PWDCMD as a command to use to get the working dir
  30. # in the form that we want.
  31. PWDCMD=pwd
  32. case "`pwd`" in
  33. //*)
  34.     # On an Apollo, discard everything before `/usr'.
  35.     PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
  36.     ;;
  37. esac
  38.  
  39. # Directory in which to store the results.
  40. LIB=${1?"fixincludes: output directory not specified"}
  41.  
  42. # Make sure it exists.
  43. if [ ! -d $LIB ]; then
  44.   mkdir $LIB || exit 1
  45. fi
  46.  
  47. # Make LIB absolute.
  48. cd $LIB; LIB=`${PWDCMD}`
  49.  
  50. # Fail if no arg to specify a directory for the output.
  51. if [ x$1 = x ]
  52. then echo fixincludes: no output directory specified
  53. exit 1
  54. fi
  55.  
  56. echo Building fixed headers in ${LIB}
  57.  
  58. # Determine whether this system has symbolic links.
  59. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  60.   rm -f $LIB/ShouldNotExist
  61.   LINKS=true
  62. else
  63.   LINKS=false
  64. fi
  65.  
  66. echo Finding directories and links to directories
  67. cd ${INPUT}
  68. # Find all directories and all symlinks that point to directories.
  69. # Put the list in $files.
  70. # Each time we find a symlink, add it to newdirs
  71. # so that we do another find within the dir the link points to.
  72. # Note that $files may have duplicates in it;
  73. # later parts of this file are supposed to ignore them.
  74. dirs="."
  75. levels=2
  76. while [ -n "$dirs" ] && [ $levels -gt 0 ]
  77. do
  78.     levels=`expr $levels - 1`
  79.     newdirs=
  80.     for d in $dirs
  81.     do
  82.     echo " Searching $INPUT/$d"
  83.     if [ "$d" != . ]
  84.     then
  85.         d=$d/.
  86.     fi
  87.  
  88.     # Find all directories under $d, relative to $d, excluding $d itself.
  89.         files="$files `find $d -type d -print | \
  90.                sed -e '/\/\.$/d' -e '/^\.$/d'`"
  91.     # Find all links to directories.
  92.     # Using `-exec test -d' in find fails on some systems,
  93.     # and trying to run test via sh fails on others,
  94.     # so this is the simplest alternative left.
  95.     # First find all the links, then test each one.
  96.     theselinks=
  97.     $LINKS && \
  98.       theselinks=`find $d -type l -print`
  99.     for d1 in $theselinks --dummy--
  100.     do
  101.         # If the link points to a directory,
  102.         # add that dir to $newdirs
  103.         if [ -d $d1 ]
  104.         then
  105.         newdirs="$newdirs $d1"
  106.         fi
  107.     done
  108.     done
  109.  
  110.     files="$files $newdirs"
  111.     dirs="$newdirs"
  112. done
  113.  
  114. dirs=
  115. echo "All directories (including links to directories):"
  116. echo $files
  117.  
  118. for file in $files; do
  119.   rm -rf $LIB/$file
  120.   if [ ! -d $LIB/$file ]
  121.   then mkdir $LIB/$file
  122.   fi
  123. done
  124. mkdir $LIB/root
  125.  
  126. # treetops gets an alternating list
  127. # of old directories to copy
  128. # and the new directories to copy to.
  129. treetops="${INPUT} ${LIB}"
  130.  
  131. if $LINKS; then
  132.   echo 'Making symbolic directory links'
  133.   for file in $files; do
  134.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  135.     if [ "$dest" ]; then    
  136.       cwd=`${PWDCMD}`
  137.       # In case $dest is relative, get to $file's dir first.
  138.       cd ${INPUT}
  139.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  140.       # Check that the target directory exists.
  141.       # Redirections changed to avoid bug in sh on Ultrix.
  142.       (cd $dest) > /dev/null 2>&1
  143.       if [ $? = 0 ]; then
  144.     cd $dest
  145.     # X gets the dir that the link actually leads to.
  146.     x=`${PWDCMD}`
  147.     # If a link points to ., make a similar link to .
  148.     if [ $x = $INPUT ]; then
  149.       echo $file '->' . ': Making link'
  150.       rm -fr ${LIB}/$file > /dev/null 2>&1
  151.       ln -s . ${LIB}/$file > /dev/null 2>&1
  152.     # If link leads back into ${INPUT},
  153.     # make a similar link here.
  154.     elif expr $x : "${INPUT}/.*" > /dev/null; then
  155.       # Y gets the actual target dir name, relative to ${INPUT}.
  156.       y=`echo $x | sed -n "s&${INPUT}/&&p"`
  157.       echo $file '->' $y ': Making link'
  158.       rm -fr ${LIB}/$file > /dev/null 2>&1
  159.       ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
  160.     else
  161.       # If the link is to a dir $target outside ${INPUT},
  162.       # repoint the link at ${INPUT}/root$target
  163.       # and process $target into ${INPUT}/root$target
  164.       # treat this directory as if it actually contained the files.
  165.       echo $file '->' root$x ': Making link'
  166.       if [ -d $LIB/root$x ]
  167.       then true
  168.       else
  169.         dirname=root$x/
  170.         dirmade=.
  171.         cd $LIB
  172.         while [ x$dirname != x ]; do
  173.           component=`echo $dirname | sed -e 's|/.*$||'`
  174.           mkdir $component >/dev/null 2>&1
  175.           cd $component
  176.           dirmade=$dirmade/$component
  177.           dirname=`echo $dirname | sed -e 's|[^/]*/||'`
  178.         done
  179.       fi
  180.       rm -fr ${LIB}/$file > /dev/null 2>&1
  181.       ln -s ${LIB}/root$x ${LIB}/$file > /dev/null 2>&1
  182.       treetops="$treetops $x ${LIB}/root$x"
  183.     fi
  184.       fi
  185.       cd $cwd
  186.     fi
  187.   done
  188. fi
  189.  
  190. set - $treetops
  191. while [ $# != 0 ]; do
  192.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  193.   cd ${INPUT}
  194.   cd $1
  195. # The same dir can appear more than once in treetops.
  196. # There's no need to scan it more than once.
  197.   if [ -f $2/DONE ]
  198.   then
  199.     files=
  200.   else
  201.     touch $2/DONE
  202.     echo Fixing directory $1 into $2
  203. # Check .h files which are symlinks as well as those which are files.
  204. # A link to a header file will not be processed by anything but this.
  205.     if $LINKS; then
  206.       files=`find . -name '*.h' \( -type f -o -type l \) -print`
  207.     else
  208.       files=`find . -name '*.h' -type f -print`
  209.     fi
  210.     echo Checking header files
  211.   fi
  212. # Note that BSD43_* are used on recent MIPS systems.
  213.   for file in $files; do
  214. # This call to egrep is essential, since checking a file with egrep
  215. # is much faster than actually trying to fix it.
  216. # It is also essential that most files *not* match!
  217. # Thus, matching every #endif is unacceptable.
  218. # But the argument to egrep must be kept small, or many versions of egrep
  219. # won't be able to handle it.
  220. # rms: I removed `|#[el].*if.*[^/     ]' because it made egrep fail.
  221.     if egrep '//|[     _]_IO|CTRL|#define.NULL|#[el]*if.*([0-9]|sparc|vax|sun|pyr)' $file > /dev/null; then
  222.       echo Fixing $file
  223.       if [ -r $file ]; then
  224.     cp $file $2/$file >/dev/null 2>&1    \
  225.     || echo "Can't copy $file"
  226.     chmod +w $2/$file
  227. # Following two lines removed.
  228. #      s%^\([     ]*#[     ]*endif[     ]*\)\([^/     ].*\)$%\1/* \2 */%
  229. #      s%^\([     ]*#[     ]*else[     ]*\)\([^/     ].*\)$%\1/* \2 */%
  230.  
  231.     sed -e '
  232.                    :loop
  233.       /\\$/            N
  234.       /\\$/            b loop
  235.       /\/\//            s|//\(.*\)$|/*\1*/|
  236.       /[     ]_IO[A-Z]*[     ]*(/    s/(\(.\),/('\''\1'\'',/
  237.       /[     ]BSD43__IO[A-Z]*[     ]*(/    s/(\(.\),/('\''\1'\'',/
  238.       /#define._IO/            s/'\''x'\''/x/g
  239.       /#define.BSD43__IO/        s/'\''x'\''/x/g
  240.       /[^A-Z]CTRL[     ]*(/        s/\([^'\'']\))/'\''\1'\'')/
  241.       /#define.CTRL/        s/'\''c'\''/c/g
  242.       /#define._CTRL/        s/'\''c'\''/c/g
  243.       /#define.BSD43_CTRL/        s/'\''c'\''/c/g
  244.       /#[a-z]*if.*[     (]m68k/    s/\([^_]\)m68k/\1__m68k__/g
  245.       /#[a-z]*if.*[     (]__i386/    s/__i386/__i386__/g
  246.       /#[a-z]*if.*[     (]i386/    s/\([^_]\)i386/\1__i386__/g
  247.       /#[a-z]*if.*[     (]sparc/    s/\([^_]\)sparc/\1__sparc__/g
  248.       /#[a-z]*if.*[     (]mc68000/    s/\([^_]\)mc68000/\1__mc68000__/g
  249.       /#[a-z]*if.*[     (]vax/        s/\([^_]\)vax/\1__vax__/g
  250.       /#[a-z]*if.*[     (]sun/        s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
  251.       /#[a-z]*if.*[     (]sun/        s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
  252.       /#[a-z]*if.*[     (]ns32000/    s/\([^_]\)ns32000/\1__ns32000__/g
  253.       /#[a-z]*if.*[     (]pyr/        s/\([^_]\)pyr/\1__pyr__/g
  254.       /#[a-z]*if.*[     (]is68k/    s/\([^_]\)is68k/\1__is68k__/g
  255.       /^#define.NULL[     ]/    i\
  256.         #undef NULL
  257.     ' $2/$file > $2/$file.sed
  258.     mv $2/$file.sed $2/$file
  259.     if cmp $file $2/$file >/dev/null 2>&1; then
  260.        echo Deleting $2/$file\; no fixes were needed.
  261.        rm $2/$file
  262.     fi
  263.       fi
  264.     fi
  265.   done
  266.   shift; shift
  267. done
  268.  
  269. cd ${INPUT}
  270.  
  271. # Fix one other error in this file: a mismatched quote not inside a C comment.
  272. file=sundev/vuid_event.h
  273. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  274.   mkdir ${LIB}/sundev 2>/dev/null
  275.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  276.   chmod +w ${LIB}/$file 2>/dev/null
  277. fi
  278.  
  279. if [ -r ${LIB}/$file ]; then
  280.   echo Fixing $file comment
  281.   ex ${LIB}/$file <<EOF
  282.   g/doesn't/s/doesn't/does not/
  283.   wq
  284. EOF
  285.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  286.     echo Deleting ${LIB}/$file\; no fixes were needed.
  287.     rm ${LIB}/$file
  288.   fi
  289. fi
  290.  
  291. # Fix this Sun file to avoid interfering with stddef.h.
  292. file=sys/stdtypes.h
  293. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  294.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  295.   chmod +w ${LIB}/$file 2>/dev/null
  296. fi
  297.  
  298. if [ -r ${LIB}/$file ]; then
  299.   echo Fixing $file
  300.   ex ${LIB}/$file <<EOF
  301.   /size_t.*;/
  302.   i
  303. #ifndef _GCC_SIZE_T
  304. #define _GCC_SIZE_T
  305. .
  306.   /size_t/+1
  307.   i
  308. #endif
  309. .
  310.   /ptrdiff_t.*;/
  311.   i
  312. #ifndef _GCC_PTRDIFF_T
  313. #define _GCC_PTRDIFF_T
  314. .
  315.   /ptrdiff_t/+1
  316.   i
  317. #endif
  318. .
  319.   /wchar_t.*;/
  320.   i
  321. #ifndef _GCC_WCHAR_T
  322. #define _GCC_WCHAR_T
  323. .
  324.   /wchar_t/+1
  325.   i
  326. #endif
  327. .
  328.   wq
  329. EOF
  330.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  331.     echo Deleting ${LIB}/$file\; no fixes were needed.
  332.     rm ${LIB}/$file
  333.   fi
  334. fi
  335.  
  336. # Fix this file to avoid interfering with stddef.h, but don't mistakenly
  337. # match e.g. ssize_t present in AIX for the ps/2.
  338. file=sys/types.h
  339. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  340.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  341.   chmod +w ${LIB}/$file 2>/dev/null
  342. fi
  343.  
  344. if [ -r ${LIB}/$file ]; then
  345.   echo Fixing $file
  346.   ex ${LIB}/$file <<EOF
  347.   /typedef.*[     ]size_t.*;/
  348.   i
  349. #ifndef _GCC_SIZE_T
  350. #define _GCC_SIZE_T
  351. .
  352.   /size_t/+1
  353.   i
  354. #endif
  355. .
  356.   wq
  357. EOF
  358.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  359.     echo Deleting ${LIB}/$file\; no fixes were needed.
  360.     rm ${LIB}/$file
  361.   fi
  362. fi
  363.  
  364. # Fix an error in this file: the #if says _cplusplus, not the double
  365. # underscore __cplusplus that it should be
  366. file=tinfo.h
  367. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  368.   mkdir ${LIB}/rpcsvc 2>/dev/null
  369.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  370.   chmod +w ${LIB}/$file 2>/dev/null
  371. fi
  372.  
  373. if [ -r ${LIB}/$file ]; then
  374.   echo Fixing $file, __cplusplus macro
  375.   sed -e 's/[     ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
  376.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  377.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  378.     rm ${LIB}/$file
  379.   fi
  380. fi
  381.  
  382. # Fix an error in this file: a missing semi-colon at the end of the statsswtch
  383. # structure definition.
  384. file=rpcsvc/rstat.h
  385. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  386.   mkdir ${LIB}/rpcsvc 2>/dev/null
  387.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  388.   chmod +w ${LIB}/$file 2>/dev/null
  389. fi
  390.  
  391. if [ -r ${LIB}/$file ]; then
  392.   echo Fixing $file, definition of statsswtch
  393.   ex ${LIB}/$file <<EOF
  394.   g/boottime$/s//&;/
  395.   wq
  396. EOF
  397.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  398.     echo Deleting ${LIB}/$file\; no fixes were needed.
  399.     rm ${LIB}/$file
  400.   fi
  401. fi
  402.  
  403. # Fix an error in this file: a missing semi-colon at the end of the nodeent
  404. # structure definition.
  405. file=netdnet/dnetdb.h
  406. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  407.   mkdir ${LIB}/netdnet 2>/dev/null
  408.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  409.   chmod +w ${LIB}/$file 2>/dev/null
  410. fi
  411.  
  412. if [ -r ${LIB}/$file ]; then
  413.   echo Fixing $file, definition of nodeent
  414.   ex ${LIB}/$file <<EOF
  415.   g/char.*na_addr *$/s//&;/
  416.   wq
  417. EOF
  418.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  419.     echo Deleting ${LIB}/$file\; no fixes were needed.
  420.     rm ${LIB}/$file
  421.   fi
  422. fi
  423.  
  424. # Check for bad #ifdef line (in Ultrix 4.1)
  425. file=sys/file.h
  426. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  427.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  428.   chmod +w ${LIB}/$file 2>/dev/null
  429. fi
  430.  
  431. if [ -r ${LIB}/$file ]; then
  432.   echo Fixing $file, bad \#ifdef line
  433.   ex ${LIB}/$file <<EOF
  434.   g/^#ifdef KERNEL && !defined/
  435.   s/#ifdef KERNEL && !defined/#if defined(KERNEL) \&\& !defined/
  436.   wq
  437. EOF
  438.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  439.     echo Deleting ${LIB}/$file\; no fixes were needed.
  440.     rm ${LIB}/$file
  441.   fi
  442. fi
  443.  
  444. # Remove nested comments created by #endifs in a comment (Ultrix 4.1)
  445. # Only needed if commenting out junk after #endif.
  446. #file=signal.h
  447. #if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  448. #  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  449. #  chmod +w ${LIB}/$file 2>/dev/null
  450. #fi
  451. #
  452. #if [ -r ${LIB}/$file ]; then
  453. #  echo Fixing $file, nested comments
  454. #  sed -e 's/#endif.*/#endif/' ${LIB}/$file > ${LIB}/${file}.sed
  455. #  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  456. #  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  457. #    echo Deleting ${LIB}/$file\; no fixes were needed.
  458. #    rm -f ${LIB}/$file
  459. #  fi
  460. #fi
  461.  
  462. # Check for superfluous `static' (in Ultrix 4.2)
  463. file=machine/cpu.h
  464. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  465.   mkdir ${LIB}/machine 2>/dev/null
  466.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  467.   chmod +w ${LIB}/$file 2>/dev/null
  468. fi
  469.  
  470. if [ -r ${LIB}/$file ]; then
  471.   echo Fixing $file, superfluous static
  472.   ex ${LIB}/$file <<EOF
  473.   g/^static struct tlb_pid_state/
  474.   s/static//
  475.   wq
  476. EOF
  477.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  478.     echo Deleting ${LIB}/$file\; no fixes were needed.
  479.     rm ${LIB}/$file
  480.   else
  481. # This file has an alternative name, mips/cpu.h.  Fix that name, too.
  482.     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>& 1; then
  483.       mkdir ${LIB}/mips 2>&-
  484.       ln ${LIB}/$file ${LIB}/mips/cpu.h 
  485.     fi
  486.   fi
  487. fi
  488.  
  489. # Incorrect sprintf declaration in X11/Xmu.h
  490. file=X11/Xmu.h
  491. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  492.   mkdir ${LIB}/X11 2>/dev/null
  493.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  494.   chmod +w ${LIB}/$file 2>/dev/null
  495. fi
  496.  
  497. if [ -r ${LIB}/$file ]; then
  498.   echo Fixing $file sprintf declaration
  499.   ex ${LIB}/$file <<EOF
  500.   /^extern char \*    sprintf();$/c
  501. #ifndef __STDC__
  502. extern char *    sprintf();
  503. #endif /* !defined __STDC__ */
  504. .
  505.   wq
  506. EOF
  507.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  508.     echo Deleting ${LIB}/$file\; no fixes were needed.
  509.     rm ${LIB}/$file
  510.   fi
  511. fi
  512.  
  513. # Incorrect sprintf declaration in X11/Xmu/Xmu.h
  514. # (It's not clear whether the right file name is this or X11/Xmu.h.)
  515. file=X11/Xmu/Xmu.h
  516. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  517.   mkdir ${LIB}/X11/Xmu 2>/dev/null
  518.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  519.   chmod +w ${LIB}/$file 2>/dev/null
  520. fi
  521.  
  522. if [ -r ${LIB}/$file ]; then
  523.   echo Fixing $file sprintf declaration
  524.   ex ${LIB}/$file <<EOF
  525.   /^extern char \*    sprintf();$/c
  526. #ifndef __STDC__
  527. extern char *    sprintf();
  528. #endif /* !defined __STDC__ */
  529. .
  530.   wq
  531. EOF
  532.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  533.     echo Deleting ${LIB}/$file\; no fixes were needed.
  534.     rm ${LIB}/$file
  535.   fi
  536. fi
  537.  
  538. # Check for missing ';' in struct
  539. file=netinet/ip.h
  540. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  541.   mkdir ${LIB}/netinet 2>/dev/null
  542.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  543.   chmod +w ${LIB}/$file 2>/dev/null
  544. fi
  545.  
  546. if [ -r ${LIB}/$file ]; then
  547.   echo Fixing $file
  548.   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
  549.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  550.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  551.     echo Deleting ${LIB}/$file\; no fixes were needed.
  552.     rm -f ${LIB}/$file
  553.   fi
  554. fi
  555.  
  556. # Fix the CAT macro in SunOS memvar.h.
  557. file=pixrect/memvar.h
  558. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  559.   mkdir ${LIB}/pixrect 2>/dev/null
  560.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  561.   chmod +w ${LIB}/$file 2>/dev/null
  562. fi
  563.  
  564. if [ -r ${LIB}/$file ]; then
  565.   echo Fixing $file
  566.   sed -e '/^#define.CAT(a,b)/ i\
  567. #ifdef __STDC__ \
  568. #define CAT(a,b) a##b\
  569. #else
  570. /^#define.CAT(a,b)/ a\
  571. #endif
  572. ' ${LIB}/$file > ${LIB}/${file}.sed
  573.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  574.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  575.     echo Deleting ${LIB}/$file\; no fixes were needed.
  576.     rm -f ${LIB}/$file
  577.   fi
  578. fi
  579.  
  580. # Check for yet more missing ';' in struct (in SunOS 4.0.x)
  581. file=rpcsvc/rusers.h
  582. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  583.   mkdir ${LIB}/rpcsvc 2>/dev/null
  584.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  585.   chmod +w ${LIB}/$file 2>/dev/null
  586. fi
  587.  
  588. if [ -r ${LIB}/$file ]; then
  589.   echo Fixing $file
  590.   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
  591.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  592.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  593.     echo Deleting ${LIB}/$file\; no fixes were needed.
  594.     rm -f ${LIB}/$file
  595.   fi
  596. fi
  597.  
  598. # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
  599. file=stdlib.h
  600. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  601.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  602.   chmod +w ${LIB}/$file 2>/dev/null
  603. fi
  604.  
  605. if [ -r ${LIB}/$file ]; then
  606.   echo Fixing $file
  607.   sed -e 's/int    abort/void    abort/g' \
  608.   -e 's/int    free/void    free/g' \
  609.   -e 's/char \*    calloc/void \*    calloc/g' \
  610.   -e 's/char \*    malloc/void \*    malloc/g' \
  611.   -e 's/char \*    realloc/void \*    realloc/g' \
  612.   -e 's/int    exit/void    exit/g' ${LIB}/$file > ${LIB}/${file}.sed
  613.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  614.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  615.     echo Deleting ${LIB}/$file\; no fixes were needed.
  616.     rm -f ${LIB}/$file
  617.   fi
  618. fi
  619.  
  620. # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
  621. file=malloc.h
  622. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  623.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  624.   chmod +w ${LIB}/$file 2>/dev/null
  625. fi
  626.  
  627. if [ -r ${LIB}/$file ]; then
  628.   echo Fixing $file
  629.   sed -e 's/typedef[     ]char \*    malloc_t/typedef void \*    malloc_t/g' \
  630.   -e 's/int[     ][     ]*free/void    free/g' \
  631.   ${LIB}/$file > ${LIB}/${file}.sed
  632.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  633.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  634.     echo Deleting ${LIB}/$file\; no fixes were needed.
  635.     rm -f ${LIB}/$file
  636.   fi
  637. fi
  638.  
  639.  
  640. # Fix bogus comment in <locale.h> on SunOS 4.1.
  641. file=locale.h
  642. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  643.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  644.   chmod +w ${LIB}/$file 2>/dev/null
  645. fi
  646.  
  647. if [ -r ${LIB}/$file ]; then
  648.   echo Fixing $file
  649.   sed -e 's%#endif / \*%#endif /\* %g' ${LIB}/$file > ${LIB}/${file}.sed
  650.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  651.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  652.     echo Deleting ${LIB}/$file\; no fixes were needed.
  653.     rm -f ${LIB}/$file
  654.   fi
  655. fi
  656.  
  657. # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
  658. file=hsfs/hsfs_spec.h
  659. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  660.   mkdir ${LIB}/hsfs 2>/dev/null
  661.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  662.   chmod +w ${LIB}/$file 2>/dev/null
  663. fi
  664.  
  665. if [ -r ${LIB}/$file ]; then
  666.   echo Fixing $file
  667.   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
  668.     ${LIB}/$file > ${LIB}/${file}.sed
  669.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  670.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  671.     echo Deleting ${LIB}/$file\; no fixes were needed.
  672.     rm -f ${LIB}/$file
  673.   fi
  674. fi
  675.  
  676. # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
  677. file=hsfs/hsnode.h
  678. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  679.   mkdir ${LIB}/hsfs 2>/dev/null
  680.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  681.   chmod +w ${LIB}/$file 2>/dev/null
  682. fi
  683.  
  684. if [ -r ${LIB}/$file ]; then
  685.   echo Fixing $file
  686.   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
  687.     ${LIB}/$file > ${LIB}/${file}.sed
  688.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  689.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  690.     echo Deleting ${LIB}/$file\; no fixes were needed.
  691.     rm -f ${LIB}/$file
  692.   fi
  693. fi
  694.  
  695. # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
  696. file=hsfs/iso_spec.h
  697. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  698.   mkdir ${LIB}/hsfs 2>/dev/null
  699.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  700.   chmod +w ${LIB}/$file 2>/dev/null
  701. fi
  702.  
  703. if [ -r ${LIB}/$file ]; then
  704.   echo Fixing $file
  705.   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
  706.     ${LIB}/$file > ${LIB}/${file}.sed
  707.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  708.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  709.     echo Deleting ${LIB}/$file\; no fixes were needed.
  710.     rm -f ${LIB}/$file
  711.   fi
  712. fi
  713.  
  714. # Incorrect #include in Sony News-OS 3.2.
  715. file=machine/machparam.h
  716. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  717.   mkdir ${LIB}/machine 2>/dev/null
  718.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  719.   chmod +w ${LIB}/$file 2>/dev/null
  720. fi
  721.  
  722. if [ -r ${LIB}/$file ]; then
  723.   echo Fixing $file, incorrect \#include
  724.   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
  725.     ${LIB}/$file > ${LIB}/${file}.sed
  726.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  727.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  728.     echo Deleting ${LIB}/$file\; no fixes were needed.
  729.     rm -f ${LIB}/$file
  730.   fi
  731. fi
  732.  
  733. # Multiline comment after typedef on IRIX 4.0.1.
  734. file=sys/types.h
  735. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  736.   mkdir ${LIB}/sys 2>/dev/null
  737.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  738.   chmod +w ${LIB}/$file 2>/dev/null
  739. fi
  740.  
  741. if [ -r ${LIB}/$file ]; then
  742.   echo Fixing $file, comment in the middle of \#ifdef
  743.   sed -e 's@type of the result@type of the result */@' \
  744.     -e 's@of the sizeof@/* of the sizeof@' \
  745.     ${LIB}/$file > ${LIB}/${file}.sed
  746.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  747.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  748.     echo Deleting ${LIB}/$file\; no fixes were needed.
  749.     rm -f ${LIB}/$file
  750.   fi
  751. fi
  752.  
  753. # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
  754. # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
  755. # many other systems have similar text but correct versions of the file.
  756. # To ensure only Sun's is fixed, we grep for a likely unique string.
  757. file=memory.h
  758. if egrep '/\*    @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2    \*/' $file > /dev/null; then
  759.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  760.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  761.     chmod +w ${LIB}/$file 2>/dev/null
  762.   fi
  763.   if [ -r ${LIB}/$file ]; then
  764.     echo Replacing $file
  765.     cat > ${LIB}/$file << EOF
  766. /* This file was generated by fixincludes */
  767. #ifndef __memory_h__
  768. #define __memory_h__
  769.  
  770. #ifdef __STDC__
  771. extern void *memccpy();
  772. extern void *memchr();
  773. extern void *memcpy();
  774. extern void *memset();
  775. #else
  776. extern char *memccpy();
  777. extern char *memchr();
  778. extern char *memcpy();
  779. extern char *memset();
  780. #endif /* __STDC__ */
  781.  
  782. extern int memcmp();
  783.  
  784. #endif __memory_h__
  785. EOF
  786.   fi
  787. fi
  788.  
  789. # parameters not const on DECstation Ultrix V4.0.
  790. file=stdio.h
  791. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  792.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  793.   chmod +w ${LIB}/$file 2>/dev/null
  794. fi
  795.  
  796. if [ -r ${LIB}/$file ]; then
  797.   echo Fixing $file, non-const arg
  798.   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
  799.       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
  800.       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
  801.       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
  802.       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
  803.       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
  804.       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
  805.     ${LIB}/$file > ${LIB}/${file}.sed
  806.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  807.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  808.     echo Deleting ${LIB}/$file\; no fixes were needed.
  809.     rm -f ${LIB}/$file
  810.   fi
  811. fi
  812.  
  813. # Don't use or define the name va_list in stdio.h.
  814. # This is for ANSI and also to interoperate properly with gvarargs.h.
  815. file=stdio.h
  816. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  817.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  818.   chmod +w ${LIB}/$file 2>/dev/null
  819. fi
  820.  
  821. if [ -r ${LIB}/$file ]; then
  822.   echo Fixing $file, use of va_list
  823.   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
  824.   (echo "#define __need___va_list"
  825.    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
  826.   # Use __gnuc_va_list in arg types in place of va_list.
  827.   # Define __va_list__ (something harmless and unused) instead of va_list.
  828.   # Don't claim to have defined va_list.
  829.   sed -e 's@ va_list @ __gnuc_va_list @' \
  830.       -e 's@ va_list@ __va_list__@' \
  831.       -e 's@\*va_list@*__va_list__@' \
  832.       -e 's@VA_LIST@DUMMY_VA_LIST@' \
  833.     ${LIB}/$file >> ${LIB}/${file}.sed
  834.   
  835.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  836.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  837.     echo Deleting ${LIB}/$file\; no fixes were needed.
  838.     rm -f ${LIB}/$file
  839.   fi
  840. fi
  841.  
  842. # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
  843. file=ansi_compat.h
  844. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  845.   if grep -s ULTRIX $file; then
  846.     echo "/* This file intentionally left blank.  */" > $LIB/$file
  847.   fi
  848. fi
  849.  
  850. # parameter to atof not const on DECstation Ultrix V4.0.
  851. # also get rid of bogus inline definitions in HP-UX 8.0
  852. file=math.h
  853. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  854.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  855.   chmod +w ${LIB}/$file 2>/dev/null
  856. fi
  857.  
  858. if [ -r ${LIB}/$file ]; then
  859.   echo Fixing $file, non-const arg
  860.   sed -e 's@atof( char \*__nptr );@atof( const char *__nptr );@' \
  861.       -e 's@inline int abs(int d) { return (d>0)?d:-d; }@@' \
  862.       -e 's@inline double abs(double d) { return fabs(d); }@@' \
  863.     ${LIB}/$file > ${LIB}/${file}.sed
  864.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  865.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  866.     echo Deleting ${LIB}/$file\; no fixes were needed.
  867.     rm -f ${LIB}/$file
  868.   fi
  869. fi
  870.  
  871. # These two files on SunOS 4 are included by other files
  872. # in the same directory, using "...".  So we must make sure they exist
  873. # in the same directory as the other fixed files.
  874. if [ -r ${INPUT}/multimedia/audio_errno.h ]
  875. then
  876.   ln -s ${INPUT}/multimedia/audio_errno.h ${LIB}/multimedia 2>/dev/null
  877. fi
  878. if [ -r ${INPUT}/multimedia/audio_hdr.h ]
  879. then
  880.   ln -s ${INPUT}/multimedia/audio_hdr.h ${LIB}/multimedia 2>/dev/null
  881. fi
  882.  
  883. echo 'Removing unneeded directories:'
  884. cd $LIB
  885. files=`find . -type d -print | sort -r`
  886. for file in $files; do
  887.   rmdir $LIB/$file > /dev/null 2>&1
  888. done
  889.  
  890. if $LINKS; then
  891.   echo 'Making internal symbolic non-directory links'
  892.   cd ${INPUT}
  893.   files=`find . -type l -print`
  894.   for file in $files; do
  895.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  896.     if expr "$dest" : '[^/].*' > /dev/null; then    
  897.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  898.       if [ -f $target ]; then
  899.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  900.       fi
  901.     fi
  902.   done
  903. fi
  904.  
  905. exit 0
  906.