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

  1. #! /bin/sh
  2. # Install modified versions of certain ANSI-incompatible
  3. # native Sequent DYNIX/ptx System V Release 3.2 system include files.
  4. # Copyright (C) 1994 Free Software Foundation, Inc.
  5. # Contributed by Bill Burton <billb@progress.com>
  6. # Portions adapted from fixinc.svr4 and fixincludes.
  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, 59 Temple Place - Suite 330,
  20. # Boston, MA 02111-1307, USA.
  21. #
  22. #    This script munges the native include files provided with DYNIX/ptx
  23. #    so as to remove things which are violations of the ANSI C standard.
  24. #    This is done by first running fixinc.svr4 which does most of the
  25. #    work.  A few includes have fixes made to them afterwards  by this
  26. #    script.  Once munged, the resulting new system include files are
  27. #    placed in a directory that GNU C will search *before* searching the
  28. #    /usr/include directory. This script should work properly for most
  29. #    DYNIX/ptx systems.  For other types of systems, you should use the
  30. #    `fixincludes' script instead.
  31. #
  32. #    See README-fixinc for more information.
  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 if it is relative.
  54. # Don't do this if not necessary, since may screw up automounters.
  55. case $LIB in
  56. /*)
  57.     ;;
  58. *)
  59.      LIB=$ORIG_DIR/$LIB
  60.     ;;
  61. esac
  62.  
  63. echo 'Running fixinc.svr4'
  64. # DYNIX/ptx has dirname so this is no problem
  65. `dirname $0`/fixinc.svr4 $*
  66. echo 'Finished fixinc.svr4'
  67.  
  68. echo 'Building fixincludes in ' ${LIB}
  69.  
  70. # Copied from fixincludes.
  71. # Don't use or define the name va_list in stdio.h.
  72. # This is for ANSI and also to interoperate properly with gcc's varargs.h.
  73. file=stdio.h
  74. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  75.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  76.   chmod +w ${LIB}/$file 2>/dev/null
  77.   chmod a+r ${LIB}/$file 2>/dev/null
  78. fi
  79.  
  80. if [ -r ${LIB}/$file ]; then
  81.   echo Fixing $file, use of va_list
  82.   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
  83.   (echo "#define __need___va_list"
  84.    echo "#include <stdarg.h>") > ${LIB}/${file}.sed
  85.   # Use __gnuc_va_list in arg types in place of va_list.
  86.   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
  87.   # trailing parentheses and semicolon save all other systems from this.
  88.   # Define __va_list__ (something harmless and unused) instead of va_list.
  89.   # Don't claim to have defined va_list.
  90.   sed -e 's@ va_list @ __gnuc_va_list @' \
  91.       -e 's@ va_list)@ __gnuc_va_list)@' \
  92.       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
  93.       -e 's@ va_list@ __va_list__@' \
  94.       -e 's@\*va_list@*__va_list__@' \
  95.       -e 's@ __va_list)@ __gnuc_va_list)@' \
  96.       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
  97.       -e 's@VA_LIST@DUMMY_VA_LIST@' \
  98.       -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
  99.     ${LIB}/$file >> ${LIB}/${file}.sed
  100.   
  101.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  102.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  103.     rm -f ${LIB}/$file
  104.   fi
  105. fi
  106.  
  107. # In pwd.h, PTX 1.x needs stdio.h included since FILE * was added in a
  108. # prototype later on in the file.
  109. file=pwd.h
  110. base=`basename $file`
  111. if [ -r ${LIB}/$file ]; then
  112.   file_to_fix=${LIB}/$file
  113. else
  114.   if [ -r ${INPUT}/$file ]; then
  115.     file_to_fix=${INPUT}/$file
  116.   else
  117.     file_to_fix=""
  118.   fi
  119. fi
  120. if [ \! -z "$file_to_fix" ]; then
  121.   echo Checking $file_to_fix
  122.   if grep stdio $file_to_fix > /dev/null; then
  123.     true
  124.   else
  125.     sed -e '/#include \<sys\types\.h\>/a\
  126. \
  127. #if defined(__STDC__) || defined(__cplusplus)\
  128. #include <stdio.h>\
  129. #endif  /* __STDC__ */' \
  130.     $file_to_fix > ${LIB}/${file}.sed
  131.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  132.     echo Fixed $file_to_fix
  133.   fi
  134. fi
  135.  
  136. # Copied from fixincludes.
  137. # math.h puts the declaration of matherr before the definition
  138. # of struct exception, so the prototype (added by fixproto) causes havoc.
  139. file=math.h
  140. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  141.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  142.   chmod +w ${LIB}/$file 2>/dev/null
  143.   chmod a+r ${LIB}/$file 2>/dev/null
  144. fi
  145.  
  146. if [ -r ${LIB}/$file ]; then
  147.   echo Fixing $file, matherr declaration
  148.   sed -e '/^struct exception/,$b' \
  149.       -e '/matherr/i\
  150. struct exception;
  151. '\
  152.     ${LIB}/$file > ${LIB}/${file}.sed
  153.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  154.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  155.     rm -f ${LIB}/$file
  156.   fi
  157. fi
  158.  
  159. # In netinet/in.h, the network byte swapping asm functions supported by the
  160. # native cc compiler on PTX 1.x and 2.x is not supported in gcc.  Instead,
  161. # include <sys/byteorder.h> written out by the fixinc.svr4 script which has
  162. # these same routines written in an asm format supported by gcc.
  163. file=netinet/in.h
  164. base=`basename $file`
  165. if [ -r ${LIB}/$file ]; then
  166.   file_to_fix=${LIB}/$file
  167. else
  168.   if [ -r ${INPUT}/$file ]; then
  169.     file_to_fix=${INPUT}/$file
  170.   else
  171.     file_to_fix=""
  172.   fi
  173. fi
  174. if [ \! -z "$file_to_fix" ]; then
  175.   echo Checking $file_to_fix
  176.   if grep __GNUC__ $file_to_fix > /dev/null; then
  177.     true
  178.   else
  179.     sed -e '/#define NETSWAP/a\
  180. \
  181. #if defined (__GNUC__) || defined (__GNUG__)\
  182. #include <sys/byteorder.h>\
  183. #else  /* not __GNUC__ */\
  184. ' \
  185.     -e '/#endif[     ]*\/\* NETSWAP \*\//i\
  186. #endif /* not __GNUC__ */' \
  187.     $file_to_fix > ${LIB}/${file}.sed
  188.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  189.     echo Fixed $file_to_fix
  190.   fi
  191. fi
  192.  
  193. exit 0
  194.  
  195.