]> git.tdb.fi Git - builder.git/blob - source/gnucxxcompiler.cpp
Make tools architecture-aware and restore cross-compilation functionality
[builder.git] / source / gnucxxcompiler.cpp
1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
3 #include <msp/io/print.h>
4 #include <msp/strings/regex.h>
5 #include <msp/strings/utils.h>
6 #include "builder.h"
7 #include "csourcefile.h"
8 #include "externaltask.h"
9 #include "gnucxxcompiler.h"
10
11 using namespace std;
12 using namespace Msp;
13
14 GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a):
15         GnuCompiler(b, a, "CXX", "g++")
16 {
17         input_suffixes.push_back(".cpp");
18         input_suffixes.push_back(".cc");
19         aux_suffixes.push_back(".hpp");
20
21         ExternalTask::Arguments argv;
22         argv.push_back(executable->get_path().str());
23         argv.push_back("--version");
24         builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
25         ExternalTask task(argv);
26         task.set_stdout(ExternalTask::CAPTURE);
27         task.set_stderr(ExternalTask::IGNORE);
28         task.start();
29         Task::Status status;
30         while((status=task.check())==Task::RUNNING) ;
31         if(status==Task::SUCCESS)
32                 if(RegMatch m = Regex("[0-9]\\.[0-9.]+").match(task.get_output()))
33                 {
34                         string cxx_ver = m[0].str;
35                         while(!cxx_ver.empty())
36                         {
37                                 FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver;
38                                 if(FS::is_dir(cxx_path))
39                                 {
40                                         builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), cxx_ver));
41                                         system_path.push_back(cxx_path);
42                                         break;
43                                 }
44
45                                 string::size_type dot = cxx_ver.rfind('.');
46                                 if(dot==string::npos)
47                                         break;
48                                 cxx_ver.erase(dot);
49                         }
50                 }
51 }
52
53 Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
54 {
55         return new CSourceFile(builder, comp, path);
56 }
57
58 Target *GnuCxxCompiler::create_source(const FS::Path &path) const
59 {
60         return new CSourceFile(builder, path);
61 }