code
makefile
# specify version id
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
GIT_COMMIT_ID = $(shell git rev-parse --short HEAD)
VERSION_ID = $(GIT_BRANCH)-$(GIT_COMMIT_ID)
MARCOS = -DVERSION_INFO=\"$(VERSION_ID)\"
main.c
#include <stdio.h>
int main(int argc, char** argv)
{
#ifdef VERSION_INFO
printf("VERSION_INFO defined,VERSION_INFO:%s\n", VERSION_INFO);
#else
printf("VERSION_INFO not define\n");
#endif
return 0;
}