Rombobjörn

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Persson <Bjorn@Rombobjörn.se>2014-02-23 15:28:49 +0100
committerBjörn Persson <Bjorn@Rombobjörn.se>2014-02-23 15:28:49 +0100
commit553cfcce4259cb2a0d622110ad52811d9ab357b6 (patch)
treeb29560a4611223c11d6c4619180dc53fac7905d3
parentb9d89b95bbb1a89842cd9a285390a265157c6779 (diff)
multi-step installation
· Added pre- and post-installation hooks to the installation phase. · No attempt to install staged files is made if the build doesn't stage any files.
-rw-r--r--comfignat.mk48
-rwxr-xr-xmanual.en.html23
2 files changed, 66 insertions, 5 deletions
diff --git a/comfignat.mk b/comfignat.mk
index be030f0..37af018 100644
--- a/comfignat.mk
+++ b/comfignat.mk
@@ -181,8 +181,8 @@ objdir = ${builddir}/obj
stagedir = ${builddir}/stage
# builddir is the build directory, which may be separate from the source tree.
# Intermediate files produced during the build are kept in objdir. Files to be
-# installed are written under stagedir, and then copied to their destination in
-# the installation step.
+# installed are written under stagedir in the build phase, and then copied to
+# their destination in the installation phase.
# Containing makefiles should avoid modifying the directory variables. Users
# should be able to rely on these defaults.
@@ -194,6 +194,12 @@ install_cp_flags = ${if ${DESTDIR},--preserve=timestamps}
# directly to the target system, because that would change the timestamps of
# existing directories.
+do_preinstall = ${if ${DESTDIR},false,true}
+do_postinstall = ${if ${DESTDIR},false,true}
+# Any pre- and post-installation commands that the containing makefile may
+# specify are executed when installation is done directly to the target system,
+# but not when installation is done to a staging directory, because such
+# commands need to be run on the target system, not on a build server.
#
# Containing makefiles may use these variables in their rules, but nothing
@@ -397,6 +403,7 @@ configuration_variables += \
localedir mandir infodir miscdocdir \
objdir stagedir \
install_cp_flags \
+ do_preinstall do_postinstall \
${options}
# configuration_variables is a list of variables that can be saved in the
# persistent configuration with "make configure". Containing makefiles may
@@ -710,11 +717,42 @@ ${make_stagedir}:
# something has been built then "make install" doesn't rebuild anything, just
# copies the built files to their destination.
+.PHONY: preinstall
+preinstall:
+# A recipe may be added to "preinstall" with commands that need to be run
+# before the files are installed when installation is done directly to the
+# target system, but should be skipped when installation is done to a staging
+# directory.
+
# How to install what has been built and staged:
-install: ${make_stagedir}
- mkdir -p "${DESTDIR}/"
- cp -RPf ${install_cp_flags} "${stagedir}"/* "${DESTDIR}/"
+.PHONY: install_stage
+install_stage: ${make_stagedir} ${if ${call checked_true,do_preinstall},preinstall}
+ if [ "`echo "${stagedir}"/*`" != "${stagedir}/*" ]; then \
+ mkdir -p "${DESTDIR}/"; \
+ cp -RPf ${install_cp_flags} "${stagedir}"/* "${DESTDIR}/"; \
+ fi
+# If stagedir doesn't exist, then the rule to make it by running the build is
+# invoked. If stagedir then exists and contains some files (the asterisk gets
+# expanded) then those files are copied recursively to DESTDIR or to the
+# filesystem root.
+
+.PHONY: install_files
+install_files: install_stage
+# A recipe may be added to "install_files" if any files have to be written,
+# deleted or moved after the staged directory tree has been installed. This
+# should be used only for workarounds. It's better to stage all the files
+# correctly under stagedir in the build phase.
+
+.PHONY: postinstall
+postinstall: install_files
+# A recipe may be added to "postinstall" with commands that need to be run
+# after the files are installed when installation is done directly to the
+# target system, but should be skipped when installation is done to a staging
+# directory. This will typically be commands that modify existing files on the
+# target system.
+
.PHONY: install
+install: install_files ${if ${call checked_true,do_postinstall},postinstall}
.PHONY: clean
clean::
diff --git a/manual.en.html b/manual.en.html
index 4d1c780..17f213a 100755
--- a/manual.en.html
+++ b/manual.en.html
@@ -594,6 +594,29 @@ be added as prerequisites.</p></dd>
<dd><p>This preprocesses files that need to be preprocessed before projects are
built.</p></dd>
+<dt><var>postinstall</var></dt>
+<dd><p>You may add a recipe to <var>postinstall</var> if there are commands
+that need to be run on the target system after the files have been installed.
+This will typically be commands that modify existing files on the target
+system. Normally “<samp>make install</samp>” runs <var>postinstall</var> after
+installing the files when <var>DESTDIR</var> is empty, but skips it when a
+directory is specified in <var>DESTDIR</var>, because such commands need to be
+run on the target system, not on a build server. Installing users can override
+this default behaviour by setting <var>do_postinstall</var> to
+“<samp>true</samp>” or “<samp>false</samp>”.</p></dd>
+
+<dt><var>preinstall</var></dt>
+<dd><p>This is like <var>postinstall</var> except that it's run before the
+files are installed, not after. Installing users can control it with
+<var>do_preinstall</var>.</p></dd>
+
+<dt><var>install_files</var></dt>
+<dd><p>You may add a recipe to <var>install_files</var> if any files have to be
+written, deleted or moved after the staged directory tree has been copied.
+Avoid using this if possible. It's better to stage all the files correctly
+under the staging directory in the build phase, but this hook exists if you
+really need it for some workaround.</p></dd>
+
<dt><var>configure</var></dt>
<dd><p>“<samp>make configure</samp>” is used to set values in the
<a href="#configuration">persistent configuration</a> and to set up a