modified: tasks/common.wdl
[GalaxyCodeBases.git] / shared / r.rb
blob76730e59436a8d6653dd7b352de2c9d508a18fff
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"
6   #revision 2
8   depends_on "pkg-config" => :build
9   depends_on "gcc" # for gfortran
10   depends_on "gettext"
11   depends_on "jpeg"
12   depends_on "libpng"
13   depends_on "pcre"
14   depends_on "readline"
15   depends_on "xz"
16   depends_on "cairo"
17   depends_on :java => :optional
19   unless OS.mac?
20     depends_on "openblas"
21     #depends_on "cairo"
22     depends_on "curl"
23     depends_on "linuxbrew/xorg/xorg"
24   else
25     depends_on "openblas" => :optional
26   end
28   # needed to preserve executable permissions on files without shebangs
29   skip_clean "lib/R/bin"
31   resource "gss" do
32     url "https://cloud.r-project.org/src/contrib/gss_2.1-9.tar.gz", :using => :nounzip
33     mirror "https://mirror.las.iastate.edu/CRAN/src/contrib/gss_2.1-9.tar.gz"
34     sha256 "2961fe61c1d3bb3fe7b8e1070d6fb1dfc5d71e0c6e8a6b7c46ff6b42867c4cf3"
35   end
37   def install
38     # Fix dyld: lazy symbol binding failed: Symbol not found: _clock_gettime
39     if MacOS.version == "10.11" && MacOS::Xcode.installed? &&
40        MacOS::Xcode.version >= "8.0"
41       ENV["ac_cv_have_decl_clock_gettime"] = "no"
42     end
44     args = [
45       "--prefix=#{prefix}",
46       "--enable-memory-profiling",
47       "--with-lapack",
48       "--enable-R-shlib",
49       #"--disable-java",
50       #"--with-blas=-L#{Formula["openblas"].opt_lib} -lopenblas",
51       "--with-cairo",
52     ]
54     # don't remember Homebrew's sed shim
55     args << "SED=/usr/bin/sed" if File.exist?("/usr/bin/sed")
57     unless OS.mac?
58       args << "--libdir=#{lib}" # avoid using lib64 on CentOS
59       #args << "--with-cairo"
61       # If LDFLAGS contains any -L options, configure sets LD_LIBRARY_PATH to
62       # search those directories. Remove -LHOMEBREW_PREFIX/lib from LDFLAGS.
63       ENV.remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"
65       args << "--with-blas=-L#{Formula["openblas"].opt_lib} -lopenblas"
66       #ENV.append "LDFLAGS", "-L#{Formula["openblas"].opt_lib}"
67     else
68       #args << "--with-cairo"
69       # https://github.com/Homebrew/homebrew-core/pull/24094/commits/22d0eeaae2f05c1a6b671728d88572b0fe8aa5ae
70       # Fix cairo detection with Quartz-only cairo
71       inreplace ["configure", "m4/cairo.m4"], "cairo-xlib.h", "cairo.h"
73       #args << "--without-cairo"
74       args << "--without-x"
75       args << "--with-aqua"
77       if build.with? "openblas"
78         args << "--with-blas=-L#{Formula["openblas"].opt_lib} -lopenblas"
79       else
80         args << "--with-blas=-framework Accelerate"
81         ENV.append_to_cflags "-D__ACCELERATE__" if ENV.compiler != :clang
82       end
83     end
85     if build.with? "java"
86       args << "--enable-java"
87     else
88       args << "--disable-java"
89     end
91     # Help CRAN packages find gettext and readline
92     ["gettext", "readline"].each do |f|
93       ENV.append "CPPFLAGS", "-I#{Formula[f].opt_include}"
94       ENV.append "LDFLAGS", "-L#{Formula[f].opt_lib}"
95     end
97     system "./configure", *args
98     system "make"
99     ENV.deparallelize do
100       system "make", "install"
101     end
103     cd "src/nmath/standalone" do
104       system "make"
105       ENV.deparallelize do
106         system "make", "install"
107       end
108     end
110     r_home = lib/"R"
112     # make Homebrew packages discoverable for R CMD INSTALL
113     inreplace r_home/"etc/Makeconf" do |s|
114       s.gsub!(/^CPPFLAGS =.*/, "\\0 -I#{HOMEBREW_PREFIX}/include")
115       s.gsub!(/^LDFLAGS =.*/, "\\0 -L#{HOMEBREW_PREFIX}/lib")
116       s.gsub!(/.LDFLAGS =.*/, "\\0 $(LDFLAGS)")
117     end
119     include.install_symlink Dir[r_home/"include/*"]
120     lib.install_symlink Dir[r_home/"lib/*"]
122     # avoid triggering mandatory rebuilds of r when gcc is upgraded
123     inreplace lib/"R/etc/Makeconf",
124       Formula["gcc"].prefix.realpath,
125       Formula["gcc"].opt_prefix,
126       OS.mac?
127   end
129   def post_install
130     short_version =
131       `#{bin}/Rscript -e 'cat(as.character(getRversion()[1,1:2]))'`.strip
132     site_library = HOMEBREW_PREFIX/"lib/R/#{short_version}/site-library"
133     site_library.mkpath
134     ln_s site_library, lib/"R/site-library"
135   end
137   test do
138     dylib_ext = OS.mac? ? ".dylib" : ".so"
139     assert_equal "[1] 2", shell_output("#{bin}/Rscript -e 'print(1+1)'").chomp
140     assert_equal dylib_ext, shell_output("#{bin}/R CMD config DYLIB_EXT").chomp
142     testpath.install resource("gss")
143     system bin/"R", "CMD", "INSTALL", "--library=.", Dir["gss*"].first
144     assert_predicate testpath/"gss/libs/gss.so", :exist?,
145                      "Failed to install gss package"
146   end