class R < Formula desc "Software environment for statistical computing" homepage "https://www.r-project.org/" url "https://cran.r-project.org/src/base/R-3/R-3.4.4.tar.gz" sha256 "b3e97d2fab7256d1c655c4075934725ba1cd7cb9237240a11bb22ccdad960337" bottle do sha256 "0bc44bf3f7de7a7bba6f25d0db2ba5525a032f8119b3bce3ecf03c40812d5c3d" => :high_sierra sha256 "cb8b59f45018cefbfad6147b1b304fd756941ea7b8038187d1292bc42b758b4e" => :sierra sha256 "d0b25446d186207b998248bbb4a30e05882a9d278a2fb12c89eca639a10c08fa" => :el_capitan end depends_on "pkg-config" => :build depends_on "gcc" # for gfortran depends_on "gettext" depends_on "jpeg" depends_on "libpng" depends_on "pcre" depends_on "readline" depends_on "xz" depends_on "openblas" => :optional depends_on :java => :optional # needed to preserve executable permissions on files without shebangs skip_clean "lib/R/bin" resource "gss" do url "https://cloud.r-project.org/src/contrib/gss_2.1-7.tar.gz", :using => :nounzip mirror "https://mirror.las.iastate.edu/CRAN/src/contrib/gss_2.1-7.tar.gz" sha256 "0405bb5e4c4d60b466335e5da07be4f9570045a24aed09e7bc0640e1a00f3adb" end def install # Fix dyld: lazy symbol binding failed: Symbol not found: _clock_gettime if MacOS.version == "10.11" && MacOS::Xcode.installed? && MacOS::Xcode.version >= "8.0" ENV["ac_cv_have_decl_clock_gettime"] = "no" end args = [ "--prefix=#{prefix}", "--enable-memory-profiling", "--without-cairo", "--without-x", "--with-aqua", "--with-lapack", "--enable-R-shlib", "SED=/usr/bin/sed", # don't remember Homebrew's sed shim ] if build.with? "openblas" args << "--with-blas=-L#{Formula["openblas"].opt_lib} -lopenblas" ENV.append "LDFLAGS", "-L#{Formula["openblas"].opt_lib}" else args << "--with-blas=-framework Accelerate" ENV.append_to_cflags "-D__ACCELERATE__" if ENV.compiler != :clang end if build.with? "java" args << "--enable-java" else args << "--disable-java" end # Help CRAN packages find gettext and readline ["gettext", "readline"].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 testpath.install resource("gss") system bin/"R", "CMD", "INSTALL", "--library=.", Dir["gss*"].first assert_predicate testpath/"gss/libs/gss.so", :exist?, "Failed to install gss package" end end