home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / gcc-2.3.3-src.lha / GNU / src / amiga / gcc-2.3.3 / fixinc.svr4 < prev    next >
Text File  |  1994-02-06  |  31KB  |  1,261 lines

  1. #! /bin/sh
  2. #
  3. #   fixinc.svr4  --  Install modified versions of certain ANSI-incompatible
  4. #   native System V Release 4 system include files.
  5. #
  6. #   Written by Ron Guilmette (rfg@ncd.com).
  7. #
  8. # This file is part of GNU CC.
  9. # GNU CC is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. # GNU CC is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. # You should have received a copy of the GNU General Public License
  18. # along with GNU CC; see the file COPYING.  If not, write to
  19. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21. #    This script munges the native include files provided with System V
  22. #    Release 4 systems so as to remove things which are violations of the
  23. #    ANSI C standard.  Once munged, the resulting new system include files
  24. #    are placed in a directory that GNU C will search *before* searching
  25. #    the /usr/include directory. This script should work properly for most
  26. #    System V Release 4 systems.  For other types of systems, you should
  27. #    use the `fixincludes' script instead.
  28. #
  29. #    See README-fixinc for more information.
  30.  
  31. # Directory where gcc sources (and sometimes special include files) live.
  32. SRCDIR=${3-${SRCDIR-.}}
  33.  
  34. # Directory containing the original header files.
  35. INPUT=${2-${INPUT-/usr/include}}
  36.  
  37. # Fail if no arg to specify a directory for the output.
  38. if [ x$1 = x ]
  39. then echo fixincludes: no output directory specified
  40. exit 1
  41. fi
  42.  
  43. # Directory in which to store the results.
  44. LIB=${1?"fixincludes: output directory not specified"}
  45.  
  46. # Make sure it exists.
  47. if [ ! -d $LIB ]; then
  48.   mkdir $LIB || exit 1
  49. fi
  50.  
  51. ORIG_DIR=`pwd`
  52.  
  53. # Make LIB absolute.
  54. cd $LIB; LIB=`pwd`
  55.  
  56. # This prevents /bin/ex from failing if the current terminal type is
  57. # unrecognizable.
  58. TERM=dumb
  59. export TERM
  60. # This prevents /bin/ex from failing if the EXINIT environment variable
  61. # was set to something invalid.
  62. EXINIT=""
  63. export EXINIT
  64.  
  65. echo 'Building fixincludes in ' ${LIB}
  66.  
  67. # Determine whether this filesystem has symbolic links.
  68. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  69.   rm -f $LIB/ShouldNotExist
  70.   LINKS=true
  71. else
  72.   LINKS=false
  73. fi
  74.  
  75. echo 'Making directories:'
  76. cd ${INPUT}
  77. if $LINKS; then
  78.   files=`ls -LR | sed -n s/:$//p`
  79. else
  80.   files=`find . -type d -print | sed '/^.$/d'`
  81. fi
  82. for file in $files; do
  83.   rm -rf $LIB/$file
  84.   if [ ! -d $LIB/$file ]
  85.   then mkdir $LIB/$file
  86.   fi
  87. done
  88.  
  89. # treetops gets an alternating list
  90. # of old directories to copy
  91. # and the new directories to copy to.
  92. treetops="${INPUT} ${LIB}"
  93.  
  94. if $LINKS; then
  95.   echo 'Making internal symbolic directory links'
  96.   for file in $files; do
  97.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  98.     if [ "$dest" ]; then    
  99.       cwd=`pwd`
  100.       # In case $dest is relative, get to $file's dir first.
  101.       cd ${INPUT}
  102.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  103.       # Check that the target directory exists.
  104.       # Redirections changed to avoid bug in sh on Ultrix.
  105.       (cd $dest) > /dev/null 2>&1
  106.       if [ $? = 0 ]; then
  107.     cd $dest
  108.     # X gets the dir that the link actually leads to.
  109.     x=`pwd`
  110.     # If link leads back into ${INPUT},
  111.     # make a similar link here.
  112.     if expr $x : "${INPUT}/.*" > /dev/null; then
  113.       # Y gets the actual target dir name, relative to ${INPUT}.
  114.       y=`echo $x | sed -n "s&${INPUT}/&&p"`
  115.       echo $file '->' $y ': Making link'
  116.       rm -fr ${LIB}/$file > /dev/null 2>&1
  117.       ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
  118.     else
  119.       # If the link is to outside ${INPUT},
  120.       # treat this directory as if it actually contained the files.
  121. # This line used to have $dest instead of $x.
  122. # $dest seemed to be wrong for links found in subdirectories
  123. # of ${INPUT}.  Does this change break anything?
  124.       treetops="$treetops $x ${LIB}/$file"
  125.     fi
  126.       fi
  127.       cd $cwd
  128.     fi
  129.   done
  130. fi
  131.  
  132. set - $treetops
  133. while [ $# != 0 ]; do
  134.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  135.   echo "Finding header files in $1:"
  136.   cd ${INPUT}
  137.   cd $1
  138.   files=`find . -name '*.h' -type f -print`
  139.   echo 'Checking header files:'
  140.   for file in $files; do
  141.       echo Fixing $file
  142.       if [ -r $file ]; then
  143.     cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
  144.     chmod +w $2/$file
  145.  
  146. # The following have been removed from the sed command below
  147. # because it is more useful to leave these things in.
  148. # The only reason to remove them was for -pedantic,
  149. # which isn't much of a reason. -- rms.
  150. #      /^[     ]*#[     ]*ident/d
  151.  
  152. # This code makes Solaris SCSI fail, because it changes the
  153. # alignment within some critical structures.  See <sys/scsi/impl/commands.h>.
  154. #      s/u_char\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  155. # Disable these also, since they probably aren't safe either.
  156. #      s/u_short\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  157. #      s/ushort\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  158. #      s/evcm_t\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  159. #      s/Pbyte\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*SEQSIZ\)/unsigned int\1/
  160.  
  161. # The change of u_char, etc, to u_int
  162. # applies to bit fields.
  163.     sed -e '
  164.       s%^\([     ]*#[     ]*endif[     ]*\)\([^/     ].*\)$%\1/* \2 */%
  165.       s%^\([     ]*#[     ]*else[     ]*\)\([^/     ].*\)$%\1/* \2 */%
  166.         s/#lint(on)/defined(lint)/g
  167.         s/#lint(off)/!defined(lint)/g
  168.         s/#machine(\([^)]*\))/defined(__\1__)/g
  169.         s/#system(\([^)]*\))/defined(__\1__)/g
  170.         s/#cpu(\([^)]*\))/defined(__\1__)/g
  171.       /#[a-z]*if.*[     (]m68k/        s/\([^_]\)m68k/\1__m68k__/g
  172.       /#[a-z]*if.*[     (]__i386\([^_]\)/    s/__i386/__i386__/g
  173.       /#[a-z]*if.*[     (]i386/        s/\([^_]\)i386/\1__i386__/g
  174.       /#[a-z]*if.*[     (]sparc/    s/\([^_]\)sparc/\1__sparc__/g
  175.       /#[a-z]*if.*[     (]mc68000/    s/\([^_]\)mc68000/\1__mc68000__/g
  176.       /#[a-z]*if.*[     (]vax/        s/\([^_]\)vax/\1__vax__/g
  177.       /#[a-z]*if.*[     (]sun/        s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
  178.       /#[a-z]*if.*[     (]sun/        s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
  179.       /#[a-z]*if.*[     (]ns32000/    s/\([^_]\)ns32000/\1__ns32000__/g
  180.       /#[a-z]*if.*[     (]pyr/        s/\([^_]\)pyr/\1__pyr__/g
  181.       /#[a-z]*if.*[     (]is68k/    s/\([^_]\)is68k/\1__is68k__/g
  182.       s/__STDC__ == 0/!defined (__STRICT_ANSI__)/g
  183.       s/__STDC__ != 0/defined (__STRICT_ANSI__)/g
  184.       s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
  185.     ' $2/$file > $2/$file.sed
  186.     mv $2/$file.sed $2/$file
  187.     if cmp $file $2/$file >/dev/null 2>&1; then
  188.        echo Deleting $2/$file\; no fixes were needed.
  189.        rm $2/$file
  190.     fi
  191.       fi
  192.   done
  193.   shift; shift
  194. done
  195.  
  196. # Fix first broken decl of getcwd present on some svr4 systems.
  197.  
  198. file=stdlib.h
  199. base=`basename $file`
  200. if [ -r ${LIB}/$file ]; then
  201.   file_to_fix=${LIB}/$file
  202. else
  203.   if [ -r ${INPUT}/$file ]; then
  204.     file_to_fix=${INPUT}/$file
  205.   else
  206.     file_to_fix=""
  207.   fi
  208. fi
  209. if [ \! -z "$file_to_fix" ]; then
  210.   echo Checking $file_to_fix
  211.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
  212.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  213.     echo No change needed in $file_to_fix
  214.   else
  215.     echo Fixed $file_to_fix
  216.     rm -f ${LIB}/$file
  217.     cp /tmp/$base ${LIB}/$file
  218.   fi
  219.   rm -f /tmp/$base
  220. fi
  221.  
  222. # Fix second broken decl of getcwd present on some svr4 systems.  Also
  223. # fix the incorrect decl of profil present on some svr4 systems.
  224.  
  225. file=unistd.h
  226. base=`basename $file`
  227. if [ -r ${LIB}/$file ]; then
  228.   file_to_fix=${LIB}/$file
  229. else
  230.   if [ -r ${INPUT}/$file ]; then
  231.     file_to_fix=${INPUT}/$file
  232.   else
  233.     file_to_fix=""
  234.   fi
  235. fi
  236. if [ \! -z "$file_to_fix" ]; then
  237.   echo Checking $file_to_fix
  238.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
  239.     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
  240.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  241.     echo No change needed in $file_to_fix
  242.   else
  243.     echo Fixed $file_to_fix
  244.     rm -f ${LIB}/$file
  245.     cp /tmp/$base ${LIB}/$file
  246.   fi
  247.   rm -f /tmp/$base
  248. fi
  249.  
  250. # Fix the definition of NULL in <sys/param.h> so that it is conditional
  251. # an