Fix VS build problems:

* rename build -> buildfiles to avoid clashing with BUILD
* set binary mode for stdin/out in bro
* convert bro to C
This commit is contained in:
Eugene Kliuchnikov 2016-06-17 16:24:51 +02:00
parent bce5c9b78c
commit b32cefe160
12 changed files with 127 additions and 100 deletions

2
.gitignore vendored
View File

@ -4,6 +4,6 @@
*.bro *.bro
*.unbro *.unbro
bin/ bin/
build/gmake/config.make buildfiles/gmake/config.make
**/obj/ **/obj/
dist/ dist/

11
BUILD
View File

@ -7,7 +7,7 @@ package(
licenses(["notice"]) # MIT licenses(["notice"]) # MIT
STRICT_COMPILER_OPTIONS = [ STRICT_C_OPTIONS = [
"--pedantic-errors", "--pedantic-errors",
"-Wall", "-Wall",
"-Wconversion", "-Wconversion",
@ -15,15 +15,12 @@ STRICT_COMPILER_OPTIONS = [
"-Wextra", "-Wextra",
"-Wlong-long", "-Wlong-long",
"-Wmissing-declarations", "-Wmissing-declarations",
"-Wmissing-prototypes",
"-Wno-strict-aliasing", "-Wno-strict-aliasing",
"-Wshadow", "-Wshadow",
"-Wsign-compare", "-Wsign-compare",
] ]
STRICT_C_OPTIONS = STRICT_COMPILER_OPTIONS + [
"-Wmissing-prototypes",
]
COMMON_HEADERS = [ COMMON_HEADERS = [
"common/constants.h", "common/constants.h",
"common/dictionary.h", "common/dictionary.h",
@ -139,8 +136,8 @@ cc_library(
cc_binary( cc_binary(
name = "bro", name = "bro",
srcs = ["tools/bro.cc"], srcs = ["tools/bro.c"],
copts = STRICT_COMPILER_OPTIONS, copts = STRICT_C_OPTIONS,
deps = [ deps = [
":brotli_dec", ":brotli_dec",
":brotli_enc", ":brotli_enc",

View File

@ -12,5 +12,5 @@ include python/brotlimodule.cc
include python/README.md include python/README.md
include README.md include README.md
include setup.py include setup.py
include tools/bro.cc include tools/bro.c
include tools/version.h include tools/version.h

View File

@ -1,11 +1,11 @@
include build/gmake/config.make include buildfiles/gmake/config.make
TARGETS=all clean brotli_common brotli_dec brotli_enc bro help TARGETS=all clean brotli_common brotli_dec brotli_enc bro help
.PHONY: $(TARGETS) install .PHONY: $(TARGETS) install
$(TARGETS): $(TARGETS):
@${MAKE} -C build/gmake $@ @${MAKE} -C buildfiles/gmake $@
install: install:
@echo "copy include and libraries to $(prefix)" @echo "copy include and libraries to $(prefix)"

View File

@ -22,10 +22,10 @@ ifeq ($(config),release_static)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -Wl,--start-group -lbrotli_common -lbrotli_dec -lbrotli_enc -Wl,--end-group LIBS += -Wl,--start-group -lbrotli_common -lbrotli_dec -lbrotli_enc -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.a ../../bin/libbrotli_dec.a ../../bin/libbrotli_enc.a LDDEPS += ../../bin/libbrotli_common.a ../../bin/libbrotli_dec.a ../../bin/libbrotli_enc.a
ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS define PREBUILDCMDS
endef endef
define PRELINKCMDS define PRELINKCMDS
@ -49,10 +49,10 @@ ifeq ($(config),release_shared)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -Wl,--start-group -lbrotli_common -lbrotli_dec -lbrotli_enc -Wl,--end-group LIBS += -Wl,--start-group -lbrotli_common -lbrotli_dec -lbrotli_enc -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.so ../../bin/libbrotli_dec.so ../../bin/libbrotli_enc.so LDDEPS += ../../bin/libbrotli_common.so ../../bin/libbrotli_dec.so ../../bin/libbrotli_enc.so
ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS define PREBUILDCMDS
endef endef
define PRELINKCMDS define PRELINKCMDS
@ -76,10 +76,10 @@ ifeq ($(config),debug_static)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -Wl,--start-group -lbrotli_common -lbrotli_dec -lbrotli_enc -Wl,--end-group LIBS += -Wl,--start-group -lbrotli_common -lbrotli_dec -lbrotli_enc -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.a ../../bin/libbrotli_dec.a ../../bin/libbrotli_enc.a LDDEPS += ../../bin/libbrotli_common.a ../../bin/libbrotli_dec.a ../../bin/libbrotli_enc.a
ALL_LDFLAGS += $(LDFLAGS) -L../../bin ALL_LDFLAGS += $(LDFLAGS) -L../../bin
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS define PREBUILDCMDS
endef endef
define PRELINKCMDS define PRELINKCMDS
@ -103,10 +103,10 @@ ifeq ($(config),debug_shared)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -Wl,--start-group -lbrotli_common -lbrotli_dec -lbrotli_enc -Wl,--end-group LIBS += -Wl,--start-group -lbrotli_common -lbrotli_dec -lbrotli_enc -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.so ../../bin/libbrotli_dec.so ../../bin/libbrotli_enc.so LDDEPS += ../../bin/libbrotli_common.so ../../bin/libbrotli_dec.so ../../bin/libbrotli_enc.so
ALL_LDFLAGS += $(LDFLAGS) -L../../bin ALL_LDFLAGS += $(LDFLAGS) -L../../bin
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS define PREBUILDCMDS
endef endef
define PRELINKCMDS define PRELINKCMDS
@ -174,12 +174,12 @@ ifneq (,$(PCH))
$(OBJECTS): $(GCH) $(PCH) $(OBJECTS): $(GCH) $(PCH)
$(GCH): $(PCH) $(GCH): $(PCH)
@echo $(notdir $<) @echo $(notdir $<)
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<" $(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
endif endif
$(OBJDIR)/bro.o: ../../tools/bro.cc $(OBJDIR)/bro.o: ../../tools/bro.c
@echo $(notdir $<) @echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" $(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
-include $(OBJECTS:%.o=%.d) -include $(OBJECTS:%.o=%.d)
ifneq (,$(PCH)) ifneq (,$(PCH))

View File

@ -22,7 +22,7 @@ ifeq ($(config),release_static)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += LIBS += -lm
LDDEPS += LDDEPS +=
ALL_LDFLAGS += $(LDFLAGS) -s ALL_LDFLAGS += $(LDFLAGS) -s
LINKCMD = $(AR) -rcs "$@" $(OBJECTS) LINKCMD = $(AR) -rcs "$@" $(OBJECTS)
@ -49,7 +49,7 @@ ifeq ($(config),release_shared)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -fPIC -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -fPIC -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += LIBS += -lm
LDDEPS += LDDEPS +=
ALL_LDFLAGS += $(LDFLAGS) -s -shared ALL_LDFLAGS += $(LDFLAGS) -s -shared
LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
@ -76,7 +76,7 @@ ifeq ($(config),debug_static)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += LIBS += -lm
LDDEPS += LDDEPS +=
ALL_LDFLAGS += $(LDFLAGS) ALL_LDFLAGS += $(LDFLAGS)
LINKCMD = $(AR) -rcs "$@" $(OBJECTS) LINKCMD = $(AR) -rcs "$@" $(OBJECTS)
@ -103,7 +103,7 @@ ifeq ($(config),debug_shared)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -fPIC -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -fPIC -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += LIBS += -lm
LDDEPS += LDDEPS +=
ALL_LDFLAGS += $(LDFLAGS) -shared ALL_LDFLAGS += $(LDFLAGS) -shared
LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)

View File

@ -22,7 +22,7 @@ ifeq ($(config),release_static)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -lbrotli_common LIBS += -Wl,--start-group -lbrotli_common -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.a LDDEPS += ../../bin/libbrotli_common.a
ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s
LINKCMD = $(AR) -rcs "$@" $(OBJECTS) LINKCMD = $(AR) -rcs "$@" $(OBJECTS)
@ -49,7 +49,7 @@ ifeq ($(config),release_shared)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -fPIC -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -fPIC -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -lbrotli_common LIBS += -Wl,--start-group -lbrotli_common -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.so LDDEPS += ../../bin/libbrotli_common.so
ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s -shared ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s -shared
LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
@ -76,7 +76,7 @@ ifeq ($(config),debug_static)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -lbrotli_common LIBS += -Wl,--start-group -lbrotli_common -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.a LDDEPS += ../../bin/libbrotli_common.a
ALL_LDFLAGS += $(LDFLAGS) -L../../bin ALL_LDFLAGS += $(LDFLAGS) -L../../bin
LINKCMD = $(AR) -rcs "$@" $(OBJECTS) LINKCMD = $(AR) -rcs "$@" $(OBJECTS)
@ -103,7 +103,7 @@ ifeq ($(config),debug_shared)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -fPIC -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -fPIC -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -lbrotli_common LIBS += -Wl,--start-group -lbrotli_common -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.so LDDEPS += ../../bin/libbrotli_common.so
ALL_LDFLAGS += $(LDFLAGS) -L../../bin -shared ALL_LDFLAGS += $(LDFLAGS) -L../../bin -shared
LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)

View File

@ -22,7 +22,7 @@ ifeq ($(config),release_static)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -lbrotli_common LIBS += -Wl,--start-group -lbrotli_common -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.a LDDEPS += ../../bin/libbrotli_common.a
ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s
LINKCMD = $(AR) -rcs "$@" $(OBJECTS) LINKCMD = $(AR) -rcs "$@" $(OBJECTS)
@ -49,7 +49,7 @@ ifeq ($(config),release_shared)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -fPIC -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3 -fPIC -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -lbrotli_common LIBS += -Wl,--start-group -lbrotli_common -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.so LDDEPS += ../../bin/libbrotli_common.so
ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s -shared ALL_LDFLAGS += $(LDFLAGS) -L../../bin -s -shared
LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
@ -76,7 +76,7 @@ ifeq ($(config),debug_static)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -lbrotli_common LIBS += -Wl,--start-group -lbrotli_common -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.a LDDEPS += ../../bin/libbrotli_common.a
ALL_LDFLAGS += $(LDFLAGS) -L../../bin ALL_LDFLAGS += $(LDFLAGS) -L../../bin
LINKCMD = $(AR) -rcs "$@" $(OBJECTS) LINKCMD = $(AR) -rcs "$@" $(OBJECTS)
@ -103,7 +103,7 @@ ifeq ($(config),debug_shared)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -fPIC -Wall -fno-omit-frame-pointer ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -fPIC -Wall -fno-omit-frame-pointer
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS += -lbrotli_common LIBS += -Wl,--start-group -lbrotli_common -lm -Wl,--end-group
LDDEPS += ../../bin/libbrotli_common.so LDDEPS += ../../bin/libbrotli_common.so
ALL_LDFLAGS += $(LDFLAGS) -L../../bin -shared ALL_LDFLAGS += $(LDFLAGS) -L../../bin -shared
LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS) LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)

4
configure vendored
View File

@ -15,5 +15,5 @@ do
esac esac
done done
echo -e "prefix=$PREFIX" > ./build/gmake/config.make echo -e "prefix=$PREFIX" > ./buildfiles/gmake/config.make
echo -e "version=$VERSION" >> ./build/gmake/config.make echo -e "version=$VERSION" >> ./buildfiles/gmake/config.make

View File

@ -3,7 +3,7 @@ solution "brotli"
configurations { "Release", "Debug" } configurations { "Release", "Debug" }
platforms { "Static", "Shared" } platforms { "Static", "Shared" }
targetdir "bin" targetdir "bin"
location "build" location "buildfiles"
flags "RelativeLinks" flags "RelativeLinks"
filter "configurations:Release" filter "configurations:Release"
@ -21,7 +21,10 @@ filter { "platforms:Shared" }
configuration { "gmake" } configuration { "gmake" }
buildoptions { "-Wall -fno-omit-frame-pointer" } buildoptions { "-Wall -fno-omit-frame-pointer" }
location "build/gmake" location "buildfiles/gmake"
configuration "linux"
links "m"
configuration { "macosx" } configuration { "macosx" }
defines { "DOS_MACOSX" } defines { "DOS_MACOSX" }
@ -42,6 +45,6 @@ project "brotli_enc"
project "bro" project "bro"
kind "ConsoleApp" kind "ConsoleApp"
language "C++" language "C"
files { "tools/bro.cc" } files { "tools/bro.c" }
links { "brotli_common", "brotli_dec", "brotli_enc" } links { "brotli_common", "brotli_dec", "brotli_enc" }

View File

@ -8,14 +8,11 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <time.h>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include "../dec/decode.h" #include "../dec/decode.h"
#include "../enc/encode.h" #include "../enc/encode.h"
@ -24,9 +21,11 @@
#include <unistd.h> #include <unistd.h>
#else #else
#include <io.h> #include <io.h>
#include <share.h>
#define STDIN_FILENO _fileno(stdin) #define MAKE_BINARY(FILENO) (_setmode((FILENO), _O_BINARY), (FILENO))
#define STDOUT_FILENO _fileno(stdout) #define STDIN_FILENO MAKE_BINARY(_fileno(stdin))
#define STDOUT_FILENO MAKE_BINARY(_fileno(stdout))
#define S_IRUSR S_IREAD #define S_IRUSR S_IREAD
#define S_IWUSR S_IWRITE #define S_IWUSR S_IWRITE
#define fdopen _fdopen #define fdopen _fdopen
@ -40,29 +39,29 @@
#define ftell _ftelli64 #define ftell _ftelli64
#endif #endif
static inline FILE* ms_fopen(const char *filename, const char *mode) { static FILE* ms_fopen(const char *filename, const char *mode) {
FILE* result = 0; FILE* result = 0;
fopen_s(&result, filename, mode); fopen_s(&result, filename, mode);
return result; return result;
} }
static inline int ms_open(const char *filename, int oflag, int pmode) { static int ms_open(const char *filename, int oflag, int pmode) {
int result = -1; int result = -1;
_sopen_s(&result, filename, oflag | O_BINARY, _SH_DENYNO, pmode); _sopen_s(&result, filename, oflag | O_BINARY, _SH_DENYNO, pmode);
return result; return result;
} }
#endif /* WIN32 */ #endif /* WIN32 */
static bool ParseQuality(const char* s, int* quality) { static int ParseQuality(const char* s, int* quality) {
if (s[0] >= '0' && s[0] <= '9') { if (s[0] >= '0' && s[0] <= '9') {
*quality = s[0] - '0'; *quality = s[0] - '0';
if (s[1] >= '0' && s[1] <= '9') { if (s[1] >= '0' && s[1] <= '9') {
*quality = *quality * 10 + s[1] - '0'; *quality = *quality * 10 + s[1] - '0';
return s[2] == 0; return (s[2] == 0) ? 1 : 0;
} }
return s[1] == 0; return (s[1] == 0) ? 1 : 0;
} }
return false; return 0;
} }
static void ParseArgv(int argc, char **argv, static void ParseArgv(int argc, char **argv,
@ -75,6 +74,7 @@ static void ParseArgv(int argc, char **argv,
int *repeat, int *repeat,
int *verbose, int *verbose,
int *lgwin) { int *lgwin) {
int k;
*force = 0; *force = 0;
*input_path = 0; *input_path = 0;
*output_path = 0; *output_path = 0;
@ -86,7 +86,7 @@ static void ParseArgv(int argc, char **argv,
*decompress = *decompress =
argv0_len >= 5 && strcmp(&argv[0][argv0_len - 5], "unbro") == 0; argv0_len >= 5 && strcmp(&argv[0][argv0_len - 5], "unbro") == 0;
} }
for (int k = 1; k < argc; ++k) { for (k = 1; k < argc; ++k) {
if (!strcmp("--force", argv[k]) || if (!strcmp("--force", argv[k]) ||
!strcmp("-f", argv[k])) { !strcmp("-f", argv[k])) {
if (*force != 0) { if (*force != 0) {
@ -172,10 +172,11 @@ error:
} }
static FILE* OpenInputFile(const char* input_path) { static FILE* OpenInputFile(const char* input_path) {
FILE* f;
if (input_path == 0) { if (input_path == 0) {
return fdopen(STDIN_FILENO, "rb"); return fdopen(STDIN_FILENO, "rb");
} }
FILE* f = fopen(input_path, "rb"); f = fopen(input_path, "rb");
if (f == 0) { if (f == 0) {
perror("fopen"); perror("fopen");
exit(1); exit(1);
@ -184,12 +185,12 @@ static FILE* OpenInputFile(const char* input_path) {
} }
static FILE *OpenOutputFile(const char *output_path, const int force) { static FILE *OpenOutputFile(const char *output_path, const int force) {
int fd;
if (output_path == 0) { if (output_path == 0) {
return fdopen(STDOUT_FILENO, "wb"); return fdopen(STDOUT_FILENO, "wb");
} }
int excl = force ? 0 : O_EXCL; fd = open(output_path, O_CREAT | (force ? 0 : O_EXCL) | O_WRONLY | O_TRUNC,
int fd = open(output_path, O_CREAT | excl | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
S_IRUSR | S_IWUSR);
if (fd < 0) { if (fd < 0) {
if (!force) { if (!force) {
struct stat statbuf; struct stat statbuf;
@ -206,6 +207,7 @@ static FILE *OpenOutputFile(const char *output_path, const int force) {
static int64_t FileSize(const char *path) { static int64_t FileSize(const char *path) {
FILE *f = fopen(path, "rb"); FILE *f = fopen(path, "rb");
int64_t retval;
if (f == NULL) { if (f == NULL) {
return -1; return -1;
} }
@ -213,37 +215,47 @@ static int64_t FileSize(const char *path) {
fclose(f); fclose(f);
return -1; return -1;
} }
int64_t retval = ftell(f); retval = ftell(f);
if (fclose(f) != 0) { if (fclose(f) != 0) {
return -1; return -1;
} }
return retval; return retval;
} }
static std::vector<uint8_t> ReadDictionary(const char* path) { /* Result ownersip is passed to caller.
|*dictionary_size| is set to resulting buffer size. */
static uint8_t* ReadDictionary(const char* path, size_t* dictionary_size) {
static const int kMaxDictionarySize = (1 << 24) - 16;
FILE *f = fopen(path, "rb"); FILE *f = fopen(path, "rb");
int64_t file_size_64;
uint8_t* buffer;
size_t bytes_read;
if (f == NULL) { if (f == NULL) {
perror("fopen"); perror("fopen");
exit(1); exit(1);
} }
int64_t file_size = FileSize(path); file_size_64 = FileSize(path);
if (file_size == -1) { if (file_size_64 == -1) {
fprintf(stderr, "could not get size of dictionary file"); fprintf(stderr, "could not get size of dictionary file");
exit(1); exit(1);
} }
static const int kMaxDictionarySize = (1 << 24) - 16; if (file_size_64 > kMaxDictionarySize) {
if (file_size > kMaxDictionarySize) {
fprintf(stderr, "dictionary is larger than maximum allowed: %d\n", fprintf(stderr, "dictionary is larger than maximum allowed: %d\n",
kMaxDictionarySize); kMaxDictionarySize);
exit(1); exit(1);
} }
*dictionary_size = (size_t)file_size_64;
std::vector<uint8_t> buffer; buffer = (uint8_t*)malloc(*dictionary_size);
buffer.resize(static_cast<size_t>(file_size)); if (!buffer) {
size_t bytes_read = fread(buffer.data(), sizeof(uint8_t), buffer.size(), f); fprintf(stderr, "could not read dictionary: out of memory\n");
if (bytes_read != buffer.size()) { exit(1);
}
bytes_read = fread(buffer, sizeof(uint8_t), *dictionary_size, f);
if (bytes_read != *dictionary_size) {
fprintf(stderr, "could not read dictionary\n"); fprintf(stderr, "could not read dictionary\n");
exit(1); exit(1);
} }
@ -255,24 +267,33 @@ static const size_t kFileBufferSize = 65536;
static int Decompress(FILE* fin, FILE* fout, const char* dictionary_path) { static int Decompress(FILE* fin, FILE* fout, const char* dictionary_path) {
/* Dictionary should be kept during first rounds of decompression. */ /* Dictionary should be kept during first rounds of decompression. */
std::vector<uint8_t> dictionary; uint8_t* dictionary = NULL;
uint8_t* input;
uint8_t* output;
size_t total_out;
size_t available_in;
const uint8_t* next_in;
size_t available_out = kFileBufferSize;
uint8_t* next_out;
BrotliResult result = BROTLI_RESULT_ERROR;
BrotliState* s = BrotliCreateState(NULL, NULL, NULL); BrotliState* s = BrotliCreateState(NULL, NULL, NULL);
if (!s) { if (!s) {
fprintf(stderr, "out of memory\n"); fprintf(stderr, "out of memory\n");
return 0; return 0;
} }
if (dictionary_path != NULL) { if (dictionary_path != NULL) {
dictionary = ReadDictionary(dictionary_path); size_t dictionary_size = 0;
BrotliSetCustomDictionary(dictionary.size(), dictionary.data(), s); dictionary = ReadDictionary(dictionary_path, &dictionary_size);
BrotliSetCustomDictionary(dictionary_size, dictionary, s);
} }
uint8_t* input = new uint8_t[kFileBufferSize]; input = (uint8_t*)malloc(kFileBufferSize);
uint8_t* output = new uint8_t[kFileBufferSize]; output = (uint8_t*)malloc(kFileBufferSize);
size_t total_out; if (!input || !output) {
size_t available_in; fprintf(stderr, "out of memory\n");
const uint8_t* next_in; goto end;
size_t available_out = kFileBufferSize; }
uint8_t* next_out = output; next_out = output;
BrotliResult result = BROTLI_RESULT_NEEDS_MORE_INPUT; result = BROTLI_RESULT_NEEDS_MORE_INPUT;
while (1) { while (1) {
if (result == BROTLI_RESULT_NEEDS_MORE_INPUT) { if (result == BROTLI_RESULT_NEEDS_MORE_INPUT) {
if (feof(fin)) { if (feof(fin)) {
@ -297,25 +318,27 @@ static int Decompress(FILE* fin, FILE* fout, const char* dictionary_path) {
&available_out, &next_out, &total_out, s); &available_out, &next_out, &total_out, s);
} }
if (next_out != output) { if (next_out != output) {
fwrite(output, 1, static_cast<size_t>(next_out - output), fout); fwrite(output, 1, (size_t)(next_out - output), fout);
} }
delete[] input;
delete[] output;
BrotliDestroyState(s);
if ((result == BROTLI_RESULT_NEEDS_MORE_OUTPUT) || ferror(fout)) { if ((result == BROTLI_RESULT_NEEDS_MORE_OUTPUT) || ferror(fout)) {
fprintf(stderr, "failed to write output\n"); fprintf(stderr, "failed to write output\n");
return 0;
} else if (result != BROTLI_RESULT_SUCCESS) { /* Error or needs more input. */ } else if (result != BROTLI_RESULT_SUCCESS) { /* Error or needs more input. */
fprintf(stderr, "corrupt input\n"); fprintf(stderr, "corrupt input\n");
return 0;
} }
return 1;
end:
free(dictionary);
free(input);
free(output);
BrotliDestroyState(s);
return (result == BROTLI_RESULT_SUCCESS) ? 1 : 0;
} }
static int Compress(int quality, int lgwin, FILE* fin, FILE* fout, static int Compress(int quality, int lgwin, FILE* fin, FILE* fout,
const char *dictionary_path) { const char *dictionary_path) {
BrotliEncoderState* s = BrotliEncoderCreateInstance(0, 0, 0); BrotliEncoderState* s = BrotliEncoderCreateInstance(0, 0, 0);
uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(kFileBufferSize << 1)); uint8_t* buffer = (uint8_t*)malloc(kFileBufferSize << 1);
uint8_t* input = buffer; uint8_t* input = buffer;
uint8_t* output = buffer + kFileBufferSize; uint8_t* output = buffer + kFileBufferSize;
size_t available_in = 0; size_t available_in = 0;
@ -333,9 +356,10 @@ static int Compress(int quality, int lgwin, FILE* fin, FILE* fout,
BrotliEncoderSetParameter(s, BROTLI_PARAM_QUALITY, (uint32_t)quality); BrotliEncoderSetParameter(s, BROTLI_PARAM_QUALITY, (uint32_t)quality);
BrotliEncoderSetParameter(s, BROTLI_PARAM_LGWIN, (uint32_t)lgwin); BrotliEncoderSetParameter(s, BROTLI_PARAM_LGWIN, (uint32_t)lgwin);
if (dictionary_path != NULL) { if (dictionary_path != NULL) {
std::vector<uint8_t> dictionary = ReadDictionary(dictionary_path); size_t dictionary_size = 0;
BrotliEncoderSetCustomDictionary(s, dictionary.size(), uint8_t* dictionary = ReadDictionary(dictionary_path, &dictionary_size);
reinterpret_cast<const uint8_t*>(dictionary.data())); BrotliEncoderSetCustomDictionary(s, dictionary_size, dictionary);
free(dictionary);
} }
while (1) { while (1) {
@ -392,13 +416,15 @@ int main(int argc, char** argv) {
int repeat = 1; int repeat = 1;
int verbose = 0; int verbose = 0;
int lgwin = 0; int lgwin = 0;
clock_t clock_start;
int i;
ParseArgv(argc, argv, &input_path, &output_path, &dictionary_path, &force, ParseArgv(argc, argv, &input_path, &output_path, &dictionary_path, &force,
&quality, &decompress, &repeat, &verbose, &lgwin); &quality, &decompress, &repeat, &verbose, &lgwin);
const clock_t clock_start = clock(); clock_start = clock();
for (int i = 0; i < repeat; ++i) { for (i = 0; i < repeat; ++i) {
FILE* fin = OpenInputFile(input_path); FILE* fin = OpenInputFile(input_path);
FILE* fout = OpenOutputFile(output_path, force); FILE* fout = OpenOutputFile(output_path, force);
int is_ok = false; int is_ok = 0;
if (decompress) { if (decompress) {
is_ok = Decompress(fin, fout, dictionary_path); is_ok = Decompress(fin, fout, dictionary_path);
} else { } else {
@ -418,19 +444,20 @@ int main(int argc, char** argv) {
} }
} }
if (verbose) { if (verbose) {
const clock_t clock_end = clock(); clock_t clock_end = clock();
double duration = double duration = (double)(clock_end - clock_start) / CLOCKS_PER_SEC;
static_cast<double>(clock_end - clock_start) / CLOCKS_PER_SEC; int64_t uncompressed_size;
double uncompressed_bytes_in_MB;
if (duration < 1e-9) { if (duration < 1e-9) {
duration = 1e-9; duration = 1e-9;
} }
int64_t uncompressed_size = FileSize(decompress ? output_path : input_path); uncompressed_size = FileSize(decompress ? output_path : input_path);
if (uncompressed_size == -1) { if (uncompressed_size == -1) {
fprintf(stderr, "failed to determine uncompressed file size\n"); fprintf(stderr, "failed to determine uncompressed file size\n");
exit(1); exit(1);
} }
double uncompressed_bytes_in_MB = uncompressed_bytes_in_MB =
static_cast<double>(repeat * uncompressed_size) / (1024.0 * 1024.0); (double)(repeat * uncompressed_size) / (1024.0 * 1024.0);
if (decompress) { if (decompress) {
printf("Brotli decompression speed: "); printf("Brotli decompression speed: ");
} else { } else {