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