1#! /bin/sh 2# Create wrappers for include files instead of replacing them. 3# 4# This script is designed for systems whose include files can be fixed 5# by creating small wrappers around them. 6# An advantage of this method is that if the system include files are changed 7# (e.g. by OS upgrade), you need not re-run fixincludes. 8# 9# See README-fixinc for more information. 10 11# Directory in which to store the results. 12LIB=${1?"fixincludes: output directory not specified"} 13 14# Make sure it exists. 15if [ ! -d $LIB ]; then 16 mkdir $LIB || exit 1 17fi 18 19ORIG_DIR=`${PWDCMD-pwd}` 20 21# Make LIB absolute if it is relative. 22# Don't do this if not necessary, since may screw up automounters. 23case $LIB in 24/*) 25 ;; 26*) 27 cd $LIB; LIB=`${PWDCMD-pwd}` 28 ;; 29esac 30 31echo Building fixed headers in ${LIB} 32# Directory containing the original header files. 33shift 34if [ $# -eq 0 ] ; then 35 set /usr/include 36fi 37 38INLIST="$@" 39 40for INPUT in ${INLIST} ; do 41cd ${ORIG_DIR} 42cd ${INPUT} 43 44# Some math.h files define struct exception, which conflicts with 45# the class exception defined in the C++ file std/stdexcept.h. We 46# redefine it to __math_exception. This is not a great fix, but I 47# haven't been able to think of anything better. 48file=math.h 49if [ -r $INPUT/$file ]; then 50 echo Checking $INPUT/$file 51 if grep 'struct exception' $INPUT/$file >/dev/null 52 then 53 echo Fixed $file 54 rm -f $LIB/$file 55 cat <<'__EOF__' >$LIB/$file 56#ifndef _MATH_H_WRAPPER 57#ifdef __cplusplus 58# define exception __math_exception 59#endif 60 #include_next <math.h> 61#ifdef __cplusplus 62# undef exception 63#endif 64#define _MATH_H_WRAPPER 65#endif /* _MATH_H_WRAPPER */ 66__EOF__ 67 # Define _MATH_H_WRAPPER at the end of the wrapper, not the start, 68 # so that if #include_next gets another instance of the wrapper, 69 # this will follow the #include_next chain until we arrive at 70 # the real <math.h>. 71 chmod a+r $LIB/$file 72 fi 73fi 74 75# Similarly for struct queue in sys/stream.h. 76file=sys/stream.h 77if [ -r $INPUT/$file ]; then 78 echo Checking $INPUT/$file 79 if grep 'struct[ ]*queue' $INPUT/$file >/dev/null 80 then 81 echo Fixed $file 82 mkdir -p $LIB/`dirname $file` 83 rm -f $LIB/$file 84 cat <<'__EOF__' >$LIB/$file 85#ifndef _SYS_STREAM_H_WRAPPER 86#ifdef __cplusplus 87# define queue __stream_queue 88#endif 89 #include_next <sys/stream.h> 90#ifdef __cplusplus 91# undef queue 92#endif 93#define _SYS_STREAM_H_WRAPPER 94#endif /* _SYS_STREAM_H_WRAPPER */ 95__EOF__ 96 # Define _SYS_STREAM_H_WRAPPER at the end of the wrapper, not the start, 97 # so that if #include_next gets another instance of the wrapper, 98 # this will follow the #include_next chain until we arrive at 99 # the real <sys/stream.h>. 100 chmod a+r $LIB/$file 101 fi 102fi 103 104# Avoid the definition of the bool type in the Solaris 2.x curses.h when using 105# g++, since it's now an official type in the C++ language. 106file=curses.h 107if [ -r $INPUT/$file ]; then 108 echo Checking $INPUT/$file 109 w='[ ]' 110 if grep "typedef$w$w*char$w$w*bool$w*;" $INPUT/$file >/dev/null 111 then 112 echo Fixed $file 113 rm -f $LIB/$file 114 cat <<'__EOF__' >$LIB/$file 115#ifndef _CURSES_H_WRAPPER 116#ifdef __cplusplus 117# define bool __curses_bool_t 118#endif 119 #include_next <curses.h> 120#ifdef __cplusplus 121# undef bool 122#endif 123#define _CURSES_H_WRAPPER 124#endif /* _CURSES_H_WRAPPER */ 125__EOF__ 126 # Define _CURSES_H_WRAPPER at the end of the wrapper, not the start, 127 # so that if #include_next gets another instance of the wrapper, 128 # this will follow the #include_next chain until we arrive at 129 # the real <curses.h>. 130 chmod a+r $LIB/$file 131 fi 132fi 133 134done 135 136exit 0 137