OSDN Git Service

Bump for snapshot
[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 # Avoid the definition of the bool type in curses.h when using
101 # g++, since it's now an official type in the C++ language.
102
103 # This is also from fixinc.wrap.
104
105 file=curses.h
106 if [ -r $INPUT/$file ]; then
107   echo Checking $INPUT/$file
108   w='[   ]'
109   if grep "typedef$w$w*char$w$w*bool$w*;" $INPUT/$file >/dev/null
110   then
111     echo Fixed $file
112     rm -f $LIB/$file
113     cat <<'__EOF__' >$LIB/$file
114 #ifndef _CURSES_H_WRAPPER
115 #ifdef __cplusplus
116 # define bool __curses_bool_t
117 #endif
118 #include_next <curses.h>
119 #ifdef __cplusplus
120 # undef bool
121 #endif
122 #define _CURSES_H_WRAPPER
123 #endif /* _CURSES_H_WRAPPER */
124 __EOF__
125     # Define _CURSES_H_WRAPPER at the end of the wrapper, not the start,
126     # so that if #include_next gets another instance of the wrapper,
127     # this will follow the #include_next chain until we arrive at
128     # the real <curses.h>.
129     chmod a+r $LIB/$file
130   fi
131 fi
132
133 # In limits.h, put #ifndefs around things that are supposed to be defined
134 # in float.h to avoid redefinition errors if float.h is included first.
135
136 file=limits.h
137 base=`basename $file`
138 if [ -r ${LIB}/$file ]; then
139   file_to_fix=${LIB}/$file
140 else
141   if [ -r ${INPUT}/$file ]; then
142     file_to_fix=${INPUT}/$file
143   else
144     file_to_fix=""
145   fi
146 fi
147 if [ \! -z "$file_to_fix" ]; then
148   echo Checking $file_to_fix
149   sed -e '/[    ]FLT_MIN[       ]/i\
150 #ifndef FLT_MIN
151 '\
152       -e '/[    ]FLT_MIN[       ]/a\
153 #endif
154 '\
155       -e '/[    ]FLT_MAX[       ]/i\
156 #ifndef FLT_MAX
157 '\
158       -e '/[    ]FLT_MAX[       ]/a\
159 #endif
160 '\
161       -e '/[    ]FLT_DIG[       ]/i\
162 #ifndef FLT_DIG
163 '\
164       -e '/[    ]FLT_DIG[       ]/a\
165 #endif
166 '\
167       -e '/[    ]DBL_MIN[       ]/i\
168 #ifndef DBL_MIN
169 '\
170       -e '/[    ]DBL_MIN[       ]/a\
171 #endif
172 '\
173       -e '/[    ]DBL_MAX[       ]/i\
174 #ifndef DBL_MAX
175 '\
176       -e '/[    ]DBL_MAX[       ]/a\
177 #endif
178 '\
179       -e '/[    ]DBL_DIG[       ]/i\
180 #ifndef DBL_DIG
181 '\
182       -e '/[    ]DBL_DIG[       ]/a\
183 #endif
184 ' $file_to_fix > /tmp/$base
185   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
186     true
187   else
188     echo Fixed $file_to_fix
189     rm -f ${LIB}/$file
190     cp /tmp/$base ${LIB}/$file
191     chmod a+r ${LIB}/$file
192   fi
193   rm -f /tmp/$base
194 fi
195
196 # The Irix unistd.h will introduce a call to __vfork in its libc, but the
197 # function is never actually prototyped.
198 file=unistd.h
199 base=`basename $file`
200 if [ -r ${LIB}/$file ]; then
201   file_to_fix=${LIB}/$file
202 else
203   if [ -r ${INPUT}/$file ]; then
204     file_to_fix=${INPUT}/$file
205   else
206     file_to_fix=""
207   fi
208 fi
209 if [ \! -z "$file_to_fix" ]; then
210   echo Checking $file_to_fix
211   sed -e '/__vfork/i\
212 extern pid_t __vfork(void);'\
213      $file_to_fix > /tmp/$base
214   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
215     true
216   else
217     echo Fixed $file_to_fix
218     rm -f ${LIB}/$file
219     cp /tmp/$base ${LIB}/$file
220     chmod a+r ${LIB}/$file
221   fi
222   rm -f /tmp/$base
223 fi
224
225 exit 0