Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sunday1103/88f12ada649eeb92a237b0cb88df34d1 to your computer and use it in GitHub Desktop.
Save sunday1103/88f12ada649eeb92a237b0cb88df34d1 to your computer and use it in GitHub Desktop.
将git commit信息嵌入可执行文件
#include <stdio.h>
int main()
{
    printf("GIT COMMIT:\n%s\n", GIT_COMMIT);
    return 0;
}
 
include gitinfo.mk
 
export VERSION_INFO LANG
 
CFLAGS+=${VERSION_INFO}
 
all:
    @echo ${GIT_COMMIT}
    @echo ${LANG}
    gcc ${CFLAGS} test.c
GIT_COMMIT:=`git log -1 | xargs`
 
VERSION_INFO=-DGIT_COMMIT="\"$(GIT_COMMIT)\""
 
LANG=zh_CN.UTF-8

注意点:

1、commit内容需要是1行,所以使用xargs讲log输出为一行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment