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