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