From 553cfcce4259cb2a0d622110ad52811d9ab357b6 Mon Sep 17 00:00:00 2001 From: Björn Persson Date: Sun, 23 Feb 2014 15:28:49 +0100 Subject: multi-step installation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit · 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. --- comfignat.mk | 48 +++++++++++++++++++++++++++++++++++++++++++----- manual.en.html | 23 +++++++++++++++++++++++ 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.

This preprocesses files that need to be preprocessed before projects are built.

+
postinstall
+

You may add a recipe to postinstall 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 “make install” runs postinstall after +installing the files when DESTDIR is empty, but skips it when a +directory is specified in DESTDIR, 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 do_postinstall to +“true” or “false”.

+ +
preinstall
+

This is like postinstall except that it's run before the +files are installed, not after. Installing users can control it with +do_preinstall.

+ +
install_files
+

You may add a recipe to install_files 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.

+
configure

make configure” is used to set values in the persistent configuration and to set up a -- cgit v1.2.3