Make bash wrapper relocatable
By having the build system put in a relative path rather than an absolute path. Unfortunately, make does not support computing relative paths manually, so a small bash script is needed that will do this for us.
This commit is contained in:
parent
80488a8ee9
commit
3e6acd43fd
|
|
@ -32,6 +32,11 @@ TCL_FILES = \
|
|||
readspice.tcl \
|
||||
magic.tcl
|
||||
|
||||
TCL_DIR_REL_OR_ABS = $(shell ${MAGICDIR}/tcltk/relpath.sh "$(DESTDIR)${INSTALL_BINDIR}" ${TCLDIR})
|
||||
ifeq ($(TCL_DIR_REL_OR_ABS),)
|
||||
TCL_DIR_REL_OR_ABS = ${TCLDIR}
|
||||
endif
|
||||
|
||||
BIN_FILES = \
|
||||
$(DESTDIR)${INSTALL_BINDIR}/magic.sh \
|
||||
$(DESTDIR)${INSTALL_BINDIR}/ext2spice.sh \
|
||||
|
|
@ -66,15 +71,15 @@ magic.tcl: magic.tcl.in ${MAGICDIR}/defs.mak ${MAGICDIR}/VERSION
|
|||
-e /SHDLIB_EXT/s%SHDLIB_EXT%${SHDLIB_EXT}%g magic.tcl.in > magic.tcl
|
||||
|
||||
magic.sh: magic.sh.in ${MAGICDIR}/defs.mak
|
||||
sed -e /TCL_DIR/s%TCL_DIR%${TCLDIR}%g \
|
||||
sed -e /TCL_DIR_REL_OR_ABS/s%TCL_DIR_REL_OR_ABS%${TCL_DIR_REL_OR_ABS}%g \
|
||||
-e /TCLLIB_DIR/s%TCLLIB_DIR%${TCL_LIB_DIR}%g \
|
||||
-e /WISH_EXE/s%WISH_EXE%${WISH_EXE}%g magic.sh.in > magic.sh
|
||||
|
||||
ext2spice.sh: ext2spice.sh.in ${MAGICDIR}/defs.mak
|
||||
sed -e /TCL_DIR/s%TCL_DIR%${TCLDIR}%g ext2spice.sh.in > ext2spice.sh
|
||||
sed -e /TCL_DIR_REL_OR_ABS/s%TCL_DIR_REL_OR_ABS%${TCL_DIR_REL_OR_ABS}%g ext2spice.sh.in > ext2spice.sh
|
||||
|
||||
ext2sim.sh: ext2sim.sh.in ${MAGICDIR}/defs.mak
|
||||
sed -e /TCL_DIR/s%TCL_DIR%${TCLDIR}%g ext2sim.sh.in > ext2sim.sh
|
||||
sed -e /TCL_DIR_REL_OR_ABS/s%TCL_DIR_REL_OR_ABS%${TCL_DIR_REL_OR_ABS}%g ext2sim.sh.in > ext2sim.sh
|
||||
|
||||
$(DESTDIR)${INSTALL_TCLDIR}/%: %
|
||||
${RM} $(DESTDIR)${INSTALL_TCLDIR}/$*
|
||||
|
|
|
|||
|
|
@ -14,8 +14,14 @@ for i in $@; do
|
|||
*) esargs="$esargs $i" ;;
|
||||
esac
|
||||
done
|
||||
TCL_REL_OR_ABS=TCL_DIR_REL_OR_ABS
|
||||
if [ "${TCL_REL_OR_ABS:0:1}" = "/" ]; then
|
||||
TCL_DIR=$TCL_REL_OR_ABS
|
||||
else
|
||||
TCL_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))/$TCL_REL_OR_ABS
|
||||
fi
|
||||
#
|
||||
eval TCL_DIR/magicdnull -dnull -noconsole -nowrapper $mgargs <<EOF
|
||||
eval ${TCL_DIR}/magicdnull -dnull -noconsole -nowrapper $mgargs <<EOF
|
||||
drc off
|
||||
box 0 0 0 0
|
||||
ext2sim $esargs
|
||||
|
|
|
|||
|
|
@ -14,8 +14,14 @@ for i in $@; do
|
|||
*) esargs="$esargs $i" ;;
|
||||
esac
|
||||
done
|
||||
TCL_REL_OR_ABS=TCL_DIR_REL_OR_ABS
|
||||
if [ "${TCL_REL_OR_ABS:0:1}" = "/" ]; then
|
||||
TCL_DIR=$TCL_REL_OR_ABS
|
||||
else
|
||||
TCL_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))/$TCL_REL_OR_ABS
|
||||
fi
|
||||
#
|
||||
eval TCL_DIR/magicdnull -dnull -noconsole -nowrapper $mgargs <<EOF
|
||||
eval ${TCL_DIR}/magicdnull -dnull -noconsole -nowrapper $mgargs <<EOF
|
||||
drc off
|
||||
box 0 0 0 0
|
||||
ext2spice $esargs
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@
|
|||
# Parse for the argument "-c[onsole]". If it exists, run magic
|
||||
# with the TkCon console. Strip this argument from the argument list.
|
||||
|
||||
TCL_REL_OR_ABS=TCL_DIR_REL_OR_ABS
|
||||
if [ "${TCL_REL_OR_ABS:0:1}" = "/" ]; then
|
||||
TCL_DIR=$TCL_REL_OR_ABS
|
||||
else
|
||||
TCL_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))/$TCL_REL_OR_ABS
|
||||
fi
|
||||
TKCON=true
|
||||
DNULL=
|
||||
MAGIC_WISH=WISH_EXE
|
||||
|
|
@ -37,12 +43,12 @@ done
|
|||
if [ $TKCON ]; then
|
||||
|
||||
if [ $DNULL ]; then
|
||||
exec TCL_DIR/tkcon.tcl -eval "source TCL_DIR/console.tcl" \
|
||||
-slave "set argc $#; set argv [list $*]; source TCL_DIR/magic.tcl"
|
||||
exec $TCL_DIR/tkcon.tcl -eval "source $TCL_DIR/console.tcl" \
|
||||
-slave "set argc $#; set argv [list $*]; source $TCL_DIR/magic.tcl"
|
||||
else
|
||||
exec TCL_DIR/tkcon.tcl -eval "source TCL_DIR/console.tcl" \
|
||||
exec $TCL_DIR/tkcon.tcl -eval "source $TCL_DIR/console.tcl" \
|
||||
-slave "package require Tk; set argc $#; set argv [list $arglist]; \
|
||||
source TCL_DIR/magic.tcl"
|
||||
source $TCL_DIR/magic.tcl"
|
||||
fi
|
||||
|
||||
else
|
||||
|
|
@ -57,8 +63,8 @@ else
|
|||
# only, efficient for running in batch mode).
|
||||
#
|
||||
if [ $DNULL ]; then
|
||||
exec TCL_DIR/magicdnull -nowrapper "$@"
|
||||
exec $TCL_DIR/magicdnull -nowrapper "$@"
|
||||
else
|
||||
exec TCL_DIR/magicexec -- "$@"
|
||||
exec $TCL_DIR/magicexec -- "$@"
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash
|
||||
# From https://stackoverflow.com/questions/2564634/convert-absolute-path-into-relative-path-given-a-current-directory-using-bash
|
||||
# both $1 and $2 are absolute paths beginning with /
|
||||
# returns relative path to $2/$target from $1/$source
|
||||
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
|
||||
Loading…
Reference in New Issue