3 #include <msp/core/maputils.h>
4 #include <msp/fs/utils.h>
5 #include <msp/io/print.h>
6 #include <msp/strings/lexicalcast.h>
7 #include <msp/strings/utils.h>
8 #include "androidapplicationcomponent.h"
9 #include "binarycomponent.h"
10 #include "binarypackage.h"
12 #include "compilecommandsjson.h"
13 #include "datapackcomponent.h"
15 #include "installcomponent.h"
16 #include "pkgconfigfile.h"
17 #include "sourcearchivecomponent.h"
18 #include "sourcegenerator.h"
19 #include "sourcepackage.h"
21 #include "vcxprojectfile.h"
26 SourcePackage::SourcePackage(Builder &b, const string &n, const FS::Path &f):
28 source_dir(FS::dirname(f)),
35 build_file = builder.get_vfs().get_target(f);
37 build_file = new File(builder, *this, f);
38 source_archive = new SourceArchiveComponent(*this);
39 components.push_back(source_archive);
42 SourcePackage::~SourcePackage()
44 for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
48 FS::Path SourcePackage::get_temp_directory() const
50 string subdir = builder.get_current_arch().get_name();
54 subdir += build_type->get_name();
57 const FS::Path &temp = builder.get_temp_directory();
58 if(temp.is_absolute())
59 return temp/name/subdir;
61 return source_dir/temp/subdir;
64 FS::Path SourcePackage::get_output_directory() const
66 const Architecture &arch = builder.get_current_arch();
70 return source_dir/arch.get_name();
73 const Component &SourcePackage::get_component(const string &n) const
75 for(ComponentList::const_iterator i=components.begin(); i!=components.end(); ++i)
76 if((*i)->get_name()==n)
81 bool SourcePackage::match_feature(const string &feat, const string *comp) const
83 string value = config.get_option("with_"+feat).value;
87 return lexical_cast<bool>(value);
90 void SourcePackage::set_build_type(const BuildType &t)
95 void SourcePackage::do_prepare()
97 BuildInfo final_build_info;
100 final_build_info.update_from(build_type->get_build_info());
102 final_build_info.update_from(build_info);
103 build_info = final_build_info;
105 build_info.incpath.push_back((builder.get_prefix()/"include").str());
106 build_info.libpath.push_back((builder.get_prefix()/"lib").str());
108 for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i)
110 string ident = "WITH_"+toupper(i->name);
111 string value = config.get_option("with_"+i->name).value;
113 if(i->choices.empty())
115 if(!lexical_cast<bool>(value))
120 build_info.defines[ident] = value;
122 export_binfo.defines[ident] = value;
125 for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
128 (*i)->create_build_info();
130 (*i)->update_exported_build_info(export_binfo);
135 for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
136 (*i)->create_targets();
138 const Architecture &arch = builder.get_native_arch();
139 if(!export_binfo.libs.empty())
141 export_binfo.incpath.push_back((builder.get_prefix()/"include").str());
142 export_binfo.libpath.push_back((builder.get_prefix()/"lib").str());
144 if(arch.get_system()=="linux")
146 PkgConfigFile *pc = new PkgConfigFile(builder, *this);
147 builder.get_build_graph().get_target("install")->add_dependency(*builder.get_toolchain().get_tool("CP").create_target(*pc));
151 export_binfo.standards = build_info.standards;
153 if(arch.get_system()=="windows")
154 new VcxProjectFile(builder, *this);
156 new CompileCommandsJson(builder, *this);
159 void SourcePackage::save_caches()
166 SourcePackage::Loader::Loader(SourcePackage &p):
167 DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>(p),
168 FeatureConditional(p, p.name)
173 SourcePackage::Loader::Loader(SourcePackage &p, const Config::InputOptions &o):
174 DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>(p),
175 FeatureConditional(p, p.name)
180 void SourcePackage::Loader::init(const Config::InputOptions *o)
183 add("android_application", &Loader::component<AndroidApplicationComponent>);
184 add("build_info", &Loader::build_info);
185 add("datapack", &Loader::component<DataPackComponent>);
186 add("description", &SourcePackage::description);
187 add("feature", &Loader::feature);
188 add("generate", &Loader::generate);
189 add("install", &Loader::component<InstallComponent>);
190 add("interface_version", &Loader::interface_version);
191 add("library", &Loader::component_arg<BinaryComponent, BinaryComponent::Type, BinaryComponent::LIBRARY>);
192 add("module", &Loader::component_arg<BinaryComponent, BinaryComponent::Type, BinaryComponent::MODULE>);
193 add("program", &Loader::component_arg<BinaryComponent, BinaryComponent::Type, BinaryComponent::PROGRAM>);
194 add("source_archive", &Loader::source_archive);
195 add("source_tarball", &Loader::source_archive);
196 add("tarball", &Loader::tarball);
197 add("version", &Loader::version);
200 void SourcePackage::Loader::finish()
202 /* Make sure the source tarball is last in the list so targets from all
203 other components wil be created first */
204 ComponentList::iterator i = find(obj.components.begin(), obj.components.end(), obj.source_archive);
205 if(i!=obj.components.end())
206 obj.components.splice(obj.components.end(), obj.components, i);
209 void SourcePackage::Loader::feature(const string &n, const string &d)
212 feat.description = d;
214 obj.features.push_back(feat);
216 const Config::Option &opt = obj.config.add_option(feat);
219 Config::InputOptions::const_iterator i = options->find(opt.name);
220 if(i!=options->end())
221 obj.config.set_option(opt.name, i->second);
226 void SourcePackage::Loader::component(const string &n)
228 C *comp = new C(obj, n);
230 obj.components.push_back(comp);
233 template<typename C, typename A, A a>
234 void SourcePackage::Loader::component_arg(const string &n)
236 C *comp = new C(obj, n, a);
238 obj.components.push_back(comp);
241 void SourcePackage::Loader::build_info()
243 load_sub(obj.build_info);
246 void SourcePackage::Loader::generate(const string &tag)
248 SourceGenerator *gen = new SourceGenerator(obj.builder, obj, tag);
250 obj.local_tools.add_tool(gen);
253 void SourcePackage::Loader::interface_version(const string &v)
255 obj.interface_version = v;
256 if(obj.version.empty())
260 void SourcePackage::Loader::source_archive()
262 load_sub(*obj.source_archive);
265 void SourcePackage::Loader::tarball(const string &)
267 IO::print("%s: Deprecated tarball component ignored\n", get_source());
270 void SourcePackage::Loader::version(const string &v)
274 string::size_type i = 0;
275 for(unsigned dots=0; i<obj.version.size(); ++i)
276 if(obj.version[i]=='.' && ++dots>=2)
278 obj.interface_version = obj.version.substr(0, i);