Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make libexec symlink relocatable #425

Closed
wants to merge 1 commit into from

Conversation

peniblec
Copy link

Hi!

This is a slight tweak to the symlink in libexec to allow packagers to archive build artifacts, and untar the archive under different paths.

As shown in the commit message, the current link is absolute, so it will not be resolved properly (1) while mold sits in DESTDIR (2) if the build artifacts are deployed under a different PREFIX.

Thank you for your time, and let me know if you need more context about the use-case!

When packaging mold, one might want to "make install" the build
artifacts into a directory that will be archived, then deployed
somewhere else.  This commit changes this result…

$ make install DESTDIR=pkg PREFIX=""
$ readlink pkg/libexec/mold/ld
/bin/mold

… into this…

$ readlink pkg/libexec/mold/ld
../../bin/mold

… which will remain correct wherever we end up installing the contents
of "pkg".

Signed-off-by: Kévin Le Gouguec <legouguec@adacore.com>
@rui314
Copy link
Owner

rui314 commented Apr 11, 2022

I wanted to do this, but it looks like ln commands on some Unixes (at least macOS) don't support the -r option, so we can't use that flag.

@peniblec
Copy link
Author

Good catch. I've thought about using realpath --relative-to, but the BSD manpages I could find[1][2] suggest that this flag is also GNU-only.

So far I haven't found a shell solution to produce relative paths without GNU coreutils, which sounds mildly surprising to me; I'll mull over this some more.

rui314 added a commit that referenced this pull request Apr 16, 2022
I didn't want to write a Python one-liner in the Makefile, but it
looks like it is in practice one of the most portable way to compute a
relative path.

#425
@rui314
Copy link
Owner

rui314 commented Apr 16, 2022

I did this using Python in the above commit.

@rui314 rui314 closed this Apr 16, 2022
@peniblec
Copy link
Author

Thanks! Sorry we couldn't find a more "lightweight" solution (IIUC pulling in GNU coreutils is doable on MacOS; not sure about the BSDs?).

I've updated my branch with a further tweak: adding $D before the link target (this was in my original PR, but not easy to spot since I didn't really advertize it). The change is here:

main...peniblec:relative-symlink

Should I submit a new PR?

rui314 added a commit that referenced this pull request Apr 16, 2022
Pointed out by Kévin Le Gouguec in #425.
@rui314
Copy link
Owner

rui314 commented Apr 16, 2022

I removed $D from both arguments instead.

@peniblec
Copy link
Author

Thanks again, should work just as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants