]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fixinc/fixincl.sh
2000-07-18 Jeff Sturm <jeff.sturm@appnet.com>
[thirdparty/gcc.git] / gcc / fixinc / fixincl.sh
CommitLineData
fdb8fb96 1#!/bin/sh
2#
c9cbfd0e 3# EDIT THIS FILE - it is no longer generated
fdb8fb96 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#
fdb8fb96 9# See README-fixinc for more information.
10#
d4c4b01d 11# fixincludes copyright (c) 1998, 1999, 2000
12# The Free Software Foundation, Inc.
c1b28c63 13#
fdb8fb96 14# fixincludes is free software.
15#
16# You may redistribute it and/or modify it under the terms of the
17# GNU General Public License, as published by the Free Software
18# Foundation; either version 2, or (at your option) any later version.
19#
20# fixincludes is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23# See the GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with fixincludes. See the file "COPYING". If not,
27# write to: The Free Software Foundation, Inc.,
28# 59 Temple Place - Suite 330,
29# Boston, MA 02111-1307, USA.
30#
31# # # # # # # # # # # # # # # # # # # # #
32#
33# Directory in which to store the results.
34# Fail if no arg to specify a directory for the output.
35if [ "x$1" = "x" ]
a98784e9 36then
37 echo fixincludes: no output directory specified
38 exit 1
fdb8fb96 39fi
40
41LIB=${1}
42shift
43
44# Make sure it exists.
45if [ ! -d $LIB ]; then
46 mkdir $LIB || {
47 echo fixincludes: output dir '`'$LIB"' cannot be created"
48 exit 1
49 }
50else
b4118095 51 ( cd $LIB && touch DONE && rm DONE ) || {
fdb8fb96 52 echo fixincludes: output dir '`'$LIB"' is an invalid directory"
53 exit 1
54 }
55fi
56
a98784e9 57if test -z "$VERBOSE"
58then
59 VERBOSE=2
60 export VERBOSE
61else
62 case "$VERBOSE" in
63 [0-9] ) : ;;
64 * ) VERBOSE=3 ;;
65 esac
66fi
67
fdb8fb96 68# Define what target system we're fixing.
69#
70if test -r ./Makefile; then
71 target_canonical="`sed -n -e 's,^target[ ]*=[ ]*\(.*\)$,\1,p' < Makefile`"
72fi
73
74# If not from the Makefile, then try config.guess
75#
76if test -z "${target_canonical}" ; then
77 if test -x ./config.guess ; then
78 target_canonical="`config.guess`" ; fi
79 test -z "${target_canonical}" && target_canonical=unknown
80fi
81export target_canonical
82
83# # # # # # # # # # # # # # # # # # # # #
84#
85# Define PWDCMD as a command to use to get the working dir
86# in the form that we want.
87PWDCMD=pwd
88
89case "`$PWDCMD`" in
90//*)
91 # On an Apollo, discard everything before `/usr'.
92 PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
93 ;;
94esac
95
96# Original directory.
97ORIGDIR=`${PWDCMD}`
09fe1d5c 98FIXINCL=${ORIGDIR}/fixinc/fixincl
fdb8fb96 99export FIXINCL
100
101# Make LIB absolute only if needed to avoid problems with the amd.
102case $LIB in
103/*)
104 ;;
105*)
106 cd $LIB; LIB=`${PWDCMD}`
107 ;;
108esac
109
a98784e9 110if test $VERBOSE -gt 0
111then echo Fixing headers into ${LIB} for ${target_canonical} target ; fi
38ebab8a 112
fdb8fb96 113# Determine whether this system has symbolic links.
114if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
115 rm -f $LIB/ShouldNotExist
116 LINKS=true
117elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
118 rm -f /tmp/ShouldNotExist
119 LINKS=true
120else
121 LINKS=false
122fi
38ebab8a 123
fdb8fb96 124# # # # # # # # # # # # # # # # # # # # #
125#
126# Search each input directory for broken header files.
127# This loop ends near the end of the file.
128#
129if test $# -eq 0
130then
131 INPUTLIST="/usr/include"
132else
133 INPUTLIST="$@"
134fi
135
136for INPUT in ${INPUTLIST} ; do
137
138cd ${ORIGDIR}
139
fa28adb8 140# Make sure a directory exists before changing into it,
141# otherwise Solaris2 will fail-exit the script.
142#
143if [ ! -d ${INPUT} ]; then
144 continue
145fi
146cd ${INPUT}
147
38ebab8a 148INPUT=`${PWDCMD}`
fdb8fb96 149
150#
151# # # # # # # # # # # # # # # # # # # # #
152#
a98784e9 153if test $VERBOSE -gt 1
154then echo Finding directories and links to directories ; fi
fdb8fb96 155
156# Find all directories and all symlinks that point to directories.
38ebab8a 157# Put the list in $all_dirs.
fdb8fb96 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.
38ebab8a 160# Note that $all_dirs may have duplicates in it;
fdb8fb96 161# later parts of this file are supposed to ignore them.
162dirs="."
163levels=2
38ebab8a 164all_dirs=""
165search_dirs=""
166
fdb8fb96 167while [ -n "$dirs" ] && [ $levels -gt 0 ]
168do
38ebab8a 169 levels=`expr $levels - 1`
170 newdirs=
171 for d in $dirs
172 do
a98784e9 173 if test $VERBOSE -gt 1
174 then echo " Searching $INPUT/$d" ; fi
38ebab8a 175
fdb8fb96 176 # Find all directories under $d, relative to $d, excluding $d itself.
177 # (The /. is needed after $d in case $d is a symlink.)
38ebab8a 178 all_dirs="$all_dirs `find $d/. -type d -print | \
fdb8fb96 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
38ebab8a 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"
fdb8fb96 195 if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
196 then
38ebab8a 197 newdirs="$newdirs $d1"
198 search_dirs="$search_dirs $d1"
fdb8fb96 199 fi
38ebab8a 200 fi
fdb8fb96 201 done
38ebab8a 202 done
203
204 dirs="$newdirs"
fdb8fb96 205done
38ebab8a 206
fdb8fb96 207# # # # # # # # # # # # # # # # # # # # #
208#
209dirs=
a98784e9 210if test $VERBOSE -gt 2
211then echo "All directories (including links to directories):"
212 echo $all_dirs
213fi
38ebab8a 214
215for file in $all_dirs; do
fdb8fb96 216 rm -rf $LIB/$file
217 if [ ! -d $LIB/$file ]
218 then mkdir $LIB/$file
219 fi
220done
221mkdir $LIB/root
38ebab8a 222
fdb8fb96 223# # # # # # # # # # # # # # # # # # # # #
224#
225# treetops gets an alternating list
226# of old directories to copy
227# and the new directories to copy to.
38ebab8a 228treetops=". ${LIB}"
229
fdb8fb96 230if $LINKS; then
a98784e9 231 if test $VERBOSE -gt 1
232 then echo 'Making symbolic directory links' ; fi
38ebab8a 233 cwd=`${PWDCMD}`
234
235 for sym_link in $search_dirs; do
236 cd ${INPUT}
237 dest=`ls -ld ${sym_link} | sed -n 's/.*-> //p'`
238
239 # In case $dest is relative, get to ${sym_link}'s dir first.
240 #
241 cd ./`echo ${sym_link} | sed 's;/[^/]*$;;'`
242
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
249
250 # full_dest_dir gets the dir that the link actually leads to.
251 #
252 full_dest_dir=`${PWDCMD}`
253
254 # Canonicalize ${INPUT} now to minimize the time an
255 # automounter has to change the result of ${PWDCMD}.
256 #
257 cinput=`cd ${INPUT}; ${PWDCMD}`
258
259 # If a link points to ., make a similar link to .
260 #
261 if [ ${full_dest_dir} = ${cinput} ]; then
a98784e9 262 if test $VERBOSE -gt 2
263 then echo ${sym_link} '->' . ': Making self link' ; fi
38ebab8a 264 rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
265 ln -s . ${LIB}/${sym_link} > /dev/null 2>&1
266
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@..$@@'`
a98784e9 276 if test $VERBOSE -gt 2
277 then echo ${sym_link} '->' $dots$y ': Making local link' ; fi
38ebab8a 278 rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
279 ln -s $dots$y ${LIB}/${sym_link} > /dev/null 2>&1
280
fdb8fb96 281 else
38ebab8a 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 #
a98784e9 287 if test $VERBOSE -gt 2
288 then echo ${sym_link} '->' root${full_dest_dir} ': Making rooted link'
289 fi
38ebab8a 290 if [ -d $LIB/root${full_dest_dir} ]
fdb8fb96 291 then true
292 else
38ebab8a 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|[^/]*/||'`
fdb8fb96 302 done
38ebab8a 303 fi
304
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"`
a98784e9 313 if test $VERBOSE -gt 2
314 then echo "Duplicating ${sym_link}'s ${dupdir}" ; fi
38ebab8a 315 if [ -d ${dupdir} ]
316 then true
317 else
318 mkdir ${dupdir}
319 fi
320 ;;
321 *)
322 ;;
323 esac
324 done
325
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}@@"`
331
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}"
fdb8fb96 338 fi
fdb8fb96 339 fi
340 done
341fi
38ebab8a 342
fdb8fb96 343# # # # # # # # # # # # # # # # # # # # #
344#
345required=
346set x $treetops
347shift
348while [ $# != 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
38ebab8a 353
354 FIND_BASE=$1
355 export FIND_BASE
fdb8fb96 356 shift
357
358 DESTDIR=`cd $1;${PWDCMD}`
359 export DESTDIR
360 shift
361
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
367
368 touch ${DESTDIR}/DONE
a98784e9 369 if test $VERBOSE -gt 1
370 then echo Fixing directory ${SRCDIR} into ${DESTDIR} ; fi
fdb8fb96 371
38ebab8a 372 # Check files which are symlinks as well as those which are files.
fdb8fb96 373 #
38ebab8a 374 cd ${INPUT}
fdb8fb96 375 required="$required `if $LINKS; then
c1b28c63 376 find ${FIND_BASE}/. -name '*.h' \( -type f -o -type l \) -print
fdb8fb96 377 else
c1b28c63 378 find ${FIND_BASE}/. -name '*.h' -type f -print
38ebab8a 379 fi | \
b4136341 380 sed -e 's;/\./;/;g' -e 's;//*;/;g' | \
38ebab8a 381 ${FIXINCL}`"
fdb8fb96 382done
383
384## Make sure that any include files referenced using double quotes
385## exist in the fixed directory. This comes last since otherwise
386## we might end up deleting some of these files "because they don't
387## need any change."
388set x `echo $required`
389shift
390while [ $# != 0 ]; do
391 newreq=
392 while [ $# != 0 ]; do
393 # $1 is the directory to copy from,
394 # $2 is the unfixed file,
395 # $3 is the fixed file name.
396 #
397 cd ${INPUT}
398 cd $1
6bd06916 399 if [ -f $2 ] ; then
400 if [ -r $2 ] && [ ! -r $3 ]; then
401 cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2
402 chmod +w $3 2>/dev/null
403 chmod a+r $3 2>/dev/null
a98784e9 404 if test $VERBOSE -gt 2
405 then echo Copied $2 ; fi
6bd06916 406 for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 |
fdb8fb96 407 sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'`
6bd06916 408 do
409 dir=`echo $2 | sed -e s'|/[^/]*$||'`
410 dir2=`echo $3 | sed -e s'|/[^/]*$||'`
411 newreq="$newreq $1 $dir/$include $dir2/$include"
412 done
413 fi
fdb8fb96 414 fi
415 shift; shift; shift
416 done
417 set x $newreq
418 shift
419done
420
a98784e9 421if test $VERBOSE -gt 2
422then echo 'Cleaning up DONE files.' ; fi
fdb8fb96 423cd $LIB
424find . -name DONE -exec rm -f '{}' ';'
425
a98784e9 426if test $VERBOSE -gt 1
427then echo 'Cleaning up unneeded directories:' ; fi
fdb8fb96 428cd $LIB
0f5d49d3 429all_dirs=`find . -type d \! -name '.' -print | sort -r`
38ebab8a 430for file in $all_dirs; do
90cca551 431 if rmdir $LIB/$file > /dev/null
432 then
433 test $VERBOSE -gt 3 && echo " removed $file"
434 fi
435done 2> /dev/null
436
437test $VERBOSE -gt 2 && echo "Removing unused symlinks"
438
439all_dirs=`find . -type l -print`
440for file in $all_dirs
441do
442 if ls -lLd $file > /dev/null
443 then :
444 else rm -f $file
445 test $VERBOSE -gt 3 && echo " removed $file"
446 rmdir `dirname $file` > /dev/null && \
447 test $VERBOSE -gt 3 && \
448 echo " removed `dirname $file`"
449 fi
450done 2> /dev/null
fdb8fb96 451
a98784e9 452if test $VERBOSE -gt 0
453then echo fixincludes is done ; fi
454
fdb8fb96 455# # # # # # # # # # # # # # # # # # # # #
456#
457# End of for INPUT directories
458#
459done
460#
461# # # # # # # # # # # # # # # # # # # # #
462
51c6d414 463if [ x${INSTALL_ASSERT_H} != x ] && [ -f ${srcdir}/assert.h ]
464then
465 cd $ORIGDIR
466 rm -f include/assert.h
467 cp ${srcdir}/assert.h include/assert.h || exit 1
468 chmod a+r include/assert.h
469fi