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