Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add premake-based build scripts #2

Merged
merged 16 commits into from Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
bin/
obj/
/bazel-*
47 changes: 47 additions & 0 deletions Makefile
@@ -0,0 +1,47 @@
# GNU Make workspace makefile autogenerated by Premake

.NOTPARALLEL:

ifndef config
config=release
endif

ifndef verbose
SILENT = @
endif

ifeq ($(config),release)
guetzli_config = release
endif
ifeq ($(config),debug)
guetzli_config = debug
endif

PROJECTS := guetzli

.PHONY: all clean help $(PROJECTS)

all: $(PROJECTS)

guetzli:
ifneq (,$(guetzli_config))
@echo "==== Building guetzli ($(guetzli_config)) ===="
@${MAKE} --no-print-directory -C . -f guetzli.make config=$(guetzli_config)
endif

clean:
@${MAKE} --no-print-directory -C . -f guetzli.make clean

help:
@echo "Usage: make [config=name] [target]"
@echo ""
@echo "CONFIGURATIONS:"
@echo " release"
@echo " debug"
@echo ""
@echo "TARGETS:"
@echo " all (default)"
@echo " clean"
@echo " guetzli"
@echo ""
@echo "For more information, see http://industriousone.com/premake/quick-start"
18 changes: 13 additions & 5 deletions README.md
Expand Up @@ -11,9 +11,17 @@ sequential (nonprogressive) JPEGs due to faster decompression speeds they offer.
downloading an
[archive](https://github.com/google/guetzli/archive/master.zip) and
unpacking it.
2. Install [Bazel](https://www.bazel.io) by following its [installation
instructions](https://www.bazel.io/versions/master/docs/install.html).
3. Run `bazel build -c opt :guetzli` in the directory this README file is in.
2. Install [libpng](http://www.libpng.org/pub/png/libpng.html) and
[gflags](https://github.com/gflags/gflags). If using your operating system
package manager, install development versions of the packages if the
distinction exists.
* On Ubuntu, do `apt-get install libpng-dev libgflags-dev`.
* On Arch Linux, do `pacman -S libpng gflags`.
3. Run `make` and expect the binary to be created in `bin/Release/guetzli`.

There's also a [Bazel](https://bazel.build) build configuration provided. If
you have Bazel installed, you can also compile Guetzli by running
`bazel -c opt :guetzli`.

# Using

Expand All @@ -22,8 +30,8 @@ To try out Guetzli you need to [build](#building) or
binary reads a PNG or JPEG image and creates an optimized JPEG image:

```bash
bazel-bin/guetzli [--quality Q] [--verbose] original.png output.jpg
bazel-bin/guetzli [--quality Q] [--verbose] original.jpg output.jpg
guetzli [--quality Q] [--verbose] original.png output.jpg
guetzli [--quality Q] [--verbose] original.jpg output.jpg
```

Note that Guetzli is designed to work on high quality images (e.g. that haven't
Expand Down
5 changes: 2 additions & 3 deletions WORKSPACE
Expand Up @@ -30,8 +30,7 @@ bind(
actual = "@gflags_git//:gflags",
)

git_repository(
local_repository(
name = "butteraugli",
commit = "037eff792f5b1cc7c21cc2cdd325de712c387e11",
remote = "https://github.com/google/butteraugli",
path = "third_party/butteraugli/",
)
213 changes: 213 additions & 0 deletions guetzli.make
@@ -0,0 +1,213 @@
# GNU Make project makefile autogenerated by Premake

ifndef config
config=release
endif

ifndef verbose
SILENT = @
endif

.PHONY: clean prebuild prelink

ifeq ($(config),release)
RESCOMP = windres
TARGETDIR = bin/Release
TARGET = $(TARGETDIR)/guetzli
OBJDIR = obj/Release
DEFINES += -DGFLAGS_NAMESPACE=google
INCLUDES += -I. -Ithird_party/butteraugli
FORCE_INCLUDE +=
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O3
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) -std=c++11
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS +=
LDDEPS +=
ALL_LDFLAGS += $(LDFLAGS) -s -lpng -lgflags_nothreads
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef
all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
@:

endif

ifeq ($(config),debug)
RESCOMP = windres
TARGETDIR = bin/Debug
TARGET = $(TARGETDIR)/guetzli
OBJDIR = obj/Debug
DEFINES += -DGFLAGS_NAMESPACE=google
INCLUDES += -I. -Ithird_party/butteraugli
FORCE_INCLUDE +=
ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS) -std=c++11
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS +=
LDDEPS +=
ALL_LDFLAGS += $(LDFLAGS) -lpng -lgflags_nothreads
LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef
all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
@:

endif

OBJECTS := \
$(OBJDIR)/butteraugli_comparator.o \
$(OBJDIR)/dct_double.o \
$(OBJDIR)/debug_print.o \
$(OBJDIR)/entropy_encode.o \
$(OBJDIR)/fdct.o \
$(OBJDIR)/gamma_correct.o \
$(OBJDIR)/guetzli.o \
$(OBJDIR)/idct.o \
$(OBJDIR)/jpeg_data.o \
$(OBJDIR)/jpeg_data_decoder.o \
$(OBJDIR)/jpeg_data_encoder.o \
$(OBJDIR)/jpeg_data_reader.o \
$(OBJDIR)/jpeg_data_writer.o \
$(OBJDIR)/jpeg_huffman_decode.o \
$(OBJDIR)/output_image.o \
$(OBJDIR)/preprocess_downsample.o \
$(OBJDIR)/processor.o \
$(OBJDIR)/quality.o \
$(OBJDIR)/quantize.o \
$(OBJDIR)/score.o \
$(OBJDIR)/butteraugli.o \

RESOURCES := \

CUSTOMFILES := \

SHELLTYPE := msdos
ifeq (,$(ComSpec)$(COMSPEC))
SHELLTYPE := posix
endif
ifeq (/bin,$(findstring /bin,$(SHELL)))
SHELLTYPE := posix
endif

$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES)
@echo Linking guetzli
$(SILENT) $(LINKCMD)
$(POSTBUILDCMDS)

$(TARGETDIR):
@echo Creating $(TARGETDIR)
ifeq (posix,$(SHELLTYPE))
$(SILENT) mkdir -p $(TARGETDIR)
else
$(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
endif

$(OBJDIR):
@echo Creating $(OBJDIR)
ifeq (posix,$(SHELLTYPE))
$(SILENT) mkdir -p $(OBJDIR)
else
$(SILENT) mkdir $(subst /,\\,$(OBJDIR))
endif

clean:
@echo Cleaning guetzli
ifeq (posix,$(SHELLTYPE))
$(SILENT) rm -f $(TARGET)
$(SILENT) rm -rf $(OBJDIR)
else
$(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
endif

prebuild:
$(PREBUILDCMDS)

prelink:
$(PRELINKCMDS)

ifneq (,$(PCH))
$(OBJECTS): $(GCH) $(PCH)
$(GCH): $(PCH)
@echo $(notdir $<)
$(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
endif

$(OBJDIR)/butteraugli_comparator.o: guetzli/butteraugli_comparator.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/dct_double.o: guetzli/dct_double.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/debug_print.o: guetzli/debug_print.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/entropy_encode.o: guetzli/entropy_encode.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/fdct.o: guetzli/fdct.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/gamma_correct.o: guetzli/gamma_correct.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/guetzli.o: guetzli/guetzli.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/idct.o: guetzli/idct.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/jpeg_data.o: guetzli/jpeg_data.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/jpeg_data_decoder.o: guetzli/jpeg_data_decoder.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/jpeg_data_encoder.o: guetzli/jpeg_data_encoder.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/jpeg_data_reader.o: guetzli/jpeg_data_reader.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/jpeg_data_writer.o: guetzli/jpeg_data_writer.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/jpeg_huffman_decode.o: guetzli/jpeg_huffman_decode.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/output_image.o: guetzli/output_image.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/preprocess_downsample.o: guetzli/preprocess_downsample.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/processor.o: guetzli/processor.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/quality.o: guetzli/quality.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/quantize.o: guetzli/quantize.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/score.o: guetzli/score.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
$(OBJDIR)/butteraugli.o: third_party/butteraugli/butteraugli/butteraugli.cc
@echo $(notdir $<)
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"

-include $(OBJECTS:%.o=%.d)
ifneq (,$(PCH))
-include $(OBJDIR)/$(notdir $(PCH)).d
endif
15 changes: 11 additions & 4 deletions guetzli/guetzli.cc
Expand Up @@ -24,6 +24,12 @@
#include "guetzli/quality.h"
#include "guetzli/stats.h"

#ifndef GFLAGS_NAMESPACE
using namespace gflags;
#else
using namespace GFLAGS_NAMESPACE;
#endif


DEFINE_bool(verbose, false,
"Print a verbose trace of all attempts to standard output.");
Expand Down Expand Up @@ -173,12 +179,13 @@ void WriteFileOrDie(FILE* f, const std::string& contents) {
} // namespace

int main(int argc, char** argv) {
gflags::SetUsageMessage("Guetzli JPEG compressor. Usage: \n"
"guetzli [flags] input_filename output_filename");
gflags::ParseCommandLineFlags(&argc, &argv, true);
SetUsageMessage(
"Guetzli JPEG compressor. Usage: \n"
"guetzli [flags] input_filename output_filename");
ParseCommandLineFlags(&argc, &argv, true);

if (argc != 3) {
gflags::ShowUsageWithFlags(argv[0]);
ShowUsageWithFlags(argv[0]);
return 1;
}

Expand Down
26 changes: 26 additions & 0 deletions premake5.lua
@@ -0,0 +1,26 @@
workspace "guetzli"
configurations { "Release", "Debug" }

flags { "C++11" }

filter "configurations:Debug"
symbols "On"
filter "configurations:Release"
optimize "Full"

project "guetzli"
kind "ConsoleApp"
language "C++"
nuget { "gflags:2.1.2.1", "libpng:1.6.26.1" }
includedirs { ".", "third_party/butteraugli" }
linkoptions { "-lpng", "-lgflags_nothreads" }
-- This should work with gflags 2.x. The gflags namespace is absent in
-- gflags-2.0, which is the version in Ubuntu Trusty package repository.
defines { "GFLAGS_NAMESPACE=google" }
files
{
"guetzli/*.cc",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is the expected state here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean first line is padded by 3 spaces here, not 2.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a github bug - it is ok in downloaded sources.

"guetzli/*.h",
"third_party/butteraugli/butteraugli/butteraugli.cc",
"third_party/butteraugli/butteraugli/butteraugli.h"
}
24 changes: 24 additions & 0 deletions third_party/butteraugli/BUILD
@@ -0,0 +1,24 @@
cc_library(
name = "butteraugli_lib",
srcs = [
"butteraugli/butteraugli.cc",
"butteraugli/butteraugli.h",
],
hdrs = [
"butteraugli/butteraugli.h",
],
copts = ["-Wno-sign-compare"],
visibility = ["//visibility:public"],
)

cc_binary(
name = "butteraugli",
srcs = ["butteraugli/butteraugli_main.cc"],
copts = ["-Wno-sign-compare"],
visibility = ["//visibility:public"],
deps = [
":butteraugli_lib",
"@jpeg_archive//:jpeg",
"@png_archive//:png",
],
)