1 // Copyright (c) 2012-2014 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 #include <boost/preprocessor/arithmetic/add.hpp>
12 #include <boost/preprocessor/arithmetic/sub.hpp>
13 #include <boost/preprocessor/comparison/equal.hpp>
14 #include <boost/preprocessor/comparison/less.hpp>
15 #include <boost/preprocessor/control/if.hpp>
18 * Name of client reported in the 'version' message. Report the same name
19 * for both bitcoind and bitcoin-core, to make it harder for attackers to
20 * target servers or GUI users specifically.
22 const std::string CLIENT_NAME("MagicBean");
25 * Client version number
27 #define CLIENT_VERSION_SUFFIX ""
31 * The following part of the code determines the CLIENT_BUILD variable.
32 * Several mechanisms are used for this:
33 * * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
34 * generated by the build environment, possibly containing the output
35 * of git-describe in a macro called BUILD_DESC
36 * * secondly, if this is an exported version of the code, GIT_ARCHIVE will
37 * be defined (automatically using the export-subst git attribute), and
38 * GIT_COMMIT will contain the commit id.
39 * * then, three options exist for determining CLIENT_BUILD:
40 * * if BUILD_DESC is defined, use that literally (output of git-describe)
41 * * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
42 * * otherwise, use v[maj].[min].[rev].[build]-unk
43 * finally CLIENT_VERSION_SUFFIX is added
46 //! First, include build.h if requested
47 #ifdef HAVE_BUILD_INFO
51 //! git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$
53 #define GIT_COMMIT_ID "$Format:%h$"
54 #define GIT_COMMIT_DATE "$Format:%cD$"
57 #define RENDER_BETA_STRING(num) "-beta" DO_STRINGIZE(num)
58 #define RENDER_RC_STRING(num) "-rc" DO_STRINGIZE(num)
59 #define RENDER_DEV_STRING(num) "-" DO_STRINGIZE(num)
61 #define RENDER_BUILD(build) \
63 BOOST_PP_LESS(build, 25), \
64 RENDER_BETA_STRING(BOOST_PP_ADD(build, 1)), \
66 BOOST_PP_LESS(build, 50), \
67 RENDER_RC_STRING(BOOST_PP_SUB(build, 24)), \
69 BOOST_PP_EQUAL(build, 50), \
71 RENDER_DEV_STRING(BOOST_PP_SUB(build, 50)))))
73 #define BUILD_DESC_WITH_SUFFIX(maj, min, rev, build, suffix) \
74 "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) RENDER_BUILD(build) "-" DO_STRINGIZE(suffix)
76 #define BUILD_DESC_FROM_COMMIT(maj, min, rev, build, commit) \
77 "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) RENDER_BUILD(build) "-g" commit
79 #define BUILD_DESC_FROM_UNKNOWN(maj, min, rev, build) \
80 "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) RENDER_BUILD(build) "-unk"
84 #define BUILD_DESC BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_SUFFIX)
85 #elif defined(GIT_COMMIT_ID)
86 #define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
88 #define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
93 #ifdef GIT_COMMIT_DATE
94 #define BUILD_DATE GIT_COMMIT_DATE
96 #define BUILD_DATE __DATE__ ", " __TIME__
100 const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
101 const std::string CLIENT_DATE(BUILD_DATE);
103 std::string FormatVersion(int nVersion)
105 if (nVersion % 100 < 25)
106 return strprintf("%d.%d.%d-beta%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, (nVersion % 100)+1);
107 if (nVersion % 100 < 50)
108 return strprintf("%d.%d.%d-rc%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, (nVersion % 100)-24);
109 else if (nVersion % 100 == 50)
110 return strprintf("%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100);
112 return strprintf("%d.%d.%d-%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, (nVersion % 100)-50);
115 std::string FormatFullVersion()
121 * Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki)
123 std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
125 std::ostringstream ss;
127 ss << name << ":" << FormatVersion(nClientVersion);
128 if (!comments.empty())
130 std::vector<std::string>::const_iterator it(comments.begin());
132 for(++it; it != comments.end(); ++it)