0005-build-check-for-ln-relative.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From c78fa2b40cb8b810d06ef225e30f12a7ed44ffa2 Mon Sep 17 00:00:00 2001
  2. From: "Yann E. MORIN" <yann.morin.1998@free.fr>
  3. Date: Sat, 1 Apr 2017 11:26:29 +0200
  4. Subject: [PATCH] build: check for ln --relative
  5. ln --relative is recent enough that not all distributions support it.
  6. This is especially the case for enterprise-grade distributions than can
  7. have a life-span of more than a decade.
  8. Detect if ln supports --relative and use it if so.
  9. If not supported, use a bit of sed magic to construct the ../ sequence,
  10. that leads back to / when appended to the destination directory.
  11. We introduce this as a macro that expands to a single command. To avoid
  12. complexity in the macro, we expect paths to be passed whitout the
  13. leading DESTDIR.
  14. ---
  15. Upstream status: submitted, disputed:
  16. https://github.com/systemd/systemd/pull/5682
  17. ---
  18. Makefile.am | 25 ++++++++++++++++++++++---
  19. configure.ac | 5 ++++-
  20. 2 files changed, 26 insertions(+), 4 deletions(-)
  21. diff --git a/Makefile.am b/Makefile.am
  22. index 1cc657a..ec503f2 100644
  23. --- a/Makefile.am
  24. +++ b/Makefile.am
  25. @@ -300,6 +300,24 @@ install-busnames-target-wants-hook:
  26. what="$(BUSNAMES_TARGET_WANTS)" && wants=busnames.target && dir=$(systemunitdir) && $(add-wants)
  27. what="$(USER_BUSNAMES_TARGET_WANTS)" && wants=busnames.target && dir=$(userunitdir) && $(add-wants)
  28. +# Macro to emulate ln --relative when needed
  29. +# $(1): options for ln, except --relative
  30. +# $(2): source file, absolute path without leading DESTDIR
  31. +# $(3): destination file, absolute path without leading DESTDIR
  32. +if HAVE_LN_RELATIVE
  33. +define ln-s-relative
  34. + $(LN_S) --relative $(1) \
  35. + $(DESTDIR)$(strip $(2)) \
  36. + $(DESTDIR)$(strip $(3))
  37. +endef
  38. +else
  39. +define ln-s-relative
  40. + $(LN_S) $(1) \
  41. + `dirname $(strip $(3)) |sed -r -e 's:/+[^/]+:../:g; s:/$$::'`$(strip $(2)) \
  42. + $(DESTDIR)$(strip $(3))
  43. +endef
  44. +endif
  45. +
  46. define add-wants
  47. [ -z "$$what" ] || ( \
  48. dir=$(DESTDIR)$$dir/$$wants.wants && \
  49. @@ -313,8 +331,9 @@ install-directories-hook:
  50. $(MKDIR_P) $(addprefix $(DESTDIR),$(INSTALL_DIRS))
  51. install-environment-conf-hook: install-directories-hook
  52. - $(AM_V_LN)$(LN_S) --relative -f $(DESTDIR)$(sysconfdir)/environment \
  53. - $(DESTDIR)$(environmentdir)/99-environment.conf
  54. + $(AM_V_LN)$(call ln-s-relative,-f,\
  55. + $(sysconfdir)/environment,\
  56. + $(environmentdir)/99-environment.conf)
  57. install-aliases-hook:
  58. set -- $(SYSTEM_UNIT_ALIASES) && \
  59. @@ -337,7 +356,7 @@ define install-relative-aliases
  60. while [ -n "$$1" ]; do \
  61. $(MKDIR_P) `dirname $(DESTDIR)$$dir/$$2` && \
  62. rm -f $(DESTDIR)$$dir/$$2 && \
  63. - $(LN_S) --relative $(DESTDIR)$$1 $(DESTDIR)$$dir/$$2 && \
  64. + $(call ln-s-relative,,$$1,$$dir/$$2) && \
  65. shift 2 || exit $$?; \
  66. done
  67. endef
  68. diff --git a/configure.ac b/configure.ac
  69. index cf37ca6..d586fc4 100644
  70. --- a/configure.ac
  71. +++ b/configure.ac
  72. @@ -108,7 +108,10 @@ AC_PATH_PROG([SULOGIN], [sulogin], [/usr/sbin/sulogin], [$PATH:/usr/sbin:/sbin])
  73. AC_PATH_PROG([MOUNT_PATH], [mount], [/usr/bin/mount], [$PATH:/usr/sbin:/sbin])
  74. AC_PATH_PROG([UMOUNT_PATH], [umount], [/usr/bin/umount], [$PATH:/usr/sbin:/sbin])
  75. -AS_IF([! ln --relative --help > /dev/null 2>&1], [AC_MSG_ERROR([*** ln doesn't support --relative ***])])
  76. +AC_MSG_CHECKING([if ln supports --relative])
  77. +AS_IF([! ${LN_S} --relative --help > /dev/null 2>&1], [ln_relative=no], [ln_relative=yes])
  78. +AC_MSG_RESULT([$ln_relative])
  79. +AM_CONDITIONAL([HAVE_LN_RELATIVE], [test "x$ln_relative" = "xyes"])
  80. M4_DEFINES=
  81. --
  82. 2.9.3