Makefile revision ddf9db52938e67d4dcbf7c4f159b094eaddbabeb
1# Default options
2USE_BSDIFF ?= y
3
4EXECUTABLES-y := bspatch
5LIBRARIES-y := libbspatch.so
6EXECUTABLES-$(USE_BSDIFF) += bsdiff
7LIBRARIES-$(USE_BSDIFF) += libbsdiff.so
8
9BINARIES := $(EXECUTABLES-y) $(LIBRARIES-y)
10
11INSTALL = install
12CPPFLAGS += -Iinclude
13CXXFLAGS += -std=c++11 -O3 -Wall -Werror -fPIC
14
15DESTDIR ?=
16PREFIX = /usr
17BINDIR = $(PREFIX)/bin
18DATADIR = $(PREFIX)/share
19MANDIR = $(DATADIR)/man
20MAN1DIR = $(MANDIR)/man1
21INCLUDEDIR ?= $(PREFIX)/include
22GENTOO_LIBDIR ?= lib
23LIBDIR ?= $(PREFIX)/$(GENTOO_LIBDIR)
24INSTALL_PROGRAM ?= $(INSTALL) -c -m 755
25INSTALL_MAN ?= $(INSTALL) -c -m 444
26
27.PHONY: all test clean install
28all: $(BINARIES)
29test: bsdiff_unittest
30clean:
31	rm -f *.o $(BINARIES) bsdiff_unittest
32
33### List of source files for each project. Keep in sync with the Android.mk.
34# "bsdiff" program.
35bsdiff_src_files := \
36    bsdiff.cc
37
38# "bspatch" program.
39bspatch_src_files := \
40    bspatch.cc \
41    buffer_file.cc \
42    extents.cc \
43    extents_file.cc \
44    file.cc \
45    memory_file.cc \
46    sink_file.cc
47
48# Unit test files.
49bsdiff_common_unittests := \
50    bsdiff_unittest.cc \
51    bspatch_unittest.cc \
52    extents_file_unittest.cc \
53    extents_unittest.cc \
54    test_utils.cc \
55    testrunner.cc
56
57
58BSDIFF_LIBS := -lbz2 -ldivsufsort -ldivsufsort64
59BSDIFF_OBJS := $(bsdiff_src_files:.cc=.o)
60
61BSPATCH_LIBS := -lbz2
62BSPATCH_OBJS := $(bspatch_src_files:.cc=.o)
63
64UNITTEST_LIBS = -lgmock -lgtest -lpthread
65UNITTEST_OBJS := $(bsdiff_common_unittests:.cc=.o)
66
67bsdiff: $(BSDIFF_OBJS) bsdiff_main.o
68bsdiff: LDLIBS += $(BSDIFF_LIBS)
69libbsdiff.so: $(BSDIFF_OBJS)
70libbsdiff.so: LDLIBS += $(BSDIFF_LIBS)
71
72bspatch: $(BSPATCH_OBJS) bspatch_main.o
73bspatch: LDLIBS += $(BSPATCH_LIBS)
74libbspatch.so: $(BSPATCH_OBJS)
75libbspatch.so: LDLIBS += $(BSPATCH_LIBS)
76
77bsdiff_unittest: LDLIBS += $(BSDIFF_LIBS) $(BSPATCH_LIBS) $(UNITTEST_LIBS)
78bsdiff_unittest: $(BSPATCH_OBJS) $(BSDIFF_OBJS) $(UNITTEST_OBJS)
79
80bsdiff_unittest bsdiff bspatch:
81	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDLIBS)
82
83libbsdiff.so libbspatch.so:
84	$(CXX) $(CXXFLAGS) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $^ $(LDLIBS)
85
86# Source file dependencies.
87bspatch.o: bspatch.cc include/bsdiff/bspatch.h \
88 include/bsdiff/extents_file.h include/bsdiff/file_interface.h \
89 buffer_file.h extents.h file.h memory_file.h sink_file.h
90bspatch_main.o: bspatch_main.cc include/bsdiff/bspatch.h \
91 include/bsdiff/extents_file.h include/bsdiff/file_interface.h
92bspatch_unittest.o: bspatch_unittest.cc include/bsdiff/bspatch.h \
93 include/bsdiff/extents_file.h include/bsdiff/file_interface.h \
94 test_utils.h
95buffer_file.o: buffer_file.cc buffer_file.h \
96 include/bsdiff/file_interface.h include/bsdiff/bspatch.h \
97 include/bsdiff/extents_file.h
98extents.o: extents.cc extents.h include/bsdiff/extents_file.h \
99 include/bsdiff/file_interface.h
100extents_file.o: extents_file.cc include/bsdiff/extents_file.h \
101 include/bsdiff/file_interface.h
102extents_file_unittest.o: extents_file_unittest.cc \
103 include/bsdiff/extents_file.h include/bsdiff/file_interface.h
104extents_unittest.o: extents_unittest.cc extents.h \
105 include/bsdiff/extents_file.h include/bsdiff/file_interface.h
106file.o: file.cc file.h include/bsdiff/file_interface.h
107memory_file.o: memory_file.cc memory_file.h \
108 include/bsdiff/file_interface.h
109sink_file.o: sink_file.cc sink_file.h include/bsdiff/file_interface.h
110testrunner.o: testrunner.cc test_utils.h
111test_utils.o: test_utils.cc test_utils.h
112
113install:
114	mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(MAN1DIR) \
115	  $(DESTDIR)/$(INCLUDEDIR)/bsdiff
116	$(INSTALL_PROGRAM) $(EXECUTABLES-y) $(DESTDIR)$(BINDIR)
117	$(INSTALL_PROGRAM) $(LIBRARIES-y) $(DESTDIR)$(LIBDIR)
118	$(INSTALL) -c -m 644 include/bsdiff/*.h $(DESTDIR)/$(INCLUDEDIR)/bsdiff
119ifndef WITHOUT_MAN
120	$(INSTALL_MAN) $(EXECUTABLES-y:=.1) $(DESTDIR)$(MAN1DIR)
121endif
122