summaryrefslogtreecommitdiff
path: root/Makefile.am
diff options
context:
space:
mode:
authorMathieu Lirzin <mthl@gnu.org>2016-11-12 16:23:00 +0100
committerMathieu Lirzin <mthl@gnu.org>2016-11-12 17:07:57 +0100
commit1e5012ca803bbc4e08982f99d6c902e75dcb4421 (patch)
tree964c405c40890ff7f9becba420eeb8ad6e5707af /Makefile.am
parent12d71ee098c3eb84a9a5dc2419bd37a3b9e55dd2 (diff)
downloadcuirass-1e5012ca803bbc4e08982f99d6c902e75dcb4421.tar
cuirass-1e5012ca803bbc4e08982f99d6c902e75dcb4421.tar.gz
build: Let 'make' generate 'src/cuirass/config.scm'.
* Makefile.am (src/cuirass/config.scm, $(go_files)): New targets. (do_subst, generate_file, go_files): New variables. (EXTRA_DIST): Distribute 'src/cuirass/config.scm.in'. (DISTCLEANFILES): Rename to ... (MOSTLYCLEANFILES): ... this. * configure.ac (AC_CONFIG_FILES): Remove 'src/cuirass/config.scm'. (@expanded_datadir@, @expanded_localstatedir@): Delete. (AC_PROG_MKDIR_P, AC_PROG_SED): Use them. * src/cuirass/config.scm (%datadir): Set it to $(localstatedir). (%localstatdir): Set it to $(datadir).
Diffstat (limited to 'Makefile.am')
-rw-r--r--Makefile.am44
1 files changed, 43 insertions, 1 deletions
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. ##
## -------------- ##