Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Top-level Makefile for Python
# Top-level Makeile for Python
#
# As distributed, this file is called Makefile.pre.in; it is processed
# into the real Makefile by running the script ./configure, which
Expand Down Expand Up @@ -58,6 +58,9 @@ DTRACE_HEADERS= @DTRACE_HEADERS@
DTRACE_OBJS= @DTRACE_OBJS@
DSYMUTIL= @DSYMUTIL@
DSYMUTIL_PATH= @DSYMUTIL_PATH@
PY_RPATH_EXEC= @PY_RPATH_EXEC@
PY_RPATH_LIB= @PY_RPATH_LIB@
PY_RPATH_MOD= @PY_RPATH_MOD@

GNULD= @GNULD@

Expand Down Expand Up @@ -915,7 +918,8 @@ clinic-tests: check-clean-src $(srcdir)/Lib/test/clinic.test.c

# Build the interpreter
$(BUILDPYTHON): Programs/python.o $(LINK_PYTHON_DEPS)
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) $(PY_RPATH_EXEC) -o $@ Programs/python.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)


platform: $(PYTHON_FOR_BUILD_DEPS) pybuilddir.txt
$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))' >platform
Expand Down Expand Up @@ -945,7 +949,7 @@ $(LIBRARY): $(LIBRARY_OBJS)
$(AR) $(ARFLAGS) $@ $(LIBRARY_OBJS)

libpython$(LDVERSION).so: $(LIBRARY_OBJS) $(DTRACE_OBJS)
$(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM)
$(BLDSHARED) -Wl,-h$(INSTSONAME) $(PY_RPATH_LIB) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM)
if test $(INSTSONAME) != $@; then \
$(LN) -f $(INSTSONAME) $@; \
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Add a new ``--with-relative-rpath`` configure option that sets $ORIGIN-based
RPATHs for Python binaries when enabled. This is a first step towards making
Python installations more relocatable on Linux by allowing shared libraries
to be found relative to their binary locations. Currently Linux-only.
2 changes: 1 addition & 1 deletion Modules/makesetup
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
;;
esac
rule="$file: $objs"
rule="$rule; \$(BLDSHARED) $objs $libs \$(LIBPYTHON) -o $file"
rule="$rule; \$(BLDSHARED) \$(PY_RPATH_MOD) $objs $libs \$(LIBPYTHON) -o $file"
echo "$rule" >>$rulesf
done
done
Expand Down
48 changes: 48 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,38 @@ AC_MSG_RESULT([no])
with_tsan="no"
])

# Check for --with-relative-rpath
AC_MSG_CHECKING([for --with-relative-rpath])
AC_ARG_WITH([relative-rpath],
[AS_HELP_STRING([--with-relative-rpath],
[use relative rpath with $ORIGIN for binaries (Linux only)])],
[], [with_relative_rpath=no])

# Initialize empty RPATH variables
PY_RPATH_EXEC=""
PY_RPATH_LIB=""
PY_RPATH_MOD=""

if test "$with_relative_rpath" = "yes"; then
if test "$ac_sys_system" = "Linux"; then
# Define the RPATH settings for each binary type
PY_RPATH_EXEC="-Wl,-rpath,\\\$\$ORIGIN/../\$(PLATLIBDIR)"
PY_RPATH_LIB="-Wl,-rpath,\\\$\$ORIGIN"
PY_RPATH_MOD="-Wl,-rpath,\\\$\$ORIGIN/../../"
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no - only supported on Linux])
with_relative_rpath=no
fi
else
AC_MSG_RESULT([no])
fi

# Export these variables for the Makefile
AC_SUBST([PY_RPATH_EXEC])
AC_SUBST([PY_RPATH_LIB])
AC_SUBST([PY_RPATH_MOD])

# Set info about shared libraries.
AC_SUBST([SHLIB_SUFFIX])
AC_SUBST([LDSHARED])
Expand Down
Loading