2 # Fix struct exception in /usr/include/math.h.
4 # We expect several systems which did not need fixincludes in the past
5 # to need to fix just math.h. So we created a separate fixinc.mathh
6 # script to fix just that problem.
7 # See README-fixinc for more information.
9 # Directory containing the original header files.
10 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
11 INPUT
=${2-${INPUT-/usr/include}}
13 # Directory in which to store the results.
14 LIB
=${1?"fixincludes: output directory not specified"}
16 # Define PWDCMD as a command to use to get the working dir
17 # in the form that we want.
21 # On an Apollo, discard everything before `/usr'.
22 PWDCMD
="eval pwd | sed -e 's,.*/usr/,/usr/,'"
29 # Make sure it exists.
30 if [ ! -d $LIB ]; then
34 # Make LIB absolute only if needed to avoid problems with the amd.
39 cd $LIB; LIB
=`${PWDCMD}`
43 # Fail if no arg to specify a directory for the output.
45 then echo fixincludes
: no output directory specified
49 echo Building fixed headers
in ${LIB}
51 # Determine whether this system has symbolic links.
52 if ln -s X
$LIB/ShouldNotExist
2>/dev
/null
; then
53 rm -f $LIB/ShouldNotExist
55 elif ln -s X
/tmp
/ShouldNotExist
2>/dev
/null
; then
56 rm -f /tmp
/ShouldNotExist
64 # Some math.h files define struct exception, which conflicts with
65 # the class exception defined in the C++ file std/stdexcept.h. We
66 # redefine it to __math_exception. This is not a great fix, but I
67 # haven't been able to think of anything better.
69 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
70 cp $file ${LIB}/$file >/dev
/null
2>&1 ||
echo "Can't copy $file"
71 chmod +w
${LIB}/$file 2>/dev
/null
72 chmod a
+r
${LIB}/$file 2>/dev
/null
75 if [ -r ${LIB}/$file ]; then
76 echo Fixing
$file, exception
77 sed -e '/struct exception/i\
79 #define exception __math_exception\
82 -e '/struct exception/a\
86 ' ${LIB}/$file > ${LIB}/${file}.
sed
87 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
88 if egrep 'matherr()' ${LIB}/$file >/dev
/null
2>&1; then
91 #define exception __math_exception\
98 ' ${LIB}/$file > ${LIB}/${file}.
sed
99 rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
101 if cmp $file ${LIB}/$file >/dev
/null
2>&1; then
104 # Find any include directives that use "file".
105 for include
in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' ${LIB}/$file | sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'`; do
106 dir
=`echo $file | sed -e s'|/[^/]*$||'`
107 required
="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"