2010-07-25 20:43:57 +00:00
|
|
|
class Target
|
2014-09-07 19:08:18 +00:00
|
|
|
public
|
|
|
|
|
2011-06-02 15:21:25 +00:00
|
|
|
begin
|
|
|
|
include Rake::DSL
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
|
2010-07-25 20:43:57 +00:00
|
|
|
def initialize(target)
|
|
|
|
@target = target
|
|
|
|
@aliases = []
|
|
|
|
@objects = []
|
|
|
|
@libraries = []
|
|
|
|
@dependencies = []
|
2010-12-24 17:18:15 +00:00
|
|
|
@file_deps = []
|
2010-07-25 20:43:57 +00:00
|
|
|
@only_if = true
|
|
|
|
@debug = {}
|
2010-07-26 10:56:42 +00:00
|
|
|
@desc = nil
|
2010-07-27 07:25:02 +00:00
|
|
|
@namespace = nil
|
2010-07-25 20:43:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def debug(category)
|
|
|
|
@debug[category] = !@debug[category]
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2014-01-22 11:11:14 +00:00
|
|
|
def debug_do
|
|
|
|
yield self
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2010-07-26 10:56:42 +00:00
|
|
|
def description(description)
|
|
|
|
@desc = description
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2010-07-25 20:43:57 +00:00
|
|
|
def only_if(condition)
|
|
|
|
@only_if = condition
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_if
|
|
|
|
only_if true
|
|
|
|
end
|
|
|
|
|
|
|
|
def extract_options(list)
|
|
|
|
options = list.empty? || !list.last.is_a?(Hash) ? {} : list.pop
|
|
|
|
return list, options
|
|
|
|
end
|
|
|
|
|
|
|
|
def aliases(*list)
|
|
|
|
@aliases += list.compact
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def sources(*list)
|
|
|
|
list, options = extract_options list
|
|
|
|
|
|
|
|
if @debug[:sources]
|
|
|
|
puts "Target::sources: only_if #{@only_if}; list & options:"
|
|
|
|
pp list
|
|
|
|
pp options
|
|
|
|
end
|
|
|
|
|
|
|
|
return self if !@only_if || (options.include?(:if) && !options[:if])
|
|
|
|
|
2010-12-20 22:32:37 +00:00
|
|
|
ext_map = {
|
2012-04-09 15:48:38 +00:00
|
|
|
'.ui' => 'h',
|
|
|
|
'.moc' => '.moco',
|
2010-12-20 22:32:37 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 11:11:14 +00:00
|
|
|
obj_re = /\.(?:moc)?o$/
|
2018-01-06 09:09:20 +00:00
|
|
|
no_file_deps_re = /\.o$/
|
2012-04-09 15:48:38 +00:00
|
|
|
|
2010-07-25 20:43:57 +00:00
|
|
|
list = list.collect { |e| e.respond_to?(:to_a) ? e.to_a : e }.flatten
|
|
|
|
file_mode = (options[:type] || :file) == :file
|
2012-08-13 19:20:50 +00:00
|
|
|
except = !file_mode && options[:except].is_a?(Array) ? options[:except].collect { |file| list.collect { |dir| "#{dir}/#{file}" } }.flatten.to_hash_by : {}
|
2018-11-04 17:17:23 +00:00
|
|
|
new_sources = list.collect { |entry| file_mode ? (entry.respond_to?(:to_a) ? entry.to_a : entry) : FileList["#{entry}/*.c", "#{entry}/*.cpp", "#{entry}/*.cc"].to_a }.flatten.select { |file| !except[file] }.for_target!
|
2010-12-24 17:18:15 +00:00
|
|
|
new_deps = new_sources.collect { |file| [ file.ext(ext_map[ file.pathmap('%x') ] || 'o'), file ] }
|
2014-01-22 11:11:14 +00:00
|
|
|
new_file_deps = new_deps.reject { |src, tgt| no_file_deps_re.match src }
|
2018-01-06 09:09:20 +00:00
|
|
|
new_file_deps += new_sources.select { |file| %r{\.moc$}.match file }.map { |file| [ file, file.ext('h') ] }
|
2012-04-09 15:48:38 +00:00
|
|
|
@objects = ( @objects + new_deps.collect { |a| a.first }.select { |file| obj_re.match file } ).uniq
|
2011-01-31 16:47:18 +00:00
|
|
|
@dependencies = ( @dependencies + new_deps.collect { |a| a.first } ).uniq
|
2014-01-22 11:11:14 +00:00
|
|
|
@file_deps = ( @file_deps + new_file_deps ).uniq
|
2015-03-31 18:45:06 +00:00
|
|
|
|
2016-03-22 09:20:12 +00:00
|
|
|
PCH.moc_users(new_deps.select { |dep| /\.moco$/.match dep[0] }.map { |dep| dep[0].ext(".moc") }.to_a)
|
2010-07-25 20:43:57 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2017-12-30 22:48:33 +00:00
|
|
|
def qt_dependencies_and_sources(subdir, options = {})
|
2018-01-01 11:17:44 +00:00
|
|
|
ui_files = FileList["src/#{subdir}/forms/**/*.ui"].to_a
|
|
|
|
ui_h_files = ui_files.collect { |ui| ui.ext 'h' }
|
|
|
|
cpp_files = FileList["src/#{subdir}/**/*.cpp"].to_a.for_target! - (options[:cpp_except] || [])
|
|
|
|
h_files = FileList["src/#{subdir}/**/*.h"].to_a.for_target! - ui_h_files
|
|
|
|
content = read_files(cpp_files + h_files)
|
|
|
|
qobject_h_files = h_files.select { |h| content[h].any? { |line| /\bQ_OBJECT\b/.match line } }
|
|
|
|
|
|
|
|
form_include_re = %r{^\s* \# \s* include \s+ \" (#{subdir}/forms/[^\"]+) }x
|
|
|
|
dep_builder = lambda do |files|
|
|
|
|
extra_dependencies = {}
|
|
|
|
|
|
|
|
files.each do |file_name|
|
|
|
|
content[file_name].each do |line|
|
|
|
|
next unless form_include_re.match line
|
|
|
|
|
|
|
|
extra_dependencies[file_name] ||= []
|
|
|
|
extra_dependencies[file_name] << "src/#{$1}"
|
|
|
|
end
|
2017-12-30 22:48:33 +00:00
|
|
|
end
|
2018-01-01 11:17:44 +00:00
|
|
|
|
|
|
|
extra_dependencies
|
2017-12-30 22:48:33 +00:00
|
|
|
end
|
|
|
|
|
2018-01-01 11:17:44 +00:00
|
|
|
dep_builder.call(cpp_files). each { |cpp, ui_hs| file cpp.ext('o') => ui_hs }
|
|
|
|
dep_builder.call(qobject_h_files).each { |h, ui_hs| file h. ext('moc') => ui_hs }
|
2017-12-30 22:48:33 +00:00
|
|
|
|
|
|
|
self.
|
|
|
|
sources(ui_files).
|
|
|
|
sources(qobject_h_files.collect { |h| h.ext 'moc' }).
|
|
|
|
sources(cpp_files)
|
|
|
|
end
|
|
|
|
|
2010-07-25 20:43:57 +00:00
|
|
|
def dependencies(*list)
|
2012-04-09 15:48:38 +00:00
|
|
|
@dependencies += list.flatten.select { |entry| !entry.blank? } if @only_if
|
2010-07-25 20:43:57 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def libraries(*list)
|
|
|
|
list, options = extract_options list
|
|
|
|
|
|
|
|
return self if !@only_if || (options.include?(:if) && !options[:if])
|
|
|
|
|
2012-03-17 00:07:45 +00:00
|
|
|
list.flatten!
|
|
|
|
|
2010-07-25 20:43:57 +00:00
|
|
|
@dependencies += list.collect do |entry|
|
|
|
|
case entry
|
2018-04-08 10:09:30 +00:00
|
|
|
when :mtxcommon then "src/common/libmtxcommon.#{$libmtxcommon_as_dll ? "dll" : "a"}"
|
2012-08-13 19:20:50 +00:00
|
|
|
when :mtxinput then "src/input/libmtxinput.a"
|
|
|
|
when :mtxoutput then "src/output/libmtxoutput.a"
|
|
|
|
when :mtxmerge then "src/merge/libmtxmerge.a"
|
|
|
|
when :mtxinfo then "src/info/libmtxinfo.a"
|
|
|
|
when :mtxextract then "src/extract/libmtxextract.a"
|
|
|
|
when :mtxpropedit then "src/propedit/libmtxpropedit.a"
|
2012-08-15 07:16:52 +00:00
|
|
|
when :mtxunittest then "tests/unit/libmtxunittest.a"
|
2012-08-13 19:20:50 +00:00
|
|
|
when :avi then "lib/avilib-0.6.10/libavi.a"
|
|
|
|
when :rmff then "lib/librmff/librmff.a"
|
|
|
|
when :mpegparser then "src/mpegparser/libmpegparser.a"
|
|
|
|
when :ebml then c?("EBML_MATROSKA_INTERNAL") ? "lib/libebml/src/libebml.a" : nil
|
|
|
|
when :matroska then c?("EBML_MATROSKA_INTERNAL") ? "lib/libmatroska/src/libmatroska.a" : nil
|
2013-12-25 12:00:28 +00:00
|
|
|
when :gtest then $gtest_internal ? "lib/gtest/src/libgtest.a" : nil
|
2014-12-05 11:35:39 +00:00
|
|
|
when :pugixml then c?(:PUGIXML_INTERNAL) ? "lib/pugixml/src/libpugixml.a" : nil
|
2018-11-19 22:40:53 +00:00
|
|
|
when :fmt then c?(:FMT_INTERNAL) ? "lib/fmt/src/libfmt.a" : nil
|
2012-08-13 19:20:50 +00:00
|
|
|
else nil
|
2010-07-25 20:43:57 +00:00
|
|
|
end
|
|
|
|
end.compact
|
|
|
|
|
|
|
|
@libraries += list.collect do |entry|
|
|
|
|
case entry
|
|
|
|
when nil then nil
|
|
|
|
when :magic then c(:MAGIC_LIBS)
|
|
|
|
when :flac then c(:FLAC_LIBS)
|
|
|
|
when :iconv then c(:ICONV_LIBS)
|
|
|
|
when :intl then c(:LIBINTL_LIBS)
|
2018-01-01 11:17:44 +00:00
|
|
|
when :cmark then c(:CMARK_LIBS)
|
2020-05-03 09:48:44 +00:00
|
|
|
when :dvdread then c(:DVDREAD_LIBS)
|
2020-08-19 15:40:04 +00:00
|
|
|
when :pcre2 then c(:PCRE2_LIBS)
|
2017-02-13 20:37:29 +00:00
|
|
|
when :pugixml then c?(:PUGIXML_INTERNAL) ? [ '-Llib/pugixml/src', '-lpugixml' ] : c(:PUGIXML_LIBS)
|
2015-04-19 17:53:12 +00:00
|
|
|
when :qt then c(:QT_LIBS)
|
2015-02-19 12:36:40 +00:00
|
|
|
when :static then c(:LINK_STATICALLY)
|
2021-02-19 23:43:48 +00:00
|
|
|
when :stdcppfs then c(:STDCPPFS_LIBS)
|
2012-08-15 07:16:52 +00:00
|
|
|
when :mpegparser then [ '-Lsrc/mpegparser', '-lmpegparser' ]
|
|
|
|
when :mtxinput then [ '-Lsrc/input', '-lmtxinput' ]
|
|
|
|
when :mtxoutput then [ '-Lsrc/output', '-lmtxoutput' ]
|
|
|
|
when :mtxmerge then [ '-Lsrc/merge', '-lmtxmerge' ]
|
|
|
|
when :mtxextract then [ '-Lsrc/extract', '-lmtxextract' ]
|
|
|
|
when :mtxpropedit then [ '-Lsrc/propedit', '-lmtxpropedit' ]
|
|
|
|
when :mtxunittest then [ '-Ltests/unit', '-lmtxunittest' ]
|
2015-11-21 10:56:27 +00:00
|
|
|
when :ebml then c(:EBML_LIBS, '-lebml')
|
|
|
|
when :matroska then c(:MATROSKA_LIBS, '-lmatroska')
|
2019-09-27 15:27:16 +00:00
|
|
|
when :CoreFoundation then '-framework CoreFoundation'
|
2010-07-25 20:43:57 +00:00
|
|
|
when String then entry
|
|
|
|
else "-l#{entry}"
|
|
|
|
end
|
|
|
|
end.compact
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def dump
|
|
|
|
%w{aliases sources objects dependencies libraries}.each do |type|
|
|
|
|
puts "@#{type}:"
|
|
|
|
pp instance_variable_get("@#{type}")
|
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2010-07-27 07:25:02 +00:00
|
|
|
definition = Proc.new do
|
2010-12-24 17:18:15 +00:00
|
|
|
@file_deps.each do |spec|
|
2010-12-25 22:00:34 +00:00
|
|
|
file spec.first => spec.last unless spec.first == spec.last
|
2010-12-24 17:18:15 +00:00
|
|
|
end
|
|
|
|
|
2010-07-27 07:25:02 +00:00
|
|
|
@aliases.each_with_index do |name, idx|
|
|
|
|
desc @desc if (0 == idx) && !@desc.empty?
|
|
|
|
task name => @target
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if @namespace
|
|
|
|
namespace @namespace, &definition
|
|
|
|
else
|
|
|
|
definition.call
|
2010-07-26 10:56:42 +00:00
|
|
|
end
|
2010-07-27 07:25:02 +00:00
|
|
|
|
2010-07-25 20:43:57 +00:00
|
|
|
create_specific
|
2010-07-27 07:25:02 +00:00
|
|
|
|
2010-07-25 20:43:57 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|