1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
###########################################################################
# Project TUPI: Magia 2D #
# Project Contact: info@maefloresta.com #
# Project Website: http://www.maefloresta.com #
# Project Leader: Gustav Gonzalez <info@maefloresta.com> #
# #
# Developers: #
# 2010: #
# Gustavo Gonzalez / xtingray #
# #
# KTooN's versions: #
# #
# 2006: #
# David Cuadrado #
# Jorge Cuadrado #
# 2003: #
# Fernado Roldan #
# Simena Dinas #
# #
# Copyright (C) 2010 Gustav Gonzalez - http://www.maefloresta.com #
# License: #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
###########################################################################
require_relative 'qmake'
require_relative 'detectos'
require 'rexml/parsers/sax2parser'
require 'rexml/sax2listener'
require_relative 'info'
module RQonf
class Test
include REXML
attr_reader :rules
attr_reader :optional
def initialize(rulesPath, qmake)
@rules = rulesPath
@qmake = qmake
@optional = false
end
def run(config, conf, debug)
parser = Parser.new
parser.os = DetectOS::OS[DetectOS.whatOS].to_s.downcase
return false if not parser.parse(@rules) or parser.name.empty?
@optional = parser.optional
Info.info << "Checking for " << parser.name << "... "
dir = "#{File.dirname(@rules)}/#{parser.dir}"
if $DEBUG
Info.warn << "Running in " << dir << $endl
end
cwd = Dir.getwd
if File.exist?(dir)
if File.stat(dir).directory?
Dir.chdir(dir)
extraLib = ""
extraInclude = ""
if RUBY_PLATFORM == "x86_64-linux"
extraLib = "-L/usr/lib64 "
end
if File.dirname(@rules).end_with?("libav")
if conf.hasArgument?("with-libav")
libavDir = conf.argumentValue("with-libav")
libavLib = libavDir + "/lib"
extraLib += "-L#{libavLib}"
extraInclude = libavDir + "/include"
qmakeLine = "'LIBS += #{extraLib}'";
qmakeLine += " 'INCLUDEPATH += #{extraInclude}'";
end
else
if File.dirname(@rules).end_with?("quazip")
if conf.hasArgument?("with-quazip")
quazipDir = conf.argumentValue("with-quazip")
quazipLib = quazipDir + "/lib"
extraLib += "-L#{quazipLib} -lquazip"
extraInclude = quazipDir + "/include"
qmakeLine = "'LIBS += #{extraLib}'"
qmakeLine += " 'INCLUDEPATH += #{extraInclude}'"
else
extraLib = "-lquazip5"
qmakeLine = "'LIBS += #{extraLib}'"
end
else
if File.dirname(@rules).end_with?("theora")
if conf.hasArgument?("with-theora")
theoraDir = conf.argumentValue("with-theora")
theoraLib = theoraDir + "/lib"
extraLib += "-L#{theoraLib}"
extraInclude = theoraDir + "/include"
qmakeLine = "'LIBS += #{extraLib}'"
qmakeLine += " 'INCLUDEPATH += #{extraInclude}'"
end
else
qmakeLine = ""
if extraLib.length > 0
qmakeLine = "'LIBS += #{extraLib} #{parser.libs.join(" ")}'"
end
end
end
end
@qmake.run(qmakeLine, true)
if not @qmake.compile(debug)
Dir.chdir(cwd)
print "[ \033[91mFAILED\033[0m ]\n"
priority = "\033[92moptional\033[0m"
flag = "\033[92mCOULD\033[0m"
if @optional == false
priority = "\033[91mrequired\033[0m"
flag = "\033[91mMUST\033[0m"
end
Info.info << "Priority: " << priority << "\n"
# Provide solution
solution = parser.solution
Info.warn << "Seems like you are running " << parser.os << "..." << $endl
Info.warn << "You " << flag << " install these dependencies: " << solution[:package] << $endl
Info.warn << "URL: " << solution[:url] << $endl
Info.warn << solution[:comment] << $endl
return false
end
else
Dir.chdir(cwd)
raise QonfException.new("'#{dir}' isn't a directory!")
return false
end
else
Dir.chdir(cwd)
raise QonfException.new("'#{dir}' doesn't exists!")
return false
end
Dir.chdir(cwd)
parser.includes.each { |inc|
config.addIncludePath(inc)
}
parser.libs.each { |lib|
config.addLib(lib)
}
if conf.hasArgument?("with-quazip")
config.addLib("-lquazip")
else
config.addLib("-lquazip5")
end
# config.addLib("-lquazip-qt5")
parser.defines.each { |define|
config.addDefine(define)
}
parser.modules.each { |mod|
config.addModule(mod)
}
print "[ \033[92mOK\033[0m ]\n"
priority = "\033[92moptional\033[0m"
if @optional == false
priority = "\033[91mrequired\033[0m"
end
Info.info << "Priority: " << priority << "\n"
return true
end
def to_s
@rules
end
private
class Parser
include REXML::SAX2Listener
attr_reader :name
attr_reader :dir
attr_reader :defines
attr_reader :includes
attr_reader :libs
attr_reader :modules
attr_accessor :os
attr_reader :solution
attr_reader :optional
def initialize
@name = ""
@current_tag = ""
@section = ""
@dir = ""
@defines = []
@includes = []
@libs = []
@modules = []
@solution = {}
@os = ""
@optional = false
end
def start_document
end
def end_document
end
def start_element( uri, localname, qname, attributes)
case qname
when "qonf"
@optional = (attributes["optional"] == "true")
when "test"
@section = qname
@name = attributes["name"].to_s
when "dir"
if @section == "test"
@dir = attributes["path"]
end
when "provide"
@section = qname
when "define"
if @section == "provide"
@defines << attributes["value"]
end
when "include"
if @section == "provide"
@includes << attributes["path"]
end
when "lib"
if @section == "provide"
@libs << attributes["path"]
end
when "module"
if @section == "provide"
@modules << attributes["value"]
end
when "command"
if @section == "provide"
if @current_tag == "includes"
IO.popen(attributes["value"]) { |c|
output = c.readlines.join("").split(" ")
output.each { |i|
if i =~ /-I(.*)/
@includes << $1.chomp
elsif not i =~ /-.*/
@includes << i
end
}
}
elsif @current_tag == "libs"
IO.popen(attributes["value"]) { |c|
output = c.readlines.join("").split(" ")
output.each { |lib|
if lib =~ /-l(.*)/
@libs << lib
elsif lib[0].chr != "-"
@libs << lib
end
}
@libs.concat(output)
}
end
end
when "solution"
@section = "solution"
when "windows"
if @os == qname and @solution.size == 0
fillSolution(attributes)
end
when "macosx"
if @os == qname and @solution.size == 0
fillSolution(attributes)
end
when "linux"
if @os == qname and @solution.size == 0
fillSolution(attributes)
end
when "distribution"
if @os == attributes["name"].to_s.downcase and @solution.size == 0
fillSolution(attributes)
end
end
@current_tag = qname
end
def end_element(uri, localname, qname)
case qname
when ""
end
end
def characters(text)
text = text.strip
if not text.empty?
end
end
def parse(path)
sax2 = REXML::Parsers::SAX2Parser.new( File.new( path ) )
sax2.listen(self)
begin
sax2.parse
rescue
return false
end
return true
end
private
def fillSolution(attributes)
@solution[:package] = attributes["package"]
@solution[:url] = attributes["url"]
@solution[:comment] = attributes["comment"]
end
end
end
end #module
|