Improve gitrev handling.

This commit is contained in:
Markus F.X.J. Oberhumer 2016-09-26 13:26:37 +02:00
parent ceddf29586
commit 8bc7880b19
4 changed files with 25 additions and 11 deletions

View File

@ -47,7 +47,7 @@ upx_SOURCES := $(sort $(wildcard $(srcdir)/*.cpp))
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
ifneq ($(wildcard $(top_srcdir)/.git/.),)
UPX_VERSION_GITREV := $(strip $(shell cd '$(top_srcdir)' && git rev-parse --short=6 HEAD || echo 'ERROR'))
UPX_VERSION_GITREV := $(strip $(shell cd '$(top_srcdir)' && git rev-parse --short=12 HEAD || echo 'ERROR'))
ifneq ($(UPX_VERSION_GITREV),)
x := $(strip $(shell cd '$(top_srcdir)' && git diff --exit-code HEAD >/dev/null && echo '' || echo '+'))
DEFS += '-DUPX_VERSION_GITREV="$(UPX_VERSION_GITREV)$(x)"'
@ -128,6 +128,7 @@ else ifeq ($(MAKECMDGOALS),maintainer-clean)
else ifeq ($(MAKECMDGOALS),clang-format)
else
-include .depend
help$(objext): $(MAKEFILE_LIST)
endif

View File

@ -670,6 +670,7 @@ void do_files(int i, int argc, char *argv[]);
// help.cpp
extern const char gitrev[];
void show_head(void);
void show_help(int verbose=0);
void show_license(void);

View File

@ -38,6 +38,12 @@
static bool head_done = 0;
#if defined(UPX_VERSION_GITREV)
const char gitrev[] = UPX_VERSION_GITREV;
#else
const char gitrev[1] = { 0 };
#endif
void show_head(void)
{
FILE *f = con_term;
@ -52,9 +58,15 @@ void show_head(void)
con_fprintf(f,
" Ultimate Packer for eXecutables\n"
" Copyright (C) 1996 - " UPX_VERSION_YEAR "\n"
"UPX %-11s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
#if defined(UPX_VERSION_GITREV)
"git-" UPX_VERSION_GITREV,
"UPX git-%6.6s%c"
#else
"UPX %-11s"
#endif
" Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
#if defined(UPX_VERSION_GITREV)
gitrev,
(sizeof(gitrev)-1 > 6 && gitrev[sizeof(gitrev)-2] == '+') ? '+' : ' ',
#elif (ACC_OS_DOS16 || ACC_OS_DOS32)
V("d"),
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
@ -386,7 +398,7 @@ void show_version(int x)
fprintf(fp, "upx %s\n", UPX_VERSION_STRING
#if defined(UPX_VERSION_GITREV)
"-" UPX_VERSION_GITREV
"-git-" UPX_VERSION_GITREV
#endif
);
#if (WITH_NRV)

View File

@ -1352,11 +1352,12 @@ __acc_static_noinline void upx_sanity_check(void)
assert(strlen(UPX_VERSION_YEAR) == 4);
assert(memcmp(UPX_VERSION_DATE_ISO, UPX_VERSION_YEAR, 4) == 0);
assert(memcmp(&UPX_VERSION_DATE[sizeof(UPX_VERSION_DATE)-1 - 4], UPX_VERSION_YEAR, 4) == 0);
#if defined(UPX_VERSION_GITREV)
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_GITREV) <= 7 + 1)
assert(strlen(UPX_VERSION_GITREV) >= 5);
assert(strlen(UPX_VERSION_GITREV) <= 7);
#endif
if (gitrev[0]) {
size_t revlen = strlen(gitrev);
if (strncmp(gitrev, "ERROR", 5) == 0) { assert(revlen == 5 || revlen == 6); }
else { assert(revlen == 12 || revlen == 13); }
if (revlen == 6 || revlen == 13) { assert(gitrev[revlen-1] == '+'); }
}
#if 1
assert(TestBELE<LE16>::test());
@ -1553,7 +1554,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
set_term(stdout);
do_files(i,argc,argv);
#if 1 && defined(UPX_VERSION_GITREV)
if (gitrev[0])
{
FILE *f = stdout;
int fg = con_fg(f,FG_RED);
@ -1561,7 +1562,6 @@ int __acc_cdecl_main main(int argc, char *argv[])
fg = con_fg(f,fg);
UNUSED(fg);
}
#endif
#if 0 && defined(__GLIBC__)
//malloc_stats();