/
tesseract.rb
127 lines (106 loc) 路 4.29 KB
/
tesseract.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
120
121
122
123
124
125
126
127
class Tesseract < Formula
desc "OCR (Optical Character Recognition) engine"
homepage "https://github.com/tesseract-ocr/"
url "https://github.com/tesseract-ocr/tesseract/archive/3.05.00.tar.gz"
sha256 "3fe83e06d0f73b39f6e92ed9fc7ccba3ef734877b76aa5ddaaa778fac095d996"
revision 1
bottle do
sha256 "d2ec7a1ef8859c28dd0d1e2e5a4bf54224bf971e11863bef693687fb3f166180" => :sierra
sha256 "ebbb35f1423ee0ee446908af35d0aa2d7cf062e709599a0f9defad8cdac4498a" => :el_capitan
sha256 "626c9003f601105a4e7e3bee9fca179f63b9823b970b547aa458e09e98644c84" => :yosemite
end
head do
url "https://github.com/tesseract-ocr/tesseract.git"
resource "tessdata-head" do
url "https://github.com/tesseract-ocr/tessdata.git"
end
end
option "with-all-languages", "Install recognition data for all languages"
option "with-training-tools", "Install OCR training tools"
option "with-opencl", "Enable OpenCL support"
option "with-serial-num-pack", "Install serial number recognition pack"
deprecated_option "all-languages" => "with-all-languages"
depends_on "autoconf" => :build
depends_on "autoconf-archive" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
depends_on "pkg-config" => :build
depends_on "leptonica"
depends_on "libtiff"
if build.with? "training-tools"
depends_on "libtool" => :build
depends_on "icu4c"
depends_on "glib"
depends_on "cairo"
depends_on "pango"
depends_on :x11
end
needs :cxx11
resource "tessdata" do
url "https://github.com/tesseract-ocr/tessdata/archive/3.04.00.tar.gz"
sha256 "5dcb37198336b6953843b461ee535df1401b41008d550fc9e43d0edabca7adb1"
end
resource "eng" do
url "https://github.com/tesseract-ocr/tessdata/raw/3.04.00/eng.traineddata"
sha256 "c0515c9f1e0c79e1069fcc05c2b2f6a6841fb5e1082d695db160333c1154f06d"
end
resource "osd" do
url "https://github.com/tesseract-ocr/tessdata/raw/3.04.00/osd.traineddata"
sha256 "9cf5d576fcc47564f11265841e5ca839001e7e6f38ff7f7aacf46d15a96b00ff"
end
resource "snum" do
url "https://github.com/USCDataScience/counterfeit-electronics-tesseract/raw/319a6eeacff181dad5c02f3e7a3aff804eaadeca/Training%20Tesseract/snum.traineddata"
sha256 "36f772980ff17c66a767f584a0d80bf2302a1afa585c01a226c1863afcea1392"
end
# remove on next release, > 3.05.00
# upstream fix for building with OpenCL enabled
# https://github.com/tesseract-ocr/tesseract/pull/814
patch do
url "https://github.com/tesseract-ocr/tesseract/commit/b18cad4.patch"
sha256 "10c59baa54c3406fcd03f36cd0f1e3cc2ba150f082d14f919274a541b3cff7b2"
end
def install
if build.head?
# ld: symbol(s) not found for _clSetKernelArg and other symbols
# Regression caused by https://github.com/tesseract-ocr/tesseract/commit/b1c921b
# Reported 13 Sep 2016 https://github.com/tesseract-ocr/tesseract/issues/426
inreplace "api/Makefile.am", "$(GENERIC_LIBRARY_VERSION) -no-undefined",
"$(GENERIC_LIBRARY_VERSION)"
end
if build.with? "training-tools"
icu4c = Formula["icu4c"]
ENV.append "CFLAGS", "-I#{icu4c.opt_include}"
ENV.append "LDFLAGS", "-L#{icu4c.opt_lib}"
end
# explicitly state leptonica header location, as the makefile defaults to /usr/local/include,
# which doesn't work for non-default homebrew location
ENV["LIBLEPT_HEADERSDIR"] = HOMEBREW_PREFIX/"include"
ENV.cxx11
system "./autogen.sh"
args = %W[
--disable-dependency-tracking
--prefix=#{prefix}
]
args << "--enable-opencl" if build.with? "opencl"
system "./configure", *args
system "make", "install"
if build.with? "serial-num-pack"
resource("snum").stage { mv "snum.traineddata", share/"tessdata" }
end
if build.with? "training-tools"
system "make", "training"
system "make", "training-install"
end
if build.head?
resource("tessdata-head").stage { mv Dir["*"], share/"tessdata" }
elsif build.with? "all-languages"
resource("tessdata").stage { mv Dir["*"], share/"tessdata" }
else
resource("eng").stage { mv "eng.traineddata", share/"tessdata" }
resource("osd").stage { mv "osd.traineddata", share/"tessdata" }
end
end
test do
assert_match version.to_s, shell_output("#{bin}/tesseract -v 2>&1")
end
end