LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2019, 04:01 AM   #1
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
How to add a git revision string when using automake


I was just trying to figure out how to add a git revision string to VERSION. After some searching, I wasn't quite happy with any of the answers so I combined some of what I read into this:

in Makefile.am

Code:
git_rev := $(shell \
if test -f @top_srcdir@/.git/refs/heads/master; then	\
	expr substr `cat @top_srcdir@/.git/refs/heads/master` 1 7;	\
else	\
	echo "unknown";	\
fi)
Add this to your DEFS:

Code:
-DGIT_REV=\"$(git_rev)\"
Probably will want a condition not to append GIT_REV to VERSION when issuing releases though.
 
Old 06-26-2019, 06:24 AM   #2
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,906

Rep: Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026
This is what I like to use.

Code:
$ #  linux tree at tagged release
$ cd /usr/src/linux
$ version=$( git describe 2>/dev/null || git rev-parse HEAD 2>/dev/null || echo 'unknown' )
$ echo $version
v5.1.15
$
$ #  My personal dwm branch, 8 commits past tagged release 
$ cd ~/projects/dwm/
$ version=$( git describe 2>/dev/null || git rev-parse HEAD 2>/dev/null || echo 'unknown' )
$ echo $version
6.0.2-8-g2f4bc6b
$ 
$ # Another project of mine with no tags as yet
$ cd ../xtc
$ version=$( git describe 2>/dev/null || git rev-parse HEAD 2>/dev/null || echo 'unknown' )
$ echo $version
a80500cda681caf5854e9e31cab4d0f8dce0b645
$
You can also add '--short' to git rev-parse if you don't want the full ref, and the '--long' option of git describe will force it to always include the number of commits since the last tag, and the ref, even when HEAD is at that tag.

Last edited by GazL; 06-26-2019 at 06:28 AM.
 
1 members found this post helpful.
Old 07-01-2019, 05:41 PM   #3
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Original Poster
Rep: Reputation: 167Reputation: 167
I'll have to rewrite mine a bit. After I turned -Wall on for the automake options, I get warnings that using ':=' as an assignment operator isn't portable. And on osx, I there are "syntax errors" when encountering the 'expr' command.

My goal is to keep related code out of configure.ac so autoconf wouldn't need to be run whenever the rev changes.

Last edited by Andy Alt; 07-01-2019 at 05:46 PM.
 
  


Reply

Tags
automake, git, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Gitpod git-bolts git-IDE onto GitHub for in-browser code git-editing LXer Syndicated Linux News 0 09-05-2018 04:50 AM
[SOLVED] Create/add a 'Revision needed' Forum (like Intro) for Threads *needing revision/rewrite* (n00bs) !!! LQ Suggestions & Feedback 1 12-20-2017 03:26 PM
[SOLVED] Can't install Git repo (I don't git git ) Nemus Linux - Software 3 05-20-2011 02:09 PM
svn restore directory to a revision also removing files not part of revision Four Linux - Software 1 03-03-2009 04:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration