include.sh
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- #! /bin/sh
- #
- # $Id: include.sh,v 1000.0 2003/10/29 14:24:48 gouriano Exp $
- # ===========================================================================
- #
- # PUBLIC DOMAIN NOTICE
- # National Center for Biotechnology Information
- #
- # This software/database is a "United States Government Work" under the
- # terms of the United States Copyright Act. It was written as part of
- # the author's official duties as a United States Government employee and
- # thus cannot be copyrighted. This software/database is freely available
- # to the public for use. The National Library of Medicine and the U.S.
- # Government have not placed any restriction on its use or reproduction.
- #
- # Although all reasonable efforts have been taken to ensure the accuracy
- # and reliability of the software and data, the NLM and the U.S.
- # Government do not and cannot warrant the performance or results that
- # may be obtained by using this software or data. The NLM and the U.S.
- # Government disclaim all warranties, express or implied, including
- # warranties of performance, merchantability or fitness for any particular
- # purpose.
- #
- # Please cite the author in any work or product based on this material.
- #
- # ===========================================================================
- #
- # Author: Anton Lavrentiev
- #
- # MSVC project file patcher. Patch include file paths when the nesting
- # directory level changes.
- #
- # ===========================================================================
- include() {
- cat <<"EOF" >$1
- #!/bin/sh
- if [ _$1 = _ -o _$2 = _ ]; then
- echo "ERROR: Incorrect call. Stop."
- exit 3
- elif [ ! -f $1 ]; then
- echo "ERROR: File "$1" inexistent. Stop."
- exit 2
- fi
- orig=$1
- shift
- for d in $* ; do
- if [ _`echo $d | sed -e 's|^/.*||'` != _ ]; then
- echo "ERROR: "$d" is not an absolute path. Stop."
- exit 2
- fi
- done
- file=/tmp/$$_file
- # DOS-2-UNIX conversion (shouldn't be here, but just in case for sanity).
- #
- sed -e 's/
*$//' $orig >$file
- # Check signature.
- #
- cat <<-"EOF" >/tmp/$$_genusign
- # Microsoft Developer Studio Project File
- # Microsoft Developer Studio Generated Build File, Format Version 6.00
- # ** DO NOT EDIT **
- # TARGTYPE
- EOF
- cat /dev/null >/tmp/$$_filesign
- head -1 $file | sed -e 's/ -.*//' >>/tmp/$$_filesign
- head -3 $file | tail +2 >>/tmp/$$_filesign
- head -5 $file | tail +4 | sed -e 's/ *".*$//' >>/tmp/$$_filesign
- diff /tmp/$$_filesign /tmp/$$_genusign >/dev/null 2>&1
- exit=$?
- rm -f /tmp/$$_filesign /tmp/$$_genusign
- if [ $exit != 0 ]; then
- echo "ERROR: $orig doesn't look like MSVC++ Project File. Stop."
- rm -f $file
- exit 2
- fi
- # Generic project?
- #
- if [ `grep -c '^# ADD .*CPP ' $file` = 0 ]; then
- echo "${orig}: Nothing to do!"
- rm -f $file
- exit 0
- fi
- # Find existing include paths in the project.
- #
- cat <<-EOF >/tmp/$$_inc.sed
- /^# ADD .*CPP / {
- s|/I *|/I_|g
- s|\\|/|g
- p
- }
- d
- EOF
- cat /dev/null >/tmp/$$_incl
- for k in `sed -n -f /tmp/$$_inc.sed $file` ; do
- if [ `echo "$k" | grep -c /I_` != 0 ]; then
- inc=`echo "$k" | sed -e 's|/I_||' -e 's|"||g'`
- ince=`echo "$inc" | sed -e 's|\.|\\.|g'`
- if [ `grep -c "^$ince\$" /tmp/$$_incl` = 0 ]; then
- echo "$inc" >>/tmp/$$_incl
- fi
- fi
- done
- rm -f /tmp/$$_inc.sed
- if [ -s /tmp/$$_incl ]; then
- echo "${orig}: The following include path(s) found:"
- cat /tmp/$$_incl | sed -e 's/^/ /'
- fi
- # Build relative include paths, using current directory and given paths.
- #
- cat /dev/null >/tmp/$$_inc
- for d in $* ; do
- dir=`echo $d | sed -e 's|/$||'`
- if [ _$dir = _ ]; then
- dir='/'
- fi
- cwd=`pwd`
- root=''
- for i in `echo $cwd | tr '/' ' '` ; do
- newroot=$root/$i
- if [ _`echo $dir | sed -e "s|^$newroot||"` = _$dir ]; then
- break;
- fi
- root=$newroot
- done
- if [ _$root = _ ]; then
- root='/'
- fi
- #echo Common root of $dir and $cwd is $root
- newdir=`echo $dir | sed -e "s|^$root||"`
- newcwd=`echo $cwd | sed -e "s|^$root||"`
- include='.'
- for i in `echo $newcwd | tr '/' ' '` ; do
- include="${include}/.."
- done
- for i in `echo $newdir | tr '/' ' '` ; do
- include="${include}/$i"
- done
- #echo Path to include files is $include
- echo "$include" >>/tmp/$$_inc
- done
- # Now replace original include paths, if they resemble calculated paths.
- # Preserve rest of original paths.
- #
- cat /dev/null >/tmp/$$_include
- for i in `cat /tmp/$$_incl` ; do
- replaced=0
- for j in `cat /tmp/$$_inc` ; do
- dir1=`echo $i | sed -e 's|^[/.]*||'`
- dir2=`echo $j | sed -e 's|^[/.]*||'`
- if [ _$dir1 = _$dir2 ]; then
- if [ $i = $j ]; then
- echo Unchanged directory ""$i""
- else
- echo Replacing directory ""$i"" with directory ""$j""
- fi
- inc="$j"
- ince=`echo "$inc" | sed -e 's|\.|\\.|g'`
- grep -v "^$ince$" /tmp/$$_inc >/tmp/$$_i
- mv /tmp/$$_i /tmp/$$_inc
- replaced=1
- break
- fi
- done
- if [ $replaced = 0 ]; then
- echo Keeping directory ""$i""
- inc="$i"
- fi
- inc=`echo "$inc" | sed -e 's|/|\\\\|g'`
- echo '/I' ""$inc"" >>/tmp/$$_include
- done
- if [ -s /tmp/$$_inc ]; then
- for i in `cat /tmp/$$_inc` ; do
- echo Appending directory ""$i""
- inc=`echo $i | sed -e 's|/|\\\\|g'`
- echo '/I' ""$inc"" >>/tmp/$$_include
- done
- fi
- #echo +++
- #cat /tmp/$$_include
- #echo ---
- rm -f /tmp/$$_incl /tmp/$$_inc
- # Form compiler "/I" options.
- #
- cat <<-EOF >/tmp/$$_inc.sed
- s|\\|\\\\|g
- /./ {
- H
- $ !d
- }
- $ {
- x
- s/n/ /g
- s/^ *//
- s/ *$//
- p
- q
- }
- EOF
- inc=`sed -n -f /tmp/$$_inc.sed /tmp/$$_include`
- rm -f /tmp/$$_inc.sed /tmp/$$_include
- #echo "$inc"
- # Incorporate compiler options into project file.
- # Output is always in UNIX text file format.
- #
- cat <<-EOF >/tmp/$$_comp.sed
- /^# ADD .*CPP / s|/I *"{0,1}[^ ]*"{0,1}|@I|g
- /^# ADD CPP / {
- s|@I|$inc|
- t success
- s| /D| $inc&|
- t success
- s| /Y| $inc&|
- t success
- s| /F| $inc&|
- t success
- s| /c| $inc&|
- t success
- s| *$| $inc|
- :success
- s| *@I||g
- }
- EOF
- #cat /tmp/$$_comp.sed
- mv $orig $orig.bak
- sed -f /tmp/$$_comp.sed $file >$orig
- rm -f /tmp/$$_comp.sed $file
- touch -r $orig.bak $orig
- exit 0
- EOF
- chmod u+x $1
- }
- usage() {
- echo 'Include path tracer for Microsoft Visual C++ Project File V 6.0'
- echo 'Usage:'
- echo `basename $0` "rel_path_to_include ..."
- exit 1
- }
- dir=$*
- dir=${dir:-../../include}
- for d in "$dir" ; do
- if [ _`echo "$d" | sed -e 's|^/.*||'` = _ ]; then
- echo "ERROR: "$d" is not a relative path. Stop."
- exit 2
- fi
- done
- dirlist=''
- for d in "$dir" ; do
- dir=`pwd`
- for i in `echo "$d" | tr '/' ' '` ; do
- if [ "$i" = ".." ]; then
- dir=`echo "$dir" | sed -e 's|/[^/]*$||'`
- elif [ "$i" != "." ]; then
- dir="${dir}/$i"
- fi
- done
- if [ _$dir = _ ]; then
- dir='/'
- fi
- dirlist="$dirlist $dir"
- done
- include /tmp/$$_inc.sh
- cat <<EOF >/tmp/$$_cmd.sh
- #!/bin/sh
- for i in * ; do
- if [ -d $i ]; then
- cd $i
- /tmp/$$_cmd.sh $1/$i
- cd ..
- elif [ -f $i -a `echo $i | grep -c '\\.dsp$'` != 0 ]; then
- echo Analyzing $1/$i
- /tmp/$$_inc.sh $i $dirlist
- exit=$?
- if [ $exit != 0 ]; then
- exit $exit
- fi
- echo
- fi
- done
- exit 0
- EOF
- chmod u+x /tmp/$$_cmd.sh
- /tmp/$$_cmd.sh .
- exit=$?
- rm -f /tmp/$$_cmd.sh /tmp/$$_inc.sh
- exit $exit
- #
- # ===========================================================================
- # PRODUCTION $Log: include.sh,v $
- # PRODUCTION Revision 1000.0 2003/10/29 14:24:48 gouriano
- # PRODUCTION PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R1.6
- # PRODUCTION
- # ===========================================================================
- #