OSDN Git Service

Avoid irix 6.2/irix 6.3 header file conflict.
[pf3gnuchains/gcc-fork.git] / gcc / fixinc.irix
1 #! /bin/sh
2 # Install modified versions of certain problematic Irix include files.
3 # If possible, create a wrapper (see fixinc.wrap) instead of copying files.
4 #
5 # Copyright (C) 1997 Free Software Foundation, Inc.
6 # Contributed by Brendan Kehoe (brendan@cygnus.com).
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 #       See README-fixinc for more information.
26
27 # Directory containing the original header files.
28 INPUT=${2-${INPUT-/usr/include}}
29
30 # Fail if no arg to specify a directory for the output.
31 if [ x$1 = x ]
32 then echo fixincludes: no output directory specified
33 exit 1
34 fi
35
36 # Directory in which to store the results.
37 LIB=${1?"fixincludes: output directory not specified"}
38
39 # Make sure it exists.
40 if [ ! -d $LIB ]; then
41   mkdir $LIB || exit 1
42 fi
43
44 ORIG_DIR=`pwd`
45
46 # Make LIB absolute if it is relative.
47 # Don't do this if not necessary, since may screw up automounters.
48 case $LIB in
49 /*)
50         ;;
51 *)
52         LIB=$ORIG_DIR/$LIB
53         ;;
54 esac
55
56 echo 'Building fixincludes in ' ${LIB}
57
58 #
59 # Note: For Irix, we deliberately don't try to create the directory trees,
60 #       since we only modify math.h, limits.h and unistd.h.  If we
61 #       ADD ANY OTHERS, the "Making directories:" and symlinks code from
62 #       fixinc.svr4 may have to go back in.
63
64 # This math.h fix is copied from fixinc.wrap.  We want to avoid copying
65 # math.h because both math.h and stdlib.h have a declaration for initstate,
66 # and this declaration changed between Irix 6.2 and Irix 6.3.  If we copy this
67 # file, then the same toolchain can't be shared between 6.2 and 6.3+.
68
69 # Some math.h files define struct exception, which conflicts with
70 # the class exception defined in the C++ file std/stdexcept.h.  We
71 # redefine it to __math_exception.  This is not a great fix, but I
72 # haven't been able to think of anything better.
73 file=math.h
74 if [ -r $INPUT/$file ]; then
75   echo Checking $INPUT/$file
76   if grep 'struct exception' $INPUT/$file >/dev/null
77   then
78     echo Fixed $file
79     rm -f $LIB/$file
80     cat <<'__EOF__' >$LIB/$file
81 #ifndef _MATH_H_WRAPPER
82 #ifdef __cplusplus
83 # define exception __math_exception
84 #endif
85 #include_next <math.h>
86 #ifdef __cplusplus
87 # undef exception
88 #endif
89 #define _MATH_H_WRAPPER
90 #endif /* _MATH_H_WRAPPER */
91 __EOF__
92     # Define _MATH_H_WRAPPER at the end of the wrapper, not the start,
93     # so that if #include_next gets another instance of the wrapper,
94     # this will follow the #include_next chain until we arrive at
95     # the real <math.h>.
96     chmod a+r $LIB/$file
97   fi
98 fi
99
100 # In limits.h, put #ifndefs around things that are supposed to be defined
101 # in float.h to avoid redefinition errors if float.h is included first.
102
103 file=limits.h
104 base=`basename $file`
105 if [ -r ${LIB}/$file ]; then
106   file_to_fix=${LIB}/$file
107 else
108   if [ -r ${INPUT}/$file ]; then
109     file_to_fix=${INPUT}/$file
110   else
111     file_to_fix=""
112   fi
113 fi
114 if [ \! -z "$file_to_fix" ]; then
115   echo Checking $file_to_fix
116   sed -e '/[    ]FLT_MIN[       ]/i\
117 #ifndef FLT_MIN
118 '\
119       -e '/[    ]FLT_MIN[       ]/a\
120 #endif
121 '\
122       -e '/[    ]FLT_MAX[       ]/i\
123 #ifndef FLT_MAX
124 '\
125       -e '/[    ]FLT_MAX[       ]/a\
126 #endif
127 '\
128       -e '/[    ]FLT_DIG[       ]/i\
129 #ifndef FLT_DIG
130 '\
131       -e '/[    ]FLT_DIG[       ]/a\
132 #endif
133 '\
134       -e '/[    ]DBL_MIN[       ]/i\
135 #ifndef DBL_MIN
136 '\
137       -e '/[    ]DBL_MIN[       ]/a\
138 #endif
139 '\
140       -e '/[    ]DBL_MAX[       ]/i\
141 #ifndef DBL_MAX
142 '\
143       -e '/[    ]DBL_MAX[       ]/a\
144 #endif
145 '\
146       -e '/[    ]DBL_DIG[       ]/i\
147 #ifndef DBL_DIG
148 '\
149       -e '/[    ]DBL_DIG[       ]/a\
150 #endif
151 ' $file_to_fix > /tmp/$base
152   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
153     true
154   else
155     echo Fixed $file_to_fix
156     rm -f ${LIB}/$file
157     cp /tmp/$base ${LIB}/$file
158     chmod a+r ${LIB}/$file
159   fi
160   rm -f /tmp/$base
161 fi
162
163 # The Irix unistd.h will introduce a call to __vfork in its libc, but the
164 # function is never actually prototyped.
165 file=unistd.h
166 base=`basename $file`
167 if [ -r ${LIB}/$file ]; then
168   file_to_fix=${LIB}/$file
169 else
170   if [ -r ${INPUT}/$file ]; then
171     file_to_fix=${INPUT}/$file
172   else
173     file_to_fix=""
174   fi
175 fi
176 if [ \! -z "$file_to_fix" ]; then
177   echo Checking $file_to_fix
178   sed -e '/__vfork/i\
179 extern pid_t __vfork(void);'\
180      $file_to_fix > /tmp/$base
181   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
182     true
183   else
184     echo Fixed $file_to_fix
185     rm -f ${LIB}/$file
186     cp /tmp/$base ${LIB}/$file
187     chmod a+r ${LIB}/$file
188   fi
189   rm -f /tmp/$base
190 fi
191
192 exit 0