* rtl.h (rtunion_def): Constify member `rtstr'.
[official-gcc.git] / gcc / fixinc / inclhack.tpl
blob7b085a75f7d23d858cea9c6eeffb16bd5b1fec53
1 [= autogen template -*- Mode: sh -*-
2 sh
5 =]
6 #!/bin/sh
8 #  DO NOT EDIT THIS FILE - it has been generated
10 # Install modified versions of certain ANSI-incompatible system header
11 # files which are fixed to work correctly with ANSI C and placed in a
12 # directory that GNU C will search.
13 #[=
14 _IF PROGRAM _env ! =]
15 # This script contains [=_eval fix _count =] fixup scripts.
16 #[=
17 _ENDIF =]
18 # See README-fixinc for more information.
20 #  fixincludes copyright (c) 1998, 1999, 2000
21 #  The Free Software Foundation, Inc.
23 [=_eval fixincludes "## " _gpl=]
25 # # # # # # # # # # # # # # # # # # # # #
27 # Directory in which to store the results.
28 # Fail if no arg to specify a directory for the output.
29 if [ "x$1" = "x" ]
30 then
31   echo fixincludes: no output directory specified
32   exit 1
35 LIB=${1}
36 shift
38 # Make sure it exists.
39 if [ ! -d $LIB ]; then
40   mkdir $LIB || {
41     echo fixincludes:  output dir '`'$LIB"' cannot be created"
42     exit 1
43   }
44 else
45   ( cd $LIB && touch DONE && rm DONE ) || {
46     echo fixincludes:  output dir '`'$LIB"' is an invalid directory"
47     exit 1
48   }
50 [=_IF PROGRAM _env ! =]
51 FIXTESTS=$PWD/fixinc/fixtests
52 FIXFIXES=$PWD/fixinc/fixfixes
53 [=_ENDIF=]
54 if test -z "$VERBOSE"
55 then
56   VERBOSE=[=
57   _IF FIXINC_DEBUG _exist =]3[=_ELSE=]2[=_ENDIF=]
58   export VERBOSE
59 else
60   case "$VERBOSE" in
61   [0-9] ) : ;;
62   * )  VERBOSE=3 ;;
63   esac
66 # Define what target system we're fixing.
68 if test -r ./Makefile; then
69   target_canonical="`sed -n -e 's,^target[      ]*=[    ]*\(.*\)$,\1,p' < Makefile`"
72 # If not from the Makefile, then try config.guess
74 if test -z "${target_canonical}" ; then
75   if test -x ./config.guess ; then
76     target_canonical="`config.guess`" ; fi
77   test -z "${target_canonical}" && target_canonical=unknown
79 export target_canonical
81 # # # # # # # # # # # # # # # # # # # # #
83 # Define PWDCMD as a command to use to get the working dir
84 # in the form that we want.
85 PWDCMD=pwd
87 case "`$PWDCMD`" in
88 //*)
89     # On an Apollo, discard everything before `/usr'.
90     PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
91     ;;
92 esac
94 # Original directory.
95 ORIGDIR=`${PWDCMD}`[=
96 _IF PROGRAM _env =]
97 FIXINCL=${ORIGDIR}/fixincl
98 export FIXINCL[=
99 _ENDIF=]
101 # Make LIB absolute only if needed to avoid problems with the amd.
102 case $LIB in
104     ;;
106     cd $LIB; LIB=`${PWDCMD}`
107     ;;
108 esac
110 if test $VERBOSE -gt 0
111 then echo Fixing headers into ${LIB} for ${target_canonical} target ; fi
113 # Determine whether this system has symbolic links.
114 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
115   rm -f $LIB/ShouldNotExist
116   LINKS=true
117 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
118   rm -f /tmp/ShouldNotExist
119   LINKS=true
120 else
121   LINKS=false
124 # # # # # # # # # # # # # # # # # # # # #
126 #  Search each input directory for broken header files.
127 #  This loop ends near the end of the file.
129 if test $# -eq 0
130 then
131     INPUTLIST="/usr/include"
132 else
133     INPUTLIST="$@"
136 for INPUT in ${INPUTLIST} ; do
138 cd ${ORIGDIR}
140 #  Make sure a directory exists before changing into it,
141 #  otherwise Solaris2 will fail-exit the script.
143 if [ ! -d ${INPUT} ]; then
144   continue
146 cd ${INPUT}
148 INPUT=`${PWDCMD}`
151 # # # # # # # # # # # # # # # # # # # # #
153 if test $VERBOSE -gt 1
154 then echo Finding directories and links to directories ; fi
156 # Find all directories and all symlinks that point to directories.
157 # Put the list in $all_dirs.
158 # Each time we find a symlink, add it to newdirs
159 # so that we do another find within the dir the link points to.
160 # Note that $all_dirs may have duplicates in it;
161 # later parts of this file are supposed to ignore them.
162 dirs="."
163 levels=2
164 all_dirs=""
165 search_dirs=""
167 while [ -n "$dirs" ] && [ $levels -gt 0 ]
169   levels=`expr $levels - 1`
170   newdirs=
171   for d in $dirs
172   do
173     if test $VERBOSE -gt 1
174     then echo " Searching $INPUT/$d" ; fi
176     # Find all directories under $d, relative to $d, excluding $d itself.
177     # (The /. is needed after $d in case $d is a symlink.)
178     all_dirs="$all_dirs `find $d/. -type d -print | \
179                sed -e '/\/\.$/d' -e 's@/./@/@g'`"
180     # Find all links to directories.
181     # Using `-exec test -d' in find fails on some systems,
182     # and trying to run test via sh fails on others,
183     # so this is the simplest alternative left.
184     # First find all the links, then test each one.
185     theselinks=
186     $LINKS && \
187       theselinks=`find $d/. -type l -print | sed -e 's@/./@/@g'`
188     for d1 in $theselinks --dummy--
189     do
190       # If the link points to a directory,
191       # add that dir to $newdirs
192       if [ -d $d1 ]
193       then
194         all_dirs="$all_dirs $d1"
195         if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
196         then
197           newdirs="$newdirs $d1"
198           search_dirs="$search_dirs $d1"
199         fi
200       fi
201     done
202   done
204   dirs="$newdirs"
205 done
207 # # # # # # # # # # # # # # # # # # # # #
209 dirs=
210 if test $VERBOSE -gt 2
211 then echo "All directories (including links to directories):"
212      echo $all_dirs
215 for file in $all_dirs; do
216   rm -rf $LIB/$file
217   if [ ! -d $LIB/$file ]
218   then mkdir $LIB/$file
219   fi
220 done
221 mkdir $LIB/root
223 # # # # # # # # # # # # # # # # # # # # #
225 # treetops gets an alternating list
226 # of old directories to copy
227 # and the new directories to copy to.
228 treetops=". ${LIB}"
230 if $LINKS; then
231   if test $VERBOSE -gt 1
232   then echo 'Making symbolic directory links' ; fi
233   cwd=`${PWDCMD}`
235   for sym_link in $search_dirs; do
236     cd ${INPUT}
237     dest=`ls -ld ${sym_link} | sed -n 's/.*-> //p'`
239     # In case $dest is relative, get to ${sym_link}'s dir first.
240     #
241     cd ./`echo ${sym_link} | sed 's;/[^/]*$;;'`
243     # Check that the target directory exists.
244     # Redirections changed to avoid bug in sh on Ultrix.
245     #
246     (cd $dest) > /dev/null 2>&1
247     if [ $? = 0 ]; then
248       cd $dest
250       # full_dest_dir gets the dir that the link actually leads to.
251       #
252       full_dest_dir=`${PWDCMD}`
254       # Canonicalize ${INPUT} now to minimize the time an
255       # automounter has to change the result of ${PWDCMD}.
256       #
257       cinput=`cd ${INPUT}; ${PWDCMD}`
259       # If a link points to ., make a similar link to .
260       #
261       if [ ${full_dest_dir} = ${cinput} ]; then
262         if test $VERBOSE -gt 2
263         then echo ${sym_link} '->' . ': Making self link' ; fi
264         rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
265         ln -s . ${LIB}/${sym_link} > /dev/null 2>&1
267       # If link leads back into ${INPUT},
268       # make a similar link here.
269       #
270       elif expr ${full_dest_dir} : "${cinput}/.*" > /dev/null; then
271         # Y gets the actual target dir name, relative to ${INPUT}.
272         y=`echo ${full_dest_dir} | sed -n "s&${cinput}/&&p"`
273         # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.
274         dots=`echo "${sym_link}" |
275           sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
276         if test $VERBOSE -gt 2
277         then echo ${sym_link} '->' $dots$y ': Making local link' ; fi
278         rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
279         ln -s $dots$y ${LIB}/${sym_link} > /dev/null 2>&1
281       else
282         # If the link is to a dir $target outside ${INPUT},
283         # repoint the link at ${INPUT}/root$target
284         # and process $target into ${INPUT}/root$target
285         # treat this directory as if it actually contained the files.
286         #
287         if test $VERBOSE -gt 2
288         then echo ${sym_link} '->' root${full_dest_dir} ': Making rooted link'
289         fi
290         if [ -d $LIB/root${full_dest_dir} ]
291         then true
292         else
293           dirname=root${full_dest_dir}/
294           dirmade=.
295           cd $LIB
296           while [ x$dirname != x ]; do
297             component=`echo $dirname | sed -e 's|/.*$||'`
298             mkdir $component >/dev/null 2>&1
299             cd $component
300             dirmade=$dirmade/$component
301             dirname=`echo $dirname | sed -e 's|[^/]*/||'`
302           done
303         fi
305         # Duplicate directory structure created in ${LIB}/${sym_link} in new
306         # root area.
307         #
308         for file2 in $all_dirs; do
309           case $file2 in
310             ${sym_link}/*)
311               dupdir=${LIB}/root${full_dest_dir}/`echo $file2 |
312                       sed -n "s|^${sym_link}/||p"`
313               if test $VERBOSE -gt 2
314               then echo "Duplicating ${sym_link}'s ${dupdir}" ; fi
315               if [ -d ${dupdir} ]
316               then true
317               else
318                 mkdir ${dupdir}
319               fi
320               ;;
321             *)
322               ;;
323           esac
324         done
326         # Get the path from ${LIB} to ${sym_link}, accounting for symlinks.
327         #
328         parent=`echo "${sym_link}" | sed -e 's@/[^/]*$@@'`
329         libabs=`cd ${LIB}; ${PWDCMD}`
330         file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"`
332         # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.
333         #
334         dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'`
335         rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
336         ln -s ${dots}root${full_dest_dir} ${LIB}/${sym_link} > /dev/null 2>&1
337         treetops="$treetops ${sym_link} ${LIB}/root${full_dest_dir}"
338       fi
339     fi
340   done
343 # # # # # # # # # # # # # # # # # # # # #
345 required=
346 set x $treetops
347 shift
348 while [ $# != 0 ]; do
349   # $1 is an old directory to copy, and $2 is the new directory to copy to.
350   #
351   SRCDIR=`cd ${INPUT} ; cd $1 ; ${PWDCMD}`
352   export SRCDIR
354   FIND_BASE=$1
355   export FIND_BASE
356   shift
358   DESTDIR=`cd $1;${PWDCMD}`
359   export DESTDIR
360   shift
362   # The same dir can appear more than once in treetops.
363   # There's no need to scan it more than once.
364   #
365   if [ -f ${DESTDIR}/DONE ]
366   then continue ; fi
368   touch ${DESTDIR}/DONE
369   if test $VERBOSE -gt 1
370   then echo Fixing directory ${SRCDIR} into ${DESTDIR} ; fi
372   # Check files which are symlinks as well as those which are files.
373   #
374   cd ${INPUT}[=
375 _IF PROGRAM _env ! =]
376   files=`if $LINKS; then
377     find ${FIND_BASE}/. -name '*.h' \( -type f -o -type l \) -print
378   else
379     find ${FIND_BASE}/. -name '*.h' -type f -print
380   fi | \
381     sed -e 's;/\./;/;g' -e 's;//*;/;g' `
384     _include hackshell =][=
386   _ELSE
389   required="$required `if $LINKS; then
390     find ${FIND_BASE}/. -name '*.h' \( -type f -o -type l \) -print
391   else
392     find ${FIND_BASE}/. -name '*.h' -type f -print
393   fi | \
394     sed -e 's;/\./;/;g' -e 's;//*;/;g' | \
395     ${FIXINCL}`"[=
398   _ENDIF =]
399 done
401 ## Make sure that any include files referenced using double quotes
402 ## exist in the fixed directory.  This comes last since otherwise
403 ## we might end up deleting some of these files "because they don't
404 ## need any change."
405 set x `echo $required`
406 shift
407 while [ $# != 0 ]; do
408   newreq=
409   while [ $# != 0 ]; do
410     # $1 is the directory to copy from,
411     # $2 is the unfixed file,
412     # $3 is the fixed file name.
413     #
414     cd ${INPUT}
415     cd $1
416     if [ -f $2 ] ; then
417       if [ -r $2 ] && [ ! -r $3 ]; then
418         cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2
419         chmod +w $3 2>/dev/null
420         chmod a+r $3 2>/dev/null
421         if test $VERBOSE -gt 2
422         then echo Copied $2 ; fi
423         for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' $3 |
424              sed -e 's/^[       ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`
425         do
426           dir=`echo $2 | sed -e s'|/[^/]*$||'`
427           dir2=`echo $3 | sed -e s'|/[^/]*$||'`
428           newreq="$newreq $1 $dir/$include $dir2/$include"
429         done
430       fi
431     fi
432     shift; shift; shift
433   done
434   set x $newreq
435   shift
436 done
438 if test $VERBOSE -gt 2
439 then echo 'Cleaning up DONE files.' ; fi
440 cd $LIB
441 find . -name DONE -exec rm -f '{}' ';'
443 if test $VERBOSE -gt 1
444 then echo 'Cleaning up unneeded directories:' ; fi
445 cd $LIB
446 all_dirs=`find . -type d \! -name '.' -print | sort -r`
447 for file in $all_dirs; do
448   if rmdir $LIB/$file > /dev/null
449   then
450     test $VERBOSE -gt 3 && echo "  removed $file"
451   fi
452 done 2> /dev/null
454 test $VERBOSE -gt 2 && echo "Removing unused symlinks"
456 all_dirs=`find . -type l -print`
457 for file in $all_dirs
459   if ls -lLd $file > /dev/null
460   then :
461   else rm -f $file
462        test $VERBOSE -gt 3 && echo "  removed $file"
463        rmdir `dirname $file` > /dev/null && \
464          test $VERBOSE -gt 3 && \
465          echo "  removed `dirname $file`"
466   fi
467 done 2> /dev/null
469 if test $VERBOSE -gt 0
470 then echo fixincludes is done ; fi
472 # # # # # # # # # # # # # # # # # # # # #
474 # End of for INPUT directories
476 done
478 # # # # # # # # # # # # # # # # # # # # #
480 if [ x${INSTALL_ASSERT_H} != x ] && [ -f ${srcdir}/assert.h ]
481 then
482   cd $ORIGDIR
483   rm -f include/assert.h
484   cp ${srcdir}/assert.h include/assert.h || exit 1
485   chmod a+r include/assert.h
486 fi[=
488 #  Make the output file executable
489 # =][=
490 _eval _outfile "chmod +x %s" _printf _shell=]