Whitespace fixup ...
[gitdeb.git] / Makefile.gitdeb
1 # -*- makefile -*-
2
3 clean::
4         fakeroot debian/rules clean
5 .PHONY: clean
6
7 prepare::
8 .PHONY: prepare
9
10 deb: prepare
11         dpkg-buildpackage -us -uc -rfakeroot -I.git -I.gitignore -I.gitmodules
12 .PHONY: deb
13
14 ###########################################################################
15 # Generate debian/changelog from git log
16
17 NAME       := $(shell awk '/^Source:/{print $$2}' debian/control)
18 CLOGDIR    := .git/changelogs
19 CHANGELOGS := $(shell lasttag=HEAD;                                             \
20                       (git tag -l 'v*'; echo)                                   \
21                           | while read tag; do                                  \
22                               echo $(CLOGDIR)/$${tag}$${tag:+-}$$lasttag;       \
23                               lasttag=$$tag;                                    \
24                           done)
25
26 # Author/Date formating could be as simple as  git log --format=' -- %an <%ae>  %cD'
27 # however, we want the tagger not the author and  git log  doesn't show tags, only commits ...
28 $(CHANGELOGS): %:
29         @echo "generating $@"
30         @mkdir -p "$(CLOGDIR)"
31         @(                                                                                       \
32             version="$@"; version="$${version#$(CLOGDIR)/}";                                     \
33             from="$${version%-*}"; version="$${version#*-}"; to="$$version";                     \
34             if [ "$$from" = "$$to" ]; then from=""; fi;                                  \
35             release="unstable";                                                                  \
36             if [ "$$version" = "HEAD" ]; then                                                    \
37                 version="`git describe --tag --match='v*' | sed -e 's/-/~/' -e 's/-/./g'`";      \
38                 release="UNRELEASED";                                                            \
39             fi;                                                                                  \
40             version="$${version#v}";                                                             \
41             echo "$(NAME) ($$version) $$release; urgency=low";                                   \
42             echo;                                                                                \
43             git log --format='  * [%h] %s' $$from$${from:+..}$$to;                               \
44             date="`echo $$to | git cat-file --batch                                              \
45                        | sed -n                                                                  \
46                              -e 's/^\(tagger\|committer\) \(.*\)00$$/\2/'                        \
47                              -eT -e 'y/+-/-+/' -ep`";                                            \
48             author="$${date% * *}"; date="$${date#$$author }"; zone="$${date#* }";               \
49             date="`TZ="UTC$$zone" date -d "1/1/1970 0:0 UTC + $${date% *} seconds" --rfc-2822`"; \
50             echo; echo " -- $$author  $$date"; echo;                                             \
51         ) >$@ || (rm -f $@; false)
52 .PHONY: $(word 1,$(CHANGELOGS)) # The first changelog entry must be recreated on each call
53
54 debian/changelog: $(CHANGELOGS)
55         cat $^ > $@ || (rm -f $@; false)
56
57 clean::
58         rm -f debian/changelog
59         rm -rf $(CLOGDIR)
60
61 prepare:: debian/changelog