root/branches/tango/rebuild/compile.c

Revision 654, 2.1 kB (checked in by Gregor, 2 years ago)

MERGE: trunk r653

Line 
1 // Component to call the compilation phase
2 // Copyright (c) 2007  Gregor Richards
3 // License for redistribution is by either the Artistic License
4 // in artistic.txt, or the GNU General Public License in gnu.txt
5 // or any later version.
6 // See the included readme.txt for details.
7
8 #include <iostream>
9 #include <string>
10 using namespace std;
11
12 extern "C" {
13 #include <stdlib.h>
14 }
15
16 #include "config.h"
17 #include "mars.h"
18 #include "module.h"
19 #include "response.h"
20
21 string compileCommand(const string &i, string &response, bool &useresponse)
22 {
23     int varLoc;
24    
25     // compile a source file into an object file
26     if (masterConfig.find("compile") == masterConfig.end() ||
27         masterConfig["compile"].find("cmd") == masterConfig["compile"].end()) {
28         cerr << "No 'compile.cmd' setting configured." << endl;
29         global.errors++;
30         return "";
31     }
32    
33     // check if we need to use a response file
34     useresponse = false;
35     if (masterConfig["compile"].find("response") != masterConfig["compile"].end()) {
36         useresponse = true;
37         response = masterConfig["compile"]["response"];
38     }
39    
40     // config: compile=[g]dmd -c $i -o $o
41     string cline = masterConfig["compile"]["cmd"];
42    
43     // replace $i
44     while ((varLoc = cline.find("$i", 0)) != string::npos) {
45         cline = cline.substr(0, varLoc) +
46             i +
47             cline.substr(varLoc + 2);
48     }
49    
50     // add flags
51     cline += compileFlags;
52    
53     return cline;
54 }
55
56 void runCompile(const std::string &files)
57 {
58     string response;
59     bool useresponse;
60     string cline = compileCommand(files, response, useresponse);
61    
62     if (global.params.verbose)
63         printf("compile   %s\n", cline.c_str());
64    
65     // run it
66     int res = 0;
67     if (cline == "") {
68         res = 1;
69     } else {
70         if (global.params.listonly) {
71             printf("%s\n", cline.c_str());
72         } else {
73             if (useresponse)
74                 res = systemResponse(cline.c_str(), response.c_str(), "compile.rf", !(global.params.keeprfiles));
75             else
76                 res = system(cline.c_str());
77         }
78     }
79     if (res) {
80         global.errors++;
81     }
82 }
Note: See TracBrowser for help on using the browser.