]>
Commit | Line | Data |
---|---|---|
fdb8fb96 | 1 | #!/bin/sh |
2 | # | |
3 | # DO NOT EDIT THIS FILE (fixincl.sh) | |
4 | # | |
b4136341 | 5 | # It has been autogen-ed Saturday April 3, 1999 at 05:12:04 PM EST |
6cf8dd2f | 6 | # From the definitions inclhack.def |
7 | # and the template file inclhack.tpl | |
fdb8fb96 | 8 | # |
9 | # Install modified versions of certain ANSI-incompatible system header | |
10 | # files which are fixed to work correctly with ANSI C and placed in a | |
11 | # directory that GNU C will search. | |
12 | # | |
38ebab8a | 13 | # This script contains 103 fixup scripts. |
fdb8fb96 | 14 | # |
15 | # See README-fixinc for more information. | |
16 | # | |
17 | # fixincludes is free software. | |
18 | # | |
19 | # You may redistribute it and/or modify it under the terms of the | |
20 | # GNU General Public License, as published by the Free Software | |
21 | # Foundation; either version 2, or (at your option) any later version. | |
22 | # | |
23 | # fixincludes is distributed in the hope that it will be useful, | |
24 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
26 | # See the GNU General Public License for more details. | |
27 | # | |
28 | # You should have received a copy of the GNU General Public License | |
29 | # along with fixincludes. See the file "COPYING". If not, | |
30 | # write to: The Free Software Foundation, Inc., | |
31 | # 59 Temple Place - Suite 330, | |
32 | # Boston, MA 02111-1307, USA. | |
33 | # | |
34 | # # # # # # # # # # # # # # # # # # # # # | |
35 | # | |
36 | # Directory in which to store the results. | |
37 | # Fail if no arg to specify a directory for the output. | |
38 | if [ "x$1" = "x" ] | |
39 | then echo fixincludes: no output directory specified | |
40 | exit 1 | |
41 | fi | |
42 | ||
43 | LIB=${1} | |
44 | shift | |
45 | ||
46 | # Make sure it exists. | |
47 | if [ ! -d $LIB ]; then | |
48 | mkdir $LIB || { | |
49 | echo fixincludes: output dir '`'$LIB"' cannot be created" | |
50 | exit 1 | |
51 | } | |
52 | else | |
53 | ( \cd $LIB && touch DONE && rm DONE ) || { | |
54 | echo fixincludes: output dir '`'$LIB"' is an invalid directory" | |
55 | exit 1 | |
56 | } | |
57 | fi | |
58 | ||
59 | # Define what target system we're fixing. | |
60 | # | |
61 | if test -r ./Makefile; then | |
62 | target_canonical="`sed -n -e 's,^target[ ]*=[ ]*\(.*\)$,\1,p' < Makefile`" | |
63 | fi | |
64 | ||
65 | # If not from the Makefile, then try config.guess | |
66 | # | |
67 | if test -z "${target_canonical}" ; then | |
68 | if test -x ./config.guess ; then | |
69 | target_canonical="`config.guess`" ; fi | |
70 | test -z "${target_canonical}" && target_canonical=unknown | |
71 | fi | |
72 | export target_canonical | |
73 | ||
74 | # # # # # # # # # # # # # # # # # # # # # | |
75 | # | |
76 | # Define PWDCMD as a command to use to get the working dir | |
77 | # in the form that we want. | |
78 | PWDCMD=pwd | |
79 | ||
80 | case "`$PWDCMD`" in | |
81 | //*) | |
82 | # On an Apollo, discard everything before `/usr'. | |
83 | PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'" | |
84 | ;; | |
85 | esac | |
86 | ||
87 | # Original directory. | |
88 | ORIGDIR=`${PWDCMD}` | |
89 | FIXINCL=${ORIGDIR}/fixincl | |
90 | export FIXINCL | |
91 | ||
92 | # Make LIB absolute only if needed to avoid problems with the amd. | |
93 | case $LIB in | |
94 | /*) | |
95 | ;; | |
96 | *) | |
97 | cd $LIB; LIB=`${PWDCMD}` | |
98 | ;; | |
99 | esac | |
100 | ||
101 | echo Fixing headers into ${LIB} for ${target_canonical} target | |
38ebab8a | 102 | |
fdb8fb96 | 103 | # Determine whether this system has symbolic links. |
104 | if ln -s X $LIB/ShouldNotExist 2>/dev/null; then | |
105 | rm -f $LIB/ShouldNotExist | |
106 | LINKS=true | |
107 | elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then | |
108 | rm -f /tmp/ShouldNotExist | |
109 | LINKS=true | |
110 | else | |
111 | LINKS=false | |
112 | fi | |
38ebab8a | 113 | |
fdb8fb96 | 114 | # # # # # # # # # # # # # # # # # # # # # |
115 | # | |
116 | # Search each input directory for broken header files. | |
117 | # This loop ends near the end of the file. | |
118 | # | |
119 | if test $# -eq 0 | |
120 | then | |
121 | INPUTLIST="/usr/include" | |
122 | else | |
123 | INPUTLIST="$@" | |
124 | fi | |
125 | ||
126 | for INPUT in ${INPUTLIST} ; do | |
127 | ||
128 | cd ${ORIGDIR} | |
129 | ||
6bd06916 | 130 | cd ${INPUT} || continue |
38ebab8a | 131 | INPUT=`${PWDCMD}` |
fdb8fb96 | 132 | |
133 | # | |
134 | # # # # # # # # # # # # # # # # # # # # # | |
135 | # | |
136 | echo Finding directories and links to directories | |
137 | ||
138 | # Find all directories and all symlinks that point to directories. | |
38ebab8a | 139 | # Put the list in $all_dirs. |
fdb8fb96 | 140 | # Each time we find a symlink, add it to newdirs |
141 | # so that we do another find within the dir the link points to. | |
38ebab8a | 142 | # Note that $all_dirs may have duplicates in it; |
fdb8fb96 | 143 | # later parts of this file are supposed to ignore them. |
144 | dirs="." | |
145 | levels=2 | |
38ebab8a | 146 | all_dirs="" |
147 | search_dirs="" | |
148 | ||
fdb8fb96 | 149 | while [ -n "$dirs" ] && [ $levels -gt 0 ] |
150 | do | |
38ebab8a | 151 | levels=`expr $levels - 1` |
152 | newdirs= | |
153 | for d in $dirs | |
154 | do | |
fdb8fb96 | 155 | echo " Searching $INPUT/$d" |
38ebab8a | 156 | |
fdb8fb96 | 157 | # Find all directories under $d, relative to $d, excluding $d itself. |
158 | # (The /. is needed after $d in case $d is a symlink.) | |
38ebab8a | 159 | all_dirs="$all_dirs `find $d/. -type d -print | \ |
fdb8fb96 | 160 | sed -e '/\/\.$/d' -e 's@/./@/@g'`" |
161 | # Find all links to directories. | |
162 | # Using `-exec test -d' in find fails on some systems, | |
163 | # and trying to run test via sh fails on others, | |
164 | # so this is the simplest alternative left. | |
165 | # First find all the links, then test each one. | |
166 | theselinks= | |
167 | $LINKS && \ | |
168 | theselinks=`find $d/. -type l -print | sed -e 's@/./@/@g'` | |
169 | for d1 in $theselinks --dummy-- | |
170 | do | |
38ebab8a | 171 | # If the link points to a directory, |
172 | # add that dir to $newdirs | |
173 | if [ -d $d1 ] | |
174 | then | |
175 | all_dirs="$all_dirs $d1" | |
fdb8fb96 | 176 | if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ] |
177 | then | |
38ebab8a | 178 | newdirs="$newdirs $d1" |
179 | search_dirs="$search_dirs $d1" | |
fdb8fb96 | 180 | fi |
38ebab8a | 181 | fi |
fdb8fb96 | 182 | done |
38ebab8a | 183 | done |
184 | ||
185 | dirs="$newdirs" | |
fdb8fb96 | 186 | done |
38ebab8a | 187 | |
fdb8fb96 | 188 | # # # # # # # # # # # # # # # # # # # # # |
189 | # | |
190 | dirs= | |
191 | echo "All directories (including links to directories):" | |
38ebab8a | 192 | echo $all_dirs |
193 | ||
194 | for file in $all_dirs; do | |
fdb8fb96 | 195 | rm -rf $LIB/$file |
196 | if [ ! -d $LIB/$file ] | |
197 | then mkdir $LIB/$file | |
198 | fi | |
199 | done | |
200 | mkdir $LIB/root | |
38ebab8a | 201 | |
fdb8fb96 | 202 | # # # # # # # # # # # # # # # # # # # # # |
203 | # | |
204 | # treetops gets an alternating list | |
205 | # of old directories to copy | |
206 | # and the new directories to copy to. | |
38ebab8a | 207 | treetops=". ${LIB}" |
208 | ||
fdb8fb96 | 209 | if $LINKS; then |
210 | echo 'Making symbolic directory links' | |
38ebab8a | 211 | cwd=`${PWDCMD}` |
212 | ||
213 | for sym_link in $search_dirs; do | |
214 | cd ${INPUT} | |
215 | dest=`ls -ld ${sym_link} | sed -n 's/.*-> //p'` | |
216 | ||
217 | # In case $dest is relative, get to ${sym_link}'s dir first. | |
218 | # | |
219 | cd ./`echo ${sym_link} | sed 's;/[^/]*$;;'` | |
220 | ||
221 | # Check that the target directory exists. | |
222 | # Redirections changed to avoid bug in sh on Ultrix. | |
223 | # | |
224 | (cd $dest) > /dev/null 2>&1 | |
225 | if [ $? = 0 ]; then | |
226 | cd $dest | |
227 | ||
228 | # full_dest_dir gets the dir that the link actually leads to. | |
229 | # | |
230 | full_dest_dir=`${PWDCMD}` | |
231 | ||
232 | # Canonicalize ${INPUT} now to minimize the time an | |
233 | # automounter has to change the result of ${PWDCMD}. | |
234 | # | |
235 | cinput=`cd ${INPUT}; ${PWDCMD}` | |
236 | ||
237 | # If a link points to ., make a similar link to . | |
238 | # | |
239 | if [ ${full_dest_dir} = ${cinput} ]; then | |
240 | echo ${sym_link} '->' . ': Making self link' | |
241 | rm -fr ${LIB}/${sym_link} > /dev/null 2>&1 | |
242 | ln -s . ${LIB}/${sym_link} > /dev/null 2>&1 | |
243 | ||
244 | # If link leads back into ${INPUT}, | |
245 | # make a similar link here. | |
246 | # | |
247 | elif expr ${full_dest_dir} : "${cinput}/.*" > /dev/null; then | |
248 | # Y gets the actual target dir name, relative to ${INPUT}. | |
249 | y=`echo ${full_dest_dir} | sed -n "s&${cinput}/&&p"` | |
250 | # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}. | |
251 | dots=`echo "${sym_link}" | | |
252 | sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'` | |
253 | echo ${sym_link} '->' $dots$y ': Making local link' | |
254 | rm -fr ${LIB}/${sym_link} > /dev/null 2>&1 | |
255 | ln -s $dots$y ${LIB}/${sym_link} > /dev/null 2>&1 | |
256 | ||
fdb8fb96 | 257 | else |
38ebab8a | 258 | # If the link is to a dir $target outside ${INPUT}, |
259 | # repoint the link at ${INPUT}/root$target | |
260 | # and process $target into ${INPUT}/root$target | |
261 | # treat this directory as if it actually contained the files. | |
262 | # | |
263 | echo ${sym_link} '->' root${full_dest_dir} ': Making rooted link' | |
264 | if [ -d $LIB/root${full_dest_dir} ] | |
fdb8fb96 | 265 | then true |
266 | else | |
38ebab8a | 267 | dirname=root${full_dest_dir}/ |
268 | dirmade=. | |
269 | cd $LIB | |
270 | while [ x$dirname != x ]; do | |
271 | component=`echo $dirname | sed -e 's|/.*$||'` | |
272 | mkdir $component >/dev/null 2>&1 | |
273 | cd $component | |
274 | dirmade=$dirmade/$component | |
275 | dirname=`echo $dirname | sed -e 's|[^/]*/||'` | |
fdb8fb96 | 276 | done |
38ebab8a | 277 | fi |
278 | ||
279 | # Duplicate directory structure created in ${LIB}/${sym_link} in new | |
280 | # root area. | |
281 | # | |
282 | for file2 in $all_dirs; do | |
283 | case $file2 in | |
284 | ${sym_link}/*) | |
285 | dupdir=${LIB}/root${full_dest_dir}/`echo $file2 | | |
286 | sed -n "s|^${sym_link}/||p"` | |
287 | echo "Duplicating ${sym_link}'s ${dupdir}" | |
288 | if [ -d ${dupdir} ] | |
289 | then true | |
290 | else | |
291 | mkdir ${dupdir} | |
292 | fi | |
293 | ;; | |
294 | *) | |
295 | ;; | |
296 | esac | |
297 | done | |
298 | ||
299 | # Get the path from ${LIB} to ${sym_link}, accounting for symlinks. | |
300 | # | |
301 | parent=`echo "${sym_link}" | sed -e 's@/[^/]*$@@'` | |
302 | libabs=`cd ${LIB}; ${PWDCMD}` | |
303 | file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"` | |
304 | ||
305 | # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}. | |
306 | # | |
307 | dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'` | |
308 | rm -fr ${LIB}/${sym_link} > /dev/null 2>&1 | |
309 | ln -s ${dots}root${full_dest_dir} ${LIB}/${sym_link} > /dev/null 2>&1 | |
310 | treetops="$treetops ${sym_link} ${LIB}/root${full_dest_dir}" | |
fdb8fb96 | 311 | fi |
fdb8fb96 | 312 | fi |
313 | done | |
314 | fi | |
38ebab8a | 315 | |
fdb8fb96 | 316 | # # # # # # # # # # # # # # # # # # # # # |
317 | # | |
318 | required= | |
319 | set x $treetops | |
320 | shift | |
321 | while [ $# != 0 ]; do | |
322 | # $1 is an old directory to copy, and $2 is the new directory to copy to. | |
323 | # | |
324 | SRCDIR=`cd ${INPUT} ; cd $1 ; ${PWDCMD}` | |
325 | export SRCDIR | |
38ebab8a | 326 | |
327 | FIND_BASE=$1 | |
328 | export FIND_BASE | |
fdb8fb96 | 329 | shift |
330 | ||
331 | DESTDIR=`cd $1;${PWDCMD}` | |
332 | export DESTDIR | |
333 | shift | |
334 | ||
335 | # The same dir can appear more than once in treetops. | |
336 | # There's no need to scan it more than once. | |
337 | # | |
338 | if [ -f ${DESTDIR}/DONE ] | |
339 | then continue ; fi | |
340 | ||
341 | touch ${DESTDIR}/DONE | |
342 | echo Fixing directory ${SRCDIR} into ${DESTDIR} | |
343 | ||
38ebab8a | 344 | # Check files which are symlinks as well as those which are files. |
fdb8fb96 | 345 | # |
38ebab8a | 346 | cd ${INPUT} |
fdb8fb96 | 347 | required="$required `if $LINKS; then |
38ebab8a | 348 | find ${FIND_BASE}/. \( -type f -o -type l \) -print |
fdb8fb96 | 349 | else |
38ebab8a | 350 | find ${FIND_BASE}/. -type f -print |
351 | fi | \ | |
b4136341 | 352 | sed -e 's;/\./;/;g' -e 's;//*;/;g' | \ |
38ebab8a | 353 | ${FIXINCL}`" |
fdb8fb96 | 354 | done |
355 | ||
356 | ## Make sure that any include files referenced using double quotes | |
357 | ## exist in the fixed directory. This comes last since otherwise | |
358 | ## we might end up deleting some of these files "because they don't | |
359 | ## need any change." | |
360 | set x `echo $required` | |
361 | shift | |
362 | while [ $# != 0 ]; do | |
363 | newreq= | |
364 | while [ $# != 0 ]; do | |
365 | # $1 is the directory to copy from, | |
366 | # $2 is the unfixed file, | |
367 | # $3 is the fixed file name. | |
368 | # | |
369 | cd ${INPUT} | |
370 | cd $1 | |
6bd06916 | 371 | if [ -f $2 ] ; then |
372 | if [ -r $2 ] && [ ! -r $3 ]; then | |
373 | cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2 | |
374 | chmod +w $3 2>/dev/null | |
375 | chmod a+r $3 2>/dev/null | |
376 | echo Copied $2 | |
377 | for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 | | |
fdb8fb96 | 378 | sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'` |
6bd06916 | 379 | do |
380 | dir=`echo $2 | sed -e s'|/[^/]*$||'` | |
381 | dir2=`echo $3 | sed -e s'|/[^/]*$||'` | |
382 | newreq="$newreq $1 $dir/$include $dir2/$include" | |
383 | done | |
384 | fi | |
fdb8fb96 | 385 | fi |
386 | shift; shift; shift | |
387 | done | |
388 | set x $newreq | |
389 | shift | |
390 | done | |
391 | ||
392 | echo 'Cleaning up DONE files.' | |
393 | cd $LIB | |
394 | find . -name DONE -exec rm -f '{}' ';' | |
395 | ||
396 | echo 'Removing unneeded directories:' | |
397 | cd $LIB | |
38ebab8a | 398 | all_dirs=`find . -type d -print | sort -r` |
399 | for file in $all_dirs; do | |
fdb8fb96 | 400 | rmdir $LIB/$file > /dev/null 2>&1 | : |
401 | done | |
402 | ||
403 | # # # # # # # # # # # # # # # # # # # # # | |
404 | # | |
405 | # End of for INPUT directories | |
406 | # | |
407 | done | |
408 | # | |
409 | # # # # # # # # # # # # # # # # # # # # # | |
410 | ||
411 | cd $ORIGDIR | |
412 | rm -f include/assert.h | |
6bd06916 | 413 | cp ${srcdir}/assert.h include/assert.h || exit 1 |
fdb8fb96 | 414 | chmod a+r include/assert.h |
415 |