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