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, 1996, 1997 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# 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# 15# GNU CC is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18# GNU General Public License for more details. 19# 20# You should have received a copy of the GNU General Public License 21# along with GNU CC; see the file COPYING. If not, write to 22# the Free Software Foundation, 59 Temple Place - Suite 330, 23# Boston, MA 02111-1307, USA. 24# 25# This script munges the native include files provided with DYNIX/ptx 26# so as to remove things which are violations of the ANSI C standard. 27# This is done by first running fixinc.svr4 which does most of the 28# work. A few includes have fixes made to them afterwards by this 29# script. Once munged, the resulting new system include files are 30# placed in a directory that GNU C will search *before* searching the 31# /usr/include directory. This script should work properly for most 32# DYNIX/ptx systems. For other types of systems, you should use the 33# `fixincludes' script instead. 34# 35# See README-fixinc for more information. 36 37# Fail if no arg to specify a directory for the output. 38if [ x$1 = x ] 39then echo fixincludes: no output directory specified 40exit 1 41fi 42 43# Directory in which to store the results. 44LIB=${1?"fixincludes: output directory not specified"} 45 46# Make sure it exists. 47if [ ! -d $LIB ]; then 48 mkdir $LIB || exit 1 49fi 50 51ORIG_DIR=`${PWDCMD-pwd}` 52 53# Make LIB absolute if it is relative. 54# Don't do this if not necessary, since may screw up automounters. 55case $LIB in 56/*) 57 ;; 58*) 59 cd $LIB; LIB=`${PWDCMD-pwd}` 60 ;; 61esac 62 63echo 'Running fixinc.svr4' 64# DYNIX/ptx has dirname so this is no problem 65`dirname $0`/fixinc.svr4 $* 66echo 'Finished fixinc.svr4' 67 68echo 'Building fixincludes in ' ${LIB} 69# Directory containing the original header files. 70shift 71if [ $# -eq 0 ] ; then 72 set /usr/include 73fi 74 75INLIST="$@" 76 77for INPUT in ${INLIST} ; do 78cd ${ORIG_DIR} 79cd ${INPUT} 80 81# Copied from fixincludes. 82# Don't use or define the name va_list in stdio.h. 83# This is for ANSI and also to interoperate properly with gcc's varargs.h. 84file=stdio.h 85if [ -r $file ] && [ ! -r ${LIB}/$file ]; then 86 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file" 87 chmod +w ${LIB}/$file 2>/dev/null 88 chmod a+r ${LIB}/$file 2>/dev/null 89fi 90 91if [ -r ${LIB}/$file ]; then 92 echo Fixing $file, use of va_list 93 # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list 94 (echo "#define __need___va_list" 95 echo "#include <stdarg.h>") > ${LIB}/${file}.sed 96 # Use __gnuc_va_list in arg types in place of va_list. 97 # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the 98 # trailing parentheses and semicolon save all other systems from this. 99 # Define __va_list__ (something harmless and unused) instead of va_list. 100 # Don't claim to have defined va_list. 101 sed -e 's@ va_list @ __gnuc_va_list @' \ 102 -e 's@ va_list)@ __gnuc_va_list)@' \ 103 -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \ 104 -e 's@ va_list@ __va_list__@' \ 105 -e 's@\*va_list@*__va_list__@' \ 106 -e 's@ __va_list)@ __gnuc_va_list)@' \ 107 -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \ 108 -e 's@VA_LIST@DUMMY_VA_LIST@' \ 109 -e 's@_NEED___Va_LIST@_NEED___VA_LIST@' \ 110 ${LIB}/$file >> ${LIB}/${file}.sed 111 112 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file 113 if cmp $file ${LIB}/$file >/dev/null 2>&1; then 114 rm -f ${LIB}/$file 115 fi 116fi 117 118# In pwd.h, PTX 1.x needs stdio.h included since FILE * was added in a 119# prototype later on in the file. 120file=pwd.h 121base=`basename $file` 122if [ -r ${LIB}/$file ]; then 123 file_to_fix=${LIB}/$file 124else 125 if [ -r ${INPUT}/$file ]; then 126 file_to_fix=${INPUT}/$file 127 else 128 file_to_fix="" 129 fi 130fi 131if [ \! -z "$file_to_fix" ]; then 132 echo Checking $file_to_fix 133 if grep stdio $file_to_fix > /dev/null; then 134 true 135 else 136 sed -e '/#include <sys\/types\.h>/a\ 137\ 138#if defined(__STDC__) || defined(__cplusplus)\ 139#include <stdio.h>\ 140#endif /* __STDC__ */ 141' \ 142 $file_to_fix > ${LIB}/${file}.sed 143 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file 144 echo Fixed $file_to_fix 145 fi 146fi 147 148# Copied from fixincludes. 149# math.h puts the declaration of matherr before the definition 150# of struct exception, so the prototype (added by fixproto) causes havoc. 151file=math.h 152if [ -r $file ] && [ ! -r ${LIB}/$file ]; then 153 cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file" 154 chmod +w ${LIB}/$file 2>/dev/null 155 chmod a+r ${LIB}/$file 2>/dev/null 156fi 157 158if [ -r ${LIB}/$file ]; then 159 echo Fixing $file, matherr declaration 160 sed -e '/^struct exception/,$b' \ 161 -e '/matherr/i\ 162struct exception; 163'\ 164 ${LIB}/$file > ${LIB}/${file}.sed 165 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file 166 if cmp $file ${LIB}/$file >/dev/null 2>&1; then 167 rm -f ${LIB}/$file 168 fi 169fi 170 171# In netinet/in.h, the network byte swapping asm functions supported by the 172# native cc compiler on PTX 1.x and 2.x is not supported in gcc. Instead, 173# include <sys/byteorder.h> written out by the fixinc.svr4 script which has 174# these same routines written in an asm format supported by gcc. 175file=netinet/in.h 176base=`basename $file` 177if [ -r ${LIB}/$file ]; then 178 file_to_fix=${LIB}/$file 179else 180 if [ -r ${INPUT}/$file ]; then 181 file_to_fix=${INPUT}/$file 182 else 183 file_to_fix="" 184 fi 185fi 186if [ \! -z "$file_to_fix" ]; then 187 echo Checking $file_to_fix 188 if grep __GNUC__ $file_to_fix > /dev/null; then 189 true 190 else 191 sed -e '/#define NETSWAP/a\ 192\ 193#if defined (__GNUC__) || defined (__GNUG__)\ 194#include <sys/byteorder.h>\ 195#else /* not __GNUC__ */ 196' \ 197 -e '/#endif[ ]*\/\* NETSWAP \*\//i\ 198#endif /* not __GNUC__ */ 199' \ 200 $file_to_fix > ${LIB}/${file}.sed 201 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file 202 echo Fixed $file_to_fix 203 fi 204fi 205 206# /usr/include/sys/mc_param.h has an embedded asm for the cpuid instruction 207# on the P5. This is not used by anything else so we ifdef it out. 208file=sys/mc_param.h 209if [ -r ${LIB}/$file ]; then 210 file_to_fix=${LIB}/$file 211else 212 if [ -r ${INPUT}/$file ]; then 213 file_to_fix=${INPUT}/$file 214 else 215 file_to_fix="" 216 fi 217fi 218if [ \! -z "$file_to_fix" ]; then 219 echo Checking $file_to_fix 220 if grep __GNUC__ $file_to_fix > /dev/null; then 221 true 222 else 223 sed -e '/__asm/,/}/{ 224/__asm/i\ 225#if !defined (__GNUC__) && !defined (__GNUG__) 226/}/a\ 227#endif 228}' \ 229 $file_to_fix > ${LIB}/${file}.sed 230 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file 231 echo Fixed $file_to_fix 232 fi 233fi 234 235# /usr/include/sys/mc_param.h has an embedded asm for the cpuid instruction 236# on the P5. This is not used by anything else so we ifdef it out. 237file=sys/mc_param.h 238if [ -r ${LIB}/$file ]; then 239 file_to_fix=${LIB}/$file 240else 241 if [ -r ${INPUT}/$file ]; then 242 file_to_fix=${INPUT}/$file 243 else 244 file_to_fix="" 245 fi 246fi 247if [ \! -z "$file_to_fix" ]; then 248 echo Checking $file_to_fix 249 if grep __GNUC__ $file_to_fix > /dev/null; then 250 true 251 else 252 sed -e '/__asm/,/}/{ 253/__asm/i\ 254#if !defined (__GNUC__) && !defined (__GNUG__) 255/}/a\ 256#endif 257}' \ 258 $file_to_fix > ${LIB}/${file}.sed 259 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file 260 echo Fixed $file_to_fix 261 fi 262fi 263 264done 265 266if [ x${INSTALL_ASSERT_H} != x ] 267then 268 cd ${ORIG_DIR} 269 rm -f include/assert.h 270 cp ${srcdir}/assert.h include/assert.h || exit 1 271 chmod a+r include/assert.h 272fi 273 274exit 0 275