-
-
Notifications
You must be signed in to change notification settings - Fork 12.3k
/
mupdf.rb
119 lines (102 loc) · 4.66 KB
/
mupdf.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class Mupdf < Formula
desc "Lightweight PDF and XPS viewer"
homepage "https://mupdf.com/"
url "https://mupdf.com/downloads/archive/mupdf-1.24.9-source.tar.gz"
sha256 "0b446aa0eecc114e9969dccd70c9789358fccb6589a81d470dc941a0874da98a"
license "AGPL-3.0-or-later"
head "https://git.ghostscript.com/mupdf.git", branch: "master"
livecheck do
url "https://mupdf.com/releases"
regex(/href=.*?mupdf[._-]v?(\d+(?:\.\d+)+)-source\.(?:t|zip)/i)
end
bottle do
sha256 cellar: :any, arm64_sequoia: "eef2190c572764150e6858ad29807000644aac70780990596df4cc6a84dcc61d"
sha256 cellar: :any, arm64_sonoma: "32cd3dac426f00ab587bed33dd60bf861179babb06fa806410433e552eed2132"
sha256 cellar: :any, arm64_ventura: "46bf0dda1818ca6a5d94eb489c3498a9aa6e5bd8f9188a223c336a820e20f7c7"
sha256 cellar: :any, arm64_monterey: "6fbe9a412b689da2d09a3e113c48e4d8b242fe232649dc22922f88f2fef36d11"
sha256 cellar: :any, sonoma: "9fcf9b17272159016a482d90eceaf739f5716482dfa7527344e264b7d9ead82c"
sha256 cellar: :any, ventura: "26744f3074268252ef4147e1d72e80f47db544516ebb219af2c6dabb7d9c325a"
sha256 cellar: :any, monterey: "5703f9d46c902dd5e538ba62cb24ff86cff69cf408c03ce4517b088014f9dc62"
sha256 cellar: :any_skip_relocation, x86_64_linux: "510087c1505b18d5f417bb5765ca4762d2a2df3a074a708b4749736ae215ae2f"
end
depends_on "llvm" => :build
depends_on "pkg-config" => :build
depends_on "swig" => :build
depends_on "freetype"
depends_on "gumbo-parser"
depends_on "harfbuzz"
depends_on "jbig2dec"
depends_on "jpeg-turbo"
depends_on "leptonica"
depends_on "mujs"
depends_on "openjpeg"
depends_on "openssl@3"
depends_on "python@3.12"
depends_on "tesseract"
uses_from_macos "zlib"
on_linux do
depends_on "freeglut"
depends_on "libx11"
depends_on "libxext"
depends_on "mesa"
end
conflicts_with "mupdf-tools", because: "both install the same binaries"
def install
# Remove bundled libraries excluding `extract` and "strongly preferred" `lcms2mt` (lcms2 fork)
keep = %w[extract lcms2]
(buildpath/"thirdparty").each_child { |path| rm_r(path) if keep.exclude? path.basename.to_s }
# For python bindings needed by `pymupdf`: https://pymupdf.readthedocs.io/en/latest/packaging.html
site_packages = Language::Python.site_packages("python3.12")
ENV.prepend_path "PYTHONPATH", Formula["llvm"].opt_prefix/site_packages
args = %W[
build=release
shared=yes
tesseract=yes
verbose=yes
prefix=#{prefix}
pydir=#{prefix/site_packages}
CC=#{ENV.cc}
USE_SYSTEM_LIBS=yes
USE_SYSTEM_MUJS=yes
VENV_FLAG=
]
# Build only runs pkg-config for libcrypto on macOS, so help find other libs
if OS.mac?
[
["FREETYPE", "freetype2"],
["GUMBO", "gumbo"],
["HARFBUZZ", "harfbuzz"],
["LEPTONICA", "lept"],
["LIBJPEG", "libjpeg"],
["OPENJPEG", "libopenjp2"],
].each do |argname, libname|
args << "SYS_#{argname}_CFLAGS=#{Utils.safe_popen_read("pkg-config", "--cflags", libname).strip}"
args << "SYS_#{argname}_LIBS=#{Utils.safe_popen_read("pkg-config", "--libs", libname).strip}"
args << "HAVE_SYS_#{argname}=yes"
end
# Workarounds since build scripts for Python bindings don't support macOS
# Issue ref: https://bugs.ghostscript.com/show_bug.cgi?id=705376
inreplace "Makefile" do |s|
# Avoid creating a symlink that overwrites installed file
s.gsub!(/^\s*ln -sf libmupdf/, "#\\0")
# FIXME: libmupdfcpp should be a shared lib (.dylib) while _mupdf should be a bundle
# (.so) as the former is a C++ library installed into `lib` while latter is loaded by
# Python bindings. However, the python build scripts hardcode `.so` and uses `-shared`
# which result in neither being correct. Also, the Makefile installs with $(SO) which
# fails to find `.so`. For now we do the easier workaround of installing as `.so`.
s.gsub! "libmupdfcpp.$(SO)", "libmupdfcpp.so"
s.gsub! "_mupdf.$(SO)", "_mupdf.so"
end
ENV.cxx11
end
system "make", "install", *args
system "make", "install-shared-python", *args
# Symlink `mutool` as `mudraw` (a popular shortcut for `mutool draw`).
bin.install_symlink bin/"mutool" => "mudraw"
man1.install_symlink man1/"mutool.1" => "mudraw.1"
lib.install_symlink lib/shared_library("libmupdf") => shared_library("libmupdf-third")
end
test do
assert_match "Homebrew test", shell_output("#{bin}/mudraw -F txt #{test_fixtures("test.pdf")}")
end
end