Skip to content

Commit

Permalink
Added some version magic.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Sep 26, 2009
1 parent 7ba2a87 commit e35aa01
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
@@ -1,6 +1,18 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(FatELF)

EXECUTE_PROCESS(
COMMAND hg tip --template hg-{rev}:{node|short}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE HGVERSION_RC
OUTPUT_VARIABLE FATELF_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)

ADD_DEFINITIONS(-DAPPID=fatelf)
ADD_DEFINITIONS(-DAPPREV="${FATELF_VERSION}")

INCLUDE_DIRECTORIES(include)
ADD_DEFINITIONS(-Wall -Werror)

Expand Down
59 changes: 59 additions & 0 deletions utils/fatelf-utils.c
Expand Up @@ -14,6 +14,60 @@
const char *unlink_on_xfail = NULL;
static uint8_t zerobuf[4096];


#ifndef APPID
#define APPID fatelf
#endif

#ifndef APPREV
#define APPREV "???"
#endif

#if (defined __GNUC__)
# define VERSTR2(x) #x
# define VERSTR(x) VERSTR2(x)
# define COMPILERVER " " VERSTR(__GNUC__) "." VERSTR(__GNUC_MINOR__) "." VERSTR(__GNUC_PATCHLEVEL__)
#elif (defined __SUNPRO_C)
# define VERSTR2(x) #x
# define VERSTR(x) VERSTR2(x)
# define COMPILERVER " " VERSTR(__SUNPRO_C)
#elif (defined __VERSION__)
# define COMPILERVER " " __VERSION__
#else
# define COMPILERVER ""
#endif

#ifndef __DATE__
#define __DATE__ "(Unknown build date)"
#endif

#ifndef __TIME__
#define __TIME__ "(Unknown build time)"
#endif

#ifndef COMPILER
#if (defined __GNUC__)
#define COMPILER "GCC"
#elif (defined _MSC_VER)
#define COMPILER "Visual Studio"
#elif (defined __SUNPRO_C)
#define COMPILER "Sun Studio"
#else
#error Please define your platform.
#endif
#endif

// macro mess so we can turn APPID and APPREV into a string literal...
#define MAKEBUILDVERSTRINGLITERAL2(id, rev) \
#id ", revision " rev ", built " __DATE__ " " __TIME__ \
", by " COMPILER COMPILERVER

#define MAKEBUILDVERSTRINGLITERAL(id, rev) MAKEBUILDVERSTRINGLITERAL2(id, rev)

const char *fatelf_build_version = MAKEBUILDVERSTRINGLITERAL(APPID, APPREV);



// Report an error to stderr and terminate immediately with exit(1).
void xfail(const char *fmt, ...)
{
Expand Down Expand Up @@ -811,6 +865,11 @@ const char *fatelf_get_target_string(const FATELF_record *rec, const int wants)
void xfatelf_init(int argc, const char **argv)
{
memset(zerobuf, '\0', sizeof (zerobuf)); // just in case.
if ((argc >= 2) && (strcmp(argv[1], "--version") == 0))
{
printf("%s\n", fatelf_build_version);
exit(0);
} // if
} // xfatelf_init

// end of fatelf-utils.c ...
Expand Down
1 change: 1 addition & 0 deletions utils/fatelf-utils.h
Expand Up @@ -25,6 +25,7 @@
#endif

extern const char *unlink_on_xfail;
extern const char *fatelf_build_version;

#define FATELF_WANT_MACHINE (1 << 0)
#define FATELF_WANT_OSABI (1 << 1)
Expand Down

0 comments on commit e35aa01

Please sign in to comment.