2 * Copyright (C) 2013 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file version.c Some helpers for printing version and copyright strings. */
11 /** \file version.h Macros for printing the version string. */
13 #include "git-version.h"
16 * Get the raw git version string
18 * \return The string generated by the GIT-VERSION-GEN script. It is passed
19 * as a preprocessor define during compilation.
21 __a_const const char *version_git(void)
27 * Get the version string for an executable.
29 * \param pfx The program name (without the leading "para_").
31 * \return A statically allocated string which contains the program name, the
32 * git version and the codename. It must not be freed by the caller.
34 const char *version_single_line(const char *pfx)
37 snprintf(buf, sizeof(buf) - 1,
38 "para_%s " GIT_VERSION, pfx);
43 * Get the full version text.
45 * \param pfx See \ref version_single_line().
47 * \return A string containing the same text as returned by \ref
48 * version_single_line(), augmented by additional build information, a
49 * copyright text and the email address of the author.
51 * Like \ref version_single_line(), this string is stored in a statically
52 * allocated buffer and must not be freed.
54 const char *version_text(const char *pfx)
58 snprintf(buf, sizeof(buf) - 1, "%s\n"
59 "Copyright (C) 2013 Andre Noll\n"
60 "This is free software with ABSOLUTELY NO WARRANTY."
61 " See COPYING for details.\n"
62 "Report bugs to <maan@systemlinux.org>.\n"
63 "build date: " BUILD_DATE ",\n"
64 "build system: " UNAME_RS ",\n"
65 "compiler: " CC_VERSION ".\n",
66 version_single_line(pfx)
72 * Print the version text and exit successfully.
74 * \param pfx See \ref version_single_line().
75 * \param flag Whether --version was given.
77 * If \a flag is false, this function does nothing. Otherwise it prints the
78 * full version text as returned by \ref version_text() and exits successfully.
80 void version_handle_flag(const char *pfx, bool flag)
84 printf("%s", version_text(pfx));