H
[official-gcc.git] / gcc / fixinc.wrap
blob406c87e9c03bd42fe5ce35d8e7f1da8927ee16b6
1 #! /bin/sh
2 # Create wrappers for include files instead of replacing them.
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.
9 # See README-fixinc for more information.
11 # Directory containing the original header files.
12 # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
13 INPUT=${2-${INPUT-/usr/include}}
15 # Directory in which to store the results.
16 LIB=${1?"fixincludes: output directory not specified"}
18 # Make sure it exists.
19 if [ ! -d $LIB ]; then
20 mkdir $LIB || exit 1
23 echo Building fixed headers in ${LIB}
25 # Some math.h files define struct exception, which conflicts with
26 # the class exception defined in the C++ file std/stdexcept.h. We
27 # redefine it to __math_exception. This is not a great fix, but I
28 # haven't been able to think of anything better.
29 file=math.h
30 if [ -r $INPUT/$file ]; then
31 echo Checking $INPUT/$file
32 if grep 'struct exception' $INPUT/$file >/dev/null
33 then
34 echo Fixed $file
35 rm -f $LIB/$file
36 cat <<'__EOF__' >$LIB/$file
37 #ifndef _MATH_H_WRAPPER
38 #ifdef __cplusplus
39 # define exception __math_exception
40 #endif
41 #include_next <math.h>
42 #ifdef __cplusplus
43 # undef exception
44 #endif
45 #define _MATH_H_WRAPPER
46 #endif /* _MATH_H_WRAPPER */
47 __EOF__
48 # Define _MATH_H_WRAPPER at the end of the wrapper, not the start,
49 # so that if #include_next gets another instance of the wrapper,
50 # this will follow the #include_next chain until we arrive at
51 # the real <math.h>.
52 chmod a+r $LIB/$file
56 # Avoid the definition of the bool type in the Solaris 2.x curses.h when using
57 # g++, since it's now an official type in the C++ language.
58 file=curses.h
59 if [ -r $INPUT/$file ]; then
60 echo Checking $INPUT/$file
61 w='[ ]'
62 if grep "typedef$w$w*char$w$w*bool$w*;" $INPUT/$file >/dev/null
63 then
64 echo Fixed $file
65 rm -f $LIB/$file
66 cat <<'__EOF__' >$LIB/$file
67 #ifndef _CURSES_H_WRAPPER
68 #ifdef __cplusplus
69 # define bool __curses_bool_t
70 #endif
71 #include_next <curses.h>
72 #ifdef __cplusplus
73 # undef bool
74 #endif
75 #define _CURSES_H_WRAPPER
76 #endif /* _CURSES_H_WRAPPER */
77 __EOF__
78 # Define _CURSES_H_WRAPPER at the end of the wrapper, not the start,
79 # so that if #include_next gets another instance of the wrapper,
80 # this will follow the #include_next chain until we arrive at
81 # the real <curses.h>.
82 chmod a+r $LIB/$file
86 exit 0