138 lines
5.3 KiB
Ruby
138 lines
5.3 KiB
Ruby
class Grokj2k < Formula
|
|
desc "JPEG 2000 Library"
|
|
homepage "https://github.com/GrokImageCompression/grok"
|
|
url "https://github.com/GrokImageCompression/grok/archive/v10.0.4.tar.gz"
|
|
sha256 "8b9e3f1f2dc9f8475221aa7c94fbdf08898ae45a8e8453aed9f0594dd7ba272f"
|
|
license "AGPL-3.0-or-later"
|
|
head "https://github.com/GrokImageCompression/grok.git", branch: "master"
|
|
|
|
livecheck do
|
|
url :stable
|
|
regex(/^v?(\d+(?:\.\d+)+)$/i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 cellar: :any, arm64_ventura: "65a4253b600244d5139aae29f4a439f314e057df2016fd8c0051ddd12e377438"
|
|
sha256 cellar: :any, arm64_monterey: "e5a0048b4a441f37aa43f8e0f58cd3e130a16f7034ac1be02031bbde7ff8b311"
|
|
sha256 cellar: :any, arm64_big_sur: "b9848a27bb829c55566579b3884ca443ec9dc134204d6046eb593b2582925e4f"
|
|
sha256 cellar: :any, ventura: "f660ea93486302ba50ba313a83ba92456a6c212b69a964cd153e5628c31cd29b"
|
|
sha256 cellar: :any, monterey: "e5f7760e2d9c344f0132093fe71702bc0fd9ced345a7f12f005c60fe39fdf298"
|
|
sha256 cellar: :any, big_sur: "d47bb02be03404ce7440f23712cd5044a4fda722441e914c36bcb19bc61a10fb"
|
|
sha256 cellar: :any, catalina: "8d2d9796e8d9a52bee653f6f1f494c59900f5f89c1eadb88d2172400dbaca455"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "03e58dff0870d9b0f58412b910cbccaf4f750bc19d679ddbb3a8f9a644760137"
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "doxygen" => :build
|
|
depends_on "pkg-config" => :build
|
|
depends_on "exiftool"
|
|
depends_on "jpeg-turbo"
|
|
depends_on "libpng"
|
|
depends_on "libtiff"
|
|
depends_on "little-cms2"
|
|
depends_on macos: :catalina
|
|
|
|
uses_from_macos "perl"
|
|
uses_from_macos "zlib"
|
|
|
|
on_macos do
|
|
depends_on "llvm" => :build if DevelopmentTools.clang_build_version <= 1200
|
|
end
|
|
|
|
fails_with :clang do
|
|
build 1200
|
|
cause "Requires C++20"
|
|
end
|
|
|
|
# https://github.com/GrokImageCompression/grok/blob/master/INSTALL.md#compilers
|
|
fails_with :gcc do
|
|
version "9"
|
|
cause "GNU compiler version must be at least 10.0"
|
|
end
|
|
|
|
resource "homebrew-test_image" do
|
|
url "https://raw.githubusercontent.com/GrokImageCompression/input_image_test_suite/173de0ae73371751f857d16fdaf2c3301e54a3a6/exif-samples/tiff/Tless0.tiff"
|
|
sha256 "32f6aab90dc2d284a83040debe379e01333107b83a98c1aa2e6dabf56790b48a"
|
|
end
|
|
|
|
def install
|
|
ENV.llvm_clang if OS.mac? && (DevelopmentTools.clang_build_version <= 1200)
|
|
|
|
# Fix: ExifTool Perl module not found
|
|
ENV.prepend_path "PERL5LIB", Formula["exiftool"].opt_libexec/"lib"
|
|
|
|
# Ensure we use Homebrew little-cms2
|
|
%w[liblcms2 libpng libtiff libz].each { |l| (buildpath/"thirdparty"/l).rmtree }
|
|
inreplace "thirdparty/CMakeLists.txt" do |s|
|
|
s.gsub! "add_subdirectory(liblcms2)", ""
|
|
s.gsub! %r{(set\(LCMS_INCLUDE_DIRNAME) \$\{GROK_SOURCE_DIR\}/thirdparty/liblcms2/include},
|
|
"\\1 #{Formula["little-cms2"].opt_include}"
|
|
end
|
|
|
|
perl = DevelopmentTools.locate("perl")
|
|
perl_archlib = Utils.safe_popen_read(perl.to_s, "-MConfig", "-e", "print $Config{archlib}")
|
|
args = %W[
|
|
-DGRK_BUILD_DOC=ON
|
|
-DGRK_BUILD_LIBPNG=OFF
|
|
-DGRK_BUILD_LIBTIFF=OFF
|
|
-DPERL_EXECUTABLE=#{perl}
|
|
]
|
|
|
|
if OS.mac?
|
|
# Workaround Perl 5.18 issues with C++11: pad.h:323:17: error: invalid suffix on literal
|
|
ENV.append "CXXFLAGS", "-Wno-reserved-user-defined-literal" if MacOS.version <= :catalina
|
|
# Help CMake find Perl libraries, which are needed to enable ExifTool feature.
|
|
# Without this, CMake outputs: Could NOT find PerlLibs (missing: PERL_INCLUDE_PATH)
|
|
args << "-DPERL_INCLUDE_PATH=#{MacOS.sdk_path_if_needed}/#{perl_archlib}/CORE"
|
|
else
|
|
# Fix linkage error due to RPATH missing directory with libperl.so
|
|
ENV.append "LDFLAGS", "-Wl,-rpath,#{perl_archlib}/CORE"
|
|
end
|
|
|
|
system "cmake", "-S", ".", "-B", "build", *std_cmake_args, *args
|
|
system "cmake", "--build", "build"
|
|
system "cmake", "--install", "build"
|
|
include.install_symlink "grok-#{version.major_minor}" => "grok"
|
|
|
|
bin.env_script_all_files libexec, PERL5LIB: ENV["PERL5LIB"]
|
|
end
|
|
|
|
test do
|
|
(testpath/"test.c").write <<~EOS
|
|
#include <grok/grok.h>
|
|
|
|
int main () {
|
|
grk_image_comp cmptparm;
|
|
const GRK_COLOR_SPACE color_space = GRK_CLRSPC_GRAY;
|
|
|
|
grk_image *image;
|
|
image = grk_image_new(1, &cmptparm, color_space);
|
|
|
|
grk_object_unref(&image->obj);
|
|
return 0;
|
|
}
|
|
EOS
|
|
system ENV.cc, "test.c", "-I#{include}", "-L#{lib}", "-lgrokj2k", "-o", "test"
|
|
system "./test"
|
|
|
|
# Test Exif metadata retrieval
|
|
resource("homebrew-test_image").stage do
|
|
system bin/"grk_compress", "-in_file", "Tless0.tiff",
|
|
"-out_file", "test.jp2", "-out_fmt", "jp2",
|
|
"-transfer_exif_tags"
|
|
output = shell_output("#{Formula["exiftool"].bin}/exiftool test.jp2")
|
|
|
|
[
|
|
"Exif Byte Order : Big-endian (Motorola, MM)",
|
|
"Orientation : Horizontal (normal)",
|
|
"X Resolution : 72",
|
|
"Y Resolution : 72",
|
|
"Resolution Unit : inches",
|
|
"Y Cb Cr Positioning : Centered",
|
|
].each do |data|
|
|
assert_match data, output
|
|
end
|
|
end
|
|
end
|
|
end
|