home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / fixinc.sco < prev    next >
Text File  |  1995-06-15  |  9KB  |  316 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, 59 Temple Place - Suite 330,
  21. # Boston, MA 02111-1307, USA.
  22. #
  23. #    This script munges the native include files provided with SCO
  24. #    3.2v4 systems so as to provide a reasonable namespace when
  25. #    compiling with gcc.  The header files by default do not
  26. #    provide many essential definitions and declarations if
  27. #    __STDC__ is 1.  This script modifies the header files to check
  28. #    for __STRICT_ANSI__ being defined instead.  Once munged, the
  29. #    resulting new system include files are placed in a directory
  30. #    that GNU C will search *before* searching the /usr/include
  31. #    directory.  This script should work properly for most SCO
  32. #    3.2v4 systems.  For other types of systems, you should use the
  33. #    `fixincludes' or the `fixinc.svr4' script instead.
  34. #
  35. #    See README-fixinc for more information.
  36.  
  37. # Directory containing the original header files.
  38. INPUT=${2-${INPUT-/usr/include}}
  39.  
  40. # Fail if no arg to specify a directory for the output.
  41. if [ x$1 = x ]
  42. then echo fixincludes: no output directory specified
  43. exit 1
  44. fi
  45.  
  46. # Directory in which to store the results.
  47. LIB=${1?"fixincludes: output directory not specified"}
  48.  
  49. # Make sure it exists.
  50. if [ ! -d $LIB ]; then
  51.   mkdir $LIB || exit 1
  52. fi
  53.  
  54. ORIG_DIR=`pwd`
  55.  
  56. # Make LIB absolute if it is relative.
  57. # Don't do this if not necessary, since may screw up automounters.
  58. case $LIB in
  59. /*)
  60.     ;;
  61. *)
  62.     cd $LIB; LIB=`${PWDCMD-pwd}`
  63.     ;;
  64. esac
  65.  
  66. echo 'Building fixincludes in ' ${LIB}
  67.  
  68. # Determine whether this filesystem has symbolic links.
  69. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  70.   rm -f $LIB/ShouldNotExist
  71.   LINKS=true
  72. else
  73.   LINKS=false
  74. fi
  75.  
  76. echo 'Making directories:'
  77. cd ${INPUT}
  78. if $LINKS; then
  79.   files=`ls -LR | sed -n s/:$//p`
  80. else
  81.   files=`find . -type d -print | sed '/^.$/d'`
  82. fi
  83. for file in $files; do
  84.   rm -rf $LIB/$file
  85.   if [ ! -d $LIB/$file ]
  86.   then mkdir $LIB/$file
  87.   fi
  88. done
  89.  
  90. # treetops gets an alternating list
  91. # of old directories to copy
  92. # and the new directories to copy to.
  93. treetops="${INPUT} ${LIB}"
  94.  
  95. if $LINKS; then
  96.   echo 'Making internal symbolic directory links'
  97.   for file in $files; do
  98.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  99.     if [ "$dest" ]; then    
  100.       cwd=`pwd`
  101.       # In case $dest is relative, get to $file's dir first.
  102.       cd ${INPUT}
  103.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  104.       # Check that the target directory exists.
  105.       # Redirections changed to avoid bug in sh on Ultrix.
  106.       (cd $dest) > /dev/null 2>&1
  107.       if [ $? = 0 ]; then
  108.     cd $dest
  109.     # X gets the dir that the link actually leads to.
  110.     x=`pwd`
  111.     # If link leads back into ${INPUT},
  112.     # make a similar link here.
  113.     if expr $x : "${INPUT}/.*" > /dev/null; then
  114.       # Y gets the actual target dir name, relative to ${INPUT}.
  115.       y=`echo $x | sed -n "s&${INPUT}/&&p"`
  116.       echo $file '->' $y ': Making link'
  117.       rm -fr ${LIB}/$file > /dev/null 2>&1
  118.       ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
  119.     else
  120.       # If the link is to outside ${INPUT},
  121.       # treat this directory as if it actually contained the files.
  122. # This line used to have $dest instead of $x.
  123. # $dest seemed to be wrong for links found in subdirectories
  124. # of ${INPUT}.  Does this change break anything?
  125.       treetops="$treetops $x ${LIB}/$file"
  126.     fi
  127.       fi
  128.       cd $cwd
  129.     fi
  130.   done
  131. fi
  132.  
  133. set - $treetops
  134. while [ $# != 0 ]; do
  135.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  136.   echo "Finding header files in $1:"
  137.   cd ${INPUT}
  138.   cd $1
  139.   files=`find . -name '*.h' -type f -print`
  140.   echo 'Checking header files:'
  141.   for file in $files; do
  142.     if egrep '!__STDC__' $file >/dev/null; then
  143.       if [ -r $file ]; then
  144.     cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
  145.     chmod +w $2/$file
  146.     chmod a+r $2/$file
  147.  
  148. # The following have been removed from the sed command below
  149. # because it is more useful to leave these things in.
  150. # The only reason to remove them was for -pedantic,
  151. # which isn't much of a reason. -- rms.
  152. #      /^[     ]*#[     ]*ident/d
  153.  
  154.     sed -e '
  155.       s/!__STDC__/!defined (__STRICT_ANSI__)/g
  156.     ' $2/$file > $2/$file.sed
  157.     mv $2/$file.sed $2/$file
  158.     if cmp $file $2/$file >/dev/null 2>&1; then
  159.        rm $2/$file
  160.     else
  161.        echo Fixed $file
  162.     fi
  163.       fi
  164.     fi
  165.   done
  166.   shift; shift
  167. done
  168.  
  169. # Fix first broken decl of getcwd present on some svr4 systems.
  170.  
  171. file=stdlib.h
  172. base=`basename $file`
  173. if [ -r ${LIB}/$file ]; then
  174.   file_to_fix=${LIB}/$file
  175. else
  176.   if [ -r ${INPUT}/$file ]; then
  177.     file_to_fix=${INPUT}/$file
  178.   else
  179.     file_to_fix=""
  180.   fi
  181. fi
  182. if [ \! -z "$file_to_fix" ]; then
  183.   echo Checking $file_to_fix
  184.   sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
  185.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  186.     true
  187.   else
  188.     echo Fixed $file_to_fix
  189.     rm -f ${LIB}/$file
  190.     cp /tmp/$base ${LIB}/$file
  191.     chmod a+r ${LIB}/$file
  192.   fi
  193.   rm -f /tmp/$base
  194. fi
  195.  
  196. # Fix second broken decl of getcwd present on some svr4 systems.  Also
  197. # fix the incorrect decl of profil present on some svr4 systems.
  198.  
  199. file=unistd.h
  200. base=`basename $file`
  201. if [ -r ${LIB}/$file ]; then
  202.   file_to_fix=${LIB}/$file
  203. else
  204.   if [ -r ${INPUT}/$file ]; then
  205.     file_to_fix=${INPUT}/$file
  206.   else
  207.     file_to_fix=""
  208.   fi
  209. fi
  210. if [ \! -z "$file_to_fix" ]; then
  211.   echo Checking $file_to_fix
  212.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
  213.     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
  214.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  215.     true
  216.   else
  217.     echo Fixed $file_to_fix
  218.     rm -f ${LIB}/$file
  219.     cp /tmp/$base ${LIB}/$file
  220.     chmod a+r ${LIB}/$file
  221.   fi
  222.   rm -f /tmp/$base
  223. fi
  224.  
  225. # Fix third broken decl of getcwd on SCO.  Also fix incorrect decl of
  226. # link.
  227. file=prototypes.h
  228. base=`basename $file`
  229. if [ -r ${LIB}/$file ]; then
  230.   file_to_fix=${LIB}/$file
  231. else
  232.   if [ -r ${INPUT}/$file ]; then
  233.     file_to_fix=${INPUT}/$file
  234.   else
  235.     file_to_fix=""
  236.   fi
  237. fi
  238. if [ \! -z "$file_to_fix" ]; then
  239.   echo Checking $file_to_fix
  240.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
  241.     | sed -e 's/const  int    link(const char \*, char \*)/extern  int    link(const char *, const char *)/' > /tmp/$base
  242.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  243.     true
  244.   else
  245.     echo Fixed $file_to_fix
  246.     rm -f ${LIB}/$file
  247.     cp /tmp/$base ${LIB}/$file
  248.     chmod a+r ${LIB}/$file
  249.   fi
  250.   rm -f /tmp/$base
  251. fi
  252.  
  253. # Fix an error in this file: the #if says _cplusplus, not the double
  254. # underscore __cplusplus that it should be
  255. file=tinfo.h
  256. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  257.   mkdir ${LIB}/rpcsvc 2>/dev/null
  258.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  259.   chmod +w ${LIB}/$file 2>/dev/null
  260.   chmod a+r ${LIB}/$file 2>/dev/null
  261. fi
  262.  
  263. if [ -r ${LIB}/$file ]; then
  264.   echo Fixing $file, __cplusplus macro
  265.   sed -e 's/[     ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
  266.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  267.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  268.     rm ${LIB}/$file
  269.   fi
  270. fi
  271.  
  272. # Fix prototype declaration of utime in sys/times.h.  In 3.2v4.0 the
  273. # const is missing.
  274. file=sys/times.h
  275. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  276.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  277.   chmod +w ${LIB}/$file 2>/dev/null
  278.   chmod a+r ${LIB}/$file 2>/dev/null
  279. fi
  280.  
  281. if [ -r ${LIB}/$file ]; then
  282.   echo Fixing $file, utime prototype
  283.   sed -e 's/(const char \*, struct utimbuf \*);/(const char *, const struct utimbuf *);/' ${LIB}/$file > ${LIB}/${file}.sed
  284.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  285.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  286.     rm ${LIB}/$file
  287.   fi
  288. fi
  289.  
  290. echo 'Removing unneeded directories:'
  291. cd $LIB
  292. files=`find . -type d -print | sort -r`
  293. for file in $files; do
  294.   rmdir $LIB/$file > /dev/null 2>&1
  295. done
  296.  
  297. if $LINKS; then
  298.   echo 'Making internal symbolic non-directory links'
  299.   cd ${INPUT}
  300.   files=`find . -type l -print`
  301.   for file in $files; do
  302.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  303.     if expr "$dest" : '[^/].*' > /dev/null; then    
  304.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  305.       if [ -f $target ]; then
  306.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  307.       fi
  308.     fi
  309.   done
  310. fi
  311.  
  312. exit 0
  313.