]> git.notmuchmail.org Git - notmuch/blob - Makefile.local
build system: use $(filter ...) to test MAKECMDGOALS
[notmuch] / Makefile.local
1 # -*- makefile -*-
2
3 # Here's the (hopefully simple) versioning scheme.
4 #
5 # Releases of notmuch have a two-digit version (0.1, 0.2, etc.). We
6 # increment the second digit for each release and increment the first
7 # digit when we reach particularly major milestones of usability.
8 #
9 # Between releases, (such as when compiling notmuch from the git
10 # repository), we let git append identification of the actual commit.
11 PACKAGE=notmuch
12
13 IS_GIT=$(shell if [ -d .git ] ; then echo yes ; else echo no; fi)
14
15 VERSION:=$(shell cat ${srcdir}/version)
16 ifeq ($filter release release-message pre-release,$(MAKECMDGOALS),)
17 ifeq ($(IS_GIT),yes)
18 VERSION:=$(shell git describe --match '[0-9.]*'|sed -e s/_/~/ -e s/-/+/ -e s/-/~/)
19 endif
20 endif
21
22 UPSTREAM_TAG=$(subst ~,_,$(VERSION))
23 DEB_TAG=debian/$(UPSTREAM_TAG)-1
24
25 RELEASE_HOST=notmuchmail.org
26 RELEASE_DIR=/srv/notmuchmail.org/www/releases
27 RELEASE_URL=http://notmuchmail.org/releases
28 TAR_FILE=$(PACKAGE)-$(VERSION).tar.gz
29 DEB_TAR_FILE=$(PACKAGE)_$(VERSION).orig.tar.gz
30 SHA1_FILE=$(TAR_FILE).sha1
31 GPG_FILE=$(SHA1_FILE).asc
32
33 PV_FILE=bindings/python/notmuch/version.py
34
35 # Smash together user's values with our extra values
36 FINAL_CFLAGS = -DNOTMUCH_VERSION=$(VERSION) $(CFLAGS) $(WARN_CFLAGS) $(CONFIGURE_CFLAGS) $(extra_cflags)
37 FINAL_CXXFLAGS = $(CXXFLAGS) $(WARN_CXXFLAGS) $(CONFIGURE_CXXFLAGS) $(extra_cflags) $(extra_cxxflags)
38 FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)
39 FINAL_NOTMUCH_LINKER = CC
40 ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1)
41 FINAL_NOTMUCH_LDFLAGS += $(CONFIGURE_LDFLAGS)
42 FINAL_NOTMUCH_LINKER = CXX
43 endif
44 ifeq ($(LIBDIR_IN_LDCONFIG),0)
45 FINAL_NOTMUCH_LDFLAGS += $(RPATH_LDFLAGS)
46 endif
47 FINAL_LIBNOTMUCH_LDFLAGS = $(LDFLAGS) $(AS_NEEDED_LDFLAGS) $(CONFIGURE_LDFLAGS)
48
49 .PHONY: all
50 all: notmuch notmuch-shared notmuch.1.gz
51 ifeq ($(MAKECMDGOALS),)
52 ifeq ($(shell cat .first-build-message 2>/dev/null),)
53         @NOTMUCH_FIRST_BUILD=1 $(MAKE) --no-print-directory all
54         @echo ""
55         @echo "Compilation of notmuch is now complete. You can install notmuch with:"
56         @echo ""
57         @echo " make install"
58         @echo ""
59         @echo "Note that depending on the prefix to which you are installing"
60         @echo "you may need root permission (such as \"sudo make install\")."
61         @echo "See \"./configure --help\" for help on setting an alternate prefix."
62         @echo Printed > .first-build-message
63 endif
64 endif
65
66 $(TAR_FILE):
67         if git tag -v $(VERSION) >/dev/null 2>&1; then \
68            ref=$(VERSION); \
69         else \
70            ref="HEAD" ; \
71            echo "Warning: No signed tag for $(VERSION)"; \
72         fi ; \
73         git archive --format=tar --prefix=$(PACKAGE)-$(VERSION)/ $$ref > $(TAR_FILE).tmp
74         echo $(VERSION) > version.tmp
75         tar --append -f $(TAR_FILE).tmp --transform s_^_$(PACKAGE)-$(VERSION)/_  --transform 's_.tmp$$__' version.tmp
76         rm version.tmp
77         gzip < $(TAR_FILE).tmp > $(TAR_FILE)
78         @echo "Source is ready for release in $(TAR_FILE)"
79
80 $(SHA1_FILE): $(TAR_FILE)
81         sha1sum $^ > $@
82
83 $(GPG_FILE): $(SHA1_FILE)
84         @echo "Please enter your GPG password to sign the checksum."
85         gpg --armor --sign $^ 
86
87 .PHONY: dist
88 dist: $(TAR_FILE)
89
90 # We invoke make recursively only to force ordering of our phony
91 # targets in the case of parallel invocation of make (-j).
92 #
93 # We carefully ensure that our VERSION variable is passed down to any
94 # sub-ordinate make invocations (which won't otherwise know that they
95 # are part of the release and need to take the version from the
96 # version file).
97 .PHONY: release
98 release: verify-source-tree-and-version
99         $(MAKE) VERSION=$(VERSION) verify-newer
100         $(MAKE) VERSION=$(VERSION) clean
101         $(MAKE) VERSION=$(VERSION) test
102         git tag -s -m "$(PACKAGE) $(VERSION) release" $(UPSTREAM_TAG)
103         $(MAKE) VERSION=$(VERSION) $(GPG_FILE)
104         ln -sf $(TAR_FILE) $(DEB_TAR_FILE)
105         pristine-tar commit $(DEB_TAR_FILE) $(UPSTREAM_TAG)
106         git tag -s -m "$(PACKAGE) Debian $(VERSION)-1 upload (same as $(VERSION))" $(DEB_TAG)
107         mkdir -p releases
108         mv $(TAR_FILE) $(SHA1_FILE) $(GPG_FILE) releases
109         $(MAKE) VERSION=$(VERSION) release-message > $(PACKAGE)-$(VERSION).announce
110 ifeq ($(REALLY_UPLOAD),yes)
111         git push origin $(VERSION)
112         cd releases && scp $(TAR_FILE) $(SHA1_FILE) $(GPG_FILE) $(RELEASE_HOST):$(RELEASE_DIR)
113         ssh $(RELEASE_HOST) "rm -f $(RELEASE_DIR)/LATEST-$(PACKAGE)-[0-9]* ; ln -s $(TAR_FILE) $(RELEASE_DIR)/LATEST-$(PACKAGE)-$(VERSION)"
114 endif
115         @echo "Please send a release announcement using $(PACKAGE)-$(VERSION).announce as a template."
116
117 .PHONY: pre-release
118 pre-release:
119         $(MAKE) VERSION=$(VERSION) clean
120         $(MAKE) VERSION=$(VERSION) test
121         git tag -s -m "$(PACKAGE) $(VERSION) release" $(UPSTREAM_TAG)
122         git tag -s -m "$(PACKAGE) Debian $(VERSION)-1 upload (same as $(VERSION))" $(DEB_TAG)
123         $(MAKE) VERSION=$(VERSION) $(TAR_FILE)
124         ln -sf $(TAR_FILE) $(DEB_TAR_FILE)
125         pristine-tar commit $(DEB_TAR_FILE) $(UPSTREAM_TAG)
126         mkdir -p releases
127         mv $(TAR_FILE) $(DEB_TAR_FILE) releases
128
129 .PHONY: debian-snapshot
130 debian-snapshot: TMPFILE := $(shell mktemp)
131 debian-snapshot:
132         make VERSION=$(VERSION) clean
133         cp debian/changelog $(TMPFILE)
134         EDITOR=/bin/true dch -v $(VERSION)+1 -D UNRELEASED 'test build, not for upload'
135         echo '3.0 (native)' > debian/source/format
136         debuild -us -uc
137         mv -f $(TMPFILE) debian/changelog
138         echo '3.0 (quilt)' > debian/source/format
139
140 .PHONY: release-message
141 release-message:
142         @echo "To: notmuch@notmuchmail.org"
143         @echo "Subject: $(PACKAGE) release $(VERSION) now available"
144         @echo ""
145         @echo "Where to obtain notmuch $(VERSION)"
146         @echo "==========================="
147         @echo "  $(RELEASE_URL)/$(TAR_FILE)"
148         @echo ""
149         @echo "Which can be verified with:"
150         @echo ""
151         @echo "  $(RELEASE_URL)/$(SHA1_FILE)"
152         @echo -n "  "
153         @cat releases/$(SHA1_FILE)
154         @echo ""
155         @echo "  $(RELEASE_URL)/$(GPG_FILE)"
156         @echo "  (signed by `getent passwd "$$USER" | cut -d: -f 5 | cut -d, -f 1`)"
157         @echo ""
158         @echo "What's new in notmuch $(VERSION)"
159         @echo "========================="
160         @sed -ne '/^[Nn]otmuch $(VERSION)/{n;n;b NEWS}; d; :NEWS /^===/q; {p;n;b NEWS}' < NEWS | head -n -2
161         @echo ""
162         @echo "What is notmuch"
163         @echo "==============="
164         @echo "Notmuch is a system for indexing, searching, reading, and tagging"
165         @echo "large collections of email messages in maildir or mh format. It uses"
166         @echo "the Xapian library to provide fast, full-text search with a convenient"
167         @echo "search syntax."
168         @echo ""
169         @echo "For more about notmuch, see http://notmuchmail.org"
170
171 # This is a chain of dependencies rather than a simple list simply to
172 # avoid the messages getting interleaved in the case of a parallel
173 # make invocation.
174 .PHONY: verify-source-tree-and-version
175 verify-source-tree-and-version: verify-no-dirty-code
176
177 .PHONY: verify-no-dirty-code
178 verify-no-dirty-code: verify-version-debian verify-version-python
179 ifeq ($(IS_GIT),yes)
180         @printf "Checking that source tree is clean..."
181 ifneq ($(shell git ls-files -m),)
182         @echo "No"
183         @echo "The following files have been modified since the most recent git commit:"
184         @echo ""
185         @git ls-files -m
186         @echo ""
187         @echo "The release will be made from the committed state, but perhaps you meant"
188         @echo "to commit this code first? Please clean this up to make it more clear."
189         @false
190 else
191         @echo "Good"
192 endif
193 endif
194
195 .PHONY: verify-version-debian
196 verify-version-debian: verify-version-components
197         @echo -n "Checking that Debian package version is $(VERSION)-1..."
198         @if [ "$(VERSION)-1" != $$(dpkg-parsechangelog | grep ^Version | awk '{print $$2}') ] ; then \
199                 (echo "No." && \
200                  echo "Please edit version and debian/changelog to have consistent versions." && false) \
201          fi
202         @echo "Good."
203
204 .PHONY: verify-version-python
205 verify-version-python: verify-version-components
206         @echo -n "Checking that python bindings version is $(VERSION)..."
207         @if [ "$(VERSION)" != $$(python -c "execfile('$(PV_FILE)'); print __VERSION__") ] ; then \
208                 (echo "No." && \
209                  echo "Please edit version and $(PV_FILE) to have consistent versions." && false) \
210          fi
211         @echo "Good."
212
213 .PHONY: verify-version-components
214 verify-version-components:
215         @echo -n "Checking that $(VERSION) consists only of digits and periods..."
216         @if echo $(VERSION) | grep -q -v -x '[0-9.]*'; then \
217                 (echo "No." && \
218                  echo "Please follow the instructions in RELEASING to choose a version" && false) \
219          else :; fi
220         @echo "Good."
221
222 .PHONY: verify-newer
223 verify-newer:
224         @echo -n "Checking that no $(VERSION) release already exists..."
225         @wget -q -O /dev/null $(RELEASE_URL)/$(TAR_FILE) ; \
226         case $$? in \
227           8) echo "Good." ;; \
228           0) echo "Ouch."; \
229              echo "Found: $(RELEASE_URL)/$(TAR_FILE)"; \
230              echo "Refusing to replace an existing release."; \
231              echo "Don't forget to update \"version\" as described in RELEASING before release." ; \
232              false ;; \
233           *) echo "An unexpected error occured"; \
234              false;; esac
235
236 # The user has not set any verbosity, default to quiet mode and inform the
237 # user how to enable verbose compiles.
238 ifeq ($(V),)
239 quiet_DOC := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n"
240 quiet = @printf $(quiet_DOC)$(eval quiet_DOC:=)"$1 $@\n"; $($(shell echo $1 | sed -e s'/ .*//'))
241 endif
242 # The user has explicitly enabled quiet compilation.
243 ifeq ($(V),0)
244 quiet = @printf "$1 $@\n"; $($(shell echo $1 | sed -e s'/ .*//'))
245 endif
246 # Otherwise, print the full command line.
247 quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))
248
249 %.o: %.cc $(global_deps)
250         $(call quiet,CXX $(CXXFLAGS)) -c $(FINAL_CXXFLAGS) $< -o $@
251
252 %.o: %.c $(global_deps)
253         $(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@
254
255 .deps/%.d: %.c $(global_deps)
256         @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
257         $(CC) -M $(CPPFLAGS) $(FINAL_CFLAGS) $< > $@.$$$$ 2>/dev/null ; \
258         sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \
259         rm -f $@.$$$$
260
261 .deps/%.d: %.cc $(global_deps)
262         @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
263         $(CXX) -M $(CPPFLAGS) $(FINAL_CXXFLAGS) $< > $@.$$$$ 2>/dev/null ; \
264         sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@.$$$$ > $@; \
265         rm -f $@.$$$$
266
267 DEPS := $(SRCS:%.c=.deps/%.d)
268 DEPS := $(DEPS:%.cc=.deps/%.d)
269 -include $(DEPS)
270
271 .PHONY : clean
272 clean:
273         rm -f $(CLEAN); rm -rf .deps
274
275 # We don't (yet) have any distributed files not in the upstream repository.
276 # So distclean is currently identical to clean.
277 .PHONY: distclean
278 distclean: clean
279
280 notmuch_client_srcs =           \
281         debugger.c              \
282         gmime-filter-reply.c    \
283         gmime-filter-headers.c  \
284         notmuch.c               \
285         notmuch-config.c        \
286         notmuch-count.c         \
287         notmuch-dump.c          \
288         notmuch-new.c           \
289         notmuch-reply.c         \
290         notmuch-restore.c       \
291         notmuch-search.c        \
292         notmuch-setup.c         \
293         notmuch-show.c          \
294         notmuch-tag.c           \
295         notmuch-time.c          \
296         query-string.c          \
297         show-message.c          \
298         json.c
299
300 notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
301
302 notmuch: $(notmuch_client_modules) lib/libnotmuch.a util/libutil.a
303         $(call quiet,CXX $(CFLAGS)) $^ $(FINAL_LIBNOTMUCH_LDFLAGS) -o $@
304
305 notmuch-shared: $(notmuch_client_modules) lib/$(LINKER_NAME)
306         $(call quiet,$(FINAL_NOTMUCH_LINKER) $(CFLAGS)) $(notmuch_client_modules) $(FINAL_NOTMUCH_LDFLAGS) -o $@
307
308 notmuch.1.gz: notmuch.1
309         gzip --stdout $^ > $@
310
311 .PHONY: install
312 install: all notmuch.1.gz
313         mkdir -p "$(DESTDIR)$(mandir)/man1"
314         install -m0644 notmuch.1.gz "$(DESTDIR)$(mandir)/man1/"
315         mkdir -p "$(DESTDIR)$(prefix)/bin/"
316         install notmuch-shared "$(DESTDIR)$(prefix)/bin/notmuch"
317 ifeq ($(MAKECMDGOALS), install)
318         @echo ""
319         @echo "Notmuch is now installed to $(DESTDIR)$(prefix)"
320         @echo ""
321         @echo "New users should simply run \"notmuch\" to be guided"
322         @echo "through the process of configuring notmuch and creating"
323         @echo "a database of existing email messages. The \"notmuch\""
324         @echo "command will also offer some sample search commands."
325 ifeq ($(WITH_EMACS), 1)
326         @echo ""
327         @echo "Beyond the command-line interface, notmuch also offers"
328         @echo "a full-featured interface for reading and writing mail"
329         @echo "within emacs. To use this, each user should add the"
330         @echo "following line to the ~/.emacs file:"
331         @echo ""
332         @echo " (require 'notmuch)"
333         @echo ""
334         @echo "And then run emacs as \"emacs -f notmuch\" or invoke"
335         @echo "the command \"M-x notmuch\" from within emacs."
336 endif
337 endif
338
339 .PHONY: install-desktop
340 install-desktop:
341         mkdir -p "$(DESTDIR)$(desktop_dir)"
342         desktop-file-install --mode 0644 --dir "$(DESTDIR)$(desktop_dir)" notmuch.desktop
343
344 SRCS  := $(SRCS) $(notmuch_client_srcs)
345 CLEAN := $(CLEAN) notmuch notmuch-shared $(notmuch_client_modules) notmuch.elc notmuch.1.gz