source: trunk/packages/xen-common/xen-common/tools/debugger/gdb/gdb-6.2.1-xen-sparse/mkbuildtree @ 34

Last change on this file since 34 was 34, checked in by hartmans, 17 years ago

Add xen and xen-common

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#!/bin/bash
2
3# mkbuildtree <build tree>
4#
5# Creates symbolic links in <build tree> for the sparse tree
6# in the current directory.
7
8# Script to determine the relative path between two directories.
9# Copyright (c) D. J. Hawkey Jr. 2002
10# Fixed for Xen project by K. Fraser in 2003. 
11abs_to_rel ()
12{
13        local CWD SRCPATH
14               
15        if [ "$1" != "/" -a "${1##*[^/]}" = "/" ]; then
16                SRCPATH=${1%?}
17        else
18                SRCPATH=$1
19        fi
20        if [ "$2" != "/" -a "${2##*[^/]}" = "/" ]; then
21                DESTPATH=${2%?}
22        else
23                DESTPATH=$2
24        fi
25
26        CWD=$PWD
27        [ "${1%%[^/]*}" != "/" ] && cd $1 && SRCPATH=$PWD
28        [ "${2%%[^/]*}" != "/" ] && cd $2 && DESTPATH=$PWD
29        [ "$CWD" != "$PWD" ] && cd $CWD
30
31        BASEPATH=$SRCPATH
32
33        [ "$SRCPATH" = "$DESTPATH" ] && DESTPATH="." && return
34        [ "$SRCPATH" = "/" ] && DESTPATH=${DESTPATH#?} && return
35
36        while [ "$BASEPATH/" != "${DESTPATH%${DESTPATH#$BASEPATH/}}" ]; do
37          BASEPATH=${BASEPATH%/*}
38        done
39
40        SRCPATH=${SRCPATH#$BASEPATH}
41        DESTPATH=${DESTPATH#$BASEPATH}
42        DESTPATH=${DESTPATH#?}
43        while [ -n "$SRCPATH" ]; do
44                SRCPATH=${SRCPATH%/*}
45                DESTPATH="../$DESTPATH"
46        done
47
48        [ -z "$BASEPATH" ] && BASEPATH="/"
49        [ "${DESTPATH##*[^/]}" = "/" ] && DESTPATH=${DESTPATH%?}
50}
51
52# relative_lndir <target_dir>
53# Creates a tree of symlinks in the current working directory that mirror
54# real files in <target_dir>. <target_dir> should be relative to the current
55# working directory. Symlinks in <target_dir> are ignored. Source-control files
56# are ignored.
57relative_lndir ()
58{
59  local SYMLINK_DIR REAL_DIR pref i j
60  SYMLINK_DIR=$PWD
61  REAL_DIR=$1
62  (
63  cd $REAL_DIR
64  for i in `find . -type d | grep -v SCCS`; do
65    [ -d $SYMLINK_DIR/$i ] || mkdir -p $SYMLINK_DIR/$i
66    (
67    cd $i
68    pref=`echo $i | sed -e 's#/[^/]*#../#g' -e 's#^\.##'`
69    for j in `find . -type f -o -type l -maxdepth 1`; do
70      ln -sf ${pref}${REAL_DIR}/$i/$j ${SYMLINK_DIR}/$i/$j
71    done
72    )
73  done
74  )
75}
76
77[ "$1" == "" ] && { echo "Syntax: $0 <linux tree to xenify>"; exit 1; }
78
79# Get absolute path to the destination directory
80pushd . >/dev/null
81cd ${1}
82AD=$PWD
83popd >/dev/null
84 
85# Get absolute path to the source directory
86AS=`pwd`
87
88# Get name of sparse directory
89SDN=$(basename $AS)
90
91# Get path to source, relative to destination
92abs_to_rel ${AD} ${AS}
93RS=$DESTPATH
94
95# We now work from the destination directory
96cd ${AD}
97
98# Remove old symlinks
99find sys -type l | while read f
100do
101  case $(readlink $f) in
102  */$SDN/*)
103    rm -f $f
104    ;;
105  esac
106done
107
108if [ -f ${AD}/BUILDING ]; then
109  # Create symlinks of files and directories which exist in the sparse source
110  (cd sys && relative_lndir ../${RS}/sys)
111else
112  # Create symlinks of files and directories which exist in the sparse source
113  relative_lndir ${RS}
114  rm -f mkbuildtree
115fi
Note: See TracBrowser for help on using the repository browser.