Home | History | Annotate | Download | only in bsdiff
      1 # Default options
      2 USE_BSDIFF ?= y
      3 
      4 EXECUTABLES-y := bspatch
      5 LIBRARIES-y := libbspatch.so
      6 EXECUTABLES-$(USE_BSDIFF) += bsdiff
      7 LIBRARIES-$(USE_BSDIFF) += libbsdiff.so
      8 
      9 BINARIES := $(EXECUTABLES-y) $(LIBRARIES-y)
     10 
     11 INSTALL = install
     12 CPPFLAGS += -Iinclude -I..
     13 CXXFLAGS += -std=c++11 -O3 -Wall -Werror -fPIC
     14 
     15 DESTDIR ?=
     16 PREFIX = /usr
     17 BINDIR = $(PREFIX)/bin
     18 DATADIR = $(PREFIX)/share
     19 MANDIR = $(DATADIR)/man
     20 MAN1DIR = $(MANDIR)/man1
     21 INCLUDEDIR ?= $(PREFIX)/include
     22 GENTOO_LIBDIR ?= lib
     23 LIBDIR ?= $(PREFIX)/$(GENTOO_LIBDIR)
     24 INSTALL_PROGRAM ?= $(INSTALL) -c -m 755
     25 INSTALL_MAN ?= $(INSTALL) -c -m 444
     26 
     27 .PHONY: all test clean install
     28 all: $(BINARIES)
     29 test: bsdiff_unittest
     30 clean:
     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.
     35 bsdiff_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.
     49 bspatch_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.
     65 bsdiff_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 
     85 BSDIFF_LIBS := -lbz2 -lbrotlienc -ldivsufsort -ldivsufsort64
     86 BSDIFF_OBJS := $(bsdiff_src_files:.cc=.o)
     87 BSPATCH_LIBS := -lbz2 -lbrotlidec
     88 BSPATCH_OBJS := $(bspatch_src_files:.cc=.o)
     89 
     90 UNITTEST_LIBS = -lgmock -lgtest -lpthread
     91 UNITTEST_OBJS := $(bsdiff_common_unittests:.cc=.o)
     92 
     93 bsdiff: $(BSDIFF_OBJS) bsdiff_arguments.o bsdiff_main.o
     94 bsdiff: LDLIBS += $(BSDIFF_LIBS)
     95 libbsdiff.so: $(BSDIFF_OBJS)
     96 libbsdiff.so: LDLIBS += $(BSDIFF_LIBS)
     97 
     98 bspatch: $(BSPATCH_OBJS) bspatch_main.o
     99 bspatch: LDLIBS += $(BSPATCH_LIBS)
    100 libbspatch.so: $(BSPATCH_OBJS)
    101 libbspatch.so: LDLIBS += $(BSPATCH_LIBS)
    102 
    103 bsdiff_unittest: LDLIBS += $(BSDIFF_LIBS) $(BSPATCH_LIBS) $(UNITTEST_LIBS)
    104 bsdiff_unittest: $(BSPATCH_OBJS) $(BSDIFF_OBJS) $(UNITTEST_OBJS)
    105 
    106 bsdiff_unittest bsdiff bspatch:
    107 	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDLIBS)
    108 
    109 libbsdiff.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 
    118 install:
    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
    124 ifndef WITHOUT_MAN
    125 	$(INSTALL_MAN) $(EXECUTABLES-y:=.1) $(DESTDIR)$(MAN1DIR)
    126 endif
    127