1 OS := $(shell uname) 2 LIBSOURCES = $(wildcard c/common/*.c) $(wildcard c/dec/*.c) \ 3 $(wildcard c/enc/*.c) 4 SOURCES = $(LIBSOURCES) c/tools/brotli.c 5 BINDIR = bin 6 OBJDIR = $(BINDIR)/obj 7 LIBOBJECTS = $(addprefix $(OBJDIR)/, $(LIBSOURCES:.c=.o)) 8 OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.c=.o)) 9 LIB_A = libbrotli.a 10 EXECUTABLE = brotli 11 DIRS = $(OBJDIR)/c/common $(OBJDIR)/c/dec $(OBJDIR)/c/enc \ 12 $(OBJDIR)/c/tools $(BINDIR)/tmp 13 CFLAGS += -O2 14 ifeq ($(os), Darwin) 15 CPPFLAGS += -DOS_MACOSX 16 endif 17 18 ifneq ($(strip $(CROSS_COMPILE)), ) 19 CC=$(CROSS_COMPILE)-gcc 20 ARCH=$(firstword $(subst -, ,$(CROSS_COMPILE))) 21 BROTLI_WRAPPER="qemu-$(ARCH) -L /usr/$(CROSS_COMPILE)" 22 endif 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. 26 ifeq ($(ARCH), arm) 27 CFLAGS += -march=armv7-a -mfloat-abi=hard -mfpu=neon 28 endif 29 30 all: 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 41 lib: $(LIBOBJECTS) 42 rm -f $(LIB_A) 43 ar -crs $(LIB_A) $(LIBOBJECTS) 44 45 test: $(EXECUTABLE) 46 tests/compatibility_test.sh $(BROTLI_WRAPPER) 47 tests/roundtrip_test.sh $(BROTLI_WRAPPER) 48 49 clean: 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