diff --git a/Makefile.am b/Makefile.am index d4ef8a0..cde4f67 100644 --- a/Makefile.am +++ b/Makefile.am @@ -86,18 +86,60 @@ sql-check: src/schema.sql EXTRA_DIST = \ .dir-locals.el \ bootstrap \ + src/cuirass/config.scm.in \ tests/gnu-system.scm \ tests/guix-jobs.scm \ tests/hello-singleton.scm \ tests/hello-subset.scm \ $(TESTS) -DISTCLEANFILES = src/cuirass/config.scm +MOSTLYCLEANFILES = src/cuirass/config.scm CLEANFILES = \ $(nodist_guilesite_DATA) \ $(dist_pkgmodule_DATA:%.scm=%.go) \ src/cuirass/config.go +## ----------------- ## +## Generated files. ## +## ----------------- ## + +# 'AC_CONFIG_FILES' doesn't fully expand variables that depend on ${prefix}. +# To use such variables in source files and scripts while following GNU Coding +# Standards, let 'make' manage their replacement. + +# Use config.status to substitute the remainder where a single expansion is +# sufficient. We use a funny notation here to avoid configure substitutions +# in our text. +do_subst = ( $(SED) \ + -e "s,@configure_input[@],Generated from $$in. Do not edit by hand.,g" \ + -e 's,@datadir[@],$(datadir),g' \ + -e 's,@localstatedir[@],$(localstatedir),g' \ + | $(SHELL) ./config.status --file=- ) + +# Generic instructions to perform the substitution. Generated files shouldn't +# contain unexpanded '@substitutions@', and should be made read-only, to +# prevent them from being edited by mistake instead of the file the are +# generated from. +generate_file = \ + $(AM_V_GEN)rm -f $@ $@-t; \ + $(MKDIR_P) $(@D); \ + in=$@.in && $(do_subst) <$(srcdir)/$$in >$@-t; \ + if LC_ALL=C grep '@[a-zA-Z0-9_][a-zA-Z0-9_]*@' $@-t; then \ + echo "$@ contains unexpanded substitution (see lines above)"; \ + exit 1; \ + fi; \ + chmod a-w $@-t; mv -f $@-t $@ + +# This file depends on Makefile so it is rebuilt if $(VERSION), +# $(datadir) or other do_subst'ituted variables change. +src/cuirass/config.scm: $(srcdir)/src/cuirass/config.scm.in Makefile + $(generate_file) + +# Guile modules require 'src/cuirass/config.scm' to exist before being +# compiled. +go_files = $(nodist_guilesite_DATA) $(dist_pkgmodule_DATA:%.scm=%.go) +$(go_files): src/cuirass/config.scm + ## -------------- ## ## Silent rules. ## ## -------------- ## diff --git a/configure.ac b/configure.ac index fb82829..ce246fa 100644 --- a/configure.ac +++ b/configure.ac @@ -8,14 +8,8 @@ AM_INIT_AUTOMAKE([foreign subdir-objects -Wall]) AM_SILENT_RULES([yes]) # enables silent rules by default AC_CANONICAL_HOST - -# Prepare a version of installation directories that does not contain -# references to shell variables. -expanded_prefix="`eval echo $prefix | sed -e "s|NONE|/usr/local|g"`" -AC_SUBST([expanded_datadir], - [`eval echo $datarootdir | sed -e "s|NONE|$expanded_prefix|g"`]) -AC_SUBST([expanded_localstatedir], - [`eval echo $localstatedir | sed -e "s|NONE|$expanded_prefix|g"`]) +AC_PROG_MKDIR_P +AC_PROG_SED PKG_CHECK_MODULES([GUILE], [guile-2.0 >= 2.0.7]) AC_PATH_PROG([GUILE], [guile]) @@ -27,8 +21,7 @@ GUILE_MODULE_REQUIRED([guix]) GUILE_MODULE_REQUIRED([json]) GUILE_MODULE_REQUIRED([sqlite3]) -AC_CONFIG_FILES([Makefile - src/cuirass/config.scm]) +AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([bin/cuirass], [chmod +x bin/cuirass]) AC_CONFIG_FILES([bin/evaluate], [chmod +x bin/evaluate]) AC_CONFIG_FILES([pre-inst-env:build-aux/pre-inst-env.in], diff --git a/src/cuirass/config.scm.in b/src/cuirass/config.scm.in index b8f4ae3..9ae99ab 100644 --- a/src/cuirass/config.scm.in +++ b/src/cuirass/config.scm.in @@ -1,4 +1,5 @@ -;;; config.scm -- variables defined at configure time +;;;; config.scm -- constants defined by the build system. +;;; @configure_input@ ;;; Copyright © 2016 Mathieu Lirzin ;;; ;;; This file is part of Cuirass. @@ -48,8 +49,8 @@ (define-public %datadir ;; Define to DATADIR without reference to '${prefix}'. - "@expanded_datadir@") + "@datadir@") (define-public %localstatedir ;; Define to LOCALSTATEDIR without reference to '${prefix}'. - "@expanded_localstatedir@") + "@localstatedir@")