1 // Copyright (c) 2012-2017 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include <clientversion.h>
7 #include <tinyformat.h>
11 * Name of client reported in the 'version' message. Report the same name
12 * for both bitcoind and bitcoin-qt, to make it harder for attackers to
13 * target servers or GUI users specifically.
15 const std::string
CLIENT_NAME("Satoshi");
18 * Client version number
20 #define CLIENT_VERSION_SUFFIX ""
24 * The following part of the code determines the CLIENT_BUILD variable.
25 * Several mechanisms are used for this:
26 * * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
27 * generated by the build environment, possibly containing the output
28 * of git-describe in a macro called BUILD_DESC
29 * * secondly, if this is an exported version of the code, GIT_ARCHIVE will
30 * be defined (automatically using the export-subst git attribute), and
31 * GIT_COMMIT will contain the commit id.
32 * * then, three options exist for determining CLIENT_BUILD:
33 * * if BUILD_DESC is defined, use that literally (output of git-describe)
34 * * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
35 * * otherwise, use v[maj].[min].[rev].[build]-unk
36 * finally CLIENT_VERSION_SUFFIX is added
39 //! First, include build.h if requested
40 #ifdef HAVE_BUILD_INFO
41 #include <obj/build.h>
44 //! git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$
46 #define GIT_COMMIT_ID "$Format:%h$"
47 #define GIT_COMMIT_DATE "$Format:%cD$"
50 #define BUILD_DESC_WITH_SUFFIX(maj, min, rev, build, suffix) \
51 "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-" DO_STRINGIZE(suffix)
53 #define BUILD_DESC_FROM_COMMIT(maj, min, rev, build, commit) \
54 "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit
56 #define BUILD_DESC_FROM_UNKNOWN(maj, min, rev, build) \
57 "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk"
61 #define BUILD_DESC BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_SUFFIX)
62 #elif defined(GIT_COMMIT_ID)
63 #define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
65 #define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
69 const std::string
CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX
);
71 static std::string
FormatVersion(int nVersion
)
73 if (nVersion
% 100 == 0)
74 return strprintf("%d.%d.%d", nVersion
/ 1000000, (nVersion
/ 10000) % 100, (nVersion
/ 100) % 100);
76 return strprintf("%d.%d.%d.%d", nVersion
/ 1000000, (nVersion
/ 10000) % 100, (nVersion
/ 100) % 100, nVersion
% 100);
79 std::string
FormatFullVersion()
85 * Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki)
87 std::string
FormatSubVersion(const std::string
& name
, int nClientVersion
, const std::vector
<std::string
>& comments
)
89 std::ostringstream ss
;
91 ss
<< name
<< ":" << FormatVersion(nClientVersion
);
92 if (!comments
.empty())
94 std::vector
<std::string
>::const_iterator
it(comments
.begin());
96 for(++it
; it
!= comments
.end(); ++it
)