赞
踩
C++/C通过Makefile设置宏定义获取git信息并打印
Makefile:(截取部分)
CXXFLAGS := -Wall -Werror -O3 -g -Wunused -Wunreachable-code -Wno-pointer-arith -Wno-unused-parameter -Wno-unused-result -Wno-deprecated -Wno-unused-variable -fPIC -std=c++0x -fno-rtti -g -v CFLAGS := -Wall -Werror -O0 -g -pg -Wno-unused -Wno-unreachable-code -Wno-unused-parameter -Wno-unused-result -Wno-deprecated -fPIC GIT_SHA = $(shell git rev-list HEAD | awk 'NR==1') GIT_SVR_PATH = $(shell git remote -v | awk 'NR==1' | sed 's/[()]//g' | sed 's/\t/ /g' |cut -d " " -f2) GIT_BRANCH = $(shell git branch | sed -n '/\* /s///p') GIT_TAG_LABLE = $(shell git tag --sort=-taggerdate|head -n 1') ifneq ($(GIT_SHA),) CXXFLAGS += -DGIT_COMMIT=\"$(GIT_SHA)\" else CXXFLAGS += -DGIT_COMMIT=\"unknown\" endif CXXFLAGS += -DGIT_PATH=\"$(GIT_SVR_PATH)\" CXXFLAGS += -DGIT_BRANCH=\"$(GIT_BRANCH)\" CXXFLAGS += -DGIT_TAG=\"$(GIT_TAG_LABLE)\"
.c文件
static void printVersionInfo() { #ifdef GIT_PATH HLOGI("**********************************************************************************"); HLOGI("* BuildTime : %s %s", __DATE__, __TIME__); HLOGI("* GitPath : %s", GIT_PATH); HLOGI("* GitBranch : %s", GIT_BRANCH); HLOGI("* GitTag : %s", GIT_TAG); HLOGI("* GitCommit : %s", GIT_COMMIT); HLOGI("* GitVersion : %s", "V1.0.1"); HLOGI("**********************************************************************************"); #else HLOGI("**********************************************************************************"); HLOGI("* BuildTime : %s %s", __DATE__, __TIME__); HLOGI("**********************************************************************************"); #endif }
结果:
END.
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。