In order to be able to figure out which binary is in use (for example
in debugging situation) it's really helpful to have the 'git describe'
ref added to the binary.
$ .build/nvme --version
nvme version 2.0 (git
2.0-2-gcbd3f8d+)
$ .build/nvme wdc --version
nvme wdc version 1.16.4 (git
2.0-2-gcbd3f8d+)
Signed-off-by: Daniel Wagner <dwagner@suse.de>
--- /dev/null
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+set -eu
+set -o pipefail
+
+dir="${1:?}"
+fallback="${2:?}"
+
+# Apparently git describe has a bug where it always considers the work-tree
+# dirty when invoked with --git-dir (even though 'git status' is happy). Work
+# around this issue by cd-ing to the source directory.
+cd "$dir"
+# Check that we have either .git/ (a normal clone) or a .git file (a work-tree)
+# and that we don't get confused if a tarball is extracted in a higher-level
+# git repository.
+[ -e .git ] && git describe --abbrev=7 --dirty=+ 2>/dev/null | sed 's/^v//' || echo "$fallback"
conf = configuration_data()
requires = ''
+version_tag = get_option('version-tag')
+if version_tag != ''
+ conf.set('GIT_VERSION', '"@0@"'.format(version_tag))
+else
+ r = run_command('meson-vcs-tag.sh',
+ meson.current_source_dir(),
+ meson.project_version(),
+ check: true)
+ conf.set('GIT_VERSION', '"@0@"'.format(r.stdout().strip()))
+endif
+
conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir))
libnvme_dep = dependency('libnvme', fallback : ['libnvme', 'libnvme_dep'])
+option('version-tag', type : 'string', description : 'override the git version string')
option('udevrulesdir', type : 'string', value : 'lib/udev/rules.d', description : 'directory for udev rules files')
option('dracutrulesdir', type : 'string', value : 'lib/dracut/dracut.conf.d/', description : 'directory for dracut rules files')
option('systemddir', type : 'string', value : 'lib/systemd/', description : 'directory for systemd files')
{
struct program *prog = plugin->parent;
- if (plugin->name)
- printf("%s %s version %s\n", prog->name, plugin->name, plugin->version);
- else
- printf("%s version %s\n", prog->name, prog->version);
+ if (plugin->name) {
+ printf("%s %s version %s (git %s)\n",
+ prog->name, plugin->name, plugin->version, GIT_VERSION);
+ } else {
+ printf("%s version %s (git %s)\n",
+ prog->name, prog->version, GIT_VERSION);
+ }
return 0;
}