-
-
Notifications
You must be signed in to change notification settings - Fork 12.3k
/
r.rb
108 lines (92 loc) · 3.63 KB
/
r.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
class R < Formula
desc "Software environment for statistical computing"
homepage "https://www.r-project.org/"
url "https://cran.r-project.org/src/base/R-4/R-4.0.3.tar.gz"
sha256 "09983a8a78d5fb6bc45d27b1c55f9ba5265f78fa54a55c13ae691f87c5bb9e0d"
license "GPL-2.0-or-later"
revision 2
livecheck do
url "https://cran.rstudio.com/banner.shtml"
regex(%r{href=(?:["']?|.*?/)R[._-]v?(\d+(?:\.\d+)+)\.t}i)
end
bottle do
sha256 "d3859bfc06a1cac65a60a43f105aec2b3c2ebdb465b69eb6988a4686eefd0819" => :big_sur
sha256 "67c3d8b4f5adcfe3da2651c5f300b56a2129130db579c65eda952023ef305849" => :arm64_big_sur
sha256 "057a9e1fafd85ec2f65ecbfb651f6299cbbaab630158d6cf6d1057b43f7b9f29" => :catalina
sha256 "ffffeb9ad7f2892187d26fde97bc8f47ba4b27bf95ea8bcc1ce43a09771f7d51" => :mojave
end
depends_on "pkg-config" => :build
depends_on "gcc" # for gfortran
depends_on "gettext"
depends_on "jpeg"
depends_on "libpng"
depends_on "openblas"
depends_on "pcre2"
depends_on "readline"
depends_on "tcl-tk"
depends_on "xz"
# needed to preserve executable permissions on files without shebangs
skip_clean "lib/R/bin", "lib/R/doc"
def install
# BLAS detection fails with Xcode 12 due to missing prototype
# https://bugs.r-project.org/bugzilla/show_bug.cgi?id=18024
ENV.append "CFLAGS", "-Wno-implicit-function-declaration"
args = [
"--prefix=#{prefix}",
"--enable-memory-profiling",
"--without-cairo",
"--without-x",
"--with-tcl-config=#{Formula["tcl-tk"].opt_lib}/tclConfig.sh",
"--with-tk-config=#{Formula["tcl-tk"].opt_lib}/tkConfig.sh",
"--with-aqua",
"--with-blas=-L#{Formula["openblas"].opt_lib} -lopenblas",
"--enable-R-shlib",
"SED=/usr/bin/sed", # don't remember Homebrew's sed shim
"--disable-java",
]
# Help CRAN packages find gettext and readline
["gettext", "readline", "xz"].each do |f|
ENV.append "CPPFLAGS", "-I#{Formula[f].opt_include}"
ENV.append "LDFLAGS", "-L#{Formula[f].opt_lib}"
end
system "./configure", *args
system "make"
ENV.deparallelize do
system "make", "install"
end
cd "src/nmath/standalone" do
system "make"
ENV.deparallelize do
system "make", "install"
end
end
r_home = lib/"R"
# make Homebrew packages discoverable for R CMD INSTALL
inreplace r_home/"etc/Makeconf" do |s|
s.gsub!(/^CPPFLAGS =.*/, "\\0 -I#{HOMEBREW_PREFIX}/include")
s.gsub!(/^LDFLAGS =.*/, "\\0 -L#{HOMEBREW_PREFIX}/lib")
s.gsub!(/.LDFLAGS =.*/, "\\0 $(LDFLAGS)")
end
include.install_symlink Dir[r_home/"include/*"]
lib.install_symlink Dir[r_home/"lib/*"]
# avoid triggering mandatory rebuilds of r when gcc is upgraded
inreplace lib/"R/etc/Makeconf", Formula["gcc"].prefix.realpath,
Formula["gcc"].opt_prefix
end
def post_install
short_version =
`#{bin}/Rscript -e 'cat(as.character(getRversion()[1,1:2]))'`.strip
site_library = HOMEBREW_PREFIX/"lib/R/#{short_version}/site-library"
site_library.mkpath
ln_s site_library, lib/"R/site-library"
end
test do
assert_equal "[1] 2", shell_output("#{bin}/Rscript -e 'print(1+1)'").chomp
assert_equal ".dylib", shell_output("#{bin}/R CMD config DYLIB_EXT").chomp
assert_equal "[1] \"aqua\"",
shell_output("#{bin}/Rscript -e 'library(tcltk)' -e 'tclvalue(.Tcl(\"tk windowingsystem\"))'").chomp
system bin/"Rscript", "-e", "install.packages('gss', '.', 'https://cloud.r-project.org')"
assert_predicate testpath/"gss/libs/gss.so", :exist?,
"Failed to install gss package"
end
end