Home | History | Annotate | Download | only in bsdiff
      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 
     39 UNITTEST_LIBS = -lgmock -lgtest
     40 UNITTEST_OBJS = \
     41   bsdiff_unittest.o \
     42   extents_file_unittest.o \
     43   extents_unittest.o \
     44   test_utils.o \
     45   testrunner.o
     46 
     47 bsdiff: $(BSDIFF_OBJS) bsdiff_main.o
     48 bsdiff: LDLIBS += $(BSDIFF_LIBS)
     49 
     50 bspatch: $(BSPATCH_OBJS) bspatch_main.o
     51 bspatch: LDLIBS += $(BSPATCH_LIBS)
     52 
     53 unittests: LDLIBS += $(BSDIFF_LIBS) $(BSPATCH_LIBS) $(UNITTEST_LIBS)
     54 unittests: $(BSPATCH_OBJS) $(BSDIFF_OBJS) $(UNITTEST_OBJS)
     55 
     56 unittests bsdiff bspatch:
     57 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDLIBS)
     58 
     59 # Source file dependencies.
     60 bsdiff.o: bsdiff.cc
     61 bsdiff_main.o: bsdiff_main.cc bsdiff.h
     62 bsdiff_unittest.o: bsdiff_unittest.cc bsdiff.h test_utils.h
     63 bspatch.o: bspatch.cc bspatch.h extents.h extents_file.h file_interface.h \
     64  file.h
     65 bspatch_main.o: bspatch_main.cc bspatch.h
     66 extents.o: extents.cc extents.h extents_file.h file_interface.h
     67 extents_file.o: extents_file.cc extents_file.h file_interface.h
     68 extents_file_unittest.o: extents_file_unittest.cc extents_file.h \
     69  file_interface.h
     70 extents_unittest.o: extents_unittest.cc extents.h extents_file.h \
     71  file_interface.h
     72 file.o: file.cc file.h file_interface.h
     73 testrunner.o: testrunner.cc
     74 test_utils.o: test_utils.cc test_utils.h
     75 
     76 install:
     77 	mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MAN1DIR)
     78 	$(INSTALL_PROGRAM) $(BINARIES) $(DESTDIR)$(BINDIR)
     79 ifndef WITHOUT_MAN
     80 	$(INSTALL_MAN) $(BINARIES:=.1) $(DESTDIR)$(MAN1DIR)
     81 endif
     82