1 #include <msp/fs/utils.h>
2 #include <msp/io/file.h>
3 #include <msp/io/print.h>
5 #include "pkgconfigfile.h"
6 #include "pkgconfiggenerator.h"
11 Target *PkgConfigGenerator::create_target(const vector<Target *> &, const string &)
13 throw logic_error("Not implemented");
16 Task *PkgConfigGenerator::run(const Target &target) const
18 const PkgConfigFile &pkgc = dynamic_cast<const PkgConfigFile &>(target);
19 Worker *worker = new Worker(pkgc);
20 return new InternalTask(worker);
24 void PkgConfigGenerator::Worker::main()
26 Builder &builder = target.get_package()->get_builder();
27 const SourcePackage &spkg = *target.get_package();
29 IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
30 IO::print(out, "prefix=%s\n", builder.get_prefix().str());
31 IO::print(out, "source=%s\n\n", spkg.get_source_directory());
33 IO::print(out, "Name: %s\n", spkg.get_label());
34 IO::print(out, "Description: %s\n", spkg.get_description());
35 IO::print(out, "Version: %s\n", spkg.get_version());
37 IO::print(out, "Requires:");
38 for(const Package *r: spkg.get_required_packages())
39 if(r->uses_pkgconfig())
40 IO::print(out, " %s", r->get_name());
43 const BuildInfo &binfo = spkg.get_exported_build_info();
44 IO::print(out, "Libs:");
45 for(const FS::Path &p: binfo.libpath)
46 IO::print(out, " -L%s", prefixify(p, builder.get_prefix()));
47 for(const string &l: binfo.libs)
48 IO::print(out, " -l%s", l);
50 out.write("-pthread");
53 IO::print(out, "Cflags:");
54 for(const FS::Path &p: binfo.incpath)
55 IO::print(out, " -I%s", prefixify(p, builder.get_prefix()));
56 for(const auto &kvp: binfo.defines)
57 if(kvp.second.empty())
58 IO::print(out, " -D%s", kvp.first);
60 IO::print(out, " -D%s=%s", kvp.first, kvp.second);
63 status = Task::SUCCESS;
66 string PkgConfigGenerator::Worker::prefixify(const FS::Path &path, const FS::Path &prefix)
68 if(FS::descendant_depth(path, prefix)>=0)
70 FS::Path rel_path = FS::relative(path, prefix);
71 return "${prefix}"+rel_path.str().substr(1);