如何添加修订和建立日期来源? [英] How do I add revision and build date to source?

查看:123
本文介绍了如何添加修订和建立日期来源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GCC项目,并愿意自动生成日期和版本编号(GIT)定义添加到我的消息来源。什么是做到这一点的最好方法是什么?

I have a GCC project and would like to automatically add defines for build date and revision number (from git) to my sources. What's the best way to do this?

我的目标很简单,能够做这样的事在启动:

My goal is simple to be able to do something like this on startup:

printf("Test app build on %s, revision %d", BUILD_DATE, REVISION)

有关构建我使用做一个简单的Makefile.inc,不是的autoconf或者这样的事。

For building I'm using make with a simple Makefile.inc, not autoconf or anything like this.

推荐答案

最后我用一个简单的命令像这样在我的的Makefile

I ended up using a simple command like this in my Makefile:

echo "#define GIT_REF \"`git show-ref refs/heads/master | cut -d " " -f 1 | cut -c 31-40`\"" > git_ref.h

这篇关于如何添加修订和建立日期来源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