From 378485b097fd7b80a5e404a3cb912f7b18f78cdb Mon Sep 17 00:00:00 2001 From: Eugene Kliuchnikov Date: Thu, 16 Jun 2016 10:52:57 +0200 Subject: [PATCH] Update build system. Now libraries are produced as build artifacts. There are currently 3 ways to build: * Easy: `./configure; make` * Simple: use Bazel * Portable: use premake5 to generate XCode / MSVS projects --- BUILD | 148 ++++++++++++++++++++++++++++++++++++ Makefile | 12 +++ WORKSPACE | 4 + common/Makefile | 12 --- configure | 19 +++++ dec/Makefile | 12 --- enc/Makefile | 13 ---- premake5.lua | 47 ++++++++++++ shared.mk | 13 ---- tests/Makefile | 4 +- tests/compatibility_test.sh | 2 +- tests/roundtrip_test.sh | 2 +- tools/Makefile | 28 ------- 13 files changed, 233 insertions(+), 83 deletions(-) create mode 100644 BUILD create mode 100644 Makefile create mode 100644 WORKSPACE delete mode 100644 common/Makefile create mode 100755 configure delete mode 100644 dec/Makefile delete mode 100644 enc/Makefile create mode 100644 premake5.lua delete mode 100644 shared.mk delete mode 100644 tools/Makefile diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..6dcc133 --- /dev/null +++ b/BUILD @@ -0,0 +1,148 @@ +# Description: +# Brotli is a generic-purpose lossless compression algorithm. + +package( + default_visibility = ["//visibility:public"], +) + +licenses(["notice"]) # MIT + +STRICT_COMPILER_OPTIONS = [ + "--pedantic-errors", + "-Wall", + "-Wconversion", + "-Werror", + "-Wextra", + "-Wlong-long", + "-Wmissing-declarations", + "-Wno-strict-aliasing", + "-Wshadow", + "-Wsign-compare", +] + +STRICT_C_OPTIONS = STRICT_COMPILER_OPTIONS + [ + "-Wmissing-prototypes", +] + +COMMON_HEADERS = [ + "common/constants.h", + "common/dictionary.h", + "common/port.h", + "common/types.h", +] + +COMMON_SOURCES = [ + "common/dictionary.c", +] + +DEC_HEADERS = [ + "dec/bit_reader.h", + "dec/context.h", + "dec/decode.h", + "dec/huffman.h", + "dec/port.h", + "dec/prefix.h", + "dec/state.h", + "dec/transform.h", +] + +DEC_SOURCES = [ + "dec/bit_reader.c", + "dec/decode.c", + "dec/huffman.c", + "dec/state.c", +] + +ENC_HEADERS = [ + "enc/backward_references.h", + "enc/backward_references_inc.h", + "enc/bit_cost.h", + "enc/bit_cost_inc.h", + "enc/block_encoder_inc.h", + "enc/block_splitter.h", + "enc/block_splitter_inc.h", + "enc/brotli_bit_stream.h", + "enc/cluster.h", + "enc/cluster_inc.h", + "enc/command.h", + "enc/compress_fragment.h", + "enc/compress_fragment_two_pass.h", + "enc/context.h", + "enc/dictionary_hash.h", + "enc/encode.h", + "enc/entropy_encode.h", + "enc/entropy_encode_static.h", + "enc/fast_log.h", + "enc/find_match_length.h", + "enc/hash.h", + "enc/hash_longest_match_inc.h", + "enc/hash_longest_match_quickly_inc.h", + "enc/histogram.h", + "enc/histogram_inc.h", + "enc/literal_cost.h", + "enc/memory.h", + "enc/metablock.h", + "enc/metablock_inc.h", + "enc/port.h", + "enc/prefix.h", + "enc/ringbuffer.h", + "enc/static_dict.h", + "enc/static_dict_lut.h", + "enc/utf8_util.h", + "enc/write_bits.h", +] + +ENC_SOURCES = [ + "enc/backward_references.c", + "enc/bit_cost.c", + "enc/block_splitter.c", + "enc/brotli_bit_stream.c", + "enc/cluster.c", + "enc/compress_fragment.c", + "enc/compress_fragment_two_pass.c", + "enc/encode.c", + "enc/entropy_encode.c", + "enc/histogram.c", + "enc/literal_cost.c", + "enc/memory.c", + "enc/metablock.c", + "enc/static_dict.c", + "enc/utf8_util.c", +] + +cc_library( + name = "brotli_common", + srcs = COMMON_SOURCES, + hdrs = COMMON_HEADERS, + copts = STRICT_C_OPTIONS, +) + +cc_library( + name = "brotli_dec", + srcs = DEC_SOURCES, + hdrs = DEC_HEADERS, + copts = STRICT_C_OPTIONS, + deps = [ + ":brotli_common", + ], +) + +cc_library( + name = "brotli_enc", + srcs = ENC_SOURCES, + hdrs = ENC_HEADERS, + copts = STRICT_C_OPTIONS, + deps = [ + ":brotli_common", + ], +) + +cc_binary( + name = "bro", + srcs = ["tools/bro.cc"], + copts = STRICT_COMPILER_OPTIONS, + deps = [ + ":brotli_dec", + ":brotli_enc", + ], +) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6a2a148 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +include build/gmake/config.make + +TARGETS=all clean brotli_common brotli_dec brotli_enc bro help + +.PHONY: $(TARGETS) install + +$(TARGETS): + @${MAKE} -C build/gmake $@ + +install: + @echo "copy include and libraries to $(prefix)" + $(error Installation is not implemented yet) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..5dd1e82 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,4 @@ +# Description: +# Bazel workspace file for Brotli. + +workspace(name = "io_brotli") diff --git a/common/Makefile b/common/Makefile deleted file mode 100644 index a3d163c..0000000 --- a/common/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -#brotli/common - -include ../shared.mk - -CFLAGS += -Wall - -OBJS = dictionary.o - -all : $(OBJS) - -clean : - rm -f $(OBJS) diff --git a/configure b/configure new file mode 100755 index 0000000..16a0341 --- /dev/null +++ b/configure @@ -0,0 +1,19 @@ +#!/bin/bash + +PREFIX=/usr/local + +VERSION=`cat tools/version.h | grep BROTLI_VERSION | grep -o \".*\"` +VERSION=${VERSION:1:${#VERSION}-2} + +for i in "$@" +do + case $i in + -p=*|--prefix=*) + PREFIX="${i#*=}" + + ;; + esac +done + +echo -e "prefix=$PREFIX" > ./build/gmake/config.make +echo -e "version=$VERSION" >> ./build/gmake/config.make diff --git a/dec/Makefile b/dec/Makefile deleted file mode 100644 index 6a5623e..0000000 --- a/dec/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -#brotli/dec - -include ../shared.mk - -CFLAGS += -Wall - -OBJS = bit_reader.o decode.o huffman.o state.o - -all : $(OBJS) - -clean : - rm -f $(OBJS) diff --git a/enc/Makefile b/enc/Makefile deleted file mode 100644 index 7a87e07..0000000 --- a/enc/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -#brotli/enc - -include ../shared.mk - -OBJS = backward_references.o bit_cost.o block_splitter.o brotli_bit_stream.o \ - cluster.o compress_fragment.o compress_fragment_two_pass.o compressor.o \ - encode.o encode_parallel.o entropy_encode.o histogram.o literal_cost.o \ - memory.o metablock.o static_dict.o streams.o utf8_util.o -all : $(OBJS) - -clean : - rm -f $(OBJS) $(SO) - diff --git a/premake5.lua b/premake5.lua new file mode 100644 index 0000000..b62abcd --- /dev/null +++ b/premake5.lua @@ -0,0 +1,47 @@ +-- A solution contains projects, and defines the available configurations +solution "brotli" +configurations { "Release", "Debug" } +platforms { "Static", "Shared" } +targetdir "bin" +location "build" +flags "RelativeLinks" + +filter "configurations:Release" + optimize "Speed" + flags { "StaticRuntime" } + +filter "configurations:Debug" + flags { "Symbols" } + +filter { "platforms:Static" } + kind "StaticLib" + +filter { "platforms:Shared" } + kind "SharedLib" + +configuration { "gmake" } + buildoptions { "-Wall -fno-omit-frame-pointer" } + location "build/gmake" + +configuration { "macosx" } + defines { "DOS_MACOSX" } + +project "brotli_common" + language "C" + files { "common/**.h", "common/**.c" } + +project "brotli_dec" + language "C" + files { "dec/**.h", "dec/**.c" } + links "brotli_common" + +project "brotli_enc" + language "C" + files { "enc/**.h", "enc/**.c" } + links "brotli_common" + +project "bro" + kind "ConsoleApp" + language "C++" + files { "tools/bro.cc" } + links { "brotli_common", "brotli_dec", "brotli_enc" } diff --git a/shared.mk b/shared.mk deleted file mode 100644 index e210e7f..0000000 --- a/shared.mk +++ /dev/null @@ -1,13 +0,0 @@ -OS := $(shell uname) - -CC ?= gcc -CXX ?= g++ - -COMMON_FLAGS = -fno-omit-frame-pointer -no-canonical-prefixes -O2 - -ifeq ($(OS), Darwin) - CPPFLAGS += -DOS_MACOSX -endif - -CFLAGS += $(COMMON_FLAGS) -Wmissing-prototypes -CXXFLAGS += $(COMMON_FLAGS) -Wmissing-declarations diff --git a/tests/Makefile b/tests/Makefile index 8b2eedb..7962cbd 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,7 +1,5 @@ #brotli/tests -include ../shared.mk - BROTLI = .. all: test @@ -11,7 +9,7 @@ test: deps ./roundtrip_test.sh deps : - $(MAKE) -C $(BROTLI)/tools + $(MAKE) -C $(BROTLI) bro clean : rm -f testdata/*.{bro,unbro,uncompressed} diff --git a/tests/compatibility_test.sh b/tests/compatibility_test.sh index e907485..6085ff7 100755 --- a/tests/compatibility_test.sh +++ b/tests/compatibility_test.sh @@ -5,7 +5,7 @@ set -o errexit -BRO=../tools/bro +BRO=../bin/bro for file in testdata/*.compressed*; do echo "Testing decompression of file $file" diff --git a/tests/roundtrip_test.sh b/tests/roundtrip_test.sh index 6bda135..bfd9885 100755 --- a/tests/roundtrip_test.sh +++ b/tests/roundtrip_test.sh @@ -4,7 +4,7 @@ set -o errexit -BRO=../tools/bro +BRO=../bin/bro INPUTS=""" testdata/alice29.txt testdata/asyoulik.txt diff --git a/tools/Makefile b/tools/Makefile deleted file mode 100644 index c2d7e83..0000000 --- a/tools/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -#brotli/tools - -include ../shared.mk - -BROTLI = .. -COMMONOBJ = $(BROTLI)/common/*.o -DECOBJ = $(BROTLI)/dec/*.o -ENCOBJ = $(BROTLI)/enc/*.o - -EXECUTABLES=bro - -EXE_OBJS=$(patsubst %, %.o, $(EXECUTABLES)) - -all : $(EXECUTABLES) - -$(EXECUTABLES) : $(EXE_OBJS) deps - $(CXX) $(LDFLAGS) $(COMMONOBJ) $(ENCOBJ) $(DECOBJ) $@.o -o $@ - -deps : - $(MAKE) -C $(BROTLI)/common - $(MAKE) -C $(BROTLI)/dec - $(MAKE) -C $(BROTLI)/enc - -clean : - rm -f $(OBJS) $(EXE_OBJS) $(EXECUTABLES) - $(MAKE) -C $(BROTLI)/common clean - $(MAKE) -C $(BROTLI)/dec clean - $(MAKE) -C $(BROTLI)/enc clean