Use tagger not commiter in debian/changelog
[mapsector.git] / Makefile
1 ###########################################################################
2 # Standard debian rules
3
4 clean::
5         fakeroot debian/rules clean
6 .PHONY: clean
7
8 prepare::
9 .PHONY: prepare
10
11 deb: prepare
12         dpkg-buildpackage -us -uc -rfakeroot -I.git -I.gitignore -I.gitmodules
13 .PHONY: deb
14
15 ###########################################################################
16 # Generate debian/changelog from git log
17
18 NAME       := $(shell awk '/^Source:/{print $$2}' debian/control)
19 CLOGDIR    := .git/changelogs
20 CHANGELOGS := $(shell lasttag=HEAD;                                             \
21                       (git tag -l 'v*'; echo)                                   \
22                           | while read tag; do                                  \
23                               echo $(CLOGDIR)/$${tag}$${tag:+-}$$lasttag;       \
24                               lasttag=$$tag;                                    \
25                           done)
26
27 # Author/Date formating could as simple as  git log --format=' -- %an <%ae>  %cD'
28 # however, we want the tagger not the author and  git log  doesn't show tags, only commits ...
29 $(CHANGELOGS): %:
30         @echo "generating $@"
31         @mkdir -p "$(CLOGDIR)"
32         @(                                                                                       \
33             version="$@"; version="$${version#$(CLOGDIR)/}";                                     \
34             from="$${version%-*}"; version="$${version#*-}"; to="$$version";                     \
35             if [ "$$from" == "$$to" ]; then from=""; fi;                                         \
36             release="unstable";                                                                  \
37             if [ "$$version" == "HEAD" ]; then                                                   \
38                 version="`git describe --tag --match='v*' | sed -e 's/-/~/' -e 's/-/./g'`";      \
39                 release="UNRELEASED";                                                            \
40             fi;                                                                                  \
41             version="$${version#v}";                                                             \
42             echo "$(NAME) ($$version) $$release; urgency=low";                                   \
43             echo;                                                                                \
44             git log --format='  * [%h] %s' $$from$${from:+..}$$to;                               \
45             date="`echo $$to | git cat-file --batch                                              \
46                        | sed -n                                                                  \
47                              -e 's/^\(tagger\|committer\) \(.*\)00$$/\2/'                        \
48                              -eT -e 'y/+-/-+/' -ep`";                                            \
49             author="$${date% * *}"; date="$${date#$$author }"; zone="$${date#* }";               \
50             date="`TZ="UTC$$zone" date -d "1/1/1970 0:0 UTC + $${date% *} seconds" --rfc-2822`"; \
51             echo; echo " -- $$author  $$date"; echo;                                             \
52         ) >$@ || (rm -f $@; false)
53 .PHONY: $(word 1,$(CHANGELOGS)) # The first changelog entry must be recreated on each call
54
55 debian/changelog: $(CHANGELOGS)
56         cat $^ > $@ || (rm -f $@; false)
57
58 clean::
59         rm -f debian/changelog
60         rm -rf $(CLOGDIR)
61
62 prepare:: debian/changelog
63
64 ###########################################################################
65 ###########################################################################
66
67 prepare::
68         echo "version='`git describe --tag`'" >lib/00_version.sh
69 clean::
70         rm -f lib/00_version.sh
71
72
73 # The $(wildcard ...) return value is sorted and duplicates are
74 # removed from the list of dependencies. I need to mention
75 # lib/00_version.sh explicitly since it might not yet exist
76 mapsectorsh: mapsector lib/00_version.sh $(wildcard lib/[0-9][0-9]_*.sh)
77         @echo "generating $@"
78         @(                                                      \
79             sed -n -e '1p' $<;                                  \
80             echo "#";                                           \
81             echo "# $@ automatically generated from";           \
82             for script in $^; do                                \
83                 echo "#         $$script";                      \
84             done;                                               \
85             sed -n -e '2,/^load$$/p' $<;                        \
86             for script in $^; do                                \
87                 if [ "$$script" == "$<" ]; then continue; fi;   \
88                 echo "#### $$script";                           \
89                 echo;                                           \
90                 cat $$script;                                   \
91                 echo;                                           \
92             done;                                               \
93             sed -n -e '/^load$$/,$$p' $<;                       \
94         ) >$@ || (rm -f $@; false)
95         @sed -i -e 's/^load$$/####/' -eT -eh -eG -eH -eG -eH -eG -e'y/\n/#/' $@
96         chmod ugo+rx $@
97 clean::
98         rm -f mapsectorsh