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

143 lines
3.2 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
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
def command
case platform
when :linux
"#{path} -spec linux-g++"
2011-07-25 13:22:04 +00:00
when :freebsd
"#{path} -spec freebsd-g++"
2011-07-18 14:52:57 +00:00
when :mac_os_x
"#{path} -spec macx-g++"
end
end
def make!(name)
@name = name
check_make!
check_qmake!
system command
system %{make}
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-07-25 13:22:04 +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
2011-07-25 13:22:04 +00:00
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)
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
qmake_path.first
else
nil
end
2011-07-18 14:52:57 +00:00
end
private
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}
2011-07-18 14:52:57 +00:00
when :darwin
%{Install XCode, and/or sudo port install make}
end
)
$stderr.puts <<-MSG
make is not installed. You'll need to install it to build #{@name}.
#{install_method} should do it for you.
MSG
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
sudo apt-get install libqt4-dev qt4-qmake on Debian-based systems, or downloading
Nokia's prebuilt binary at http://qt.nokia.com/downloads/
2011-07-25 13:22:04 +00:00
MSG
when :freebsd
<<-MSG
2011-07-30 01:33:19 +00:00
Install /usr/ports/www/qt4-webkit and /usr/ports/devel/qmake4.
2011-07-18 14:52:57 +00:00
MSG
when :darwin
<<-MSG
sudo port install qt4-mac (for the patient) or downloading Nokia's pre-built binary
at http://qt.nokia.com/downloads/
MSG
end
2011-07-29 13:58:59 +00:00
).strip
2011-07-18 14:52:57 +00:00
$stderr.puts <<-MSG
2011-07-30 01:33:19 +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}.
2011-07-18 14:52:57 +00:00
#{install_method} should do it for you.
MSG
end
end
end
end
end