3 # EDIT THIS FILE - it is no longer generated
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.
9 # See README-fixinc for more information.
11 # fixincludes copyright (c) 1998, 1999, 2000
12 # The Free Software Foundation, Inc.
14 # fixincludes is free software.
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.
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.
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.
31 # # # # # # # # # # # # # # # # # # # # #
33 # Directory in which to store the results.
34 # Fail if no arg to specify a directory for the output.
37 echo fixincludes: no output directory specified
44 # Make sure it exists.
45 if [ ! -d $LIB ]; then
47 echo fixincludes: output dir '`'$LIB"' cannot be created"
51 ( cd $LIB && touch DONE && rm DONE ) || {
52 echo fixincludes: output dir '`'$LIB"' is an invalid directory"
68 # Define what target system we're fixing.
70 if test -r ./Makefile; then
71 target_canonical="`sed -n -e 's,^target[ ]*=[ ]*\(.*\)$,\1,p' < Makefile`"
74 # If not from the Makefile, then try config.guess
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
81 export target_canonical
83 # # # # # # # # # # # # # # # # # # # # #
85 # Define PWDCMD as a command to use to get the working dir
86 # in the form that we want.
91 # On an Apollo, discard everything before `/usr'.
92 PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
99 FIXINCL=${ORIGDIR}/fixinc/fixincl
102 # Make LIB absolute only if needed to avoid problems with the amd.
107 cd $LIB; LIB=`${PWDCMD}`
111 if test $VERBOSE -gt 0
112 then echo Fixing headers into ${LIB} for ${target_canonical} target ; fi
114 # Determine whether this system has symbolic links.
115 if test -n "$DJDIR"; then
117 elif ln -s X $LIB/ShouldNotExist 2>/dev/null; then
118 rm -f $LIB/ShouldNotExist
120 elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
121 rm -f /tmp/ShouldNotExist
127 # # # # # # # # # # # # # # # # # # # # #
129 # Search each input directory for broken header files.
130 # This loop ends near the end of the file.
134 INPUTLIST="/usr/include"
139 for INPUT in ${INPUTLIST} ; do
143 # Make sure a directory exists before changing into it,
144 # otherwise Solaris2 will fail-exit the script.
146 if [ ! -d ${INPUT} ]; then
155 # # # # # # # # # # # # # # # # # # # # #
157 if test $VERBOSE -gt 1
158 then echo Finding directories and links to directories ; fi
160 # Find all directories and all symlinks that point to directories.
161 # Put the list in $all_dirs.
162 # Each time we find a symlink, add it to newdirs
163 # so that we do another find within the dir the link points to.
164 # Note that $all_dirs may have duplicates in it;
165 # later parts of this file are supposed to ignore them.
171 while [ -n "$dirs" ] && [ $levels -gt 0 ]
173 levels=`expr $levels - 1`
177 if test $VERBOSE -gt 1
178 then echo " Searching $INPUT/$d" ; fi
180 # Find all directories under $d, relative to $d, excluding $d itself.
181 # (The /. is needed after $d in case $d is a symlink.)
182 all_dirs="$all_dirs `find $d/. -type d -print | \
183 sed -e '/\/\.$/d' -e 's@/./@/@g'`"
184 # Find all links to directories.
185 # Using `-exec test -d' in find fails on some systems,
186 # and trying to run test via sh fails on others,
187 # so this is the simplest alternative left.
188 # First find all the links, then test each one.
191 theselinks=`find $d/. -type l -print | sed -e 's@/./@/@g'`
192 for d1 in $theselinks --dummy--
194 # If the link points to a directory,
195 # add that dir to $newdirs
198 all_dirs="$all_dirs $d1"
199 if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
201 newdirs="$newdirs $d1"
202 search_dirs="$search_dirs $d1"
211 # # # # # # # # # # # # # # # # # # # # #
214 if test $VERBOSE -gt 2
215 then echo "All directories (including links to directories):"
219 for file in $all_dirs; do
221 if [ ! -d $LIB/$file ]
222 then mkdir $LIB/$file
227 # # # # # # # # # # # # # # # # # # # # #
229 # treetops gets an alternating list
230 # of old directories to copy
231 # and the new directories to copy to.
235 if test $VERBOSE -gt 1
236 then echo 'Making symbolic directory links' ; fi
239 for sym_link in $search_dirs; do
241 dest=`ls -ld ${sym_link} | sed -n 's/.*-> //p'`
243 # In case $dest is relative, get to ${sym_link}'s dir first.
245 cd ./`echo ${sym_link} | sed 's;/[^/]*$;;'`
247 # Check that the target directory exists.
248 # Redirections changed to avoid bug in sh on Ultrix.
250 (cd $dest) > /dev/null 2>&1
254 # full_dest_dir gets the dir that the link actually leads to.
256 full_dest_dir=`${PWDCMD}`
258 # Canonicalize ${INPUT} now to minimize the time an
259 # automounter has to change the result of ${PWDCMD}.
261 cinput=`cd ${INPUT}; ${PWDCMD}`
263 # If a link points to ., make a similar link to .
265 if [ ${full_dest_dir} = ${cinput} ]; then
266 if test $VERBOSE -gt 2
267 then echo ${sym_link} '->' . ': Making self link' ; fi
268 rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
269 ln -s . ${LIB}/${sym_link} > /dev/null 2>&1
271 # If link leads back into ${INPUT},
272 # make a similar link here.
274 elif expr ${full_dest_dir} : "${cinput}/.*" > /dev/null; then
275 # Y gets the actual target dir name, relative to ${INPUT}.
276 y=`echo ${full_dest_dir} | sed -n "s&${cinput}/&&p"`
277 # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.
278 dots=`echo "${sym_link}" |
279 sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
280 if test $VERBOSE -gt 2
281 then echo ${sym_link} '->' $dots$y ': Making local link' ; fi
282 rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
283 ln -s $dots$y ${LIB}/${sym_link} > /dev/null 2>&1
286 # If the link is to a dir $target outside ${INPUT},
287 # repoint the link at ${INPUT}/root$target
288 # and process $target into ${INPUT}/root$target
289 # treat this directory as if it actually contained the files.
291 if test $VERBOSE -gt 2
292 then echo ${sym_link} '->' root${full_dest_dir} ': Making rooted link'
294 if [ -d $LIB/root${full_dest_dir} ]
297 dirname=root${full_dest_dir}/
300 while [ x$dirname != x ]; do
301 component=`echo $dirname | sed -e 's|/.*$||'`
302 mkdir $component >/dev/null 2>&1
304 dirmade=$dirmade/$component
305 dirname=`echo $dirname | sed -e 's|[^/]*/||'`
309 # Duplicate directory structure created in ${LIB}/${sym_link} in new
312 for file2 in $all_dirs; do
315 dupdir=${LIB}/root${full_dest_dir}/`echo $file2 |
316 sed -n "s|^${sym_link}/||p"`
317 if test $VERBOSE -gt 2
318 then echo "Duplicating ${sym_link}'s ${dupdir}" ; fi
330 # Get the path from ${LIB} to ${sym_link}, accounting for symlinks.
332 parent=`echo "${sym_link}" | sed -e 's@/[^/]*$@@'`
333 libabs=`cd ${LIB}; ${PWDCMD}`
334 file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"`
336 # DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.
338 dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'`
339 rm -fr ${LIB}/${sym_link} > /dev/null 2>&1
340 ln -s ${dots}root${full_dest_dir} ${LIB}/${sym_link} > /dev/null 2>&1
341 treetops="$treetops ${sym_link} ${LIB}/root${full_dest_dir}"
347 # # # # # # # # # # # # # # # # # # # # #
352 while [ $# != 0 ]; do
353 # $1 is an old directory to copy, and $2 is the new directory to copy to.
355 SRCDIR=`cd ${INPUT} ; cd $1 ; ${PWDCMD}`
362 DESTDIR=`cd $1;${PWDCMD}`
366 # The same dir can appear more than once in treetops.
367 # There's no need to scan it more than once.
369 if [ -f ${DESTDIR}/DONE ]
372 touch ${DESTDIR}/DONE
373 if test $VERBOSE -gt 1
374 then echo Fixing directory ${SRCDIR} into ${DESTDIR} ; fi
376 # Check files which are symlinks as well as those which are files.
379 required="$required `if $LINKS; then
380 find ${FIND_BASE}/. -name '*.h' \( -type f -o -type l \) -print
382 find ${FIND_BASE}/. -name '*.h' -type f -print
384 sed -e 's;/\./;/;g' -e 's;//*;/;g' | \
388 ## Make sure that any include files referenced using double quotes
389 ## exist in the fixed directory. This comes last since otherwise
390 ## we might end up deleting some of these files "because they don't
392 set x `echo $required`
394 while [ $# != 0 ]; do
396 while [ $# != 0 ]; do
397 # $1 is the directory to copy from,
398 # $2 is the unfixed file,
399 # $3 is the fixed file name.
404 if [ -r $2 ] && [ ! -r $3 ]; then
405 cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2
406 chmod +w $3 2>/dev/null
407 chmod a+r $3 2>/dev/null
408 if test $VERBOSE -gt 2
409 then echo Copied $2 ; fi
410 for include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 |
411 sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'`
413 dir=`echo $2 | sed -e s'|/[^/]*$||'`
414 dir2=`echo $3 | sed -e s'|/[^/]*$||'`
415 newreq="$newreq $1 $dir/$include $dir2/$include"
425 if test $VERBOSE -gt 2
426 then echo 'Cleaning up DONE files.' ; fi
428 # Look for files case-insensitively, for the benefit of
429 # DOS/Windows filesystems.
430 find . -name '[Dd][Oo][Nn][Ee]' -exec rm -f '{}' ';'
432 if test $VERBOSE -gt 1
433 then echo 'Cleaning up unneeded directories:' ; fi
435 all_dirs=`find . -type d \! -name '.' -print | sort -r`
436 for file in $all_dirs; do
437 if rmdir $LIB/$file > /dev/null
439 test $VERBOSE -gt 3 && echo " removed $file"
443 # On systems which don't support symlinks, `find' may barf
444 # if called with "-type l" predicate. So only use that if
445 # we know we should look for symlinks.
447 test $VERBOSE -gt 2 && echo "Removing unused symlinks"
449 all_dirs=`find . -type l -print`
450 for file in $all_dirs
452 if ls -lLd $file > /dev/null
455 test $VERBOSE -gt 3 && echo " removed $file"
456 rmdir `dirname $file` > /dev/null && \
457 test $VERBOSE -gt 3 && \
458 echo " removed `dirname $file`"
463 if test $VERBOSE -gt 0
464 then echo fixincludes is done ; fi
466 # # # # # # # # # # # # # # # # # # # # #
468 # End of for INPUT directories
472 # # # # # # # # # # # # # # # # # # # # #
474 if [ x${INSTALL_ASSERT_H} != x ] && [ -f ${srcdir}/assert.h ]
477 rm -f include/assert.h
478 cp ${srcdir}/assert.h include/assert.h || exit 1
479 chmod a+r include/assert.h