diff --git a/scripts/linklibs.sh b/scripts/linklibs.sh --- a/scripts/linklibs.sh +++ b/scripts/linklibs.sh @@ -25,17 +25,14 @@ echo echo echo -# Absolute path to this script. /home/user/bin/foo.sh -#SCRIPT=$(readlink -f $0) -# Absolute path this script is in. /home/user/bin -#LPP_PATCHPATH=`dirname $SCRIPT` -LPP_PATCHPATH=`pwd -L` - +VHDLIB_LIB_PATH=`pwd -L` +source $VHDLIB_LIB_PATH/scripts/lpp_bash_functions.sh GRLIBPATH=$1 -echo $LPP_PATCHPATH if [ -d "$GRLIBPATH" ]; then + LPP_PATCHPATH=`relpath $GRLIBPATH $VHDLIB_LIB_PATH` + echo $LPP_PATCHPATH if [ -d "$GRLIBPATH/lib" ]; then if [ -d "$GRLIBPATH/designs" ]; then if [ -d "$GRLIBPATH/boards" ]; then diff --git a/scripts/lpp_bash_functions.sh b/scripts/lpp_bash_functions.sh new file mode 100644 --- /dev/null +++ b/scripts/lpp_bash_functions.sh @@ -0,0 +1,82 @@ +#!/bin/bash +#"=======================================================================================" +#"---------------------------------------------------------------------------------------" +#" LPP VHDL lib makeDirs " +#" Copyright (C) 2010 Laboratory of Plasmas Physic. " +#"=======================================================================================" +#---------------------------------------------------------------------------------------- +# This file is a part of the LPP VHDL IP LIBRARY +# Copyright (C) 2010, Laboratory of Plasmas Physic - CNRS +# +# This program is free software; you can 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 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#---------------------------------------------------------------------------------------- + + + +# Full path function +function fullpath() { + if test $# -gt 0 + then + cd $1 + echo `pwd` + fi +} + + + +# Relative path function +# both $1 and $2 are absolute paths (biginning with /) +# returns $2 relative to $1 +function relpath() { + if test $# -gt 1 + then + source=`fullpath $1` + target=`fullpath $2` + + common_part=$source # for now + result="" # for now + + while [[ "${target#$common_part}" == "${target}" ]]; do + # no match, means that candidate common part is not correct + # go up one level (reduce common part) + common_part="$(dirname $common_part)" + # and record that we went back, with correct / handling + if [[ -z $result ]]; then + result=".." + else + result="../$result" + fi + done + + if [[ $common_part == "/" ]]; then + # special case for root (no common path) + result="$result/" + fi + + # since we now have identified the common part, + # compute the non-common part + forward_part="${target#$common_part}" + + # and now stick all parts together + if [[ -n $result ]] && [[ -n $forward_part ]]; then + result="$result$forward_part" + elif [[ -n $forward_part ]]; then + # extra slash removal + result="${forward_part:1}" + fi + + echo $result + fi +} diff --git a/scripts/relative_path.sh b/scripts/relative_path.sh deleted file mode 100644 --- a/scripts/relative_path.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -# both $1 and $2 are absolute paths (biginning with /) -# returns $2 relative to $1 - -source=$1 -target=$2 - -common_part=$source # for now -result="" # for now - -while [[ "${target#$common_part}" == "${target}" ]]; do - # no match, means that candidate common part is not correct - # go up one level (reduce common part) - common_part="$(dirname $common_part)" - # and record that we went back, with correct / handling - if [[ -z $result ]]; then - result=".." - else - result="../$result" - fi -done - -if [[ $common_part == "/" ]]; then - # special case for root (no common path) - result="$result/" -fi - -# since we now have identified the common part, -# compute the non-common part -forward_part="${target#$common_part}" - -# and now stick all parts together -if [[ -n $result ]] && [[ -n $forward_part ]]; then - result="$result$forward_part" -elif [[ -n $forward_part ]]; then - # extra slash removal - result="${forward_part:1}" -fi - -echo $result