• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1OS := $(shell uname)
2LIBSOURCES = $(wildcard c/common/*.c) $(wildcard c/dec/*.c) \
3             $(wildcard c/enc/*.c)
4SOURCES = $(LIBSOURCES) c/tools/brotli.c
5BINDIR = bin
6OBJDIR = $(BINDIR)/obj
7LIBOBJECTS = $(addprefix $(OBJDIR)/, $(LIBSOURCES:.c=.o))
8OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.c=.o))
9LIB_A = libbrotli.a
10EXECUTABLE = brotli
11DIRS = $(OBJDIR)/c/common $(OBJDIR)/c/dec $(OBJDIR)/c/enc \
12       $(OBJDIR)/c/tools $(BINDIR)/tmp
13CFLAGS += -O2
14ifeq ($(os), Darwin)
15  CPPFLAGS += -DOS_MACOSX
16endif
17
18ifneq ($(strip $(CROSS_COMPILE)), )
19	CC=$(CROSS_COMPILE)-gcc
20	ARCH=$(firstword $(subst -, ,$(CROSS_COMPILE)))
21	BROTLI_WRAPPER="qemu-$(ARCH) -L /usr/$(CROSS_COMPILE)"
22endif
23
24# The arm-linux-gnueabi compiler defaults to Armv5. Since we only support Armv7
25# and beyond, we need to select Armv7 explicitly with march.
26ifeq ($(ARCH), arm)
27	CFLAGS += -march=armv7-a -mfloat-abi=hard -mfpu=neon
28endif
29
30all: test
31	@:
32
33.PHONY: all clean test
34
35$(DIRS):
36	mkdir -p $@
37
38$(EXECUTABLE): $(OBJECTS)
39	$(CC) $(LDFLAGS) $(OBJECTS) -lm -o $(BINDIR)/$(EXECUTABLE)
40
41lib: $(LIBOBJECTS)
42	rm -f $(LIB_A)
43	ar -crs $(LIB_A) $(LIBOBJECTS)
44
45test: $(EXECUTABLE)
46	tests/compatibility_test.sh $(BROTLI_WRAPPER)
47	tests/roundtrip_test.sh $(BROTLI_WRAPPER)
48
49clean:
50	rm -rf $(BINDIR) $(LIB_A)
51
52.SECONDEXPANSION:
53$(OBJECTS): $$(patsubst %.o,%.c,$$(patsubst $$(OBJDIR)/%,%,$$@)) | $(DIRS)
54	$(CC) $(CFLAGS) $(CPPFLAGS) -Ic/include \
55        -c $(patsubst %.o,%.c,$(patsubst $(OBJDIR)/%,%,$@)) -o $@
56