Fix wx-config symlink in out-of-tree installs

When we install out-of-tree, i.e. with a non-empty DESTDIR, the
wx-config symlink is broken: the target of the symlink is not rooted
in DESTDIR.

It would seem the obvious solution would be to prefix the target of
the symlink with $(DESTDIR) and be done with it. That would solves
cross-compilation cases, but would not fix native build when the
install is done in a staging area to prepare a binary package (e.g.
Linux distributions à-la Debian do that for example).

A way to make the symlink work in both cases is by making it relative.
ln has been supporting a --relative option since coreutils 8.16,
released 2012-03-26, more than 12 years ago now; it is relatively safe
to assume that distributions of today do have an ln that supports that
flag.

For systems that do not support that flag (e.g. *BSD, MacOS), fallback
to creating a non-relative symlink, on the assumpion [0] that on those
systems, DESTDIR is most probably never used. Eventually, in case
creating both symlinks fails, keep doing a copy as the ultimate
fallback.

[0] https://github.com/wxWidgets/wxWidgets/pull/24622#issuecomment-2184047170

Closes #24622.

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
Yann E. MORIN
2024-06-18 21:47:01 +02:00
committed by Vadim Zeitlin
parent 4d6bcd833f
commit b2cb336b78
2 changed files with 4 additions and 2 deletions

View File

@@ -13782,7 +13782,8 @@ install-wxconfig:
$(INSTALL_DIR) $(DESTDIR)$(bindir)
$(INSTALL_DIR) $(DESTDIR)$(libdir)/wx/config
$(INSTALL_SCRIPT) lib/wx/config/$(TOOLCHAIN_FULLNAME) $(DESTDIR)$(libdir)/wx/config
(cd $(DESTDIR)$(bindir) && rm -f wx-config && $(LN_S) $(libdir)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config || cp -p $(DESTDIR)$(libdir)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config)
# Warning! If the --relative symlink fails (e.g. *BSD), then we'd create an absolute symlink, which will be broken if DESTDIR is moved
(cd $(DESTDIR)$(bindir) && rm -f wx-config && $(LN_S) --relative $(DESTDIR)$(libdir)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config || $(LN_S) $(DESTDIR)$(libdir)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config || cp -p $(DESTDIR)$(libdir)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config)
locale_install:
$(INSTALL_DIR) $(DESTDIR)$(datadir)/locale

View File

@@ -96,7 +96,8 @@
$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
$(INSTALL_DIR) $(DESTDIR)$(LIBDIR)/wx/config
$(INSTALL_SCRIPT) lib/wx/config/$(TOOLCHAIN_FULLNAME) $(DESTDIR)$(LIBDIR)/wx/config
(cd $(DESTDIR)$(BINDIR) &amp;&amp; rm -f wx-config &amp;&amp; $(LN_S) $(LIBDIR)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config || cp -p $(DESTDIR)$(LIBDIR)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config)
# Warning! If the --relative symlink fails (e.g. *BSD), then we'd create an absolute symlink, which will be broken if DESTDIR is moved
(cd $(DESTDIR)$(BINDIR) &amp;&amp; rm -f wx-config &amp;&amp; $(LN_S) --relative $(DESTDIR)$(LIBDIR)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config || $(LN_S) $(DESTDIR)$(LIBDIR)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config || cp -p $(DESTDIR)$(LIBDIR)/wx/config/$(TOOLCHAIN_FULLNAME) wx-config)
</command>
</action>