Skip to content

Commit 798a945

Browse files
funchalgitster
authored andcommitted
configure: auto detect dynamic library path switches
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f5b904d commit 798a945

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

config.mak.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
CC = @CC@
55
CFLAGS = @CFLAGS@
6+
CC_LD_DYNPATH = @CC_LD_DYNPATH@
67
AR = @AR@
78
TAR = @TAR@
89
#INSTALL = @INSTALL@ # needs install-sh or install.sh in sources

configure.ac

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,38 @@ GIT_PARSE_WITH(tcltk))
103103
AC_MSG_NOTICE([CHECKS for programs])
104104
#
105105
AC_PROG_CC([cc gcc])
106+
# which switch to pass runtime path to dynamic libraries to the linker
107+
AC_CACHE_CHECK([if linker supports -R], ld_dashr, [
108+
SAVE_LDFLAGS="${LDFLAGS}"
109+
LDFLAGS="${SAVE_LDFLAGS} -R /"
110+
AC_LINK_IFELSE(AC_LANG_PROGRAM([], []), [ld_dashr=yes], [ld_dashr=no])
111+
LDFLAGS="${SAVE_LDFLAGS}"
112+
])
113+
if test "$ld_dashr" = "yes"; then
114+
AC_SUBST(CC_LD_DYNPATH, [-R])
115+
else
116+
AC_CACHE_CHECK([if linker supports -Wl,-rpath,], ld_wl_rpath, [
117+
SAVE_LDFLAGS="${LDFLAGS}"
118+
LDFLAGS="${SAVE_LDFLAGS} -Wl,-rpath,/"
119+
AC_LINK_IFELSE(AC_LANG_PROGRAM([], []), [ld_wl_rpath=yes], [ld_wl_rpath=no])
120+
LDFLAGS="${SAVE_LD_FLAGS}"
121+
])
122+
if test "$ld_wl_rpath" = "yes"; then
123+
AC_SUBST(CC_LD_DYNPATH, [-Wl,-rpath,])
124+
else
125+
AC_CACHE_CHECK([if linker supports -rpath], ld_rpath, [
126+
SAVE_LDFLAGS="${LDFLAGS}"
127+
LDFLAGS="${SAVE_LDFLAGS} -rpath /"
128+
AC_LINK_IFELSE(AC_LANG_PROGRAM([], []), [ld_rpath=yes], [ld_rpath=no])
129+
LDFLAGS="${SAVE_LD_FLAGS}"
130+
])
131+
if test "$ld_rpath" = "yes"; then
132+
AC_SUBST(CC_LD_DYNPATH, [-rpath])
133+
else
134+
AC_MSG_WARN([linker does not support runtime path to dynamic libraries])
135+
fi
136+
fi
137+
fi
106138
#AC_PROG_INSTALL # needs install-sh or install.sh in sources
107139
AC_CHECK_TOOLS(AR, [gar ar], :)
108140
AC_CHECK_PROGS(TAR, [gtar tar])

0 commit comments

Comments
 (0)