2
0

Added version into compiled binary.

This commit is contained in:
Maarten Billemont 2017-08-08 00:00:14 -04:00
parent ee50a4d025
commit b1985a2bf2
3 changed files with 25 additions and 8 deletions

View File

@ -85,6 +85,12 @@ extern int mpw_verbosity;
#ifndef ERR #ifndef ERR
#define ERR -1 #define ERR -1
#endif #endif
#ifndef stringify
#define stringify(s) #s
#endif
#ifndef stringify_def
#define stringify_def(s) stringify(s)
#endif
//// Buffers and memory. //// Buffers and memory.

View File

@ -47,6 +47,12 @@ mpw_sodium=${mpw_sodium:-1} # Use libsodium if available instead of cperciva's l
export CFLAGS="-O3 $CFLAGS" export CFLAGS="-O3 $CFLAGS"
export LDFLAGS="$LDFLAGS" export LDFLAGS="$LDFLAGS"
# Version.
if { mpw_version=$(git describe --match '*-cli*' --long --dirty --broken) || mpw_version=$(<VERSION); } 2>/dev/null; then
CFLAGS+=" -DMP_VERSION=$mpw_version"
fi
echo 2>&1 "Building mpw version ${mpw_version:-<unknown>}..."
# Distribution specific configuration. # Distribution specific configuration.
# Homebrew - openssl for scrypt # Homebrew - openssl for scrypt
if hash brew 2>/dev/null; then if hash brew 2>/dev/null; then
@ -144,7 +150,6 @@ fetchSource() (
} }
else else
echo >&2 "error: Missing git-svn or svn." echo >&2 "error: Missing git-svn or svn."
echo >&2 "error: Please install either or manually check out the sources" echo >&2 "error: Please install either or manually check out the sources"
echo >&2 "error: from: $home" echo >&2 "error: from: $home"

View File

@ -16,11 +16,17 @@
#include "mpw-util.h" #include "mpw-util.h"
#include "mpw-marshall.h" #include "mpw-marshall.h"
#define MP_env_fullName "MP_FULLNAME" #ifndef MP_VERSION
#define MP_env_algorithm "MP_ALGORITHM" #define MP_VERSION ?
#endif
#define MP_ENV_fullName "MP_FULLNAME"
#define MP_ENV_algorithm "MP_ALGORITHM"
static void usage() { static void usage() {
inf( ""
" Master Password v%s\n"
" https://masterpasswordapp.com\n\n", stringify_def( MP_VERSION ) );
inf( "" inf( ""
"Usage:\n" "Usage:\n"
" mpw [-u|-U full-name] [-t pw-type] [-c counter] [-a algorithm] [-s value]\n" " mpw [-u|-U full-name] [-t pw-type] [-c counter] [-a algorithm] [-s value]\n"
@ -29,7 +35,7 @@ static void usage() {
" -u full-name Specify the full name of the user.\n" " -u full-name Specify the full name of the user.\n"
" -u checks the master password against the config,\n" " -u checks the master password against the config,\n"
" -U allows updating to a new master password.\n" " -U allows updating to a new master password.\n"
" Defaults to %s in env or prompts.\n\n", MP_env_fullName ); " Defaults to %s in env or prompts.\n\n", MP_ENV_fullName );
inf( "" inf( ""
" -t pw-type Specify the password's template.\n" " -t pw-type Specify the password's template.\n"
" Defaults to 'long' (-p a), 'name' (-p i) or 'phrase' (-p r).\n" " Defaults to 'long' (-p a), 'name' (-p i) or 'phrase' (-p r).\n"
@ -48,7 +54,7 @@ static void usage() {
inf( "" inf( ""
" -a version The algorithm version to use, %d - %d.\n" " -a version The algorithm version to use, %d - %d.\n"
" Defaults to %s in env or %d.\n\n", " Defaults to %s in env or %d.\n\n",
MPAlgorithmVersionFirst, MPAlgorithmVersionLast, MP_env_algorithm, MPAlgorithmVersionCurrent ); MPAlgorithmVersionFirst, MPAlgorithmVersionLast, MP_ENV_algorithm, MPAlgorithmVersionCurrent );
inf( "" inf( ""
" -s value The value to save for -t P or -p i.\n\n" ); " -s value The value to save for -t P or -p i.\n\n" );
inf( "" inf( ""
@ -81,7 +87,7 @@ static void usage() {
" ENVIRONMENT\n\n" " ENVIRONMENT\n\n"
" %-14s | The full name of the user (see -u).\n" " %-14s | The full name of the user (see -u).\n"
" %-14s | The default algorithm version (see -a).\n\n", " %-14s | The default algorithm version (see -a).\n\n",
MP_env_fullName, MP_env_algorithm ); MP_ENV_fullName, MP_ENV_algorithm );
exit( 0 ); exit( 0 );
} }
@ -156,8 +162,8 @@ int main(int argc, char *const argv[]) {
const char *fullNameArg = NULL, *masterPasswordArg = NULL, *siteNameArg = NULL; const char *fullNameArg = NULL, *masterPasswordArg = NULL, *siteNameArg = NULL;
const char *passwordTypeArg = NULL, *siteCounterArg = NULL, *algorithmVersionArg = NULL, *saveValueArg = NULL; const char *passwordTypeArg = NULL, *siteCounterArg = NULL, *algorithmVersionArg = NULL, *saveValueArg = NULL;
const char *keyPurposeArg = NULL, *keyContextArg = NULL, *sitesFormatArg = NULL, *sitesRedactedArg = NULL; const char *keyPurposeArg = NULL, *keyContextArg = NULL, *sitesFormatArg = NULL, *sitesRedactedArg = NULL;
fullNameArg = mpw_getenv( MP_env_fullName ); fullNameArg = mpw_getenv( MP_ENV_fullName );
algorithmVersionArg = mpw_getenv( MP_env_algorithm ); algorithmVersionArg = mpw_getenv( MP_ENV_algorithm );
// Read the command-line options. // Read the command-line options.
for (int opt; (opt = getopt( argc, argv, "u:U:P:t:c:a:s:p:C:f:F:R:vqh" )) != EOF;) for (int opt; (opt = getopt( argc, argv, "u:U:P:t:c:a:s:p:C:f:F:R:vqh" )) != EOF;)