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 PkgConfigGenerator::PkgConfigGenerator(Builder &b):
16 Target *PkgConfigGenerator::create_target(const list<Target *> &, const string &)
18 throw logic_error("Not implemented");
21 Task *PkgConfigGenerator::run(const Target &target) const
23 const PkgConfigFile &pkgc = dynamic_cast<const PkgConfigFile &>(target);
24 Worker *worker = new Worker(pkgc);
25 return new InternalTask(worker);
29 PkgConfigGenerator::Worker::Worker(const PkgConfigFile &t):
33 void PkgConfigGenerator::Worker::main()
35 Builder &builder = target.get_package()->get_builder();
36 const SourcePackage &spkg = *target.get_package();
38 IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
39 IO::print(out, "prefix=%s\n", builder.get_prefix().str());
40 IO::print(out, "source=%s\n\n", spkg.get_source_directory());
42 IO::print(out, "Name: %s\n", spkg.get_label());
43 IO::print(out, "Description: %s\n", spkg.get_description());
44 IO::print(out, "Version: %s\n", spkg.get_version());
46 IO::print(out, "Requires:");
47 for(const Package *r: spkg.get_required_packages())
48 if(r->uses_pkgconfig())
49 IO::print(out, " %s", r->get_name());
52 const BuildInfo &binfo = spkg.get_exported_build_info();
53 IO::print(out, "Libs:");
54 for(const FS::Path &p: binfo.libpath)
55 IO::print(out, " -L%s", prefixify(p, builder.get_prefix()));
56 for(const string &l: binfo.libs)
57 IO::print(out, " -l%s", l);
59 out.write("-pthread");
62 IO::print(out, "Cflags:");
63 for(const FS::Path &p: binfo.incpath)
64 IO::print(out, " -I%s", prefixify(p, builder.get_prefix()));
65 for(const auto &kvp: binfo.defines)
66 if(kvp.second.empty())
67 IO::print(out, " -D%s", kvp.first);
69 IO::print(out, " -D%s=%s", kvp.first, kvp.second);
72 status = Task::SUCCESS;
75 string PkgConfigGenerator::Worker::prefixify(const FS::Path &path, const FS::Path &prefix)
77 if(FS::descendant_depth(path, prefix)>=0)
79 FS::Path rel_path = FS::relative(path, prefix);
80 return "${prefix}"+rel_path.str().substr(1);