2002-03-31 Segher Boessenkool <segher@koffie.nl>
[official-gcc.git] / gcc / fixinc / fixinc.wrap
blobe242d5aa5cf3a10d3393daf2a05a9071620d0978
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 in which to store the results.
12 LIB=${1?"fixincludes: output directory not specified"}
14 # Make sure it exists.
15 if [ ! -d $LIB ]; then
16 mkdir $LIB || exit 1
19 ORIG_DIR=`${PWDCMD-pwd}`
21 # Make LIB absolute if it is relative.
22 # Don't do this if not necessary, since may screw up automounters.
23 case $LIB in
24 /*)
27 cd $LIB; LIB=`${PWDCMD-pwd}`
29 esac
31 echo Building fixed headers in ${LIB}
32 # Directory containing the original header files.
33 shift
34 if [ $# -eq 0 ] ; then
35 set /usr/include
38 INLIST="$@"
40 for INPUT in ${INLIST} ; do
41 cd ${ORIG_DIR}
42 cd ${INPUT}
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.
48 file=math.h
49 if [ -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
75 # Similarly for struct queue in sys/stream.h.
76 file=sys/stream.h
77 if [ -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
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.
106 file=curses.h
107 if [ -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
134 done
136 exit 0