1 # Default options 2 USE_BSDIFF ?= y 3 4 BINARIES-y = bspatch 5 BINARIES-$(USE_BSDIFF) += bsdiff 6 7 BINARIES += $(BINARIES-y) 8 9 INSTALL = install 10 CFLAGS += -O3 -Wall -Werror 11 CXXFLAGS += -std=c++11 12 13 DESTDIR ?= 14 PREFIX = /usr 15 BINDIR = $(PREFIX)/bin 16 DATADIR = $(PREFIX)/share 17 MANDIR = $(DATADIR)/man 18 MAN1DIR = $(MANDIR)/man1 19 INSTALL_PROGRAM ?= $(INSTALL) -c -m 755 20 INSTALL_MAN ?= $(INSTALL) -c -m 444 21 22 .PHONY: all test clean 23 all: $(BINARIES) 24 test: unittests 25 clean: 26 rm -f *.o $(BINARIES) unittests 27 28 BSDIFF_LIBS = -lbz2 -ldivsufsort -ldivsufsort64 29 BSDIFF_OBJS = \ 30 bsdiff.o 31 32 BSPATCH_LIBS = -lbz2 33 BSPATCH_OBJS = \ 34 bspatch.o \ 35 extents.o \ 36 extents_file.o \ 37 file.o \ 38 memory_file.o 39 40 UNITTEST_LIBS = -lgmock -lgtest -lpthread 41 UNITTEST_OBJS = \ 42 bsdiff_unittest.o \ 43 bspatch_unittest.o \ 44 extents_file_unittest.o \ 45 extents_unittest.o \ 46 test_utils.o \ 47 testrunner.o 48 49 bsdiff: $(BSDIFF_OBJS) bsdiff_main.o 50 bsdiff: LDLIBS += $(BSDIFF_LIBS) 51 52 bspatch: $(BSPATCH_OBJS) bspatch_main.o 53 bspatch: LDLIBS += $(BSPATCH_LIBS) 54 55 unittests: LDLIBS += $(BSDIFF_LIBS) $(BSPATCH_LIBS) $(UNITTEST_LIBS) 56 unittests: $(BSPATCH_OBJS) $(BSDIFF_OBJS) $(UNITTEST_OBJS) 57 58 unittests bsdiff bspatch: 59 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDLIBS) 60 61 # Source file dependencies. 62 bsdiff.o: bsdiff.cc 63 bsdiff_main.o: bsdiff_main.cc bsdiff.h 64 bsdiff_unittest.o: bsdiff_unittest.cc bsdiff.h test_utils.h 65 bspatch.o: bspatch.cc bspatch.h extents.h extents_file.h file_interface.h \ 66 file.h 67 bspatch_main.o: bspatch_main.cc bspatch.h 68 bspatch_unittest.o: bspatch_unittest.cc bspatch.h test_utils.h 69 extents.o: extents.cc extents.h extents_file.h file_interface.h 70 extents_file.o: extents_file.cc extents_file.h file_interface.h 71 extents_file_unittest.o: extents_file_unittest.cc extents_file.h \ 72 file_interface.h 73 extents_unittest.o: extents_unittest.cc extents.h extents_file.h \ 74 file_interface.h 75 file.o: file.cc file.h file_interface.h 76 memory_file.o: memory_file.cc memory_file.h file_interface.h 77 testrunner.o: testrunner.cc 78 test_utils.o: test_utils.cc test_utils.h 79 80 install: 81 mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MAN1DIR) 82 $(INSTALL_PROGRAM) $(BINARIES) $(DESTDIR)$(BINDIR) 83 ifndef WITHOUT_MAN 84 $(INSTALL_MAN) $(BINARIES:=.1) $(DESTDIR)$(MAN1DIR) 85 endif 86