diff mbox series

[v4,7/7] media-ctl: Add version command

Message ID 20200714055915.640438-7-paul.elder@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series [v4,1/7] configure.ac: Export git commit count | expand

Commit Message

Paul Elder July 14, 2020, 5:59 a.m. UTC
Add a --version option to media-ctl to retrieve the version of
media-ctl.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

---
Changes in v4:
- add git commit count to version

Changes in v3:
- embed PACKAGE_VERSION instead of string concatenation
---
 utils/media-ctl/Makefile.am |  1 +
 utils/media-ctl/options.c   | 14 ++++++++++++++
 utils/media-ctl/options.h   |  2 ++
 3 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/utils/media-ctl/Makefile.am b/utils/media-ctl/Makefile.am
index ee7dcc96..860e6f5a 100644
--- a/utils/media-ctl/Makefile.am
+++ b/utils/media-ctl/Makefile.am
@@ -27,3 +27,4 @@  noinst_HEADERS = mediactl.h v4l2subdev.h
 bin_PROGRAMS = media-ctl
 media_ctl_SOURCES = media-ctl.c options.c options.h tools.h
 media_ctl_LDADD = libmediactl.la libv4l2subdev.la
+media_ctl_CFLAGS = $(GIT_COMMIT_CNT)
diff --git a/utils/media-ctl/options.c b/utils/media-ctl/options.c
index fb923775..55376323 100644
--- a/utils/media-ctl/options.c
+++ b/utils/media-ctl/options.c
@@ -42,6 +42,13 @@  struct media_options media_opts = {
 	.devname = MEDIA_DEVNAME_DEFAULT,
 };
 
+static void print_version()
+{
+#define STR(x) #x
+#define STRING(x) STR(x)
+	printf("media-ctl %s%s\n", PACKAGE_VERSION, STRING(GIT_COMMIT_CNT));
+}
+
 static void usage(const char *argv0)
 {
 	unsigned int i;
@@ -66,6 +73,7 @@  static void usage(const char *argv0)
 	printf("    --print-dot		Print the device topology as a dot graph\n");
 	printf("-r, --reset		Reset all links to inactive\n");
 	printf("-v, --verbose		Be verbose\n");
+	printf("    --version		Show version information\n");
 	printf("\n");
 	printf("Links and formats are defined as\n");
 	printf("\tlinks           = link { ',' link } ;\n");
@@ -127,6 +135,7 @@  static void usage(const char *argv0)
 #define OPT_SET_DV			258
 #define OPT_LIST_KNOWN_MBUS_FMTS	259
 #define OPT_GET_DV			260
+#define OPT_VERSION			261
 
 static struct option opts[] = {
 	{"device", 1, 0, 'd'},
@@ -145,6 +154,7 @@  static struct option opts[] = {
 	{"print-topology", 0, 0, 'p'},
 	{"reset", 0, 0, 'r'},
 	{"verbose", 0, 0, 'v'},
+	{"version", 0, 0, OPT_VERSION},
 	{ },
 };
 
@@ -287,6 +297,10 @@  int parse_cmdline(int argc, char **argv)
 			list_known_mbus_formats();
 			exit(0);
 
+		case OPT_VERSION:
+			print_version();
+			exit(0);
+
 		default:
 			printf("Invalid option -%c\n", opt);
 			printf("Run %s -h for help.\n", argv[0]);
diff --git a/utils/media-ctl/options.h b/utils/media-ctl/options.h
index 7e0556fc..b1751f56 100644
--- a/utils/media-ctl/options.h
+++ b/utils/media-ctl/options.h
@@ -22,6 +22,8 @@ 
 #ifndef __OPTIONS_H
 #define __OPTIONS_H
 
+#include <config.h>
+
 struct media_options
 {
 	const char *devname;