]> git.tdb.fi Git - builder.git/blob - source/pkgconfigaction.cpp
6e2ae1facf222c68393b89e2bc03b90779ef92fd
[builder.git] / source / pkgconfigaction.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <msp/fs/utils.h>
9 #include <msp/io/file.h>
10 #include <msp/io/print.h>
11 #include "builder.h"
12 #include "package.h"
13 #include "pkgconfig.h"
14 #include "pkgconfigaction.h"
15
16 using namespace std;
17 using namespace Msp;
18
19 PkgConfigAction::PkgConfigAction(Builder &b, const PkgConfig &p):
20         Action(b)
21 {
22         const SourcePackage &spkg = *static_cast<const SourcePackage *>(p.get_package());
23
24         announce(spkg.get_name(), "PC", basename(p.get_path()));
25
26         IO::BufferedFile out(p.get_path().str(), IO::M_WRITE);
27         IO::print(out, "prefix=%s\n", builder.get_prefix().str());
28         IO::print(out, "source=%s\n\n", spkg.get_source());
29
30         IO::print(out, "Name: %s\n", spkg.get_name());
31         IO::print(out, "Description: %s\n", spkg.get_description());
32         IO::print(out, "Version: %s\n", spkg.get_version());
33
34         IO::print(out, "Requires:");
35         const PackageList &reqs = spkg.get_requires();
36         for(PackageList::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
37                 if((*i)->get_use_pkgconfig())
38                         IO::print(out, " %s", (*i)->get_name());
39         out.put('\n');
40
41         const BuildInfo &binfo = spkg.get_exported_binfo();
42         IO::print(out, "Libs:");
43         for(StringList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
44                 IO::print(out, " -L%s", prefixify(*i));
45         for(StringList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
46                 IO::print(out, " -l%s", *i);
47         for(StringList::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
48                 IO::print(out, " %s", *i);
49         out.put('\n');
50
51         IO::print(out, "Cflags:");
52         for(StringList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
53                 IO::print(out, " -I%s", prefixify(*i));
54         for(StringList::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
55                 IO::print(out, " -D%s", *i);
56         for(StringList::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
57                 IO::print(out, " %s", *i);
58         out.put('\n');
59 }
60
61 int PkgConfigAction::check()
62 {
63         signal_done.emit();
64         return 0;
65 }
66
67 string PkgConfigAction::prefixify(const std::string &path)
68 {
69         const string &prefix = builder.get_prefix().str();
70         if(!path.compare(0, prefix.size(), prefix))
71                 return "${prefix}"+path.substr(prefix.size());
72         return path;
73 }