OSDN Git Service

9a9bf9fa10e65434e2f081bfff697a6e00260bf4
[pf3gnuchains/gcc-fork.git] / gcc / fixinc / fixincl.sh
1 #!/bin/sh
2 #
3 #  DO NOT EDIT THIS FILE - it has been generated
4 #
5 # Install modified versions of certain ANSI-incompatible system header
6 # files which are fixed to work correctly with ANSI C and placed in a
7 # directory that GNU C will search.
8 #
9 # This script contains 113 fixup scripts.
10 #
11 # See README-fixinc for more information.
12 #
13 #  fixincludes copyright (c) 2000 The Free Software Foundation, Inc.
14 #
15 # fixincludes is free software.
16
17 # You may redistribute it and/or modify it under the terms of the
18 # GNU General Public License, as published by the Free Software
19 # Foundation; either version 2, or (at your option) any later version.
20
21 # fixincludes is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 # See the GNU General Public License for more details.
25
26 # You should have received a copy of the GNU General Public License
27 # along with fixincludes.  See the file "COPYING".  If not,
28 # write to:  The Free Software Foundation, Inc.,
29 #            59 Temple Place - Suite 330,
30 #            Boston,  MA  02111-1307, USA.
31 #
32 # # # # # # # # # # # # # # # # # # # # #
33 #
34 # Directory in which to store the results.
35 # Fail if no arg to specify a directory for the output.
36 if [ "x$1" = "x" ]
37 then
38   echo fixincludes: no output directory specified
39   exit 1
40 fi
41
42 LIB=${1}
43 shift
44
45 # Make sure it exists.
46 if [ ! -d $LIB ]; then
47   mkdir $LIB || {
48     echo fixincludes:  output dir '`'$LIB"' cannot be created"
49     exit 1
50   }
51 else
52   ( cd $LIB && touch DONE && rm DONE ) || {
53     echo fixincludes:  output dir '`'$LIB"' is an invalid directory"
54     exit 1
55   }
56 fi
57
58 if test -z "$VERBOSE"
59 then
60   VERBOSE=2
61   export VERBOSE
62 else
63   case "$VERBOSE" in
64   [0-9] ) : ;;
65   * )  VERBOSE=3 ;;
66   esac
67 fi
68
69 # Define what target system we're fixing.
70 #
71 if test -r ./Makefile; then
72   target_canonical="`sed -n -e 's,^target[      ]*=[    ]*\(.*\)$,\1,p' < Makefile`"
73 fi
74
75 # If not from the Makefile, then try config.guess
76 #
77 if test -z "${target_canonical}" ; then
78   if test -x ./config.guess ; then
79     target_canonical="`config.guess`" ; fi
80   test -z "${target_canonical}" && target_canonical=unknown
81 fi
82 export target_canonical
83
84 # # # # # # # # # # # # # # # # # # # # #
85 #
86 # Define PWDCMD as a command to use to get the working dir
87 # in the form that we want.
88 PWDCMD=pwd
89
90 case "`$PWDCMD`" in
91 //*)
92     # On an Apollo, discard everything before `/usr'.
93     PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
94     ;;
95 esac
96
97 # Original directory.
98 ORIGDIR=`${PWDCMD}`
99 FIXINCL=${ORIGDIR}/fixincl
100 export FIXINCL
101
102 # Make LIB absolute only if needed to avoid problems with the amd.
103 case $LIB in
104 /*)
105     ;;
106 *)
107     cd $LIB; LIB=`${PWDCMD}`
108     ;;
109 esac
110
111 if test $VERBOSE -gt 0
112 then echo Fixing headers into ${LIB} for ${target_canonical} target ; fi
113
114 # Determine whether this system has symbolic links.
115 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
116   rm -f $LIB/ShouldNotExist
117   LINKS=true
118 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
119   rm -f /tmp/ShouldNotExist
120   LINKS=true
121 else
122   LINKS=false
123 fi
124
125 # # # # # # # # # # # # # # # # # # # # #
126 #
127 #  Search each input directory for broken header files.
128 #  This loop ends near the end of the file.
129 #
130 if test $# -eq 0
131 then
132     INPUTLIST="/usr/include"
133 else
134     INPUTLIST="$@"
135 fi
136
137 for INPUT in ${INPUTLIST} ; do
138
139 cd ${ORIGDIR}
140
141 cd ${INPUT} || continue
142 INPUT=`${PWDCMD}`
143
144 #
145 # # # # # # # # # # # # # # # # # # # # #
146 #
147 if test $VERBOSE -gt 1
148 then echo Finding directories and links to directories ; fi
149
150 # Find all directories and all symlinks that point to directories.
151 # Put the list in $all_dirs.
152 # Each time we find a symlink, add it to newdirs
153 # so that we do another find within the dir the link points to.
154 # Note that $all_dirs may have duplicates in it;
155 # later parts of this file are supposed to ignore them.
156 dirs="."
157 levels=2
158 all_dirs=""
159 search_dirs=""
160
161 while [ -n "$dirs" ] && [ $levels -gt 0 ]
162 do
163   levels=`expr $levels - 1`
164   newdirs=
165   for d in $dirs
166   do
167     if test $VERBOSE -gt 1
168     then echo " Searching $INPUT/$d" ; fi
169
170     # Find all directories under $d, relative to $d, excluding $d itself.
171     # (The /. is needed after $d in case $d is a symlink.)
172     all_dirs="$all_dirs `find $d/. -type d -print | \
173                sed -e '/\/\.$/d' -e 's@/./@/@g'`"
174     # Find all links to directories.
175     # Using `-exec test -d' in find fails on some systems,
176     # and trying to run test via sh fails on others,
177     # so this is the simplest alternative left.
178     # First find all the links, then test each one.
179     theselinks=
180     $LINKS && \
181       theselinks=`find $d/. -type l -print | sed -e 's@/./@/@g'`
182     for d1 in $theselinks --dummy--
183     do
184       # If the link points to a directory,
185       # add that dir to $newdirs
186       if [ -d $d1 ]
187       then
188         all_dirs="$all_dirs $d1"
189         if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
190         then
191           newdirs="$newdirs $d1"
192           search_dirs="$search_dirs $d1"
193         fi
194       fi
195     done
196   done
197
198   dirs="$newdirs"
199 done
200
201 # # # # # # # # # # # # # # # # # # # # #
202 #
203 dirs=
204 if test $VERBOSE -gt 2
205 then echo "All directories (including links to directories):"
206      echo $all_dirs
207 fi
208
209 for file in $all_dirs; do
210   rm -rf $LIB/$file
211   if [ ! -d $LIB/$file ]
212   then mkdir $LIB/$file
213   fi
214 done
215 mkdir $LIB/root
216
217 # # # # # # # # # # # # # # # # # # # # #
218 #
219 # treetops gets an alternating list
220 # of old directories to copy
221 # and the new directories to copy to.
222 treetops=". ${LIB}"
223
224 if $LINKS; then
225   if test $VERBOSE -gt 1
226   then echo 'Making symbolic directory links' ; fi
227   cwd=`${PWDCMD}`
228
229   for sym_link in $search_dirs; do
230     cd ${INPUT}
231     dest=`ls -ld ${sym_link} | sed -n 's/.*-> //p'`
232
233     # In case $dest is relative, get to ${sym_link}'s dir first.
234     #
235     cd ./`echo ${sym_link} | sed 's;/[^/]*$;;'`
236
237     # Check that the target directory exists.
238     # Redirections changed to avoid bug in sh on Ultrix.
239     #
240     (cd $dest) > /dev/null 2>&1
241     if [ $? = 0 ]; then
242       cd $dest
243
244       # full_dest_dir gets the dir that the link actually leads to.
245       #
246       full_dest_dir=`${PWDCMD}`
247
248       # Canonicalize ${INPUT} now to minimize the time an
249       # automounter has to change the result of ${PWDCMD}.
250       #
251       cinput=`cd ${INPUT}; ${PWDCMD}`
252
253       # If a link points to ., make a similar link to .
254       #
255       if [ ${full_dest_dir} = ${cinput} ]; then
256         if test $VERBOSE -gt 2
257         then echo ${sym_link} '->' . ': Making self link' ; fi
258         rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
259         ln -s . ${LIB}/${sym_link} > /dev/null 2>&1
260
261       # If link leads back into ${INPUT},
262       # make a similar link here.
263       #
264       elif expr ${full_dest_dir} : "${cinput}/.*" > /dev/null; then
265         # Y gets the actual target dir name, relative to ${INPUT}.
266         y=`echo ${full_dest_dir} | sed -n "s&${cinput}/&&p"`
267         # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.
268         dots=`echo "${sym_link}" |
269           sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
270         if test $VERBOSE -gt 2
271         then echo ${sym_link} '->' $dots$y ': Making local link' ; fi
272         rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
273         ln -s $dots$y ${LIB}/${sym_link} > /dev/null 2>&1
274
275       else
276         # If the link is to a dir $target outside ${INPUT},
277         # repoint the link at ${INPUT}/root$target
278         # and process $target into ${INPUT}/root$target
279         # treat this directory as if it actually contained the files.
280         #
281         if test $VERBOSE -gt 2
282         then echo ${sym_link} '->' root${full_dest_dir} ': Making rooted link'
283         fi
284         if [ -d $LIB/root${full_dest_dir} ]
285         then true
286         else
287           dirname=root${full_dest_dir}/
288           dirmade=.
289           cd $LIB
290           while [ x$dirname != x ]; do
291             component=`echo $dirname | sed -e 's|/.*$||'`
292             mkdir $component >/dev/null 2>&1
293             cd $component
294             dirmade=$dirmade/$component
295             dirname=`echo $dirname | sed -e 's|[^/]*/||'`
296           done
297         fi
298
299         # Duplicate directory structure created in ${LIB}/${sym_link} in new
300         # root area.
301         #
302         for file2 in $all_dirs; do
303           case $file2 in
304             ${sym_link}/*)
305               dupdir=${LIB}/root${full_dest_dir}/`echo $file2 |
306                       sed -n "s|^${sym_link}/||p"`
307               if test $VERBOSE -gt 2
308               then echo "Duplicating ${sym_link}'s ${dupdir}" ; fi
309               if [ -d ${dupdir} ]
310               then true
311               else
312                 mkdir ${dupdir}
313               fi
314               ;;
315             *)
316               ;;
317           esac
318         done
319
320         # Get the path from ${LIB} to ${sym_link}, accounting for symlinks.
321         #
322         parent=`echo "${sym_link}" | sed -e 's@/[^/]*$@@'`
323         libabs=`cd ${LIB}; ${PWDCMD}`
324         file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"`
325
326         # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.
327         #
328         dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'`
329         rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
330         ln -s ${dots}root${full_dest_dir} ${LIB}/${sym_link} > /dev/null 2>&1
331         treetops="$treetops ${sym_link} ${LIB}/root${full_dest_dir}"
332       fi
333     fi
334   done
335 fi
336
337 # # # # # # # # # # # # # # # # # # # # #
338 #
339 required=
340 set x $treetops
341 shift
342 while [ $# != 0 ]; do
343   # $1 is an old directory to copy, and $2 is the new directory to copy to.
344   #
345   SRCDIR=`cd ${INPUT} ; cd $1 ; ${PWDCMD}`
346   export SRCDIR
347
348   FIND_BASE=$1
349   export FIND_BASE
350   shift
351
352   DESTDIR=`cd $1;${PWDCMD}`
353   export DESTDIR
354   shift
355
356   # The same dir can appear more than once in treetops.
357   # There's no need to scan it more than once.
358   #
359   if [ -f ${DESTDIR}/DONE ]
360   then continue ; fi
361
362   touch ${DESTDIR}/DONE
363   if test $VERBOSE -gt 1
364   then echo Fixing directory ${SRCDIR} into ${DESTDIR} ; fi
365
366   # Check files which are symlinks as well as those which are files.
367   #
368   cd ${INPUT}
369   required="$required `if $LINKS; then
370     find ${FIND_BASE}/. -name '*.h' \( -type f -o -type l \) -print
371   else
372     find ${FIND_BASE}/. -name '*.h' -type f -print
373   fi | \
374     sed -e 's;/\./;/;g' -e 's;//*;/;g' | \
375     ${FIXINCL}`"
376 done
377
378 ## Make sure that any include files referenced using double quotes
379 ## exist in the fixed directory.  This comes last since otherwise
380 ## we might end up deleting some of these files "because they don't
381 ## need any change."
382 set x `echo $required`
383 shift
384 while [ $# != 0 ]; do
385   newreq=
386   while [ $# != 0 ]; do
387     # $1 is the directory to copy from,
388     # $2 is the unfixed file,
389     # $3 is the fixed file name.
390     #
391     cd ${INPUT}
392     cd $1
393     if [ -f $2 ] ; then
394       if [ -r $2 ] && [ ! -r $3 ]; then
395         cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2
396         chmod +w $3 2>/dev/null
397         chmod a+r $3 2>/dev/null
398         if test $VERBOSE -gt 2
399         then echo Copied $2 ; fi
400         for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' $3 |
401              sed -e 's/^[       ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`
402         do
403           dir=`echo $2 | sed -e s'|/[^/]*$||'`
404           dir2=`echo $3 | sed -e s'|/[^/]*$||'`
405           newreq="$newreq $1 $dir/$include $dir2/$include"
406         done
407       fi
408     fi
409     shift; shift; shift
410   done
411   set x $newreq
412   shift
413 done
414
415 if test $VERBOSE -gt 2
416 then echo 'Cleaning up DONE files.' ; fi
417 cd $LIB
418 find . -name DONE -exec rm -f '{}' ';'
419
420 if test $VERBOSE -gt 1
421 then echo 'Cleaning up unneeded directories:' ; fi
422 cd $LIB
423 all_dirs=`find . -type d \! -name '.' -print | sort -r`
424 for file in $all_dirs; do
425   rmdir $LIB/$file > /dev/null 2>&1
426 done
427
428 if test $VERBOSE -gt 0
429 then echo fixincludes is done ; fi
430
431 # # # # # # # # # # # # # # # # # # # # #
432 #
433 # End of for INPUT directories
434 #
435 done
436 #
437 # # # # # # # # # # # # # # # # # # # # #
438
439 if [ x${INSTALL_ASSERT_H} != x ] && [ -f ${srcdir}/assert.h ]
440 then
441   cd $ORIGDIR
442   rm -f include/assert.h
443   cp ${srcdir}/assert.h include/assert.h || exit 1
444   chmod a+r include/assert.h
445 fi