2 * Copyright (C) 2013-2014 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. */
12 /** \file version.h Macros for printing the version string. */
14 #include "git-version.h"
17 * Get the raw git version string
19 * \return The string generated by the GIT-VERSION-GEN script. It is passed
20 * as a preprocessor define during compilation.
22 __a_const const char *version_git(void)
28 * Get the version string for an executable.
30 * \param pfx The program name (without the leading "para_").
32 * \return A statically allocated string which contains the program name and
33 * the git version. It must not be freed by the caller.
35 const char *version_single_line(const char *pfx)
38 snprintf(buf, sizeof(buf) - 1,
39 "para_%s " GIT_VERSION, pfx);
44 * Get the full version text.
46 * \param pfx See \ref version_single_line().
48 * \return A string containing the same text as returned by \ref
49 * version_single_line(), augmented by additional build information, a
50 * copyright text and the email address of the author.
52 * Like \ref version_single_line(), this string is stored in a statically
53 * allocated buffer and must not be freed.
55 const char *version_text(const char *pfx)
59 snprintf(buf, sizeof(buf) - 1, "%s\n"
60 "Copyright (C) 2014 Andre Noll\n"
61 "This is free software with ABSOLUTELY NO WARRANTY."
62 " See COPYING for details.\n"
63 "Report bugs to <maan@systemlinux.org>.\n"
64 "build date: " BUILD_DATE ",\n"
65 "build system: " UNAME_RS ",\n"
66 "compiler: " CC_VERSION ".\n",
67 version_single_line(pfx)
73 * Print the version text and exit successfully.
75 * \param pfx See \ref version_single_line().
76 * \param flag Whether --version was given.
78 * If \a flag is false, this function does nothing. Otherwise it prints the
79 * full version text as returned by \ref version_text() and exits successfully.
81 void version_handle_flag(const char *pfx, bool flag)
85 printf("%s", version_text(pfx));