macports-base icon indicating copy to clipboard operation
macports-base copied to clipboard

Make port-tclsh a relative symlink, not absolute

Open ryandesign opened this issue 7 years ago • 6 comments

This is a step toward allowing the MacPorts installer package to install to any prefix.

Using Perl is the most straightforward and most compatible way I found to compute a relative path from two absolute paths.

I wrote the Perl command inline because this is the only place where it's needed right now. But it could be broken out into a custom Makefile function to make it reusable.

Is it ok to just use perl, since it is so widely available, or do we need to do autoconf stuff to find it and set a variable with its path? We already use sed in the same Makefile without checking for it.

ryandesign avatar Jun 02 '18 11:06 ryandesign

Given that we know that ${TCLSH} is inside ${INSTALLDIR}, how about using the ${foo#bar} prefix pattern expansion syntax to get the relative path? Needs a shell variable first, though.

Something like this, but it is untested:

tclshpath=${TCLSH}; $(LN_S) -f "../$${tclshpath#${INSTALLDIR}}" "${DESTDIR}${INSTALLDIR}/bin/port-tclsh"

raimue avatar Jun 02 '18 12:06 raimue

That should work and would be simpler.

ryandesign avatar Jun 02 '18 22:06 ryandesign

Are you going to update the PR with the shell-based solution?

neverpanic avatar Jun 08 '18 22:06 neverpanic

Yes I should do that.

ryandesign avatar Jun 09 '18 09:06 ryandesign

how about using the ${foo#bar} prefix pattern expansion syntax to get the relative path?

The problem with this is that we are perpetuating the mistake of making assumptions about the "bin" and "libexec" directory names/paths and their locations relative to one another. If we fix that mistake, then we need to compute the relative path from the one to the other, e.g. using the Perl solution I proposed.

ryandesign avatar Jul 01 '18 22:07 ryandesign

If avoiding Perl is strongly desired, the following should work:

bindir="${INSTALLDIR}/bin" && shopt -s extglob && rel="$${bindir//+([^\/])/..}" && $(LN_S) -f "$${rel:1}${TCLSH}" "${DESTDIR}${INSTALLDIR}/bin/port-tclsh"

The relative path this constructs is not minimal/optimal, but it should be correct regardless of how different bindir and libexecdir are from one another.

(Obviously this still incorrectly hardcodes the bin directory, but at least it makes it obvious where ${INSTALLDIR}/bin could be replaced by the right thing.)

ryandesign avatar Jul 01 '18 23:07 ryandesign