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