Re: Relative path without realpath
suggests that it can be scripted in portable shell ( So it seems, although: current="${2:+"$1"}" target="${2:-"$1"}" ... etc... all these myriad fancy variable substitutions would have to be replaced with sed, or something ... --thanks, karl.
Re: Relative path without realpath
I would use or copy the definition in GNU Autoconf. Portable and battle tested. You can dig through their macros or look in a configure script to see how they generate abs_builddir, abs_srcdir, abs_top_builddir, ... - Daniel On Fri, 9 Oct 2020, Cristian Morales Vega wrote: I would like to send some patches making pkg-config files relocatable. pkg-config offers the "pcfiledir" variable to do this. The thing is that I need to be able to obtain prefix, libdir, includedir, etc. relative to the directory where the .pc file gets installed. I can easily do this with realpath, from coreutils, but it's not POSIX and I'm not sure people will accept such a dependency. The use of automake per se has no dependency to coreutils, does it? There is any way to obtain the path of one directory relative to another in automake without adding a new dependency? "realpath" implemented as a m4 macro, maybe? Thanks.
Re: Relative path without realpath
On 10/9/20 10:46 AM, Cristian Morales Vega wrote: > I would like to send some patches making pkg-config files relocatable. > pkg-config offers the "pcfiledir" variable to do this. > The thing is that I need to be able to obtain prefix, libdir, > includedir, etc. relative to the directory where the .pc file gets > installed. I can easily do this with realpath, from coreutils, but > it's not POSIX and I'm not sure people will accept such a dependency. > The use of automake per se has no dependency to coreutils, does it? > > There is any way to obtain the path of one directory relative to > another in automake without adding a new dependency? "realpath" > implemented as a m4 macro, maybe? https://stackoverflow.com/questions/2564634/convert-absolute-path-into-relative-path-given-a-current-directory-using-bash suggests that it can be scripted in portable shell (although I did not test if it has odd corner cases when one or the other input contains things like foo/../bar or symlinks): #!/bin/sh relpath () { [ $# -ge 1 ] && [ $# -le 2 ] || return 1 current="${2:+"$1"}" target="${2:-"$1"}" [ "$target" != . ] || target=/ target="/${target##/}" [ "$current" != . ] || current=/ current="${current:="/"}" current="/${current##/}" appendix="${target##/}" relative='' while appendix="${target#"$current"/}" [ "$current" != '/' ] && [ "$appendix" = "$target" ]; do if [ "$current" = "$appendix" ]; then relative="${relative:-.}" echo "${relative#/}" return 0 fi current="${current%/*}" relative="$relative${relative:+/}.." done relative="$relative${relative:+${appendix:+/}}${appendix#/}" echo "$relative" } relpath "$@" -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org signature.asc Description: OpenPGP digital signature
Re: Relative path without realpath
The use of automake per se has no dependency to coreutils, does it? No. There is any way to obtain the path of one directory relative to another in automake without adding a new dependency? "realpath" implemented as a m4 macro, maybe? Sorry, I'm clueless. Anyone else out there with info? Thanks, Karl
Relative path without realpath
I would like to send some patches making pkg-config files relocatable. pkg-config offers the "pcfiledir" variable to do this. The thing is that I need to be able to obtain prefix, libdir, includedir, etc. relative to the directory where the .pc file gets installed. I can easily do this with realpath, from coreutils, but it's not POSIX and I'm not sure people will accept such a dependency. The use of automake per se has no dependency to coreutils, does it? There is any way to obtain the path of one directory relative to another in automake without adding a new dependency? "realpath" implemented as a m4 macro, maybe? Thanks.