From b93fe31f7e0cde00b42e205f02d992674142633f Mon Sep 17 00:00:00 2001 From: David Seguin Date: Sun, 17 Jun 2018 21:13:26 -0400 Subject: [PATCH] Integrate version number into makefile (fixes #6) Running with --version relied on having a VERSION file in current directory. Having the version number in the makefile ensures it is built into the binary so that --version works all the time. --- Makefile | 4 +++- VERSION | 1 - src/ttysolitaire.c | 17 +++++------------ 3 files changed, 8 insertions(+), 14 deletions(-) delete mode 100644 VERSION diff --git a/Makefile b/Makefile index c17ccda..5440039 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ +VERSION = 1.0.0 + CC = gcc -CFLAGS = -W -Wall -pedantic -ansi -std=c99 -g +CFLAGS = -W -Wall -pedantic -ansi -std=c99 -g -DTS_VERSION=\"$(VERSION)\" LDFLAGS = -lncursesw diff --git a/VERSION b/VERSION deleted file mode 100644 index 3eefcb9..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.0.0 diff --git a/src/ttysolitaire.c b/src/ttysolitaire.c index b7091a1..cbc5442 100644 --- a/src/ttysolitaire.c +++ b/src/ttysolitaire.c @@ -8,6 +8,10 @@ #include "keyboard.h" #include "common.h" +#ifndef TS_VERSION +#define TS_VERSION "n/a" +#endif + const char *program_name; struct game game; @@ -123,16 +127,5 @@ void usage(const char *program_name) { } void version() { - FILE *version_file; - char version_string[6]; - - if (!(version_file = fopen("VERSION", "rb"))) { - tty_solitaire_generic_error(errno, __FILE__, __LINE__); - } - if (!fread(version_string, 1, 5, version_file)) { - // TODO: handle this. - } - version_string[5] = '\0'; - printf("%s\n", version_string); - fclose(version_file); + printf("%s\n", TS_VERSION); }