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 -I.. 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 .deps 32 33### List of source files for each project. Keep in sync with the Android.mk. 34# "bsdiff" program. 35bsdiff_src_files := \ 36 brotli_compressor.cc \ 37 bsdiff.cc \ 38 bz2_compressor.cc \ 39 compressor_buffer.cc \ 40 diff_encoder.cc \ 41 endsley_patch_writer.cc \ 42 logging.cc \ 43 patch_writer.cc \ 44 patch_writer_factory.cc \ 45 split_patch_writer.cc \ 46 suffix_array_index.cc 47 48# "bspatch" program. 49bspatch_src_files := \ 50 brotli_decompressor.cc \ 51 bspatch.cc \ 52 bz2_decompressor.cc \ 53 buffer_file.cc \ 54 decompressor_interface.cc \ 55 extents.cc \ 56 extents_file.cc \ 57 file.cc \ 58 logging.cc \ 59 memory_file.cc \ 60 patch_reader.cc \ 61 sink_file.cc \ 62 utils.cc 63 64# Unit test files. 65bsdiff_common_unittests := \ 66 brotli_compressor_unittest.cc \ 67 brotli_decompressor_unittest.cc \ 68 bsdiff_arguments.cc \ 69 bsdiff_arguments_unittest.cc \ 70 bsdiff_unittest.cc \ 71 bspatch_unittest.cc \ 72 bz2_decompressor_unittest.cc \ 73 diff_encoder_unittest.cc \ 74 endsley_patch_writer_unittest.cc \ 75 extents_file_unittest.cc \ 76 extents_unittest.cc \ 77 patch_reader_unittest.cc \ 78 patch_writer_unittest.cc \ 79 split_patch_writer_unittest.cc \ 80 suffix_array_index_unittest.cc \ 81 test_utils.cc \ 82 testrunner.cc 83 84 85BSDIFF_LIBS := -lbz2 -lbrotlienc -ldivsufsort -ldivsufsort64 86BSDIFF_OBJS := $(bsdiff_src_files:.cc=.o) 87BSPATCH_LIBS := -lbz2 -lbrotlidec 88BSPATCH_OBJS := $(bspatch_src_files:.cc=.o) 89 90UNITTEST_LIBS = -lgmock -lgtest -lpthread 91UNITTEST_OBJS := $(bsdiff_common_unittests:.cc=.o) 92 93bsdiff: $(BSDIFF_OBJS) bsdiff_arguments.o bsdiff_main.o 94bsdiff: LDLIBS += $(BSDIFF_LIBS) 95libbsdiff.so: $(BSDIFF_OBJS) 96libbsdiff.so: LDLIBS += $(BSDIFF_LIBS) 97 98bspatch: $(BSPATCH_OBJS) bspatch_main.o 99bspatch: LDLIBS += $(BSPATCH_LIBS) 100libbspatch.so: $(BSPATCH_OBJS) 101libbspatch.so: LDLIBS += $(BSPATCH_LIBS) 102 103bsdiff_unittest: LDLIBS += $(BSDIFF_LIBS) $(BSPATCH_LIBS) $(UNITTEST_LIBS) 104bsdiff_unittest: $(BSPATCH_OBJS) $(BSDIFF_OBJS) $(UNITTEST_OBJS) 105 106bsdiff_unittest bsdiff bspatch: 107 $(CXX) $(CXXFLAGS) -o $@ $^ $(LDLIBS) 108 109libbsdiff.so libbspatch.so: 110 $(CXX) $(CXXFLAGS) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $^ $(LDLIBS) 111 112# Source file dependencies. 113.deps: $(bsdiff_src_files) $(bspatch_src_files) $(bsdiff_common_unittests) \ 114 bsdiff_main.cc bspatch_main.cc 115 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MM $^ >$@ || (rm -f $@; false) 116-include .deps 117 118install: 119 mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(MAN1DIR) \ 120 $(DESTDIR)/$(INCLUDEDIR)/bsdiff 121 $(INSTALL_PROGRAM) $(EXECUTABLES-y) $(DESTDIR)$(BINDIR) 122 $(INSTALL_PROGRAM) $(LIBRARIES-y) $(DESTDIR)$(LIBDIR) 123 $(INSTALL) -c -m 644 include/bsdiff/*.h $(DESTDIR)/$(INCLUDEDIR)/bsdiff 124ifndef WITHOUT_MAN 125 $(INSTALL_MAN) $(EXECUTABLES-y:=.1) $(DESTDIR)$(MAN1DIR) 126endif 127