build: Support VPATH builds.

This allows using 'mcron' before it is installed without hardcoding the
local build environment in the executable.

* build-aux/pre-inst-env.in: New script.
* configure.ac (AC_CONFIG_FILES): Create it.
(AC_CONFIG_HEADER): Add 'config.h'.
(moduledir): New variable.
(PACKAGE_LOAD_PATH): new C preprocessor macro.
* mcron.c: Include "config.h".
(main): Don't overwrite Guile load paths.
(inner_main): Prepend Mcron modules load paths.
* Makefile.am (.scm.go, doc/mcron.1): Use 'pre-inst-env'.
(mcron_CFLAGS): Remove GUILE_LOAD_PATH macro.
(noinst_SCRIPTS): New variable.
* .gitignore: Update.
This commit is contained in:
Mathieu Lirzin 2015-10-17 20:05:08 +02:00
commit 8952d2dc44
5 changed files with 59 additions and 7 deletions

10
mcron.c
View file

@ -22,6 +22,7 @@
is needed because the crontab personality requires SUID which is not
permitted for executable scripts. */
#include "config.h"
#include <libguile.h>
#include <signal.h>
#include <stdlib.h>
@ -35,7 +36,6 @@ static SCM set_cron_signals (void);
int
main (int argc, char **argv)
{
setenv ("GUILE_LOAD_PATH", GUILE_LOAD_PATH, 1);
scm_boot_guile (argc, argv, inner_main, 0);
return EXIT_SUCCESS;
@ -45,6 +45,14 @@ main (int argc, char **argv)
static void
inner_main (void *closure, int argc, char **argv)
{
/* Set Guile load paths to ensure that Mcron modules will be found. */
if (getenv ("MCRON_UNINSTALLED") == NULL)
{
scm_c_eval_string ("(set! %load-path (cons \""
PACKAGE_LOAD_PATH "\" %load-path))");
scm_c_eval_string ("(set! %load-compiled-path (cons \""
PACKAGE_LOAD_PATH "\" %load-compiled-path))");
}
scm_set_current_module (scm_c_resolve_module ("mcron main"));
/* Register set_cron_signals to be called from Guile. */
scm_c_define_gsubr ("c-set-cron-signals", 0, 0, 0, set_cron_signals);