URL
https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk
Subversion Repositories openrisc_me
[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [fixincludes/] [fixinc.in] - Rev 478
Go to most recent revision | Compare with Previous | Blame | View Log
#!/bin/sh## Install modified versions of certain ANSI-incompatible system header# files which are fixed to work correctly with ANSI C and placed in a# directory that GCC will search.## See README-fixinc for more information.## fixincludes copyright (c) 1998, 1999, 2000, 2002, 2009# The Free Software Foundation, Inc.## fixincludes is free software.## You may redistribute it and/or modify it under the terms of the# GNU General Public License, as published by the Free Software# Foundation; either version 3, or (at your option) any later version.## fixincludes is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.# See the GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with fixincludes; see the file COPYING3. If not see# <http://www.gnu.org/licenses/>.## # # # # # # # # # # # # # # # # # # # ## Usage: fixinc.sh output-dir input-dir## Directory in which to store the results.# Fail if no arg to specify a directory for the output.if [ "x$1" = "x" ]thenecho fixincludes: no output directory specifiedexit 1fiLIB=${1}shift# Make sure it exists.if [ ! -d $LIB ]; thenmkdir $LIB || {echo fixincludes: output dir '`'$LIB"' cannot be created"exit 1}else( cd $LIB && touch DONE && rm DONE ) || {echo fixincludes: output dir '`'$LIB"' is an invalid directory"exit 1}fiif test -z "$VERBOSE"thenVERBOSE=2export VERBOSEelsecase "$VERBOSE" in[0-9] ) : ;;* ) VERBOSE=3 ;;esacfi# Define what target system we're fixing.#if test -r ./Makefile; thentarget_canonical="`sed -n -e 's,^target[ ]*=[ ]*\(.*\)$,\1,p' < Makefile`"fi# If not from the Makefile, then try config.guess#if test -z "${target_canonical}" ; thenif test -x ./config.guess ; thentarget_canonical="`config.guess`" ; fitest -z "${target_canonical}" && target_canonical=unknownfiexport target_canonical# # # # # # # # # # # # # # # # # # # # ### Define PWDCMD as a command to use to get the working dir# in the form that we want.PWDCMD=${PWDCMD-pwd}case "`$PWDCMD`" in//*)# On an Apollo, discard everything before `/usr'.PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'";;esac# Original directory.ORIGDIR=`${PWDCMD}`export ORIGDIRFIXINCL=`${PWDCMD}`/fixinclif [ ! -x $FIXINCL ] ; thenecho "Cannot find fixincl" >&2exit 1fiexport FIXINCL# Make LIB absolute only if needed to avoid problems with the amd.case $LIB in/*);;*)cd $LIB; LIB=`${PWDCMD}`;;esacif test $VERBOSE -gt 0then echo Fixing headers into ${LIB} for ${target_canonical} target ; fi# Determine whether this system has symbolic links.if test -n "$DJDIR"; thenLINKS=falseelif ln -s X $LIB/ShouldNotExist 2>/dev/null; thenrm -f $LIB/ShouldNotExistLINKS=trueelif ln -s X /tmp/ShouldNotExist 2>/dev/null; thenrm -f /tmp/ShouldNotExistLINKS=trueelseLINKS=falsefi# # # # # # # # # # # # # # # # # # # # ### In the file macro_list are listed all the predefined# macros that are not in the C89 reserved namespace (the reserved# namespace is all identifiers beginnning with two underscores or one# underscore followed by a capital letter). A regular expression to find# any of those macros in a header file is written to MN_NAME_PAT.## Note dependency on ASCII. \012 = newline.# tr ' ' '\n' is, alas, not portable.if test -s ${MACRO_LIST}thenif test $VERBOSE -gt 0; thenecho "Forbidden identifiers: `tr '\012' ' ' < ${MACRO_LIST}`"fiMN_NAME_PAT="`sed 's/^/\\\\</; s/$/\\\\>/; $!s/$/|/' \< ${MACRO_LIST} | tr -d '\012'`"export MN_NAME_PATelseif test $VERBOSE -gt 0then echo "No forbidden identifiers defined by this target" ; fifi# # # # # # # # # # # # # # # # # # # # ### Search each input directory for broken header files.# This loop ends near the end of the file.#if test $# -eq 0thenINPUTLIST="/usr/include"elseINPUTLIST="$@"fifor INPUT in ${INPUTLIST} ; docd ${ORIGDIR}# Make sure a directory exists before changing into it,# otherwise Solaris2 will fail-exit the script.#if [ ! -d ${INPUT} ]; thencontinueficd ${INPUT}INPUT=`${PWDCMD}`export INPUT## # # # # # # # # # # # # # # # # # # # ##if test $VERBOSE -gt 1then echo Finding directories and links to directories ; fi# Find all directories and all symlinks that point to directories.# Put the list in $all_dirs.# Each time we find a symlink, add it to newdirs# so that we do another find within the dir the link points to.# Note that $all_dirs may have duplicates in it;# later parts of this file are supposed to ignore them.dirs="."levels=2all_dirs=""search_dirs=""while [ -n "$dirs" ] && [ $levels -gt 0 ]dolevels=`expr $levels - 1`newdirs=for d in $dirsdoif test $VERBOSE -gt 1then echo " Searching $INPUT/$d" ; fi# Find all directories under $d, relative to $d, excluding $d itself.# (The /. is needed after $d in case $d is a symlink.)all_dirs="$all_dirs `find $d/. -type d -print | \sed -e '/\/\.$/d' -e 's@/./@/@g'`"# Find all links to directories.# Using `-exec test -d' in find fails on some systems,# and trying to run test via sh fails on others,# so this is the simplest alternative left.# First find all the links, then test each one.theselinks=$LINKS && \theselinks=`find $d/. -type l -print | sed -e 's@/./@/@g'`for d1 in $theselinks --dummy--do# If the link points to a directory,# add that dir to $newdirsif [ -d $d1 ]thenall_dirs="$all_dirs $d1"if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]thennewdirs="$newdirs $d1"search_dirs="$search_dirs $d1"fifidonedonedirs="$newdirs"done# # # # # # # # # # # # # # # # # # # # ##dirs=if test $VERBOSE -gt 2then echo "All directories (including links to directories):"echo $all_dirsfifor file in $all_dirs; dorm -rf $LIB/$fileif [ ! -d $LIB/$file ]then mkdir $LIB/$filefidonemkdir $LIB/root# # # # # # # # # # # # # # # # # # # # ### treetops gets an alternating list# of old directories to copy# and the new directories to copy to.treetops=". ${LIB}"if $LINKS; thenif test $VERBOSE -gt 1then echo 'Making symbolic directory links' ; ficwd=`${PWDCMD}`for sym_link in $search_dirs; docd ${INPUT}dest=`ls -ld ${sym_link} | sed -n 's/.*-> //p'`# In case $dest is relative, get to ${sym_link}'s dir first.#cd ./`echo ${sym_link} | sed 's;/[^/]*$;;'`# Check that the target directory exists.# Redirections changed to avoid bug in sh on Ultrix.#(cd $dest) > /dev/null 2>&1if [ $? = 0 ]; thencd $dest# full_dest_dir gets the dir that the link actually leads to.#full_dest_dir=`${PWDCMD}`# Canonicalize ${INPUT} now to minimize the time an# automounter has to change the result of ${PWDCMD}.#cinput=`cd ${INPUT}; ${PWDCMD}`# If a link points to ., make a similar link to .#if [ ${full_dest_dir} = ${cinput} ]; thenif test $VERBOSE -gt 2then echo ${sym_link} '->' . ': Making self link' ; firm -fr ${LIB}/${sym_link} > /dev/null 2>&1ln -s . ${LIB}/${sym_link} > /dev/null 2>&1# If link leads back into ${INPUT},# make a similar link here.#elif expr ${full_dest_dir} : "${cinput}/.*" > /dev/null; then# Y gets the actual target dir name, relative to ${INPUT}.y=`echo ${full_dest_dir} | sed -n "s&${cinput}/&&p"`# DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.dots=`echo "${sym_link}" |sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`if test $VERBOSE -gt 2then echo ${sym_link} '->' $dots$y ': Making local link' ; firm -fr ${LIB}/${sym_link} > /dev/null 2>&1ln -s $dots$y ${LIB}/${sym_link} > /dev/null 2>&1else# If the link is to a dir $target outside ${INPUT},# repoint the link at ${INPUT}/root$target# and process $target into ${INPUT}/root$target# treat this directory as if it actually contained the files.#if test $VERBOSE -gt 2then echo ${sym_link} '->' root${full_dest_dir} ': Making rooted link'fiif [ -d $LIB/root${full_dest_dir} ]then trueelsedirname=root${full_dest_dir}/dirmade=.cd $LIBwhile [ x$dirname != x ]; docomponent=`echo $dirname | sed -e 's|/.*$||'`mkdir $component >/dev/null 2>&1cd $componentdirmade=$dirmade/$componentdirname=`echo $dirname | sed -e 's|[^/]*/||'`donefi# Duplicate directory structure created in ${LIB}/${sym_link} in new# root area.#for file2 in $all_dirs; docase $file2 in${sym_link}/*)dupdir=${LIB}/root${full_dest_dir}/`echo $file2 |sed -n "s|^${sym_link}/||p"`if test $VERBOSE -gt 2then echo "Duplicating ${sym_link}'s ${dupdir}" ; fiif [ -d ${dupdir} ]then trueelsemkdir ${dupdir}fi;;*);;esacdone# Get the path from ${LIB} to ${sym_link}, accounting for symlinks.#parent=`echo "${sym_link}" | sed -e 's@/[^/]*$@@'`libabs=`cd ${LIB}; ${PWDCMD}`file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"`# DOTS is the relative path from ${LIB}/${sym_link} back to ${LIB}.#dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'`rm -fr ${LIB}/${sym_link} > /dev/null 2>&1ln -s ${dots}root${full_dest_dir} ${LIB}/${sym_link} > /dev/null 2>&1treetops="$treetops ${sym_link} ${LIB}/root${full_dest_dir}"fifidonefi# # # # # # # # # # # # # # # # # # # # ##required=set x $treetopsshiftwhile [ $# != 0 ]; do# $1 is an old directory to copy, and $2 is the new directory to copy to.#SRCDIR=`cd ${INPUT} ; cd $1 ; ${PWDCMD}`export SRCDIRFIND_BASE=$1export FIND_BASEshiftDESTDIR=`cd $1;${PWDCMD}`export DESTDIRshift# The same dir can appear more than once in treetops.# There's no need to scan it more than once.#if [ -f ${DESTDIR}/DONE ]then continue ; fitouch ${DESTDIR}/DONEif test $VERBOSE -gt 1then echo Fixing directory ${SRCDIR} into ${DESTDIR} ; fi# Check files which are symlinks as well as those which are files.#cd ${INPUT}required="$required `if $LINKS; thenfind ${FIND_BASE}/. -name '*.h' \( -type f -o -type l \) -printelsefind ${FIND_BASE}/. -name '*.h' -type f -printfi | \sed -e 's;/\./;/;g' -e 's;//*;/;g' | \${FIXINCL}`"done## Make sure that any include files referenced using double quotes## exist in the fixed directory. This comes last since otherwise## we might end up deleting some of these files "because they don't## need any change."set x `echo $required`shiftwhile [ $# != 0 ]; donewreq=while [ $# != 0 ]; do# $1 is the directory to copy from,# $2 is the unfixed file,# $3 is the fixed file name.#cd ${INPUT}cd $1if [ -f $2 ] ; thenif [ -r $2 ] && [ ! -r $3 ]; thencp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2" >&2chmod +w $3 2>/dev/nullchmod a+r $3 2>/dev/nullif test $VERBOSE -gt 2then echo Copied $2 ; fifor include in `egrep '^[ ]*#[ ]*include[ ]*"[^/]' $3 |sed -e 's/^[ ]*#[ ]*include[ ]*"\([^"]*\)".*$/\1/'`dodir=`echo $2 | sed -e s'|/[^/]*$||'`dir2=`echo $3 | sed -e s'|/[^/]*$||'`newreq="$newreq $1 $dir/$include $dir2/$include"donefifishift; shift; shiftdoneset x $newreqshiftdoneif test $VERBOSE -gt 2then echo 'Cleaning up DONE files.' ; ficd $LIB# Look for files case-insensitively, for the benefit of# DOS/Windows filesystems.find . -name '[Dd][Oo][Nn][Ee]' -exec rm -f '{}' ';'if test $VERBOSE -gt 1then echo 'Cleaning up unneeded directories:' ; ficd $LIBall_dirs=`find . -type d \! -name '.' -print | sort -r`for file in $all_dirs; doif rmdir $LIB/$file > /dev/nullthentest $VERBOSE -gt 3 && echo " removed $file"fidone 2> /dev/null# On systems which don't support symlinks, `find' may barf# if called with "-type l" predicate. So only use that if# we know we should look for symlinks.if $LINKS; thentest $VERBOSE -gt 2 && echo "Removing unused symlinks"all_dirs=`find . -type l -print`for file in $all_dirsdoif test ! -d $filethenrm -f $filetest $VERBOSE -gt 3 && echo " removed $file"rmdir `dirname $file` > /dev/null && \test $VERBOSE -gt 3 && \echo " removed `dirname $file`"fidone 2> /dev/nullfiif test $VERBOSE -gt 0then echo fixincludes is done ; fi# # # # # # # # # # # # # # # # # # # # ### End of for INPUT directories#done## # # # # # # # # # # # # # # # # # # # #
Go to most recent revision | Compare with Previous | Blame | View Log
