Reputation: 13
I'm writing a program C and tracking my source with git.
Every time I run my makefile I need to commit my build. (Yes, I know this isn't an ideal thing to do or 'smart' idea but I have to do this for school.)
How would I commit myprogram to my git repo with the comment of date from my make file? Should I use a shell script instead?
Here is my Makefile below
BUILDID=$(shell date +%Y%m%d-%H:%M:%S)
CFLAGS=-Wall -g
all: myprogram
clean:
rm -f *.o
rm -f myprogram
Upvotes: 1
Views: 3148
Reputation: 467311
There are lots of ways in which doing this doesn't make sense, as you acknowledge in your question. However, assuming that what you want is to make your git repository reflect all the changes in your working tree (apart from ignored files), you could do the following:
.PHONY: all commit
BUILDID=$(shell date +%Y%m%d-%H:%M:%S)
CFLAGS=-Wall -g
all: myprogram commit
commit:
git add -A .
git commit -m 'Automatic commit of successful build $(BUILDID)'
clean:
rm -f *.o
rm -f myprogram
(The .PHONY
is GNU make specific, meaning that its dependencies aren't real targets.)
Upvotes: 1