]> git.tdb.fi Git - builder.git/blobdiff - source/component.cpp
Support conditionals inside components
[builder.git] / source / component.cpp
index d1849f4027ead3b480af4db82294537fe0d7d124..5104cdf3e92b04c8567304baae993bf974f9952c 100644 (file)
@@ -243,6 +243,8 @@ Component::SourceList Component::collect_source_files() const
 Component::Loader::Loader(Component &c):
        DataFile::ObjectLoader<Component>(c)
 {
+       add("if_arch",         &Loader::if_arch);
+       add("if_feature",      &Loader::if_feature);
        add("source",          &Loader::source);
        add("install",         &Component::install);
        add("install_map",     &Loader::install_map);
@@ -252,6 +254,24 @@ Component::Loader::Loader(Component &c):
        add("use",             &Loader::use);
 }
 
+void Component::Loader::if_arch(const string &cond)
+{
+       bool match = obj.package.get_builder().get_current_arch().match_name(cond);
+       obj.package.get_builder().get_logger().log("configure",
+               format("%s/%s: arch %s %smatched", obj.package.get_name(), obj.name, cond, (match ? "" : "not ")));
+       if(match)
+               load_sub_with(*this);
+}
+
+void Component::Loader::if_feature(const string &cond)
+{
+       bool match = obj.package.match_feature(cond);
+       obj.package.get_builder().get_logger().log("configure",
+               format("%s/%s: feature %s %smatched", obj.package.get_name(), obj.name, cond, (match ? "" : "not ")));
+       if(match)
+               load_sub_with(*this);
+}
+
 void Component::Loader::source(const string &s)
 {
        obj.sources.push_back((obj.package.get_source_directory()/s).str());