Sometimes you need to do more than just install basic targets. Meson makes this easy by allowing you to specify a custom script to execute at install time. As an example, here is a script that generates an empty file in a custom directory.
Sometimes you need to do more than just install basic targets. Meson
makes this easy by allowing you to specify a custom script to execute
at install time. As an example, here is a script that generates an
As you can see, Meson sets up some environment variables to help you write your script (`DESTDIR` is not set by Meson, it is inherited from the outside environment). In addition to the install prefix, Meson also sets the variables `MESON_SOURCE_ROOT` and `MESON_BUILD_ROOT`.
As you can see, Meson sets up some environment variables to help you
write your script (`DESTDIR` is not set by Meson, it is inherited from
the outside environment). In addition to the install prefix, Meson
also sets the variables `MESON_SOURCE_ROOT` and `MESON_BUILD_ROOT`.
Telling Meson to run this script at install time is a one-liner.
@ -76,12 +85,32 @@ Telling Meson to run this script at install time is a one-liner.
meson.add_install_script('myscript.sh')
```
The argument is the name of the script file relative to the current subdirectory.
The argument is the name of the script file relative to the current
subdirectory.
## DESTDIR support
Sometimes you need to install to a different directory than the install prefix. This is most common when building rpm or deb packages. This is done with the `DESTDIR` environment variable and it is used just like with other build systems:
Sometimes you need to install to a different directory than the
install prefix. This is most common when building rpm or deb
packages. This is done with the `DESTDIR` environment variable and it
is used just like with other build systems:
```console
$ DESTDIR=/path/to/staging/area ninja install
```
## Custom install behaviour
The default install target (executed via, e.g., `ninja install`) does
installing with reasonable default options. More control over the
install behaviour can be achieved with the `meson install` command,
that has been available since 0.47.0.
For example, if you wish to install the current setup without
rebuilding the code (which the default install target always does) and
only installing those files that have changed, you would run this