-dir=lib
-
-lib_notmuch_modules = \
- $(dir)/database.o \
- $(dir)/index.o \
- $(dir)/$(dir)sha1.o \
- $(dir)/message.o \
- $(dir)/message-file.o \
- $(dir)/query.o \
- $(dir)/sha1.o \
- $(dir)/tags.o \
- $(dir)/thread.o \
- $(dir)/xutil.o
-
-$(dir)/notmuch.a: $(lib_notmuch_modules)
- $(AR) rcs $@ $^
-
-SRCS := $(SRCS) lib/*.c lib/*.cc
-CLEAN := $(CLEAN) $(dir)/*.o $(dir)/notmuch.a
+# -*- makefile -*-
+
+# The major version of the library interface. This will control the soname.
+# As such, this number must be incremented for any incompatible change to
+# the library interface, (such as the deletion of an API or a major
+# semantic change that breaks formerly functioning code).
+#
+# Note: We don't currently have plans to increment this at this time.
+# If we *do* want to make an incompatible change to the library
+# interface, we'll have to decide whether to increment this (creating
+# a new soname) or to introduce symbol versioning to be able to
+# provide support for both old and new interfaces without having to
+# increment this.
+LIBNOTMUCH_VERSION_MAJOR = 1
+
+# The minor version of the library interface. This should be incremented at
+# the time of release for any additions to the library interface.
+LIBNOTMUCH_VERSION_MINOR = 0
+
+# The release version the library interface. This should be incremented at
+# the time of release if there have been no changes to the interface, (but
+# simply compatible changes to the implementation).
+LIBNOTMUCH_VERSION_RELEASE = 0
+
+LINKER_NAME = libnotmuch.so
+SONAME = $(LINKER_NAME).$(LIBNOTMUCH_VERSION_MAJOR)
+LIBNAME = $(SONAME).$(LIBNOTMUCH_VERSION_MINOR).$(LIBNOTMUCH_VERSION_RELEASE)
+
+dir := lib
+extra_cflags += -I$(dir) -fPIC
+
+libnotmuch_c_srcs = \
+ $(dir)/libsha1.c \
+ $(dir)/message-file.c \
+ $(dir)/messages.c \
+ $(dir)/sha1.c \
+ $(dir)/tags.c \
+ $(dir)/xutil.c
+
+libnotmuch_cxx_srcs = \
+ $(dir)/database.cc \
+ $(dir)/directory.cc \
+ $(dir)/index.cc \
+ $(dir)/message.cc \
+ $(dir)/query.cc \
+ $(dir)/thread.cc
+
+libnotmuch_modules = $(libnotmuch_c_srcs:.c=.o) $(libnotmuch_cxx_srcs:.cc=.o)
+
+$(dir)/libnotmuch.a: $(libnotmuch_modules)
+ $(call quiet,AR) rcs $@ $^
+
+$(dir)/$(LIBNAME): $(libnotmuch_modules)
+ $(call quiet,CXX $(CXXFLAGS)) $^ $(FINAL_LIBNOTMUCH_LDFLAGS) -shared -Wl,-soname=$(SONAME) -o $@
+
+$(dir)/$(SONAME): $(dir)/$(LIBNAME)
+ ln -sf $(LIBNAME) $@
+
+$(dir)/$(LINKER_NAME): $(dir)/$(SONAME)
+ ln -sf $(LIBNAME) $@
+
+install: install-$(dir)
+
+install-$(dir):
+ mkdir -p $(DESTDIR)$(libdir)/
+ install -m0644 $(dir)/$(LIBNAME) $(DESTDIR)$(libdir)/
+ ln -sf $(LIBNAME) $(DESTDIR)$(libdir)/$(SONAME)
+ ln -sf $(LIBNAME) $(DESTDIR)$(libdir)/$(LINKER_NAME)
+ mkdir -p $(DESTDIR)$(includedir)
+ install -m0644 $(dir)/notmuch.h $(DESTDIR)$(includedir)/
+
+SRCS := $(SRCS) $(libnotmuch_c_srcs) $(libnotmuch_cxx_srcs)
+CLEAN := $(CLEAN) $(libnotmuch_modules) $(dir)/$(SONAME) $(dir)/$(LINKER_NAME) $(dir)$(LIBNAME) libnotmuch.a