1 [= autogen template -*- Mode: sh -*-
8 # DO NOT EDIT THIS FILE - it has been generated
10 # Install modified versions of certain ANSI-incompatible system header
11 # files which are fixed to work correctly with ANSI C and placed in a
12 # directory that GNU C will search.
14 # This script contains [=_eval fix _count =] fixup scripts.
16 # See README-fixinc for more information.
18 # fixincludes copyright (c) [=_eval "date +%Y" _shell
19 =] The Free Software Foundation, Inc.
21 [=_eval fixincludes "## " _gpl=]
23 # # # # # # # # # # # # # # # # # # # # #
25 # Directory in which to store the results.
26 # Fail if no arg to specify a directory for the output.
29 echo fixincludes: no output directory specified
36 # Make sure it exists.
37 if [ ! -d $LIB ]; then
39 echo fixincludes: output dir '`'$LIB"' cannot be created"
43 ( cd $LIB && touch DONE && rm DONE ) || {
44 echo fixincludes: output dir '`'$LIB"' is an invalid directory"
48 [=_IF PROGRAM _env ! =]
49 FIXTESTS=$PWD/fixinc/fixtests
50 FIXFIXES=$PWD/fixinc/fixfixes
55 _IF FIXINC_DEBUG _exist =]3[=_ELSE=]2[=_ENDIF=]
64 # Define what target system we're fixing.
66 if test -r ./Makefile; then
67 target_canonical="`sed -n -e 's,^target[ ]*=[ ]*\(.*\)$,\1,p' < Makefile`"
70 # If not from the Makefile, then try config.guess
72 if test -z "${target_canonical}" ; then
73 if test -x ./config.guess ; then
74 target_canonical="`config.guess`" ; fi
75 test -z "${target_canonical}" && target_canonical=unknown
77 export target_canonical
79 # # # # # # # # # # # # # # # # # # # # #
81 # Define PWDCMD as a command to use to get the working dir
82 # in the form that we want.
87 # On an Apollo, discard everything before `/usr'.
88 PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
95 FIXINCL=${ORIGDIR}/fixincl
99 # Make LIB absolute only if needed to avoid problems with the amd.
104 cd $LIB; LIB=`${PWDCMD}`
108 if test $VERBOSE -gt 0
109 then echo Fixing headers into ${LIB} for ${target_canonical} target ; fi
111 # Determine whether this system has symbolic links.
112 if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
113 rm -f $LIB/ShouldNotExist
115 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
116 rm -f /tmp/ShouldNotExist
122 # # # # # # # # # # # # # # # # # # # # #
124 # Search each input directory for broken header files.
125 # This loop ends near the end of the file.
129 INPUTLIST="/usr/include"
134 for INPUT in ${INPUTLIST} ; do
138 cd ${INPUT} || continue
142 # # # # # # # # # # # # # # # # # # # # #
144 if test $VERBOSE -gt 1
145 then echo Finding directories and links to directories ; fi
147 # Find all directories and all symlinks that point to directories.
148 # Put the list in $all_dirs.
149 # Each time we find a symlink, add it to newdirs
150 # so that we do another find within the dir the link points to.
151 # Note that $all_dirs may have duplicates in it;
152 # later parts of this file are supposed to ignore them.
158 while [ -n "$dirs" ] && [ $levels -gt 0 ]
160 levels=`expr $levels - 1`
164 if test $VERBOSE -gt 1
165 then echo " Searching $INPUT/$d" ; fi
167 # Find all directories under $d, relative to $d, excluding $d itself.
168 # (The /. is needed after $d in case $d is a symlink.)
169 all_dirs="$all_dirs `find $d/. -type d -print | \
170 sed -e '/\/\.$/d' -e 's@/./@/@g'`"
171 # Find all links to directories.
172 # Using `-exec test -d' in find fails on some systems,
173 # and trying to run test via sh fails on others,
174 # so this is the simplest alternative left.
175 # First find all the links, then test each one.
178 theselinks=`find $d/. -type l -print | sed -e 's@/./@/@g'`
179 for d1 in $theselinks --dummy--
181 # If the link points to a directory,
182 # add that dir to $newdirs
185 all_dirs="$all_dirs $d1"
186 if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
188 newdirs="$newdirs $d1"
189 search_dirs="$search_dirs $d1"
198 # # # # # # # # # # # # # # # # # # # # #
201 if test $VERBOSE -gt 2
202 then echo "All directories (including links to directories):"
206 for file in $all_dirs; do
208 if [ ! -d $LIB/$file ]
209 then mkdir $LIB/$file
214 # # # # # # # # # # # # # # # # # # # # #
216 # treetops gets an alternating list
217 # of old directories to copy
218 # and the new directories to copy to.
222 if test $VERBOSE -gt 1
223 then echo 'Making symbolic directory links' ; fi
226 for sym_link in $search_dirs; do
228 dest=`ls -ld ${sym_link} | sed -n 's/.*-> //p'`
230 # In case $dest is relative, get to ${sym_link}'s dir first.
232 cd ./`echo ${sym_link} | sed 's;/[^/]*$;;'`
234 # Check that the target directory exists.
235 # Redirections changed to avoid bug in sh on Ultrix.
237 (cd $dest) > /dev/null 2>&1
241 # full_dest_dir gets the dir that the link actually leads to.
243 full_dest_dir=`${PWDCMD}`
245 # Canonicalize ${INPUT} now to minimize the time an
246 # automounter has to change the result of ${PWDCMD}.
248 cinput=`cd ${INPUT}; ${PWDCMD}`
250 # If a link points to ., make a similar link to .
252 if [ ${full_dest_dir} = ${cinput} ]; then
253 if test $VERBOSE -gt 2
254 then echo ${sym_link} '->' . ': Making self link' ; fi
255 rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
256 ln -s . ${LIB}/${sym_link} > /dev/null 2>&1
258 # If link leads back into ${INPUT},
259 # make a similar link here.
261 elif expr ${full_dest_dir} : "${cinput}/.*" > /dev/null; then
262 # Y gets the actual target dir name, relative to ${INPUT}.
263 y=`echo ${full_dest_dir} | sed -n "s&${cinput}/&&p"`
264 # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.
265 dots=`echo "${sym_link}" |
266 sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
267 if test $VERBOSE -gt 2
268 then echo ${sym_link} '->' $dots$y ': Making local link' ; fi
269 rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
270 ln -s $dots$y ${LIB}/${sym_link} > /dev/null 2>&1
273 # If the link is to a dir $target outside ${INPUT},
274 # repoint the link at ${INPUT}/root$target
275 # and process $target into ${INPUT}/root$target
276 # treat this directory as if it actually contained the files.
278 if test $VERBOSE -gt 2
279 then echo ${sym_link} '->' root${full_dest_dir} ': Making rooted link'
281 if [ -d $LIB/root${full_dest_dir} ]
284 dirname=root${full_dest_dir}/
287 while [ x$dirname != x ]; do
288 component=`echo $dirname | sed -e 's|/.*$||'`
289 mkdir $component >/dev/null 2>&1
291 dirmade=$dirmade/$component
292 dirname=`echo $dirname | sed -e 's|[^/]*/||'`
296 # Duplicate directory structure created in ${LIB}/${sym_link} in new
299 for file2 in $all_dirs; do
302 dupdir=${LIB}/root${full_dest_dir}/`echo $file2 |
303 sed -n "s|^${sym_link}/||p"`
304 if test $VERBOSE -gt 2
305 then echo "Duplicating ${sym_link}'s ${dupdir}" ; fi
317 # Get the path from ${LIB} to ${sym_link}, accounting for symlinks.
319 parent=`echo "${sym_link}" | sed -e 's@/[^/]*$@@'`
320 libabs=`cd ${LIB}; ${PWDCMD}`
321 file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"`
323 # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.
325 dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'`
326 rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
327 ln -s ${dots}root${full_dest_dir} ${LIB}/${sym_link} > /dev/null 2>&1
328 treetops="$treetops ${sym_link} ${LIB}/root${full_dest_dir}"
334 # # # # # # # # # # # # # # # # # # # # #
339 while [ $# != 0 ]; do
340 # $1 is an old directory to copy, and $2 is the new directory to copy to.
342 SRCDIR=`cd ${INPUT} ; cd $1 ; ${PWDCMD}`
349 DESTDIR=`cd $1;${PWDCMD}`
353 # The same dir can appear more than once in treetops.
354 # There's no need to scan it more than once.
356 if [ -f ${DESTDIR}/DONE ]
359 touch ${DESTDIR}/DONE
360 if test $VERBOSE -gt 1
361 then echo Fixing directory ${SRCDIR} into ${DESTDIR} ; fi
363 # Check files which are symlinks as well as those which are files.
366 _IF PROGRAM _env ! =]
367 files=`if $LINKS; then
368 find ${FIND_BASE}/. -name '*.h' \( -type f -o -type l \) -print
370 find ${FIND_BASE}/. -name '*.h' -type f -print
372 sed -e 's;/\./;/;g' -e 's;//*;/;g' `
375 _include hackshell =][=
380 required="$required `if $LINKS; then
381 find ${FIND_BASE}/. -name '*.h' \( -type f -o -type l \) -print
383 find ${FIND_BASE}/. -name '*.h' -type f -print
385 sed -e 's;/\./;/;g' -e 's;//*;/;g' | \
392 ## Make sure that any include files referenced using double quotes
393 ## exist in the fixed directory. This comes last since otherwise
394 ## we might end up deleting some of these files "because they don't
396 set x `echo $required`
398 while [ $# != 0 ]; do
400 while [ $# != 0 ]; do
401 # $1 is the directory to copy from,
402 # $2 is the unfixed file,
403 # $3 is the fixed file name.
408 if [ -r $2 ] && [ ! -r $3 ]; then
409 cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2
410 chmod +w $3 2>/dev/null
411 chmod a+r $3 2>/dev/null
412 if test $VERBOSE -gt 2
413 then echo Copied $2 ; fi
414 for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 |
415 sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'`
417 dir=`echo $2 | sed -e s'|/[^/]*$||'`
418 dir2=`echo $3 | sed -e s'|/[^/]*$||'`
419 newreq="$newreq $1 $dir/$include $dir2/$include"
429 if test $VERBOSE -gt 2
430 then echo 'Cleaning up DONE files.' ; fi
432 find . -name DONE -exec rm -f '{}' ';'
434 if test $VERBOSE -gt 1
435 then echo 'Cleaning up unneeded directories:' ; fi
437 all_dirs=`find . -type d \! -name '.' -print | sort -r`
438 for file in $all_dirs; do
439 rmdir $LIB/$file > /dev/null 2>&1
442 if test $VERBOSE -gt 0
443 then echo fixincludes is done ; fi
445 # # # # # # # # # # # # # # # # # # # # #
447 # End of for INPUT directories
451 # # # # # # # # # # # # # # # # # # # # #
453 if [ x${INSTALL_ASSERT_H} != x ] && [ -f ${srcdir}/assert.h ]
456 rm -f include/assert.h
457 cp ${srcdir}/assert.h include/assert.h || exit 1
458 chmod a+r include/assert.h
461 # Make the output file executable
463 _eval _outfile "chmod +x %s" _printf _shell=]