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