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