d36fd5a0678e7cf11cebe13d565feb4520e71d16
[notmuch] / lib / Makefile.local
1 # -*- makefile -*-
2
3 ifeq ($(PLATFORM),MACOSX)
4 LIBRARY_SUFFIX = dylib
5 # On OS X, library version numbers go before suffix.
6 LINKER_NAME = libnotmuch.$(LIBRARY_SUFFIX)
7 SONAME = libnotmuch.$(LIBNOTMUCH_VERSION_MAJOR).$(LIBRARY_SUFFIX)
8 LIBNAME = libnotmuch.$(LIBNOTMUCH_VERSION_MAJOR).$(LIBNOTMUCH_VERSION_MINOR).$(LIBNOTMUCH_VERSION_RELEASE).$(LIBRARY_SUFFIX)
9 LIBRARY_LINK_FLAG = -dynamiclib -install_name $(libdir)/$(SONAME) -compatibility_version $(LIBNOTMUCH_VERSION_MAJOR).$(LIBNOTMUCH_VERSION_MINOR) -current_version $(LIBNOTMUCH_VERSION_MAJOR).$(LIBNOTMUCH_VERSION_MINOR).$(LIBNOTMUCH_VERSION_RELEASE)
10 else
11 LIBRARY_SUFFIX = so
12 LINKER_NAME = libnotmuch.$(LIBRARY_SUFFIX)
13 SONAME = $(LINKER_NAME).$(LIBNOTMUCH_VERSION_MAJOR)
14 LIBNAME = $(SONAME).$(LIBNOTMUCH_VERSION_MINOR).$(LIBNOTMUCH_VERSION_RELEASE)
15 LIBRARY_LINK_FLAG = -shared -Wl,--version-script=notmuch.sym,-soname=$(SONAME) $(NO_UNDEFINED_LDFLAGS)
16 ifeq ($(PLATFORM),OPENBSD)
17 LIBRARY_LINK_FLAG += -lc
18 endif
19 ifeq ($(LIBDIR_IN_LDCONFIG),1)
20 ifeq ($(DESTDIR),)
21 LIBRARY_INSTALL_POST_COMMAND=ldconfig
22 endif
23 endif
24 endif
25
26 dir := lib
27 extra_cflags += -I$(srcdir)/$(dir) -fPIC
28
29 # The (often-reused) $dir works fine within targets/prerequisites,
30 # but cannot be used reliably within commands, so copy its value to a
31 # variable that is not reused.
32 lib := $(dir)
33
34 libnotmuch_c_srcs =             \
35         $(notmuch_compat_srcs)  \
36         $(dir)/filenames.c      \
37         $(dir)/string-list.c    \
38         $(dir)/message-file.c   \
39         $(dir)/messages.c       \
40         $(dir)/sha1.c           \
41         $(dir)/built-with.c     \
42         $(dir)/string-map.c     \
43         $(dir)/tags.c
44
45 libnotmuch_cxx_srcs =           \
46         $(dir)/database.cc      \
47         $(dir)/parse-time-vrp.cc        \
48         $(dir)/directory.cc     \
49         $(dir)/index.cc         \
50         $(dir)/message.cc       \
51         $(dir)/message-property.cc \
52         $(dir)/query.cc         \
53         $(dir)/query-fp.cc      \
54         $(dir)/config.cc        \
55         $(dir)/regexp-fields.cc \
56         $(dir)/thread.cc
57
58 libnotmuch_modules := $(libnotmuch_c_srcs:.c=.o) $(libnotmuch_cxx_srcs:.cc=.o)
59
60 $(dir)/libnotmuch.a: $(libnotmuch_modules)
61         $(call quiet,AR) rcs $@ $^
62
63 $(dir)/$(LIBNAME): $(libnotmuch_modules) notmuch.sym util/libnotmuch_util.a parse-time-string/libparse-time-string.a
64         $(call quiet,CXX $(CXXFLAGS)) $(libnotmuch_modules) $(FINAL_LIBNOTMUCH_LDFLAGS) $(LIBRARY_LINK_FLAG) -o $@ util/libnotmuch_util.a parse-time-string/libparse-time-string.a
65
66 notmuch.sym: $(srcdir)/$(dir)/notmuch.h $(libnotmuch_modules)
67         sh $(srcdir)/$(lib)/gen-version-script.sh $< $(libnotmuch_modules) > $@
68
69 $(dir)/$(SONAME): $(dir)/$(LIBNAME)
70         ln -sf $(LIBNAME) $@
71
72 $(dir)/$(LINKER_NAME): $(dir)/$(SONAME)
73         ln -sf $(LIBNAME) $@
74
75 install: install-$(dir)
76
77 install-$(dir): $(dir)/$(LIBNAME)
78         mkdir -p "$(DESTDIR)$(libdir)/"
79         install -m0644 "$(lib)/$(LIBNAME)" "$(DESTDIR)$(libdir)/"
80         ln -sf $(LIBNAME) "$(DESTDIR)$(libdir)/$(SONAME)"
81         ln -sf $(LIBNAME) "$(DESTDIR)$(libdir)/$(LINKER_NAME)"
82         mkdir -p "$(DESTDIR)$(includedir)"
83         install -m0644 "$(srcdir)/$(lib)/notmuch.h" "$(DESTDIR)$(includedir)/"
84         $(LIBRARY_INSTALL_POST_COMMAND)
85
86 SRCS  := $(SRCS) $(libnotmuch_c_srcs) $(libnotmuch_cxx_srcs)
87 CLEAN += $(libnotmuch_modules) $(dir)/$(SONAME) $(dir)/$(LINKER_NAME)
88 CLEAN += $(dir)/$(LIBNAME) $(dir)/libnotmuch.a notmuch.sym
89 CLEAN += $(dir)/notmuch.h.gch