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.sco < prev    next >
Text File  |  1994-02-06  |  8KB  |  276 lines

  1. #! /bin/sh
  2. #
  3. #   fixinc.sco  --  Install modified versions of SCO system include
  4. #   files.
  5. #
  6. #   Based on fixinc.svr4 script by Ron Guilmette (rfg@ncd.com) (SCO
  7. #   modifications by Ian Lance Taylor (ian@airs.com)).
  8. #
  9. # This file is part of GNU CC.
  10. # GNU CC is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2, or (at your option)
  13. # any later version.
  14. # GNU CC is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. # You should have received a copy of the GNU General Public License
  19. # along with GNU CC; see the file COPYING.  If not, write to
  20. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21. #
  22. #    This script munges the native include files provided with SCO
  23. #    3.2v4 systems so as to provide a reasonable namespace when
  24. #    compiling with gcc.  The header files by default do not
  25. #    provide many essential definitions and declarations if
  26. #    __STDC__ is 1.  This script modifies the header files to check
  27. #    for __STRICT_ANSI__ being defined instead.  Once munged, the
  28. #    resulting new system include files are placed in a directory
  29. #    that GNU C will search *before* searching the /usr/include
  30. #    directory.  This script should work properly for most SCO
  31. #    3.2v4 systems.  For other types of systems, you should use the
  32. #    `fixincludes' or the `fixinc.svr4' script instead.
  33. #
  34. #    See README-fixinc for more information.
  35.  
  36. # Directory where gcc sources (and sometimes special include files) live.
  37. SRCDIR=${3-${SRCDIR-.}}
  38.  
  39. # Directory containing the original header files.
  40. INPUT=${2-${INPUT-/usr/include}}
  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. # Directory in which to store the results.
  49. LIB=${1?"fixincludes: output directory not specified"}
  50.  
  51. # Make sure it exists.
  52. if [ ! -d $LIB ]; then
  53.   mkdir $LIB || exit 1
  54. fi
  55.  
  56. ORIG_DIR=`pwd`
  57.  
  58. # Make LIB absolute.
  59. cd $LIB; LIB=`pwd`
  60.  
  61. # This prevents /bin/ex from failing if the current terminal type is
  62. # unrecognizable.
  63. TERM=dumb
  64. export TERM
  65. # This prevents /bin/ex from failing if the EXINIT environment variable
  66. # was set to something invalid.
  67. EXINIT=""
  68. export EXINIT
  69.  
  70. echo 'Building fixincludes in ' ${LIB}
  71.  
  72. # Determine whether this filesystem has symbolic links.
  73. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  74.   rm -f $LIB/ShouldNotExist
  75.   LINKS=true
  76. else
  77.   LINKS=false
  78. fi
  79.  
  80. echo 'Making directories:'
  81. cd ${INPUT}
  82. if $LINKS; then
  83.   files=`ls -LR | sed -n s/:$//p`
  84. else
  85.   files=`find . -type d -print | sed '/^.$/d'`
  86. fi
  87. for file in $files; do
  88.   rm -rf $LIB/$file
  89.   if [ ! -d $LIB/$file ]
  90.   then mkdir $LIB/$file
  91.   fi
  92. done
  93.  
  94. # treetops gets an alternating list
  95. # of old directories to copy
  96. # and the new directories to copy to.
  97. treetops="${INPUT} ${LIB}"
  98.  
  99. if $LINKS; then
  100.   echo 'Making internal symbolic directory links'
  101.   for file in $files; do
  102.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  103.     if [ "$dest" ]; then    
  104.       cwd=`pwd`
  105.       # In case $dest is relative, get to $file's dir first.
  106.       cd ${INPUT}
  107.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  108.       # Check that the target directory exists.
  109.       # Redirections changed to avoid bug in sh on Ultrix.
  110.       (cd $dest) > /dev/null 2>&1
  111.       if [ $? = 0 ]; then
  112.     cd $dest
  113.     # X gets the dir that the link actually leads to.
  114.     x=`pwd`
  115.     # If link leads back into ${INPUT},
  116.     # make a similar link here.
  117.     if expr $x : "${INPUT}/.*" > /dev/null; then
  118.       # Y gets the actual target dir name, relative to ${INPUT}.
  119.       y=`echo $x | sed -n "s&${INPUT}/&&p"`
  120.       echo $file '->' $y ': Making link'
  121.       rm -fr ${LIB}/$file > /dev/null 2>&1
  122.       ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
  123.     else
  124.       # If the link is to outside ${INPUT},
  125.       # treat this directory as if it actually contained the files.
  126. # This line used to have $dest instead of $x.
  127. # $dest seemed to be wrong for links found in subdirectories
  128. # of ${INPUT}.  Does this change break anything?
  129.       treetops="$treetops $x ${LIB}/$file"
  130.     fi
  131.       fi
  132.       cd $cwd
  133.     fi
  134.   done
  135. fi
  136.  
  137. set - $treetops
  138. while [ $# != 0 ]; do
  139.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  140.   echo "Finding header files in $1:"
  141.   cd ${INPUT}
  142.   cd $1
  143.   files=`find . -name '*.h' -type f -print`
  144.   echo 'Checking header files:'
  145.   for file in $files; do
  146.     if egrep '!__STDC__' $file >/dev/null; then
  147.       echo Fixing $file
  148.       if [ -r $file ]; then
  149.     cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
  150.     chmod +w $2/$file
  151.  
  152. # The following have been removed from the sed command below
  153. # because it is more useful to leave these things in.
  154. # The only reason to remove them was for -pedantic,
  155. # which isn't much of a reason. -- rms.
  156. #      /^[     ]*#[     ]*ident/d
  157.  
  158.     sed -e '
  159.       s/!__STDC__/!defined (__STRICT_ANSI__)/g
  160.     ' $2/$file > $2/$file.sed
  161.     mv $2/$file.sed $2/$file
  162.     if cmp $file $2/$file >/dev/null 2>&1; then
  163.        echo Deleting $2/$file\; no fixes were needed.
  164.        rm $2/$file
  165.     fi
  166.       fi
  167.     fi
  168.   done
  169.   shift; shift
  170. done
  171.  
  172. # Fix first broken decl of getcwd present on some svr4 systems.
  173.  
  174. file=stdlib.h
  175. base=`basename $file`
  176. if [ -r ${LIB}/$file ]; then
  177.   file_to_fix=${LIB}/$file
  178. else
  179.   if [ -r ${INPUT}/$file ]; then
  180.     file_to_fix=${INPUT}/$file
  181.   else
  182.     file_to_fix=""
  183.   fi
  184. fi
  185. if [ \! -z "$file_to_fix" ]; then
  186.   echo Checking $file_to_fix
  187.   sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
  188.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  189.     echo No change needed in $file_to_fix
  190.   else
  191.     echo Fixed $file_to_fix
  192.     rm -f ${LIB}/$file
  193.     cp /tmp/$base ${LIB}/$file
  194.   fi
  195.   rm -f /tmp/$base
  196. fi
  197.  
  198. # Fix second broken decl of getcwd present on some svr4 systems.  Also
  199. # fix the incorrect decl of profil present on some svr4 systems.
  200.  
  201. file=unistd.h
  202. base=`basename $file`
  203. if [ -r ${LIB}/$file ]; then
  204.   file_to_fix=${LIB}/$file
  205. else
  206.   if [ -r ${INPUT}/$file ]; then
  207.     file_to_fix=${INPUT}/$file
  208.   else
  209.     file_to_fix=""
  210.   fi
  211. fi
  212. if [ \! -z "$file_to_fix" ]; then
  213.   echo Checking $file_to_fix
  214.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
  215.     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
  216.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  217.     echo No change needed in $file_to_fix
  218.   else
  219.     echo Fixed $file_to_fix
  220.     rm -f ${LIB}/$file
  221.     cp /tmp/$base ${LIB}/$file
  222.   fi
  223.   rm -f /tmp/$base
  224. fi
  225.  
  226. # Fix an error in this file: the #if says _cplusplus, not the double
  227. # underscore __cplusplus that it should be
  228. file=tinfo.h
  229. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  230.   mkdir ${LIB}/rpcsvc 2>/dev/null
  231.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  232.   chmod +w ${LIB}/$file 2>/dev/null
  233. fi
  234.  
  235. if [ -r ${LIB}/$file ]; then
  236.   echo Fixing $file, __cplusplus macro
  237.   sed -e 's/[     ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
  238.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  239.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  240.     rm ${LIB}/$file
  241.   fi
  242. fi
  243.  
  244. echo 'Removing unneeded directories:'
  245. cd $LIB
  246. files=`find . -type d -print | sort -r`
  247. for file in $files; do
  248.   rmdir $LIB/$file > /dev/null 2>&1
  249. done
  250.  
  251. if $LINKS; then
  252.   echo 'Making internal symbolic non-directory links'
  253.   cd ${INPUT}
  254.   files=`find . -type l -print`
  255.   for file in $files; do
  256.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  257.     if expr "$dest" : '[^/].*' > /dev/null; then    
  258.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  259.       if [ -f $target ]; then
  260.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  261.       fi
  262.     fi
  263.   done
  264. fi
  265.  
  266. cd ${ORIG_DIR}
  267.  
  268. echo 'Replacing <sys/byteorder.h>'
  269. rm -f ${LIB}/sys/byteorder.h
  270. cp ${SRCDIR}/byteorder.h ${LIB}/sys/byteorder.h
  271.  
  272. exit 0
  273.