fixinc.ptx 7.41 KB
Newer Older
Richard Kenner committed
1 2 3
#! /bin/sh
# Install modified versions of certain ANSI-incompatible
# native Sequent DYNIX/ptx System V Release 3.2 system include files.
4
# Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
Richard Kenner committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Contributed by Bill Burton <billb@progress.com>
# Portions adapted from fixinc.svr4 and fixincludes.
#
# This file is part of GNU CC.
# 
# GNU CC is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# 
# GNU CC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with GNU CC; see the file COPYING.  If not, write to
Richard Kenner committed
22 23
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
Richard Kenner committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
#
#	This script munges the native include files provided with DYNIX/ptx
#	so as to remove things which are violations of the ANSI C standard.
#	This is done by first running fixinc.svr4 which does most of the
#	work.  A few includes have fixes made to them afterwards  by this
#	script.  Once munged, the resulting new system include files are
#	placed in a directory that GNU C will search *before* searching the
#	/usr/include directory. This script should work properly for most
#	DYNIX/ptx systems.  For other types of systems, you should use the
#	`fixincludes' script instead.
#
#	See README-fixinc for more information.

# Directory containing the original header files.
INPUT=${2-${INPUT-/usr/include}}

# Fail if no arg to specify a directory for the output.
if [ x$1 = x ]
then echo fixincludes: no output directory specified
exit 1
fi

# Directory in which to store the results.
LIB=${1?"fixincludes: output directory not specified"}

# Make sure it exists.
if [ ! -d $LIB ]; then
  mkdir $LIB || exit 1
fi

ORIG_DIR=`pwd`

# Make LIB absolute if it is relative.
# Don't do this if not necessary, since may screw up automounters.
case $LIB in
/*)
	;;
*)
 	LIB=$ORIG_DIR/$LIB
	;;
esac

echo 'Running fixinc.svr4'
# DYNIX/ptx has dirname so this is no problem
`dirname $0`/fixinc.svr4 $*
echo 'Finished fixinc.svr4'

echo 'Building fixincludes in ' ${LIB}

# Copied from fixincludes.
# Don't use or define the name va_list in stdio.h.
# This is for ANSI and also to interoperate properly with gcc's varargs.h.
file=stdio.h
if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  chmod +w ${LIB}/$file 2>/dev/null
  chmod a+r ${LIB}/$file 2>/dev/null
fi

if [ -r ${LIB}/$file ]; then
  echo Fixing $file, use of va_list
  # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
  (echo "#define __need___va_list"
   echo "#include <stdarg.h>") > ${LIB}/${file}.sed
  # Use __gnuc_va_list in arg types in place of va_list.
  # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
  # trailing parentheses and semicolon save all other systems from this.
  # Define __va_list__ (something harmless and unused) instead of va_list.
  # Don't claim to have defined va_list.
  sed -e 's@ va_list @ __gnuc_va_list @' \
      -e 's@ va_list)@ __gnuc_va_list)@' \
      -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
      -e 's@ va_list@ __va_list__@' \
      -e 's@\*va_list@*__va_list__@' \
      -e 's@ __va_list)@ __gnuc_va_list)@' \
      -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
      -e 's@VA_LIST@DUMMY_VA_LIST@' \
      -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \
    ${LIB}/$file >> ${LIB}/${file}.sed
  
  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
    rm -f ${LIB}/$file
  fi
fi

# In pwd.h, PTX 1.x needs stdio.h included since FILE * was added in a
# prototype later on in the file.
file=pwd.h
base=`basename $file`
if [ -r ${LIB}/$file ]; then
  file_to_fix=${LIB}/$file
else
  if [ -r ${INPUT}/$file ]; then
    file_to_fix=${INPUT}/$file
  else
    file_to_fix=""
  fi
fi
if [ \! -z "$file_to_fix" ]; then
  echo Checking $file_to_fix
  if grep stdio $file_to_fix > /dev/null; then
    true
  else
128
    sed -e '/#include <sys\/types\.h>/a\
Richard Kenner committed
129 130 131
\
#if defined(__STDC__) || defined(__cplusplus)\
#include <stdio.h>\
132 133
#endif  /* __STDC__ */
' \
Richard Kenner committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    $file_to_fix > ${LIB}/${file}.sed
    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
    echo Fixed $file_to_fix
  fi
