aboutsummaryrefslogtreecommitdiff
path: root/meson
diff options
context:
space:
mode:
authorQyriad <qyriad@qyriad.me>2024-03-21 13:41:23 -0600
committerQyriad <qyriad@qyriad.me>2024-03-22 08:36:50 -0600
commitb4d07656ff2c43b1144eb97658b9528dd39418ce (patch)
treed6aeb04613749884ca328f41bdbab16a4585e17f /meson
parenta7161b6c0f6f9640acc065f0bd18579babacb0cf (diff)
build: optionally build and install with meson
This commit adds several meson.build, which successfully build and install Lix executables, libraries, and headers. Meson does not yet build docs, Perl bindings, or run tests, which will be added in following commits. As such, this commit does not remove the existing build system, or make it the default, and also as such, this commit has several FIXMEs and TODOs as notes for what should be done before the existing autoconf + make buildsystem can be removed and Meson made the default. This commit does not modify any source files. A Meson-enabled build is also added as a Hydra job, and to `nix flake check`. Change-Id: I667c8685b13b7bab91e281053f807a11616ae3d4
Diffstat (limited to 'meson')
-rwxr-xr-xmeson/cleanup-install.bash50
1 files changed, 50 insertions, 0 deletions
diff --git a/meson/cleanup-install.bash b/meson/cleanup-install.bash
new file mode 100755
index 000000000..3e229cbc6
--- /dev/null
+++ b/meson/cleanup-install.bash
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+# Meson will call this with an absolute path to Bash.
+# The shebang is just for convenience.
+
+# The parser and lexer tab are generated via custom Meson targets in src/libexpr/meson.build,
+# but Meson doesn't support marking only part of a target for install. The generation creates
+# both headers (parser-tab.hh, lexer-tab.hh) and source files (parser-tab.cc, lexer-tab.cc),
+# and we definitely want the former installed, but not the latter. This script is added to
+# Meson's install steps to correct this, as the logic for it is just complex enough to
+# warrant separate and careful handling, because both Meson's configured include directory
+# may or may not be an absolute path, and DESTDIR may or may not be set at all, but can't be
+# manipulated in Meson logic.
+
+set -euo pipefail
+
+echo "cleanup-install: removing Meson-placed C++ sources from dest includedir"
+
+if [[ "${1/--help/}" != "$1" ]]; then
+ echo "cleanup-install: this script should only be called from the Meson build system"
+ exit 1
+fi
+
+# Ensure the includedir was passed as the first argument
+# (set -u will make this fail otherwise).
+includedir="$1"
+# And then ensure that first argument is a directory that exists.
+if ! [[ -d "$1" ]]; then
+ echo "cleanup-install: this script should only be called from the Meson build system"
+ echo "argv[1] (${1@Q}) is not a directory"
+ exit 2
+fi
+
+# If DESTDIR environment variable is set, prepend it to the include dir.
+# Unfortunately, we cannot do this on the Meson side. We do have an environment variable
+# `MESON_INSTALL_DESTDIR_PREFIX`, but that will not refer to the include directory if
+# includedir has been set separately, which Lix's split-output derivation does.
+# We also cannot simply do an inline bash conditional like "${DESTDIR:=}" or similar,
+# because we need to specifically *join* DESTDIR and includedir with a slash, and *not*
+# have a slash if DESTDIR isn't set at all, since $includedir could be a relative directory.
+# Finally, DESTDIR is only available to us as an environment variable in these install scripts,
+# not in Meson logic.
+# Therefore, our best option is to have Meson pass this script the configured includedir,
+# and perform this dance with it and $DESTDIR.
+if [[ -n "${DESTDIR:-}" ]]; then
+ includedir="$DESTDIR/$includedir"
+fi
+
+# Intentionally not using -f.
+# If these files don't exist then our assumptions have been violated and we should fail.
+rm -v "$includedir/nix/parser-tab.cc" "$includedir/nix/lexer-tab.cc"