Skip to content

Commit be6475b

Browse files
landstander668dscho
authored andcommitted
Preliminary support for reporting build platform
Add preliminary support for detection of the build plaform, and reporting of same with the `git version --build-options' command. This can be useful for bug reporting, to distinguish between 32 and 64-bit builds for example. The current implementation can only distinguish between x86 and x86_64. This will be extended in future patches. In addition, all 32-bit variants (i686, i586, etc.) are collapsed into `x86'. An example of the output is: $ git version --build-options git version 2.9.3.windows.2.826.g06c0f2f sizeof-long: 4 machine: x86_64 The label of `machine' was chosen so the new information will approximate the output of `uname -m'. Signed-off-by: Adric Norris <[email protected]>
1 parent 489cb6f commit be6475b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

help.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ const char *help_unknown_cmd(const char *cmd)
423423

424424
int cmd_version(int argc, const char **argv, const char *prefix)
425425
{
426+
static char build_platform[] = GIT_BUILD_PLATFORM;
427+
426428
/*
427429
* The format of this string should be kept stable for compatibility
428430
* with external projects that rely on the output of "git version".
@@ -431,6 +433,7 @@ int cmd_version(int argc, const char **argv, const char *prefix)
431433
while (*++argv) {
432434
if (!strcmp(*argv, "--build-options")) {
433435
printf("sizeof-long: %d\n", (int)sizeof(long));
436+
printf("machine: %s\n", build_platform);
434437
/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
435438
}
436439
}

help.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,16 @@ extern void list_commands(unsigned int colopts, struct cmdnames *main_cmds, stru
3333
*/
3434
extern void help_unknown_ref(const char *ref, const char *cmd, const char *error);
3535
#endif /* HELP_H */
36+
37+
/*
38+
* identify build platform
39+
*/
40+
#ifndef GIT_BUILD_PLATFORM
41+
#if defined __x86__ || defined __i386__ || defined __i586__ || defined __i686__
42+
#define GIT_BUILD_PLATFORM "x86";
43+
#elif defined __x86_64__
44+
#define GIT_BUILD_PLATFORM "x86_64";
45+
#else
46+
#define GIT_BUILD_PLATFORM "unknown";
47+
#endif
48+
#endif

0 commit comments

Comments
 (0)