ad1a9fe920c2106c63e94400f0d502f2e98d7a79
[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 $(CHANGELOGS): %:
28         @echo "generating $@"
29         @mkdir -p "$(CLOGDIR)"
30         @(                                                                                      \
31             set -e;                                                                             \
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 --pretty=oneline --abbrev-commit $$from$${from:+..}$$to                     \
44                 | while read commit description; do                                             \
45                     echo "  * [$$commit] $$description";                                        \
46             done;                                                                               \
47             git log --format='%n -- %an <%ae>  %cD%n' $$to'^!';                                 \
48         ) >$@ || (rm -f $@; false)
49 .PHONY: $(word 1,$(CHANGELOGS)) # The first changelog entry must be recreated on each call
50
51 debian/changelog: $(CHANGELOGS)
52         cat $^ > $@ || (rm -f $@; false)
53
54 clean::
55         rm -f debian/changelog
56         rm -rf $(CLOGDIR)
57
58 prepare:: debian/changelog
59
60 ###########################################################################
61 ###########################################################################
62
63 prepare::
64         echo "version='`git describe --tag`'" >lib/00_version.sh
65 clean::
66         rm -f lib/00_version.sh
67
68
69 # The $(wildcard ...) return value is sorted and duplicates are
70 # removed from the list of dependencies. I need to mention
71 # lib/00_version.sh explicitly since it might not yet exist
72 mapsectorsh: mapsector lib/00_version.sh $(wildcard lib/[0-9][0-9]_*.sh)
73         @echo "generating $@"
74         @(                                                      \
75             set -e;                                             \
76             sed -n -e '1p' $<;                                  \
77             echo "#";                                           \
78             echo "# $@ automatically generated from";           \
79             for script in $^; do                                \
80                 echo "#         $$script";                      \
81             done;                                               \
82             sed -n -e '2,/^load$$/p' $<;                        \
83             for script in $^; do                                \
84                 if [ "$$script" == "$<" ]; then continue; fi;   \
85                 echo "#### $$script";                           \
86                 echo;                                           \
87                 cat $$script;                                   \
88                 echo;                                           \
89             done;                                               \
90             sed -n -e '/^load$$/,$$p' $<;                       \
91         ) >$@ || (rm -f $@; false)
92         @sed -i -e 's/^load$$/####/' -eT -eh -eG -eH -eG -eH -eG -e'y/\n/#/' $@
93         chmod ugo+rx $@
94 clean::
95         rm -f mapsectorsh