OSDN Git Service

(notice_cc_update): Set CC_FCOMI is this is a float compare.
[pf3gnuchains/gcc-fork.git] / gcc / fixinc.sco
1 #! /bin/sh
2 #
3 #   fixinc.sco  --  Install modified versions of SCO system include
4 #   files.
5 #
6 #   Based on fixinc.svr4 script by Ron Guilmette (rfg@ncd.com) (SCO
7 #   modifications by Ian Lance Taylor (ian@airs.com)).
8 #
9 # This file is part of GNU CC.
10
11 # GNU CC is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
14 # any later version.
15
16 # GNU CC is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20
21 # You should have received a copy of the GNU General Public License
22 # along with GNU CC; see the file COPYING.  If not, write to
23 # the Free Software Foundation, 59 Temple Place - Suite 330,
24 # Boston, MA 02111-1307, USA.
25 #
26 #       This script munges the native include files provided with SCO
27 #       3.2v4 systems so as to provide a reasonable namespace when
28 #       compiling with gcc.  The header files by default do not
29 #       provide many essential definitions and declarations if
30 #       __STDC__ is 1.  This script modifies the header files to check
31 #       for __STRICT_ANSI__ being defined instead.  Once munged, the
32 #       resulting new system include files are placed in a directory
33 #       that GNU C will search *before* searching the /usr/include
34 #       directory.  This script should work properly for most SCO
35 #       3.2v4 systems.  For other types of systems, you should use the
36 #       `fixincludes' or the `fixinc.svr4' script instead.
37 #
38 #       See README-fixinc for more information.
39
40 # Directory containing the original header files.
41 INPUT=${2-${INPUT-/usr/include}}
42
43 # Fail if no arg to specify a directory for the output.
44 if [ x$1 = x ]
45 then echo fixincludes: no output directory specified
46 exit 1
47 fi
48
49 # Directory in which to store the results.
50 LIB=${1?"fixincludes: output directory not specified"}
51
52 # Make sure it exists.
53 if [ ! -d $LIB ]; then
54   mkdir $LIB || exit 1
55 fi
56
57 ORIG_DIR=`pwd`
58
59 # Make LIB absolute if it is relative.
60 # Don't do this if not necessary, since may screw up automounters.
61 case $LIB in
62 /*)
63         ;;
64 *)
65         cd $LIB; LIB=`${PWDCMD-pwd}`
66         ;;
67 esac
68
69 echo 'Building fixincludes in ' ${LIB}
70
71 # Determine whether this filesystem has symbolic links.
72 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
73   rm -f $LIB/ShouldNotExist
74   LINKS=true
75 else
76   LINKS=false
77 fi
78
79 echo 'Making directories:'
80 cd ${INPUT}
81 if $LINKS; then
82   files=`ls -LR | sed -n s/:$//p`
83 else
84   files=`find . -type d -print | sed '/^.$/d'`
85 fi
86 for file in $files; do
87   rm -rf $LIB/$file
88   if [ ! -d $LIB/$file ]
89   then mkdir $LIB/$file
90   fi
91 done
92
93 # treetops gets an alternating list
94 # of old directories to copy
95 # and the new directories to copy to.
96 treetops="${INPUT} ${LIB}"
97
98 if $LINKS; then
99   echo 'Making internal symbolic directory links'
100   for file in $files; do
101     dest=`ls -ld $file | sed -n 's/.*-> //p'`
102     if [ "$dest" ]; then    
103       cwd=`pwd`
104       # In case $dest is relative, get to $file's dir first.
105       cd ${INPUT}
106       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
107       # Check that the target directory exists.
108       # Redirections changed to avoid bug in sh on Ultrix.
109       (cd $dest) > /dev/null 2>&1
110       if [ $? = 0 ]; then
111         cd $dest
112         # X gets the dir that the link actually leads to.
113         x=`pwd`
114         # If link leads back into ${INPUT},
115         # make a similar link here.
116         if expr $x : "${INPUT}/.*" > /dev/null; then
117           # Y gets the actual target dir name, relative to ${INPUT}.
118           y=`echo $x | sed -n "s&${INPUT}/&&p"`
119           echo $file '->' $y ': Making link'
120           rm -fr ${LIB}/$file > /dev/null 2>&1
121           ln -s ${LIB}/$y ${LIB}/$file > /dev/null 2>&1
122         else
123           # If the link is to outside ${INPUT},
124           # treat this directory as if it actually contained the files.
125 # This line used to have $dest instead of $x.
126 # $dest seemed to be wrong for links found in subdirectories
127 # of ${INPUT}.  Does this change break anything?
128           treetops="$treetops $x ${LIB}/$file"
129         fi
130       fi
131       cd $cwd
132     fi
133   done
134 fi
135
136 set - $treetops
137 while [ $# != 0 ]; do
138   # $1 is an old directory to copy, and $2 is the new directory to copy to.
139   echo "Finding header files in $1:"
140   cd ${INPUT}
141   cd $1
142   files=`find . -name '*.h' -type f -print`
143   echo 'Checking header files:'
144   for file in $files; do
145     if egrep '!__STDC__' $file >/dev/null; then
146       if [ -r $file ]; then
147         cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
148         chmod +w $2/$file
149         chmod a+r $2/$file
150
151 # The following have been removed from the sed command below
152 # because it is more useful to leave these things in.
153 # The only reason to remove them was for -pedantic,
154 # which isn't much of a reason. -- rms.
155 #         /^[   ]*#[    ]*ident/d
156
157         sed -e '
158           s/!__STDC__/!defined (__STRICT_ANSI__)/g
159         ' $2/$file > $2/$file.sed
160         mv $2/$file.sed $2/$file
161         if cmp $file $2/$file >/dev/null 2>&1; then
162            rm $2/$file
163         else
164            echo Fixed $file
165         fi
166       fi
167     fi
168   done
169   shift; shift
170 done
171
172 # Fix first broken decl of getcwd present on some svr4 systems.
173
174 file=stdlib.h
175 base=`basename $file`
176 if [ -r ${LIB}/$file ]; then
177   file_to_fix=${LIB}/$file
178 else
179   if [ -r ${INPUT}/$file ]; then
180     file_to_fix=${INPUT}/$file
181   else
182     file_to_fix=""
183   fi
184 fi
185 if [ \! -z "$file_to_fix" ]; then
186   echo Checking $file_to_fix
187   sed -e 's/getcwd(char \{0,\}\*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
188   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
189     true
190   else
191     echo Fixed $file_to_fix
192     rm -f ${LIB}/$file
193     cp /tmp/$base ${LIB}/$file
194     chmod a+r ${LIB}/$file
195   fi
196   rm -f /tmp/$base
197 fi
198
199 # Fix second broken decl of getcwd present on some svr4 systems.  Also
200 # fix the incorrect decl of profil present on some svr4 systems.
201
202 file=unistd.h
203 base=`basename $file`
204 if [ -r ${LIB}/$file ]; then
205   file_to_fix=${LIB}/$file
206 else
207   if [ -r ${INPUT}/$file ]; then
208     file_to_fix=${INPUT}/$file
209   else
210     file_to_fix=""
211   fi
212 fi
213 if [ \! -z "$file_to_fix" ]; then
214   echo Checking $file_to_fix
215   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
216     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
217   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
218     true
219   else
220     echo Fixed $file_to_fix
221     rm -f ${LIB}/$file
222     cp /tmp/$base ${LIB}/$file
223     chmod a+r ${LIB}/$file
224   fi
225   rm -f /tmp/$base
226 fi
227
228 # Fix third broken decl of getcwd on SCO.  Also fix incorrect decl of
229 # link.
230 file=prototypes.h
231 base=`basename $file`
232 if [ -r ${LIB}/$file ]; then
233   file_to_fix=${LIB}/$file
234 else
235   if [ -r ${INPUT}/$file ]; then
236     file_to_fix=${INPUT}/$file
237   else
238     file_to_fix=""
239   fi
240 fi
241 if [ \! -z "$file_to_fix" ]; then
242   echo Checking $file_to_fix
243   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
244     | sed -e 's/const  int      link(const char \*, char \*)/extern  int        link(const char *, const char *)/' > /tmp/$base
245   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
246     true
247   else
248     echo Fixed $file_to_fix
249     rm -f ${LIB}/$file
250     cp /tmp/$base ${LIB}/$file
251     chmod a+r ${LIB}/$file
252   fi
253   rm -f /tmp/$base
254 fi
255
256 # Fix an error in this file: the #if says _cplusplus, not the double
257 # underscore __cplusplus that it should be
258 file=tinfo.h
259 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
260   mkdir ${LIB}/rpcsvc 2>/dev/null
261   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
262   chmod +w ${LIB}/$file 2>/dev/null
263   chmod a+r ${LIB}/$file 2>/dev/null
264 fi
265
266 if [ -r ${LIB}/$file ]; then
267   echo Fixing $file, __cplusplus macro
268   sed -e 's/[   ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
269   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
270   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
271     rm ${LIB}/$file
272   fi
273 fi
274
275 # Fix prototype declaration of utime in sys/times.h.  In 3.2v4.0 the
276 # const is missing.
277 file=sys/times.h
278 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
279   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
280   chmod +w ${LIB}/$file 2>/dev/null
281   chmod a+r ${LIB}/$file 2>/dev/null
282 fi
283
284 if [ -r ${LIB}/$file ]; then
285   echo Fixing $file, utime prototype
286   sed -e 's/(const char \*, struct utimbuf \*);/(const char *, const struct utimbuf *);/' ${LIB}/$file > ${LIB}/${file}.sed
287   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
288   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
289     rm ${LIB}/$file
290   fi
291 fi
292
293 echo 'Removing unneeded directories:'
294 cd $LIB
295 files=`find . -type d -print | sort -r`
296 for file in $files; do
297   rmdir $LIB/$file > /dev/null 2>&1
298 done
299
300 if $LINKS; then
301   echo 'Making internal symbolic non-directory links'
302   cd ${INPUT}
303   files=`find . -type l -print`
304   for file in $files; do
305     dest=`ls -ld $file | sed -n 's/.*-> //p'`
306     if expr "$dest" : '[^/].*' > /dev/null; then    
307       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
308       if [ -f $target ]; then
309         ln -s $dest ${LIB}/$file >/dev/null 2>&1
310       fi
311     fi
312   done
313 fi
314
315 exit 0