]> git.tdb.fi Git - builder.git/blob - source/compile.cpp
61b17ad90807c65b0c85c649fbabe7c31a5cc6cc
[builder.git] / source / compile.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <msp/path/utils.h>
9 #include "builder.h"
10 #include "buildinfo.h"
11 #include "compile.h"
12 #include "component.h"
13 #include "objectfile.h"
14 #include "sourcepackage.h"
15
16 using namespace std;
17 using namespace Msp;
18
19 Compile::Compile(Builder &b, const ObjectFile &obj):
20         ExternalAction(b)
21 {
22         const Component &comp=obj.get_component();
23
24         const TargetList &deps=obj.get_depends();
25         Path::Path spath=deps.front()->get_name();
26
27         string ext=Path::splitext(spath.str()).ext;
28         const char *tool=0;
29         if(ext==".cpp" || ext==".cc")
30                 tool="CXX";
31         else
32                 tool="CC";
33
34         argv.push_back(builder.get_architecture(comp.get_package().get_arch()).get_tool(tool));
35         argv.push_back("-c");
36
37         const BuildInfo &binfo=comp.get_build_info();
38         for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
39                 argv.push_back(*i);
40         for(list<string>::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
41                 argv.push_back("-I"+*i);
42         for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
43                 argv.push_back("-D"+*i);
44
45         Path::Path opath=obj.get_name();
46         argv.push_back("-o");
47         argv.push_back(opath.str());
48         argv.push_back(spath.str());
49
50         if(!builder.get_dry_run())
51                 Path::mkpath(opath.subpath(0, opath.size()-1), 0755);
52
53         announce(comp.get_package().get_name(), tool, relative(opath, comp.get_package().get_source()).str());
54
55         launch();
56 }