1 #include <msp/fs/dir.h>
2 #include <msp/fs/utils.h>
5 #include "externaltask.h"
6 #include "gnucompiler.h"
7 #include "objectfile.h"
8 #include "sourcefile.h"
9 #include "sourcepackage.h"
14 GnuCompiler::GnuCompiler(Builder &b, const string &t, const string &n):
19 Target *GnuCompiler::create_source(const Component &comp, const FS::Path &path) const
21 return new SourceFile(builder, comp, path);
24 Target *GnuCompiler::create_target(const list<Target *> &sources, const std::string &) const
27 throw invalid_argument("GnuCCompiler::create_target");
28 SourceFile &source = dynamic_cast<SourceFile &>(*sources.front());
29 ObjectFile *obj = new ObjectFile(builder, *source.get_component(), source);
34 Task *GnuCompiler::run(const Target &target) const
36 const ObjectFile &object = dynamic_cast<const ObjectFile &>(target);
37 const Component &comp = object.get_component();
43 const BuildInfo &binfo = comp.get_build_info();
44 for(list<string>::const_iterator i=binfo.warnings.begin(); i!=binfo.warnings.end(); ++i)
45 argv.push_back("-W"+*i);
46 for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
48 for(list<string>::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
49 argv.push_back("-I"+*i);
50 for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
51 argv.push_back("-D"+*i);
53 FS::Path obj_path = object.get_path();
54 FS::Path src_path = object.get_source().get_path();
55 FS::Path work_dir = comp.get_package().get_source();
58 argv.push_back(relative(obj_path, work_dir).str());
59 argv.push_back(relative(src_path, work_dir).str());
61 if(!builder.get_dry_run())
62 FS::mkpath(FS::dirname(obj_path), 0755);
64 return new ExternalTask(argv, work_dir);