From 7cd47ee97084f4ad71a9884049c744243788f717 Mon Sep 17 00:00:00 2001 From: Manuel Domke Date: Thu, 1 Mar 2018 21:57:21 +0100 Subject: [PATCH] added --version for git releases --- software/Makefile | 11 ++++++++++- software/infnoise.c | 11 +++++++++++ software/infnoise.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/software/Makefile b/software/Makefile index 2dde9d7..09fd8b9 100644 --- a/software/Makefile +++ b/software/Makefile @@ -1,6 +1,15 @@ +GIT_VERSION := $(shell git --no-pager describe --tags --always) +GIT_COMMIT := $(shell git rev-parse --verify HEAD) +GIT_DATE := $(firstword $(shell git --no-pager show --date=iso-strict --format="%ad" --name-only)) +BUILD_DATE := $(shell date --iso=seconds) + PREFIX = $(DESTDIR)/usr/local -CFLAGS = -Wall -Wextra -Werror -std=c99 -O3 -I Keccak -I /usr/include/libftdi1 +CFLAGS = -Wall -Wextra -Werror -std=c99 -O3 -I Keccak -I /usr/include/libftdi1 \ + -DGIT_VERSION=\"$(GIT_VERSION)\"\ + -DGIT_COMMIT=\"$(GIT_COMMIT)\"\ + -DGIT_DATE=\"$(GIT_DATE)\"\ + -DBUILD_DATE=\"$(BUILD_DATE)\" FOUND = $(shell ldconfig -p | grep --silent libftdi.so && echo found) ifeq ($(FOUND), found) diff --git a/software/infnoise.c b/software/infnoise.c index 804b1a2..1190c5f 100644 --- a/software/infnoise.c +++ b/software/infnoise.c @@ -299,6 +299,8 @@ int main(int argc, char **argv) opts.daemon = true; } else if(!strcmp(argv[xArg], "--list-devices")) { opts.listDevices = true; + } else if(!strcmp(argv[xArg], "--version")) { + opts.version = true; } else if(!strcmp(argv[xArg], "--help") || !strcmp(argv[xArg], "-h")) { opts.help = true; } else { @@ -320,6 +322,7 @@ int main(int argc, char **argv) " --daemon - run in the background\n" " --serial - use specified device\n" " --list-devices - list available devices\n" + " --version - show version information\n" " --help - this help output\n", stdout); if (opts.none) { return 1; @@ -360,6 +363,14 @@ int main(int argc, char **argv) opts.outputMultiplier = 2u; // Don't throw away entropy when writing to /dev/random unless told to do so } + if (opts.version) { + printf("GIT VERSION - %s\n", GIT_VERSION); + printf("GIT COMMIT - %s\n", GIT_COMMIT); + printf("GIT DATE - %s\n", GIT_DATE); + printf("BUILD DATE - %s\n", BUILD_DATE); + return 0; + } + if (opts.listDevices) { listUSBDevices(&ftdic); return 0; diff --git a/software/infnoise.h b/software/infnoise.h index f5850d6..3646ab5 100644 --- a/software/infnoise.h +++ b/software/infnoise.h @@ -41,6 +41,7 @@ struct opt_struct { bool help; // Show help bool none; // set to true when no valid arguments where detected bool raw; // No whitening? + bool version; // Show version char *pidFileName; // Name of optional PID-file char *serial; // Name of selected device };