137 lines
5.2 KiB
Ruby
137 lines
5.2 KiB
Ruby
class Grokj2k < Formula
|
|
desc "JPEG 2000 Library"
|
|
homepage "https://github.com/GrokImageCompression/grok"
|
|
url "https://github.com/GrokImageCompression/grok/archive/v10.0.5.tar.gz"
|
|
sha256 "963a067aaa986e13d8000af82a47d25df974050a0a3c1c8cfb78ebc37797daf4"
|
|
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: "c7ba1197d32ea033a1d546858ffda5338382dc58767ae36c74ae186135757933"
|
|
sha256 cellar: :any, arm64_monterey: "144959592dc5de0d34e0f4137d8afa4fe982ccc6f3c292ea0de899313c434913"
|
|
sha256 cellar: :any, arm64_big_sur: "0934e68d2459f9ad9642f2a8dc588f92985bff49bf8359a60336128a8e1ec11c"
|
|
sha256 cellar: :any, ventura: "0c4b5c52cbbbf3426ee1a75683b69774405b2eb1796ef9a799ea27d9816cfcf3"
|
|
sha256 cellar: :any, monterey: "08836fab26d7d2c5938fca9b7ecf570293687951e93c37f4f5ec3a082bcb2c66"
|
|
sha256 cellar: :any, big_sur: "678a28f222a634058d19fc3ce834ef79cb884feab047440ad715e138b1244239"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "e5646cd29a861cfd7a652c271676bc00a7c739b782441f1d6f413977d3cf1a75"
|
|
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
|