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