jasmine-headless-webkit/lib/qt/qmake.rb

175 lines
4.0 KiB
Ruby
Raw Normal View History

2011-07-18 14:52:57 +00:00
require 'rbconfig'
require 'rubygems'
2011-07-30 01:33:19 +00:00
require 'rubygems/version'
2011-07-18 14:52:57 +00:00
2011-08-23 23:49:47 +00:00
begin
require 'facter'
rescue LoadError
warn 'Including Facter allows for detection of # of cpus, resulting in faster compilations.'
end
2011-07-18 14:52:57 +00:00
module Qt
class NotInstalledError < StandardError; end
class Qmake
class << self
2011-07-30 01:33:19 +00:00
QMAKES = %w{qmake-qt4 qmake}
2011-07-18 14:52:57 +00:00
def installed?
path != nil
end
def make_installed?
make_path != nil
end
2011-08-02 19:47:14 +00:00
def command(project_file = nil)
spec = (case platform
2011-07-18 14:52:57 +00:00
when :linux
2011-08-23 22:47:15 +00:00
"linux-g++"
2011-07-25 13:22:04 +00:00
when :freebsd
2011-08-23 22:47:15 +00:00
"freebsd-g++"
2011-07-18 14:52:57 +00:00
when :mac_os_x
2011-08-23 22:47:15 +00:00
"macx-g++"
2011-08-02 19:47:14 +00:00
end)
2011-08-26 15:18:04 +00:00
command = "#{path} #{envs} -spec #{spec}"
2011-08-02 19:47:14 +00:00
command << " #{project_file}" if project_file
command
2011-07-18 14:52:57 +00:00
end
2011-08-02 19:47:14 +00:00
def make!(name, project_file = nil)
2011-07-18 14:52:57 +00:00
@name = name
check_make!
check_qmake!
2011-08-02 19:47:14 +00:00
system command(project_file)
2011-08-23 23:49:47 +00:00
system %{make #{make_options}}
end
def make_options
"-j#{number_of_cpus}"
2011-07-18 14:52:57 +00:00
end
#
# We need integration tests for these!
#
def path
2011-07-30 01:33:19 +00:00
@path ||= best_qmake
2011-07-18 14:52:57 +00:00
end
def make_path
2011-08-23 22:47:15 +00:00
get_exe_path('gmake') || get_exe_path('make')
2011-07-18 14:52:57 +00:00
end
def platform
case RbConfig::CONFIG['host_os']
when /linux/
:linux
when /freebsd/i
:freebsd
2011-07-18 14:52:57 +00:00
when /darwin/
:mac_os_x
end
end
2011-07-30 01:33:19 +00:00
def qt_version_of(qmake_path)
$stderr.puts %x{#{qmake_path} -v}
2011-07-30 01:33:19 +00:00
Gem::Version.new(%x{#{qmake_path} -v}.lines.to_a[1][%r{Using Qt version ([^ ]+) },1])
2011-07-18 14:52:57 +00:00
end
2011-07-30 01:33:19 +00:00
def best_qmake
if qmake_path = QMAKES.collect do |path|
result = nil
if qmake_path = get_exe_path(path)
if (qt_version = qt_version_of(qmake_path)) >= Gem::Version.create('4.7')
result = [ qmake_path, qt_version ]
end
end
result
end.compact.sort { |a, b| b.last <=> a.last }.first
2011-08-23 22:47:15 +00:00
qmake_path.first
2011-07-30 01:33:19 +00:00
else
nil
end
2011-07-18 14:52:57 +00:00
end
private
2011-08-26 15:18:04 +00:00
def envs
%w{QMAKE_CC QMAKE_CXX}.collect do |env|
if ENV[env]
"#{env}=#{ENV[env]}"
end
end.compact.join(" ")
end
2011-08-23 23:49:47 +00:00
def number_of_cpus
if defined?(Facter)
Facter.sp_number_processors rescue Facter.processorcount
else
1
end
end
2011-07-18 14:52:57 +00:00
def get_exe_path(command)
path = %x{which #{command}}.strip
path = nil if path == ''
path
end
def check_make!
if !make_installed?
install_method = (
case platform
when :linux
%{sudo apt-get install make or sudo yum install make}
2011-07-25 13:22:04 +00:00
when :freebsd
%{install /usr/ports/devel/gmake}
when :mac_os_x
2011-07-18 14:52:57 +00:00
%{Install XCode, and/or sudo port install make}
end
)
$stderr.puts <<-MSG
2011-08-23 22:47:15 +00:00
make is not installed. You'll need to install it to build #{@name}.
#{install_method} should do it for you.
MSG
2011-07-18 14:52:57 +00:00
raise NotInstalledError
end
end
def check_qmake!
if !installed?
2011-07-29 13:58:59 +00:00
install_method = (
2011-07-18 14:52:57 +00:00
case platform
when :linux
<<-MSG
2011-08-23 22:47:15 +00:00
sudo apt-get install libqt4-dev qt4-qmake on Debian-based systems, or downloading
Nokia's prebuilt binary at http://qt.nokia.com/downloads/
MSG
2011-07-25 13:22:04 +00:00
when :freebsd
<<-MSG
2011-08-23 22:47:15 +00:00
Install /usr/ports/www/qt4-webkit and /usr/ports/devel/qmake4.
2011-07-18 14:52:57 +00:00
MSG
2011-08-23 22:47:15 +00:00
MSG
when :mac_os_x
2011-07-18 14:52:57 +00:00
<<-MSG
2011-08-23 22:47:15 +00:00
sudo port install qt4-mac (for the patient) or downloading Nokia's pre-built binary
at http://qt.nokia.com/downloads/
MSG
2011-07-18 14:52:57 +00:00
end
2011-07-29 13:58:59 +00:00
).strip
2011-07-18 14:52:57 +00:00
$stderr.puts <<-MSG
2011-08-23 22:47:15 +00:00
qmake is not installed or is not the right version (#{@name} needs Qt 4.7 or above).
You'll need to install it to build #{@name}.
#{install_method} should do it for you.
MSG
2011-07-18 14:52:57 +00:00
end
end
end
end
end