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