fd428280b72ca1db4a85b2e6222eab3751c02e54
[lazar] / ext / lazar / extconf.rb
1 require 'fileutils'
2 require 'rbconfig'
3 require 'mkmf'
4
5 main_dir = File.expand_path(File.join(File.dirname(__FILE__),"..",".."))
6
7 # check for required programs
8 programs = ["R","Rscript","mongod","java","getconf","wget","unzip","xls2csv"]
9 programs.each do |program|
10   abort "Please install #{program} on your system." unless find_executable program
11 end
12
13 abort "Please install Rserve on your system. Execute 'install.packages('Rserve')' in a R console running as root ('sudo R')."  unless `R CMD Rserve --version`.match(/^Rserve/)
14
15 # install R packages
16 r_dir = File.join main_dir, "R"
17 FileUtils.mkdir_p r_dir
18 #FileUtils.mkdir_p File.join(main_dir,"bin") # for Rserve binary
19 rinstall = File.expand_path(File.join(File.dirname(__FILE__),"rinstall.R"))
20 puts `Rscript --vanilla #{rinstall} #{r_dir}`
21
22 r_libs = Dir[File.join(r_dir,"*")].collect{|l| l.sub(r_dir, '').sub('/','')}.sort
23 ["caret","doMC","foreach","ggplot2","gridExtra","iterators","pls"].each do |lib|
24   abort "Failed to install R package '#{lib}'." unless r_libs.include?(lib)
25 end
26
27 # create a fake Makefile
28 File.open(File.join(File.dirname(__FILE__),"Makefile"),"w+") do |makefile|
29   makefile.puts "all:\n\ttrue\n\ninstall:\n\ttrue\n"
30 end
31
32 $makefile_created = true