build: Avoid excessive dep generation on Makefile changes.
[paraslash.git] / version.c
1 /*
2  * Copyright (C) 2013-2014 Andre Noll <maan@tuebingen.mpg.de>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file version.c Some helpers for printing version and copyright strings. */
8
9 #include "para.h"
10 #include "version.h"
11 #include "git-version.h"
12
13 /**
14  * Get the raw git version string
15  *
16  * \return The string generated by the GIT-VERSION-GEN script. It is passed
17  * as a preprocessor define during compilation.
18  */
19 __a_const const char *version_git(void)
20 {
21         return GIT_VERSION;
22 }
23
24 /**
25  * Get the version string for an executable.
26  *
27  * \param pfx The program name (without the leading "para_").
28  *
29  * \return A statically allocated string which contains the program name and
30  * the git version. It must not be freed by the caller.
31  */
32 const char *version_single_line(const char *pfx)
33 {
34         static char buf[100];
35         snprintf(buf, sizeof(buf) - 1,
36                 "para_%s " GIT_VERSION, pfx);
37         return buf;
38 }
39
40 /**
41  * Get the full version text.
42  *
43  * \param pfx See \ref version_single_line().
44  *
45  * \return A string containing the same text as returned by \ref
46  * version_single_line(), augmented by additional build information, a
47  * copyright text and the email address of the author.
48  *
49  * Like \ref version_single_line(), this string is stored in a statically
50  * allocated buffer and must not be freed.
51  */
52 const char *version_text(const char *pfx)
53 {
54         static char buf[512];
55
56         snprintf(buf, sizeof(buf) - 1, "%s\n"
57                 "Copyright (C) 2014 Andre Noll\n"
58                 "This is free software with ABSOLUTELY NO WARRANTY."
59                 " See COPYING for details.\n"
60                 "Report bugs to <maan@tuebingen.mpg.de>.\n"
61                 "build date: " BUILD_DATE ",\n"
62                 "build system: " UNAME_RS ",\n"
63                 "compiler: " CC_VERSION ".\n",
64                 version_single_line(pfx)
65         );
66         return buf;
67 }
68
69 /**
70  * Print the version text and exit successfully.
71  *
72  * \param pfx See \ref version_single_line().
73  * \param flag Whether --version was given.
74  *
75  * If \a flag is false, this function does nothing. Otherwise it prints the
76  * full version text as returned by \ref version_text() and exits successfully.
77  */
78 void version_handle_flag(const char *pfx, bool flag)
79 {
80         if (!flag)
81                 return;
82         printf("%s", version_text(pfx));
83         exit(EXIT_SUCCESS);
84 }