modified: tasks/common.wdl
[GalaxyCodeBases.git] / shared / r.lc.rb
blob41b5dfbf24b2cb874ecb93c429a670251f6ac1ca
1 class R < Formula
2   desc "Software environment for statistical computing"
3   homepage "https://www.r-project.org/"
4   url "https://cran.r-project.org/src/base/R-3/R-3.5.3.tar.gz"
5   sha256 "2bfa37b7bd709f003d6b8a172ddfb6d03ddd2d672d6096439523039f7a8e678c"
7   bottle do
8     root_url "https://linuxbrew.bintray.com/bottles"
9     sha256 "8d1c5161ae03b34d8ed55bd7aa60c708b196b39929cd867bf80973640915f86e" => :mojave
10     sha256 "e1d29ef3229094d533527fa8caaf1d747548b06ef03260dbda3b490f8ee85904" => :high_sierra
11     sha256 "e3da4551f917e2846fb7c887c1bffdd923fcd8abab3f035d69c592ef74d9a18a" => :sierra
12     sha256 "448ad4b364a862a39e95c515110a15725061fe52bbd354a90a08013e978d786a" => :x86_64_linux
13   end
15   depends_on "pkg-config" => :build
16   depends_on "gcc" # for gfortran
17   depends_on "gettext"
18   depends_on "jpeg"
19   depends_on "libpng"
20   depends_on "openblas"
21   depends_on "pcre"
22   depends_on "readline"
23   depends_on "xz"
25   unless OS.mac?
26     depends_on "cairo"
27     depends_on "curl"
28     depends_on "linuxbrew/xorg/xorg"
29   end
31   # needed to preserve executable permissions on files without shebangs
32   skip_clean "lib/R/bin"
34   resource "gss" do
35     url "https://cloud.r-project.org/src/contrib/gss_2.1-9.tar.gz", :using => :nounzip
36     mirror "https://mirror.las.iastate.edu/CRAN/src/contrib/gss_2.1-9.tar.gz"
37     sha256 "2961fe61c1d3bb3fe7b8e1070d6fb1dfc5d71e0c6e8a6b7c46ff6b42867c4cf3"
38   end
40   def install
41     # Fix dyld: lazy symbol binding failed: Symbol not found: _clock_gettime
42     if MacOS.version == "10.11" && MacOS::Xcode.installed? &&
43        MacOS::Xcode.version >= "8.0"
44       ENV["ac_cv_have_decl_clock_gettime"] = "no"
45     end
47     args = [
48       "--prefix=#{prefix}",
49       "--enable-memory-profiling",
50       "--with-lapack",
51       "--enable-R-shlib",
52       "--disable-java",
53       "--with-blas=-L#{Formula["openblas"].opt_lib} -lopenblas",
54     ]
56     # don't remember Homebrew's sed shim
57     args << "SED=/usr/bin/sed" if File.exist?("/usr/bin/sed")
59     unless OS.mac?
60       args << "--libdir=#{lib}" # avoid using lib64 on CentOS
61       args << "--with-cairo"
63       # If LDFLAGS contains any -L options, configure sets LD_LIBRARY_PATH to
64       # search those directories. Remove -LHOMEBREW_PREFIX/lib from LDFLAGS.
65       ENV.remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"
66     end
68     # Help CRAN packages find gettext and readline
69     ["gettext", "readline"].each do |f|
70       ENV.append "CPPFLAGS", "-I#{Formula[f].opt_include}"
71       ENV.append "LDFLAGS", "-L#{Formula[f].opt_lib}"
72     end
74     system "./configure", *args
75     system "make"
76     ENV.deparallelize do
77       system "make", "install"
78     end
80     cd "src/nmath/standalone" do
81       system "make"
82       ENV.deparallelize do
83         system "make", "install"
84       end
85     end
87     r_home = lib/"R"
89     # make Homebrew packages discoverable for R CMD INSTALL
90     inreplace r_home/"etc/Makeconf" do |s|
91       s.gsub!(/^CPPFLAGS =.*/, "\\0 -I#{HOMEBREW_PREFIX}/include")
92       s.gsub!(/^LDFLAGS =.*/, "\\0 -L#{HOMEBREW_PREFIX}/lib")
93       s.gsub!(/.LDFLAGS =.*/, "\\0 $(LDFLAGS)")
94     end
96     include.install_symlink Dir[r_home/"include/*"]
97     lib.install_symlink Dir[r_home/"lib/*"]
99     # avoid triggering mandatory rebuilds of r when gcc is upgraded
100     inreplace lib/"R/etc/Makeconf",
101       Formula["gcc"].prefix.realpath,
102       Formula["gcc"].opt_prefix,
103       OS.mac?
104   end
106   def post_install
107     short_version =
108       `#{bin}/Rscript -e 'cat(as.character(getRversion()[1,1:2]))'`.strip
109     site_library = HOMEBREW_PREFIX/"lib/R/#{short_version}/site-library"
110     site_library.mkpath
111     ln_s site_library, lib/"R/site-library"
112   end
114   test do
115     dylib_ext = OS.mac? ? ".dylib" : ".so"
116     assert_equal "[1] 2", shell_output("#{bin}/Rscript -e 'print(1+1)'").chomp
117     assert_equal dylib_ext, shell_output("#{bin}/R CMD config DYLIB_EXT").chomp
119     testpath.install resource("gss")
120     system bin/"R", "CMD", "INSTALL", "--library=.", Dir["gss*"].first
121     assert_predicate testpath/"gss/libs/gss.so", :exist?,
122                      "Failed to install gss package"
123   end