From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jan Nieuwenhuizen Newsgroups: gmane.lisp.guile.devel Subject: Re: Relocatable installation Date: Mon, 31 Jan 2011 21:26:53 +0100 Organization: www.AvatarAcademy.nl Message-ID: <1296505613.17905.18.camel@vuurvlieg> References: <1296330082.8111.371.camel@vuurvlieg> <87lj2375k1.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-aIdJmevokS2NcHq2Q0VW" X-Trace: dough.gmane.org 1296505832 19811 80.91.229.12 (31 Jan 2011 20:30:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 31 Jan 2011 20:30:32 +0000 (UTC) Cc: guile-devel@gnu.org To: Ludovic =?ISO-8859-1?Q?Court=E8s?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jan 31 21:30:28 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Pk0OH-0004OX-Va for guile-devel@m.gmane.org; Mon, 31 Jan 2011 21:30:28 +0100 Original-Received: from localhost ([127.0.0.1]:58420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pk0MD-000446-3k for guile-devel@m.gmane.org; Mon, 31 Jan 2011 15:28:17 -0500 Original-Received: from [140.186.70.92] (port=55309 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pk0Lz-00042C-7I for guile-devel@gnu.org; Mon, 31 Jan 2011 15:28:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pk0Ku-0002SB-9k for guile-devel@gnu.org; Mon, 31 Jan 2011 15:26:58 -0500 Original-Received: from smtp-vbr19.xs4all.nl ([194.109.24.39]:4476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pk0Kt-0002Rm-SG; Mon, 31 Jan 2011 15:26:56 -0500 Original-Received: from [192.168.1.112] (peder.onsbrabantnet.nl [88.159.206.46] (may be forged)) (authenticated bits=0) by smtp-vbr19.xs4all.nl (8.13.8/8.13.8) with ESMTP id p0VKQrXr093269; Mon, 31 Jan 2011 21:26:53 +0100 (CET) (envelope-from janneke-list@xs4all.nl) In-Reply-To: <87lj2375k1.fsf@gnu.org> X-Mailer: Evolution 2.30.3 X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-operating-system: by eggs.gnu.org: FreeBSD 4.6-4.9 X-Received-From: 194.109.24.39 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11460 Archived-At: --=-aIdJmevokS2NcHq2Q0VW Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by smtp-vbr19.xs4all.nl id p0VKQrXr093269 Ludovic Court=C3=A8s schreef op za 29-01-2011 om 22:39 [+0100]: Hi Ludovic, > I=E2=80=99m not sure about this patch. My feeling is that it would tak= e more > than this to allow Guile to be truly relocatable, e.g., all of > $GUILE_LOAD_PATH, $GUILE_LOAD_COMPILED_PATH, $LD_LIBRARY_PATH, > etc. would have to work. I realised we need GUILE_LOAD_COMPILED_PATH too. Added that in this new patch. I added a bit more explanation: this should be used together with a sane -rpath $ORIGIN/../lib build. > And some of them are hardcoded in the binary, > as is usual with the GNU Build System. Yes, that's why the new, argv0-based directories are prepended to those paths. > Furthermore, I think all these paths cannot be reliably inferred from > argv[0]. For instance because libdir doesn=E2=80=99t have to be $bindi= r/../lib. > It doesn=E2=80=99t seem to fit well in the GNU software installation pr= ocess. No, you can choose all kinds of freaky install directories. However, if you don't do that and use the normal, default directory structure, this enables binary packages with guile that can be installed in $HOME or on Windows in c:/Program Files/Whatever. > Still I=E2=80=99d be glad to hear arguments for and against. :-) One argument for is that we've been using this in LilyPond binary packages (for linux and windows) since 2005. Greetings, Jan --=20 Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar=C2=AE http://AvatarAcademy.= nl =20 --=-aIdJmevokS2NcHq2Q0VW Content-Disposition: attachment; filename="0001-Add-dynamic-relocation-support-default-off.patch" Content-Type: text/x-patch; name="0001-Add-dynamic-relocation-support-default-off.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From d93b5bd21e99cda017e1b2d7b459e453113fbfa6 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 31 Jan 2011 21:05:48 +0100 Subject: [PATCH] Add dynamic relocation support, default off. Set PATH, GUILE_LOAD_PATH, GUILE_LOAD_COMPILED_PATH according to location of the guile executable. Using this together with -rpath $ORIGIN/../lib and not changing the general installed directory layout, this enables relocatable binary packages, for use in $HOME or for Windows. 2005-06-08 Jan Nieuwenhuizen * configure.in: Add --enable-relocation option. Default off. libguile/ ChangeLog 2005-06-09 Jan Nieuwenhuizen Experimental relocation patch. * load.c (scm_init_argv0_relocation)[ARGV0_RELOCATION]: New function. (scm_init_load_path)[ARGV0_RELOCATION]: Use it. * load.c (scm_c_argv0_relocation)[ARGV0_RELOCATION]: * guile.c (main)[ARGV0_RELOCATION]: Use it to append from executable location derived scm library directory. [__MINGW32__|__CYGWIN__]: Append directory of executable to PATH. --- configure.ac | 12 +++++++++++ libguile/guile.c | 3 ++ libguile/load.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ libguile/load.h | 5 ++++ 4 files changed, 75 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index 5c70aa8..5fa6cf4 100644 --- a/configure.ac +++ b/configure.ac @@ -1452,6 +1452,18 @@ GUILE_THREAD_LOCAL_STORAGE fi # with_threads=pthreads +## Dynamic relocation, based on argv[0]. +reloc_p=no +AC_ARG_ENABLE(relocation, + [ --enable-relocation compile with dynamic relocation. Default: off], + [reloc_p=$enableval]) + +if test "$reloc_p" = "yes"; then + AC_DEFINE([ARGV0_RELOCATION], [1], [Dynamic relocation]) + AC_DEFINE_UNQUOTED([PATH_SEPARATOR], "$PATH_SEPARATOR", [Path separator]) + AC_DEFINE_UNQUOTED([GUILE_EFFECTIVE_VERSION], "$GUILE_EFFECTIVE_VERSION", [GUILE_EFFECTIVE_VERSION]) +fi # $reloc_b + ## Cross building if test "$cross_compiling" = "yes"; then AC_MSG_CHECKING(cc for build) diff --git a/libguile/guile.c b/libguile/guile.c index 6da547b..896adc4 100644 --- a/libguile/guile.c +++ b/libguile/guile.c @@ -67,6 +67,9 @@ inner_main (void *closure SCM_UNUSED, int argc, char **argv) int main (int argc, char **argv) { +#if ARGV0_RELOCATION + scm_c_argv0_relocation (argv[0]); +#endif /* ARGV0_RELOCATION */ scm_boot_guile (argc, argv, inner_main, 0); return 0; /* never reached */ } diff --git a/libguile/load.c b/libguile/load.c index cbf9dc0..9ad1008 100644 --- a/libguile/load.c +++ b/libguile/load.c @@ -234,6 +234,53 @@ SCM_DEFINE (scm_parse_path, "parse-path", 1, 1, 0, } #undef FUNC_NAME +#if ARGV0_RELOCATION +#include "filesys.h" +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include "posix.h" +#endif + +char const *global_argv0 = 0; + +void +scm_c_argv0_relocation (char const *argv0) +{ + global_argv0 = argv0; +} + +SCM +scm_init_argv0_relocation (char const* argv0) +{ + SCM bindir = scm_dirname (scm_from_locale_string (argv0)); + SCM prefix = scm_dirname (bindir); + SCM datadir = scm_string_append (scm_list_2 (prefix, + scm_from_locale_string ("/share/guile/" GUILE_EFFECTIVE_VERSION))); + SCM path; + char *env = getenv ("PATH"); + if (env) + path = scm_string_append (scm_list_3 (bindir, + scm_from_locale_string (env), + scm_from_locale_string (PATH_SEPARATOR))); + else + path = bindir; + scm_putenv (scm_string_append (scm_list_2 (scm_from_locale_string ("PATH="), path))); + + return scm_list_1 (datadir); +} + +SCM +scm_init_argv0_compiled_relocation (char const* argv0) +{ + SCM bindir = scm_dirname (scm_from_locale_string (argv0)); + SCM prefix = scm_dirname (bindir); + SCM pkglibdir = scm_string_append (scm_list_2 (prefix, + scm_from_locale_string ("/lib/guile"))); + SCM ccachedir = scm_string_append (scm_list_2 (pkglibdir, + scm_from_locale_string ("/" GUILE_EFFECTIVE_VERSION "/ccache"))); + + return scm_list_1 (ccachedir); +} +#endif /* ARGV0_RELOCATION */ /* Initialize the global variable %load-path, given the value of the SCM_SITE_DIR and SCM_LIBRARY_DIR preprocessor symbols and the @@ -304,6 +351,14 @@ scm_init_load_path () if (env) cpath = scm_parse_path (scm_from_locale_string (env), cpath); +#if ARGV0_RELOCATION + if (global_argv0) + { + path = scm_append (scm_list_2 (path, scm_init_argv0_relocation (global_argv0))); + cpath = scm_append (scm_list_2 (cpath, scm_init_argv0_compiled_relocation (global_argv0))); + } +#endif /* __CYGWIN__ || __MINGW32__ */ + *scm_loc_load_path = path; *scm_loc_load_compiled_path = cpath; } diff --git a/libguile/load.h b/libguile/load.h index d1afefb..ea29d3a 100644 --- a/libguile/load.h +++ b/libguile/load.h @@ -27,6 +27,11 @@ SCM_API SCM scm_parse_path (SCM path, SCM tail); +#if ARGV0_RELOCATION +SCM_API void scm_c_argv0_relocation (char const *argv0); +SCM_API SCM scm_init_argv0_relocation (char const* argv0); +SCM_API SCM scm_init_argv0_compiled_relocation (char const* argv0); +#endif SCM_API SCM scm_primitive_load (SCM filename); SCM_API SCM scm_c_primitive_load (const char *filename); SCM_API SCM scm_sys_package_data_dir (void); -- 1.7.1 --=-aIdJmevokS2NcHq2Q0VW--