]> git.tdb.fi Git - builder.git/blob - source/pkgconfiggenerator.cpp
Set success status at the end of PkgConfigGenerator's worker
[builder.git] / source / pkgconfiggenerator.cpp
1 #include <msp/fs/utils.h>
2 #include <msp/io/file.h>
3 #include <msp/io/print.h>
4 #include "builder.h"
5 #include "pkgconfig.h"
6 #include "pkgconfiggenerator.h"
7
8 using namespace std;
9 using namespace Msp;
10
11 PkgConfigGenerator::PkgConfigGenerator(Builder &b):
12         Tool(b, "PCG")
13 {
14 }
15
16 Target *PkgConfigGenerator::create_target(const list<Target *> &, const string &) const
17 {
18         throw logic_error("Not implemented");
19 }
20
21 Task *PkgConfigGenerator::run(const Target &target) const
22 {
23         const PkgConfig &pkgc = dynamic_cast<const PkgConfig &>(target);
24         Worker *worker = new Worker(pkgc);
25         return new InternalTask(worker);
26 }
27
28
29 PkgConfigGenerator::Worker::Worker(const PkgConfig &t):
30         target(t)
31 { }
32
33 void PkgConfigGenerator::Worker::main()
34 {
35         Builder &builder = target.get_package()->get_builder();
36         const SourcePackage &spkg = dynamic_cast<const SourcePackage &>(*target.get_package());
37
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());
41
42         IO::print(out, "Name: %s\n", spkg.get_name());
43         IO::print(out, "Description: %s\n", spkg.get_description());
44         IO::print(out, "Version: %s\n", spkg.get_version());
45
46         IO::print(out, "Requires:");
47         const PackageList &reqs = spkg.get_requires();
48         for(PackageList::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
49                 if((*i)->get_use_pkgconfig())
50                         IO::print(out, " %s", (*i)->get_name());
51         out.put('\n');
52
53         const BuildInfo &binfo = spkg.get_exported_binfo();
54         IO::print(out, "Libs:");
55         for(StringList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
56                 IO::print(out, " -L%s", FS::relative(*i, builder.get_prefix()).str());
57         for(StringList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
58                 IO::print(out, " -l%s", *i);
59         if(binfo.threads)
60                 out.write("-pthread");
61         out.put('\n');
62
63         IO::print(out, "Cflags:");
64         for(StringList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
65                 IO::print(out, " -I%s", FS::relative(*i, builder.get_prefix()).str());
66         for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
67                 if(i->second.empty())
68                         IO::print(out, " -D%s", i->first);
69                 else
70                         IO::print(out, " -D%s=%s", i->first, i->second);
71         out.put('\n');
72
73         status = Task::SUCCESS;
74 }