threads / patch / 15034

patch, 2 partsAdd tests for runpath switches in configure

Subject: [PATCH 2/2] Add tests for runpath switches in configure

## tl;dr

2 messages between Aug 16, 2008 and Aug 16, 2008. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Giovanni Funchal· Aug 16, 2008, 13:01 UTC · lore

Most systems (e.g. Linux gcc) use "-Wl,-rpath," to pass to the linker the runtime dynamic library paths. Some other systems (e.g. Sun, some BSD) use "-R" etc. This patch adds tests in configure for the three most common switches (to my best knowledge) which should cover all current platforms where Git is used.

Signed-Off-By: Giovanni Funchal <gafunchal@gmail.com>
---

This second part of this patch follows the idea of Junio that Makefile changes should be minimal, but I think this is better solution because it uses CC_LD_DYNPATH directly instead of NO_R_TO_GCC_LINKER, and thus it is not anymore a matter of "to -R or not to -R".

Note, however, that the current Makefile default is "-R" which is by far not the most common thing. This is left unchanged for backward compatibility. You should probably be defining NO_R_TO_GCC_LINKER or using configure!!

 config.mak.in |    1 +
 configure.ac  |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
Show changes to 2 files +33 −0

config.mak.in, configure.ac

diff --git a/config.mak.in b/config.mak.in
index b776149..467b4aa 100644
--- a/config.mak.in
+++ b/config.mak.in
@@ -3,6 +3,7 @@
 
 CC = @CC@
 CFLAGS = @CFLAGS@
+CC_LD_DYNPATH = @CC_LD_DYNPATH@
 AR = @AR@
 TAR = @TAR@
 #INSTALL = @INSTALL@		# needs install-sh or install.sh in sources
diff --git a/configure.ac b/configure.ac
index 7c2856e..27bab00 100644
--- a/configure.ac
+++ b/configure.ac
@@ -103,6 +103,38 @@ GIT_PARSE_WITH(tcltk))
 AC_MSG_NOTICE([CHECKS for programs])
 #
 AC_PROG_CC([cc gcc])
+# which switch to pass runtime path to dynamic libraries to the linker
+AC_CACHE_CHECK([if linker supports -R], ld_dashr, [
+   SAVE_LDFLAGS="${LDFLAGS}"
+   LDFLAGS="${SAVE_LDFLAGS} -R /"
+   AC_LINK_IFELSE(AC_LANG_PROGRAM([], []), [ld_dashr=yes], [ld_dashr=no])
+   LDFLAGS="${SAVE_LDFLAGS}"
+])
+if test "$ld_dashr" = "yes"; then
+   AC_SUBST(CC_LD_DYNPATH, [-R])
+else
+   AC_CACHE_CHECK([if linker supports -Wl,-rpath,], ld_wl_rpath, [
+      SAVE_LDFLAGS="${LDFLAGS}"
+      LDFLAGS="${SAVE_LDFLAGS} -Wl,-rpath,/"
+      AC_LINK_IFELSE(AC_LANG_PROGRAM([], []), [ld_wl_rpath=yes], [ld_wl_rpath=no])
+      LDFLAGS="${SAVE_LD_FLAGS}"
+   ])
+   if test "$ld_wl_rpath" = "yes"; then
+      AC_SUBST(CC_LD_DYNPATH, [-Wl,-rpath,])
+   else
+      AC_CACHE_CHECK([if linker supports -rpath], ld_rpath, [
+         SAVE_LDFLAGS="${LDFLAGS}"
+         LDFLAGS="${SAVE_LDFLAGS} -rpath /"
+         AC_LINK_IFELSE(AC_LANG_PROGRAM([], []), [ld_rpath=yes], [ld_rpath=no])
+         LDFLAGS="${SAVE_LD_FLAGS}"
+      ])
+      if test "$ld_rpath" = "yes"; then
+         AC_SUBST(CC_LD_DYNPATH, [-rpath])
+      else
+         AC_MSG_WARN([linker does not support runtime path to dynamic libraries])
+      fi
+   fi
+fi
 #AC_PROG_INSTALL		# needs install-sh or install.sh in sources
 AC_CHECK_TOOLS(AR, [gar ar], :)
 AC_CHECK_PROGS(TAR, [gtar tar])
-- 
1.5.4.3
Junio C Hamano· Aug 16, 2008, 19:03 UTC · re: Giovanni Funchal · lore

Re: [PATCH 2/2] Add tests for runpath switches in configure

Giovanni Funchal <gafunchal@gmail.com> writes:
Show 7 quoted lines
> Most systems (e.g. Linux gcc) use "-Wl,-rpath," to pass to the linker the
> runtime dynamic library paths. Some other systems (e.g. Sun, some BSD) use
> "-R" etc. This patch adds tests in configure for the three most common
> switches (to my best knowledge) which should cover all current platforms
> where Git is used.
>
> Signed-Off-By: Giovanni Funchal <gafunchal@gmail.com>

s/O/o/; s/B/b/; (this is not a reason to reject your patch; I am making corrections, just for future reference).

> This second part of this patch follows the idea of Junio that Makefile changes
> should be minimal, but I think this is better solution because it uses
> CC_LD_DYNPATH directly instead of NO_R_TO_GCC_LINKER, and thus it is not
> anymore a matter of "to -R or not to -R".

I do not think I have enough time to make sure to build confidence that the changes to the Makefile won't have any downside that break people's existing setups that use handcrafted config.mak file before the 1.6.0 final. I am very hesitant to take [PATCH 1/2].

I thought it would suffice to autodetect NO_R_TO_GCC_LINKER without changing Makefile at all, which would have had no risk breaking people's existing setups, so plase let me ask you why you went this route.

Is it because you needed to support both styles ("-Wl,-rpath,$path" and "-Wl,-rpath $path"), iow, there are combinations of gcc/gld that you cannot pass -R and need to pass some variant of "-Wl,-rpath", and they won't work if you give "-Wl,-rpath=$(path)" (or "-Wl,-rpath,$(path)" for that matter) as our existing NO_R_TO_GCC_LINKER make variable arranged to do?

← back to recent threads