fi

# Copied from fixincludes.
# math.h puts the declaration of matherr before the definition
# of struct exception, so the prototype (added by fixproto) causes havoc.
file=math.h
if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  chmod +w ${LIB}/$file 2>/dev/null
  chmod a+r ${LIB}/$file 2>/dev/null
fi

if [ -r ${LIB}/$file ]; then
  echo Fixing $file, matherr declaration
  sed -e '/^struct exception/,$b' \
      -e '/matherr/i\
struct exception;
'\
    ${LIB}/$file > ${LIB}/${file}.sed
  rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
    rm -f ${LIB}/$file
  fi
fi

# In netinet/in.h, the network byte swapping asm functions supported by the
# native cc compiler on PTX 1.x and 2.x is not supported in gcc.  Instead,
# include <sys/byteorder.h> written out by the fixinc.svr4 script which has
# these same routines written in an asm format supported by gcc.
file=netinet/in.h
base=`basename $file`
if [ -r ${LIB}/$file ]; then
  file_to_fix=${LIB}/$file
else
  if [ -r ${INPUT}/$file ]; then
    file_to_fix=${INPUT}/$file
  else
    file_to_fix=""
  fi
fi
if [ \! -z "$file_to_fix" ]; then
  echo Checking $file_to_fix
  if grep __GNUC__ $file_to_fix > /dev/null; then
    true
  else
    sed -e '/#define NETSWAP/a\
\
#if defined (__GNUC__) || defined (__GNUG__)\
#include <sys/byteorder.h>\
187
#else  /* not __GNUC__ */
Richard Kenner committed
188 189
' \
    -e '/#endif[ 	]*\/\* NETSWAP \*\//i\
190 191
#endif /* not __GNUC__ */
' \
Richard Kenner committed
192 193 194 195 196 197
    $file_to_fix > ${LIB}/${file}.sed
    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
    echo Fixed $file_to_fix
  fi
fi

Jeff Law committed
198
# /usr/include/sys/mc_param.h has an embedded asm for the cpuid instruction
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
# on the P5. This is not used by anything else so we ifdef it out.
file=sys/mc_param.h
if [ -r ${LIB}/$file ]; then
  file_to_fix=${LIB}/$file
else
  if [ -r ${INPUT}/$file ]; then
    file_to_fix=${INPUT}/$file
  else
    file_to_fix=""
  fi
fi
if [ \! -z "$file_to_fix" ]; then
  echo Checking $file_to_fix
  if grep __GNUC__ $file_to_fix > /dev/null; then
    true
  else
    sed -e '/__asm/,/}/{
/__asm/i\
#if !defined (__GNUC__) && !defined (__GNUG__)
/}/a\
#endif
}' \
    $file_to_fix > ${LIB}/${file}.sed
    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
    echo Fixed $file_to_fix
  fi
fi

Jeff Law committed
227
# /usr/include/sys/mc_param.h has an embedded asm for the cpuid instruction
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
# on the P5. This is not used by anything else so we ifdef it out.
file=sys/mc_param.h
if [ -r ${LIB}/$file ]; then
  file_to_fix=${LIB}/$file
else
  if [ -r ${INPUT}/$file ]; then
    file_to_fix=${INPUT}/$file
  else
    file_to_fix=""
  fi
fi
if [ \! -z "$file_to_fix" ]; then
  echo Checking $file_to_fix
  if grep __GNUC__ $file_to_fix > /dev/null; then
    true
  else
    sed -e '/__asm/,/}/{
/__asm/i\
#if !defined (__GNUC__) && !defined (__GNUG__)
/}/a\
#endif
}' \
    $file_to_fix > ${LIB}/${file}.sed
    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
    echo Fixed $file_to_fix
  fi
fi

Richard Kenner committed
256 257
exit 0