home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / fixinc.winnt < prev    next >
Text File  |  1995-12-29  |  6KB  |  233 lines

  1. #! sh
  2. #
  3. #   fixinc.winnt  --  Install modified versions of Windows NT system include
  4. #   files.
  5. #
  6. #   Based on fixinc.sco script by Ian Lance Taylor (ian@airs.com)).
  7. #   Modifications by Douglas Rupp (drupp@cs.washington.edu)
  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 Windows NT
  24. #    3.5 SDK 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 Include
  31. #    directory.
  32. #
  33. #    See README-fixinc for more information.
  34.  
  35. ORIG_DIR=`pwd`
  36.  
  37. # Directory containing the original header files.
  38. cd $2; SEDFILE=`${PWDCMD-pwd}`/fixinc-nt.sed
  39. echo $SEDFILE
  40. if [ ! -f $SEDFILE ]
  41. then echo fixincludes: sed script 'fixinc-nt.sed' not found
  42. exit 1
  43. fi
  44. echo 'Using sed script: ' ${SEDFILE}
  45.  
  46. cd $ORIG_DIR
  47.  
  48. INPUT=${INCLUDE}
  49. echo 'Using the Include environment variable to find header files to fix'
  50.  
  51. # Fail if no arg to specify a directory for the output.
  52. if [ x$1 = x ]
  53. then echo fixincludes: no output directory specified
  54. exit 1
  55. fi
  56.  
  57. # Directory in which to store the results.
  58. LIB=${1?"fixincludes: output directory not specified"}
  59.  
  60. # Make sure it exists.
  61. if [ ! -d $LIB ]; then
  62.   mkdir $LIB || exit 1
  63. fi
  64.  
  65. ORIG_DIR=`pwd`
  66.  
  67. # Make LIB absolute if it is relative.
  68. # Don't do this if not necessary, since may screw up automounters.
  69. case $LIB in
  70. /*)
  71.     ;;
  72. *)
  73.     cd $LIB; LIB=`${PWDCMD-pwd}`
  74.     ;;
  75. esac
  76.  
  77. echo 'Building fixincludes in ' ${LIB}
  78.  
  79. # Determine whether this filesystem has symbolic links.
  80. if ln -s X $LIB/ShouldNotExist 2>NUL; then
  81.   rm -f $LIB/ShouldNotExist
  82.   LINKS=true
  83. else
  84.   LINKS=false
  85. fi
  86.  
  87. echo 'Making directories:'
  88. cd ${INPUT}
  89. if $LINKS; then
  90.   files=`ls -LR | sed -n s/:$//p`
  91. else
  92.   files=`find . -type d -print | sed '/^.$/d'`
  93. fi
  94. for file in $files; do
  95.   rm -rf $LIB/$file
  96.   if [ ! -d $LIB/$file ]
  97.   then mkdir $LIB/$file
  98.   fi
  99. done
  100.  
  101. # treetops gets an alternating list
  102. # of old directories to copy
  103. # and the new directories to copy to.
  104. treetops="${INPUT} ${LIB}"
  105.  
  106. set - $treetops
  107. while [ $# != 0 ]; do
  108.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  109.   echo "Finding header files in $1:"
  110.   cd ${INPUT}
  111.   cd $1
  112.   files=`find . -name '*.[hH]' -type f -print`
  113.   echo 'Checking header files:'
  114.   for file in $files; do
  115.     echo $file
  116.     if egrep "!__STDC__" $file >NUL; then
  117.       if [ -r $file ]; then
  118.     cp $file $2/$file >NUL 2>&1 || echo "Can't copy $file"
  119.     chmod +w,a+r $2/$file
  120.  
  121. # The following have been removed from the sed command below
  122. # because it is more useful to leave these things in.
  123. # The only reason to remove them was for -pedantic,
  124. # which isn't much of a reason. -- rms.
  125. #      /^[     ]*#[     ]*ident/d
  126.  
  127.     sed -e '
  128.       s/!__STDC__/!defined (__STRICT_ANSI__)/g
  129.     ' $2/$file > $2/$file.sed
  130.     mv $2/$file.sed $2/$file
  131.     if cmp $file $2/$file >NUL 2>&1; then
  132.        rm $2/$file
  133.     else
  134.        echo Fixed $file
  135.     fi
  136.       fi
  137.     fi
  138.   done
  139.   shift; shift
  140. done
  141.  
  142. # Fix first broken decl of getcwd present on some svr4 systems.
  143.  
  144. file=direct.h
  145. base=`basename $file`
  146. if [ -r ${LIB}/$file ]; then
  147.   file_to_fix=${LIB}/$file
  148. else
  149.   if [ -r ${INPUT}/$file ]; then
  150.     file_to_fix=${INPUT}/$file
  151.   else
  152.     file_to_fix=""
  153.   fi
  154. fi
  155. if [ \! -z "$file_to_fix" ]; then
  156.   echo Checking $file_to_fix
  157.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
  158.   if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
  159.     true
  160.   else
  161.     echo Fixed $file_to_fix
  162.     rm -f ${LIB}/$file
  163.     cp /tmp/$base ${LIB}/$file
  164.     chmod a+r ${LIB}/$file
  165.   fi
  166.   rm -f /tmp/$base
  167. fi
  168.  
  169. file=rpcndr.h
  170. base=`basename $file`
  171. if [ -r ${LIB}/$file ]; then
  172.   file_to_fix=${LIB}/$file
  173. else
  174.   if [ -r ${INPUT}/$file ]; then
  175.     file_to_fix=${INPUT}/$file
  176.   else
  177.     file_to_fix=""
  178.   fi
  179. fi
  180. if [ \! -z "$file_to_fix" ]; then
  181.   echo Checking $file_to_fix
  182.   sed -e 's/Format\[\]/Format\[1\]/' $file_to_fix > /tmp/$base
  183.   if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
  184.     true
  185.   else
  186.     echo Fixed $file_to_fix
  187.     rm -f ${LIB}/$file
  188.     cp /tmp/$base ${LIB}/$file
  189.     chmod a+r ${LIB}/$file
  190.   fi
  191.   rm -f /tmp/$base
  192. fi
  193.  
  194. file=winnt.h
  195. base=`basename $file`
  196. if [ -r ${LIB}/$file ]; then
  197.   file_to_fix=${LIB}/$file
  198. else
  199.   if [ -r ${INPUT}/$file ]; then
  200.     file_to_fix=${INPUT}/$file
  201.   else
  202.     file_to_fix=""
  203.   fi
  204. fi
  205. if [ \! -z "$file_to_fix" ]; then
  206.   echo Checking $file_to_fix
  207.   sed -e '
  208.     s/^#if !defined (__cplusplus)/#if 0/
  209.     s/^#define DECLSPEC_IMPORT __declspec(dllimport)/#define DECLSPEC_IMPORT/
  210.   ' $file_to_fix > /tmp/$base
  211.   if cmp $file_to_fix /tmp/$base >NUL 2>&1; then \
  212.     true
  213.   else
  214.     echo Fixed $file_to_fix
  215.     rm -f ${LIB}/$file
  216.     cp /tmp/$base ${LIB}/$file
  217.     chmod a+r ${LIB}/$file
  218.   fi
  219.   rm -f /tmp/$base
  220. fi
  221.  
  222. echo 'Removing unneeded directories:'
  223. cd $LIB
  224. files=`find . -type d -print | sort -r`
  225. for file in $files; do
  226.   rmdir $LIB/$file > NUL 2>&1
  227. done
  228.  
  229. exit 0
  230.