aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-23 03:22:03 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-23 03:22:03 +0000
commit7a7390337e04d0163b97c1da7bdaa198bacaff72 (patch)
tree019eb3f455b0e8b35be9ae4560da319f377ea14e
parentf5cf5725026ecb2fa63d729fb6745b4da15e69d8 (diff)
downloadbuild-7a7390337e04d0163b97c1da7bdaa198bacaff72.tar.gz
build-7a7390337e04d0163b97c1da7bdaa198bacaff72.tar.bz2
build-7a7390337e04d0163b97c1da7bdaa198bacaff72.tar.xz
build-7a7390337e04d0163b97c1da7bdaa198bacaff72.zip
Loads more stuff...it's nearly working now.
Diffstat (limited to '')
-rw-r--r--build.conf48
-rw-r--r--src/build.cpp40
-rw-r--r--src/build.h30
-rw-r--r--src/build.y108
-rw-r--r--src/builder.cpp255
-rw-r--r--src/builder.h94
-rw-r--r--src/function.h2
-rw-r--r--src/functioncommandtolist.cpp2
-rw-r--r--src/functioncommandtolist.h2
-rw-r--r--src/functiondirectoriesin.cpp2
-rw-r--r--src/functiondirectoriesin.h2
-rw-r--r--src/functionfilesin.cpp2
-rw-r--r--src/functionfilesin.h2
-rw-r--r--src/functionregexp.cpp2
-rw-r--r--src/functionregexp.h2
-rw-r--r--src/functiontostring.cpp2
-rw-r--r--src/functiontostring.h2
-rw-r--r--src/main.cpp5
-rw-r--r--src/perform.cpp6
-rw-r--r--src/perform.h6
-rw-r--r--src/rule.cpp9
-rw-r--r--src/rule.h17
-rw-r--r--src/target.cpp1
-rw-r--r--src/target.h33
24 files changed, 577 insertions, 97 deletions
diff --git a/build.conf b/build.conf
index 4d2e61b..6a1b611 100644
--- a/build.conf
+++ b/build.conf
@@ -1,43 +1,35 @@
1# build.conf for build, kind of whacky, eh? 1# build.conf for build, kind of whacky, eh?
2 2
3default action: check "build", check "cleanup" 3default action: check "build"
4"clean" action: clean ["build", "cleanup"] 4"clean" action: clean "build"
5"rebuild" action: clean "build", check "build"
5 6
6set "CXXFLAGS" += "-ggdb" 7set "CXXFLAGS" += "-ggdb"
7 8
8["build", "cleanup"]: 9"build":
9 rule "exe",
10 target file,
11 set "CXXFLAGS" = "-lBob",
12 input [filesIn("src/{target}"), filesIn("src/shared")]
13
14[directoriesIn("src/tests")] filter regexp("src/tests/(.*)", "tests/{re:1}"):
15 rule "exe",
16 target prefix "tests/",
17 target file,
18 input filesIn("src/tests/{target}")
19
20[directoriesIn("src/tests"), "aoeua"]:
21 rule "exe", 10 rule "exe",
22 target file, 11 target file,
23 input filesIn("src/{target}") 12 requires "libbu++/libbu++.a",
24 13 set "CXXFLAGS" += "-Ilibbu++/src",
25"build": 14 input filesIn("src")
26 input [filesIn("src"), "boy.cpp"] filter regexp(".*\\.cpp$"),
27 input filter regexp(".*\\.cpp$"),
28 requires ["bob.cpp", "libbuild.a", "libbu++/libbu++.a"]
29
30"bob.cpp": set "aoeu" = "food", requires "bob.bastard"
31 15
32rule "exe": 16rule "exe":
33 matches regexp("(.*)\\.o$"), 17 matches regexp("(.*)\\.o$"),
34 input filter toString(), 18 input filter toString(),
35 perform command("stuff") 19 perform command("g++ {LDFLAGS} -o {target} {match}")
36 20
37rule "cpp": 21rule "cpp":
38 matches regexp("(.*)\\.cpp$"), 22 matches regexp("(.*)\\.cpp$"),
39 produces "{re:1}.o", 23 produces "{re:1}.o",
40 requires commandToList("make", "g++ -M {match}"), 24 requires commandToList("g++ -M {match}", "make"),
41 perform command("stuff") 25 perform command("g++ {CXXFLAGS} -c -o {target} {match}")
42 26
43 27rule "bison":
28 matches regexp("(.*)\\.y$"),
29 produces ["{re:1}.tab.c", "{re:1}.tab.h", "{re:1}.output"],
30 perform command("bison -v -b{re:1} {match}")
31
32rule "flex":
33 matches regexp("(.*)\\.l$"),
34 produces "{re:1}.yy.c",
35 perform command("flex --bison-bridge --bison-locations -o {target} {match}")
diff --git a/src/build.cpp b/src/build.cpp
index d3bd960..d9a8b39 100644
--- a/src/build.cpp
+++ b/src/build.cpp
@@ -1,5 +1,8 @@
1#include "build.h" 1#include "build.h"
2 2
3subExceptionDef( BuildException );
4
5
3Build::Build() 6Build::Build()
4{ 7{
5} 8}
@@ -7,3 +10,40 @@ Build::Build()
7Build::~Build() 10Build::~Build()
8{ 11{
9} 12}
13
14void Build::addTarget( Target *pTarget )
15{
16 TargetMap::iterator i = mTarget.find( pTarget->getName() );
17 if( i == mTarget.end() )
18 {
19 mTarget[pTarget->getName()] = pTarget;
20 }
21 else
22 {
23 throw BuildException("Merging targets isn't working yet.");
24 }
25}
26
27void Build::addRequires( const std::string &who, const std::string &what )
28{
29 mRequires[who].push_back( what );
30}
31
32void Build::debugDump()
33{
34 printf("Requires:\n");
35 for( ReqMap::iterator i = mRequires.begin(); i != mRequires.end(); i++ )
36 {
37 printf(" %s: ", (*i).first.c_str() );
38
39 for( StringList::iterator j = (*i).second.begin();
40 j != (*i).second.end(); j++ )
41 {
42 if( j != (*i).second.begin() )
43 printf(", ");
44 printf("%s", (*j).c_str() );
45 }
46 printf("\n");
47 }
48}
49
diff --git a/src/build.h b/src/build.h
index a2bf3ed..00acbfc 100644
--- a/src/build.h
+++ b/src/build.h
@@ -3,6 +3,15 @@
3 3
4#include <stdint.h> 4#include <stdint.h>
5 5
6#include <map>
7#include <string>
8
9#include "exceptions.h"
10#include "rule.h"
11#include "target.h"
12#include "action.h"
13
14subExceptionDecl( BuildException );
6 15
7class Build 16class Build
8{ 17{
@@ -10,7 +19,28 @@ public:
10 Build(); 19 Build();
11 virtual ~Build(); 20 virtual ~Build();
12 21
22 /**
23 * Adds a target to the build. If the target already exists, this will
24 * attempt to merge them as best it can. If there are any conflicts, it
25 * will throw an exception.
26 *@param pTarget A pointer to a Target object that Build takes ownership of.
27 */
28 void addTarget( Target *pTarget );
29 void addRequires( const std::string &who, const std::string &what );
30
31 void debugDump();
32
13private: 33private:
34 typedef std::map<std::string, Target *> TargetMap;
35 typedef std::list<std::string> StringList;
36 typedef std::map<std::string, StringList> ReqMap;
37
38 TargetMap mTarget;
39 ReqMap mRequires;
40
41 //std::map<std::string, Rule *> mRule;
42 //Action *pActDefault;
43 //std::map<std::string, Action *> mAction;
14 44
15}; 45};
16 46
diff --git a/src/build.y b/src/build.y
index 40f8d34..e9c0083 100644
--- a/src/build.y
+++ b/src/build.y
@@ -55,18 +55,37 @@ input:
55 ; 55 ;
56 56
57// Rule interpretation 57// Rule interpretation
58rule: TOK_RULE STRING {printf("Rule %s:\n", $2 ); } ':' rulecmds 58rule: TOK_RULE STRING ':'
59 {
60 bld.addRule( $2 );
61 }
62 rulecmds
59 ; 63 ;
60 64
61rulecmds: rulecmd 65rulecmds: rulecmd
62 | rulecmds ',' rulecmd 66 | rulecmds ',' rulecmd
63 ; 67 ;
64 68
65rulecmd: TOK_MATCHES { printf(" Matches: " ); } func { printf("\n"); } 69rulecmd: TOK_MATCHES func
66 | TOK_PRODUCES STRING { printf(" Produces: %s\n", $2 ); } 70 {
67 | TOK_REQUIRES { printf(" Requires:\n"); } list {printf("\n");} 71 bld.addRuleMatches();
68 | TOK_INPUT TOK_FILTER { printf(" Input Filter: "); } func {printf("\n");} 72 }
69 | TOK_PERFORM { printf(" Perform: "); } perf {printf("\n");} 73 | TOK_PRODUCES list
74 {
75 bld.addRuleProduces();
76 }
77 | TOK_REQUIRES list
78 {
79 bld.addRuleRequires();
80 }
81 | TOK_INPUT TOK_FILTER func
82 {
83 bld.addRuleInputFilter();
84 }
85 | TOK_PERFORM perf
86 {
87 bld.addRulePerform();
88 }
70 ; 89 ;
71 90
72// Action interpretation 91// Action interpretation
@@ -102,32 +121,62 @@ actioncmd: TOK_CHECK list
102 ; 121 ;
103 122
104// Target interpretation 123// Target interpretation
105target: list ':' { printf(" are targets:\n"); } targetcmds 124target: list ':'
125 {
126 bld.newTarget();
127 }
128 targetcmds
106 ; 129 ;
107 130
108targetcmds: targetcmd 131targetcmds: targetcmd
109 | targetcmds ',' targetcmd 132 | targetcmds ',' targetcmd
110 ; 133 ;
111 134
112targetcmd: TOK_RULE STRING { printf(" Rule %s\n", $2 ); } 135targetcmd: TOK_RULE STRING
113 | TOK_TARGET TOK_PREFIX STRING { printf(" Target prefix: %s\n", $3 ); } 136 {
114 | TOK_TARGET TARGETTYPE { printf(" Target Type: %s\n", $2 ); } 137 bld.setTargetRule( $2 );
115 | TOK_INPUT { printf(" Input: "); } list { printf("\n"); } 138 }
116 | TOK_INPUT TOK_FILTER { printf(" Input filter: "); } func { printf("\n"); } 139 | TOK_TARGET TOK_PREFIX STRING
117 | TOK_REQUIRES { printf(" Requires: "); } list { printf("\n"); } 140 {
118 | TOK_SET { printf(" Set: "); } targetset 141 bld.setTargetPrefix( $3 );
142 }
143 | TOK_TARGET TARGETTYPE
144 {
145 bld.setTargetType( $2 );
146 }
147 | TOK_INPUT list
148 {
149 bld.addTargetInput();
150 }
151 | TOK_REQUIRES list
152 {
153 bld.addTargetRequires();
154 }
155 | TOK_SET targetset
119 ; 156 ;
120 157
121targetset: STRING '=' STRING { printf("%s = %s\n", $1, $3 ); } 158targetset: STRING '=' STRING
122 | STRING TOK_ADDSET STRING { printf("%s += %s\n", $1, $3 ); } 159 {
160 bld.addTargetSet( $1, $3, setSet );
161 }
162 | STRING TOK_ADDSET STRING
163 {
164 bld.addTargetSet( $1, $3, setAdd );
165 }
123 ; 166 ;
124 167
125// global set 168// global set
126set: TOK_SET { printf("Set: "); } setwhat 169set: TOK_SET setwhat
127 ; 170 ;
128 171
129setwhat: STRING '=' STRING { printf("%s = %s\n", $1, $3 ); } 172setwhat: STRING '=' STRING
130 | STRING TOK_ADDSET STRING { printf("%s += %s\n", $1, $3 ); } 173 {
174 bld.addGlobalSet( $1, $3, setSet );
175 }
176 | STRING TOK_ADDSET STRING
177 {
178 bld.addGlobalSet( $1, $3, setAdd );
179 }
131 ; 180 ;
132 181
133// list goo 182// list goo
@@ -140,7 +189,10 @@ list: singlelistitem listfilter
140 ; 189 ;
141 190
142listfilter: 191listfilter:
143 | TOK_FILTER { printf(" filtered by "); } func 192 | TOK_FILTER func
193 {
194 bld.filterList();
195 }
144 ; 196 ;
145 197
146listitems: listitem 198listitems: listitem
@@ -183,12 +235,22 @@ funcparams:
183 ; 235 ;
184 236
185// Perform 237// Perform
186perf: PERFORM { printf("%s(", $1 ); } '(' perfparams ')' { printf(")"); } 238perf: PERFORM
239 {
240 bld.newPerform( $1 );
241 }
242 '(' perfparams ')'
187 ; 243 ;
188 244
189perfparams: 245perfparams:
190 | STRING { printf("%s", $1 ); } 246 | STRING
191 | perfparams ',' STRING { printf(", %s", $3 ); } 247 {
248 bld.addPerformParam( $1 );
249 }
250 | perfparams ',' STRING
251 {
252 bld.addPerformParam( $3 );
253 }
192 ; 254 ;
193%% 255%%
194 256
diff --git a/src/builder.cpp b/src/builder.cpp
index 70be725..4d377a8 100644
--- a/src/builder.cpp
+++ b/src/builder.cpp
@@ -3,8 +3,8 @@
3#include "performfactory.h" 3#include "performfactory.h"
4#include "targetfactory.h" 4#include "targetfactory.h"
5#include "action.h" 5#include "action.h"
6 6#include "build.h"
7subExceptionDef( BuildException ); 7#include "rule.h"
8 8
9Builder::Builder() : 9Builder::Builder() :
10 fFunction( FunctionFactory::getInstance() ), 10 fFunction( FunctionFactory::getInstance() ),
@@ -20,13 +20,15 @@ Builder::~Builder()
20void yyparse( Builder &bld ); 20void yyparse( Builder &bld );
21extern int yydebug; 21extern int yydebug;
22 22
23void Builder::load( const std::string &sFile ) 23Build *Builder::load( const std::string &sFile )
24{ 24{
25 file = sFile; 25 file = sFile;
26 scanBegin(); 26 scanBegin();
27 //yydebug = 1; 27 //yydebug = 1;
28 yyparse( *this ); 28 yyparse( *this );
29 scanEnd(); 29 scanEnd();
30
31 return genBuild();
30} 32}
31 33
32void Builder::error( YYLTYPE *locp, const char *msg ) 34void Builder::error( YYLTYPE *locp, const char *msg )
@@ -52,6 +54,47 @@ bool Builder::isTarget( const char *sType )
52{ 54{
53 return fTarget.hasPlugin( sType ); 55 return fTarget.hasPlugin( sType );
54} 56}
57
58void Builder::newTarget()
59{
60 lTargetTmp.push_back( TargetTmp(lTmp, TargetInfo()) );
61}
62
63void Builder::setTargetRule( const char *sRule )
64{
65 lTargetTmp.back().second.sRule = sRule;
66}
67
68void Builder::setTargetPrefix( const char *sPrefix )
69{
70 lTargetTmp.back().second.sPrefix = sPrefix;
71}
72
73void Builder::setTargetType( const char *sType )
74{
75 lTargetTmp.back().second.sType = sType;
76}
77
78void Builder::addTargetInput()
79{
80 lTargetTmp.back().second.lInput.insert(
81 lTargetTmp.back().second.lInput.end(),
82 lTmp.begin(), lTmp.end()
83 );
84}
85
86void Builder::addTargetRequires()
87{
88 lTargetTmp.back().second.lRequires.insert(
89 lTargetTmp.back().second.lRequires.end(),
90 lTmp.begin(), lTmp.end()
91 );
92}
93
94void Builder::addTargetSet( const char *sVar, const char *sVal, int nHow )
95{
96 lTargetTmp.back().second.lVar.push_back( SetVar( sVar, sVal, nHow ) );
97}
55 98
56// 99//
57// Function functions 100// Function functions
@@ -71,6 +114,9 @@ void Builder::addFunctionParam( const char *sParam )
71 pTmpFunc->addParam( sParam ); 114 pTmpFunc->addParam( sParam );
72} 115}
73 116
117//
118// List functions
119//
74void Builder::newList() 120void Builder::newList()
75{ 121{
76 lTmp.clear(); 122 lTmp.clear();
@@ -86,11 +132,16 @@ void Builder::addListFunc()
86 lTmp.push_back( BuildListItem("", pTmpFunc ) ); 132 lTmp.push_back( BuildListItem("", pTmpFunc ) );
87} 133}
88 134
89StringList Builder::buildToStringList( Builder::BuildList &lSrc, StringList &lIn ) 135void Builder::filterList()
136{
137 printf("Filters aren't done yet.\n");
138}
139
140StringList Builder::buildToStringList( const BuildList &lSrc, const StringList &lIn )
90{ 141{
91 StringList lOut; 142 StringList lOut;
92 143
93 for( BuildList::iterator i = lSrc.begin(); i != lSrc.end(); i++ ) 144 for( BuildList::const_iterator i = lSrc.begin(); i != lSrc.end(); i++ )
94 { 145 {
95 if( (*i).second ) 146 if( (*i).second )
96 { 147 {
@@ -106,6 +157,46 @@ StringList Builder::buildToStringList( Builder::BuildList &lSrc, StringList &lIn
106} 157}
107 158
108// 159//
160// Rule functions
161//
162void Builder::addRule( const char *sName )
163{
164 lRuleTmp.push_back( RuleInfo() );
165 lRuleTmp.back().sName = sName;
166}
167
168void Builder::addRuleMatches()
169{
170 lRuleTmp.back().pMatches = pTmpFunc;
171}
172
173void Builder::addRuleProduces()
174{
175 lRuleTmp.back().lProduces.insert(
176 lRuleTmp.back().lProduces.end(),
177 lTmp.begin(), lTmp.end()
178 );
179}
180
181void Builder::addRuleRequires()
182{
183 lRuleTmp.back().lRequires.insert(
184 lRuleTmp.back().lRequires.end(),
185 lTmp.begin(), lTmp.end()
186 );
187}
188
189void Builder::addRuleInputFilter()
190{
191 lRuleTmp.back().lFilter.push_back( pTmpFunc );
192}
193
194void Builder::addRulePerform()
195{
196 lRuleTmp.back().lPerform.push_back( pTmpPerform );
197}
198
199//
109// Perform functions 200// Perform functions
110// 201//
111bool Builder::isPerform( const char *sPerf ) 202bool Builder::isPerform( const char *sPerf )
@@ -115,10 +206,12 @@ bool Builder::isPerform( const char *sPerf )
115 206
116void Builder::newPerform( const char *sName ) 207void Builder::newPerform( const char *sName )
117{ 208{
209 pTmpPerform = fPerform.instantiate( sName );
118} 210}
119 211
120void Builder::addPerformParam( const char *sParam ) 212void Builder::addPerformParam( const char *sParam )
121{ 213{
214 pTmpPerform->addParam( sParam );
122} 215}
123 216
124// 217//
@@ -140,6 +233,14 @@ void Builder::addCommand( int nType )
140} 233}
141 234
142// 235//
236// Global variable functions
237//
238void Builder::addGlobalSet( const char *sVar, const char *sValue, int nHow )
239{
240 lGlobalVars.push_back( SetVar( sVar, sValue, nHow ) );
241}
242
243//
143// Debug 244// Debug
144// 245//
145void Builder::debugDump() 246void Builder::debugDump()
@@ -159,25 +260,137 @@ void Builder::debugDump()
159 for( ActionTmpCmdList::iterator j = (*i).second.begin(); 260 for( ActionTmpCmdList::iterator j = (*i).second.begin();
160 j != (*i).second.end(); j++ ) 261 j != (*i).second.end(); j++ )
161 { 262 {
162 printf(" %d [", (*j).first ); 263 printf(" %d ", (*j).first );
163 for( BuildList::iterator k = (*j).second.begin(); 264 printBuildList( (*j).second );
164 k != (*j).second.end(); k++ ) 265 printf("\n");
266 }
267 }
268
269 printf("\nTargets:\n");
270 for( TargetTmpList::iterator i = lTargetTmp.begin();
271 i != lTargetTmp.end(); i++ )
272 {
273 printf(" ");
274 printBuildList( (*i).first );
275 printf(":\n");
276
277 printf(" Rule: %s\n", (*i).second.sRule.c_str() );
278 printf(" Prefix: %s\n", (*i).second.sPrefix.c_str() );
279 printf(" Type: %s\n", (*i).second.sType.c_str() );
280 printf(" Input: ");
281 printBuildList( (*i).second.lInput );
282 printf("\n Requires: ");
283 printBuildList( (*i).second.lRequires );
284 printf("\n Vars:\n");
285
286 for( SetVarList::iterator j = (*i).second.lVar.begin();
287 j != (*i).second.lVar.end(); j++ )
288 {
289 char *op;
290 switch( (*j).third )
165 { 291 {
166 if( k != (*j).second.begin() ) 292 case setSet: op = "="; break;
167 { 293 case setAdd: op = "+="; break;
168 printf(", ");
169 }
170 if( (*k).second )
171 {
172 printf("func()");
173 }
174 else
175 {
176 printf("\"%s\"", (*k).first.c_str() );
177 }
178 } 294 }
179 printf("]\n"); 295 printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() );
296 }
297 }
298
299 printf("\nGlobals:\n");
300 for( SetVarList::iterator j = lGlobalVars.begin();
301 j != lGlobalVars.end(); j++ )
302 {
303 char *op;
304 switch( (*j).third )
305 {
306 case setSet: op = "="; break;
307 case setAdd: op = "+="; break;
180 } 308 }
309 printf(" %s %s %s\n", (*j).first.c_str(), op, (*j).second.c_str() );
310 }
311
312 printf("\nRules:\n");
313 for( RuleTmpList::iterator i = lRuleTmp.begin();
314 i != lRuleTmp.end(); i++ )
315 {
316 printf(" %s:\n", (*i).sName.c_str() );
317 printf(" Matches: func()\n");
318 printf(" Produces: ");
319 printBuildList( (*i).lProduces );
320 printf("\n Requires: ");
321 printBuildList( (*i).lRequires );
322 printf("\n Filters: %d\n", (*i).lFilter.size() );
323 printf(" Performs: %d\n", (*i).lPerform.size() );
181 } 324 }
182} 325}
183 326
327void Builder::printBuildList( const BuildList &lst )
328{
329 printf("[");
330 for( BuildList::const_iterator k = lst.begin();
331 k != lst.end(); k++ )
332 {
333 if( k != lst.begin() )
334 {
335 printf(", ");
336 }
337 if( (*k).second )
338 {
339 printf("func()");
340 }
341 else
342 {
343 printf("\"%s\"", (*k).first.c_str() );
344 }
345 }
346 printf("]");
347}
348
349//
350// Actually make a build object
351//
352Build *Builder::genBuild()
353{
354 Build *bld = new Build;
355
356 for( TargetTmpList::iterator i = lTargetTmp.begin();
357 i != lTargetTmp.end(); i++ )
358 {
359 StringList lTargetNames = buildToStringList(
360 (*i).first, StringList()
361 );
362 for( StringList::iterator j = lTargetNames.begin();
363 j != lTargetNames.end(); j++ )
364 {
365 if( (*i).second.sType != "" )
366 {
367 Target *pTarget = fTarget.instantiate(
368 (*i).second.sType.c_str()
369 );
370 pTarget->setName( *j );
371 pTarget->setRule( (*i).second.sRule );
372
373 StringList lInputs = buildToStringList(
374 (*i).second.lInput, StringList()
375 );
376 pTarget->getInput().insert(
377 pTarget->getInput().end(),
378 lInputs.begin(), lInputs.end()
379 );
380
381 bld->addTarget( pTarget );
382 }
383 StringList lReqs = buildToStringList(
384 (*i).second.lRequires, StringList()
385 );
386 for( StringList::iterator k = lReqs.begin();
387 k != lReqs.end(); k++ )
388 {
389 bld->addRequires( (*j), (*k) );
390 }
391 }
392 }
393
394 return bld;
395}
396
diff --git a/src/builder.h b/src/builder.h
index 1d126dc..8d72627 100644
--- a/src/builder.h
+++ b/src/builder.h
@@ -6,8 +6,8 @@
6#include <list> 6#include <list>
7#include <utility> 7#include <utility>
8#include "build.tab.h" 8#include "build.tab.h"
9#include "exceptions.h"
10 9
10class Build;
11class Builder; 11class Builder;
12class Function; 12class Function;
13class FunctionFactory; 13class FunctionFactory;
@@ -19,12 +19,37 @@ class TargetFactory;
19#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld ) 19#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld )
20YY_DECL; 20YY_DECL;
21 21
22subExceptionDecl( BuildException );
23
24typedef std::list<std::string> StringList; 22typedef std::list<std::string> StringList;
25 23
24template<class tx, class ty, class tz>
25class Triplet
26{
27public:
28 Triplet( const tx &x, const ty &y, const tz &z ) :
29 first( x ), second( y ), third( z )
30 {}
31
32 Triplet( const Triplet &src ) :
33 first( src.first ), second( src.second ), third( src.third )
34 {}
35
36 tx first;
37 ty second;
38 tz third;
39};
40
41enum eSetHow
42{
43 setSet,
44 setAdd
45};
46
26class Builder 47class Builder
27{ 48{
49 typedef std::pair<std::string, Function *> BuildListItem;
50 typedef std::list<BuildListItem> BuildList;
51 typedef Triplet<std::string, std::string, int> SetVar;
52 typedef std::list<SetVar> SetVarList;
28public: 53public:
29 Builder(); 54 Builder();
30 virtual ~Builder(); 55 virtual ~Builder();
@@ -32,19 +57,40 @@ public:
32 void error( YYLTYPE *locp, const char *msg ); 57 void error( YYLTYPE *locp, const char *msg );
33 void error( const std::string &msg ); 58 void error( const std::string &msg );
34 59
35 void load( const std::string &sFile ); 60 Build *load( const std::string &sFile );
36 61
37private: 62private:
38 std::string file; 63 std::string file;
39 void scanBegin(); 64 void scanBegin();
40 void scanEnd(); 65 void scanEnd();
41 66
67 Build *genBuild();
68
42public: // Target functions 69public: // Target functions
43 bool isTarget( const char *sType ); 70 bool isTarget( const char *sType );
71 void newTarget();
72 void setTargetRule( const char *sRule );
73 void setTargetPrefix( const char *sPrefix );
74 void setTargetType( const char *sType );
75 void addTargetInput();
76 void addTargetRequires();
77 void addTargetSet( const char *sVar, const char *sVal, int nHow );
44 78
45private: // Target variables 79private: // Target variables
46 Target *pTmpTarget;
47 TargetFactory &fTarget; 80 TargetFactory &fTarget;
81 class TargetInfo
82 {
83 public:
84 std::string sRule;
85 std::string sPrefix;
86 std::string sType;
87 BuildList lInput;
88 BuildList lRequires;
89 SetVarList lVar;
90 };
91 typedef std::pair<BuildList,TargetInfo> TargetTmp;
92 typedef std::list<TargetTmp> TargetTmpList;
93 TargetTmpList lTargetTmp;
48 94
49public: // Function functions 95public: // Function functions
50 bool isFunction( const char *sFunc ); 96 bool isFunction( const char *sFunc );
@@ -68,16 +114,35 @@ public: // List functions
68 void newList(); 114 void newList();
69 void addListString( const char *str ); 115 void addListString( const char *str );
70 void addListFunc(); 116 void addListFunc();
117 void filterList();
71 118
72 typedef std::pair<std::string, Function *> BuildListItem; 119 StringList buildToStringList( const BuildList &lSrc, const StringList &lIn );
73 typedef std::list<BuildListItem> BuildList;
74 120
75 StringList buildToStringList( BuildList &lSrc, StringList &lIn ); 121private: // List variables
76
77private:
78 BuildList lTmp; 122 BuildList lTmp;
79 123
80public: // Functions for dealing with rules 124public: // Rules functions
125 void addRule( const char *sName );
126 void addRuleMatches();
127 void addRuleProduces();
128 void addRuleRequires();
129 void addRuleInputFilter();
130 void addRulePerform();
131
132private: // Rule variables
133 class RuleInfo
134 {
135 public:
136 std::string sName;
137 Function *pMatches;
138 BuildList lProduces;
139 BuildList lRequires;
140 std::list<Function *> lFilter;
141 std::list<Perform *> lPerform;
142 };
143
144 typedef std::list<RuleInfo> RuleTmpList;
145 RuleTmpList lRuleTmp;
81 146
82public: // Functions for dealing with actions 147public: // Functions for dealing with actions
83 void addAction(); 148 void addAction();
@@ -91,8 +156,15 @@ private: // Action variables
91 typedef std::list<ActionTmp> ActionTmpList; 156 typedef std::list<ActionTmp> ActionTmpList;
92 ActionTmpList lActions; 157 ActionTmpList lActions;
93 158
159public: // Global variable functions
160 void addGlobalSet( const char *sVar, const char *sValue, int nHow );
161
162private: // Global variable variables
163 SetVarList lGlobalVars;
164
94public: // Debug 165public: // Debug
95 void debugDump(); 166 void debugDump();
167 void printBuildList( const BuildList &lst );
96}; 168};
97 169
98#endif 170#endif
diff --git a/src/function.h b/src/function.h
index c840922..1a71f8a 100644
--- a/src/function.h
+++ b/src/function.h
@@ -11,7 +11,7 @@ public:
11 virtual ~Function(); 11 virtual ~Function();
12 12
13 void addParam( const char *str ); 13 void addParam( const char *str );
14 virtual void execute( StringList &lInput, StringList &lOutput )=0; 14 virtual void execute( const StringList &lInput, StringList &lOutput )=0;
15 15
16private: 16private:
17 StringList lParams; 17 StringList lParams;
diff --git a/src/functioncommandtolist.cpp b/src/functioncommandtolist.cpp
index 6299f6f..46762b5 100644
--- a/src/functioncommandtolist.cpp
+++ b/src/functioncommandtolist.cpp
@@ -11,7 +11,7 @@ FunctionCommandToList::~FunctionCommandToList()
11{ 11{
12} 12}
13 13
14void FunctionCommandToList::execute( StringList &lInput, StringList &lOutput ) 14void FunctionCommandToList::execute( const StringList &lInput, StringList &lOutput )
15{ 15{
16} 16}
17 17
diff --git a/src/functioncommandtolist.h b/src/functioncommandtolist.h
index 5bebe16..176e40f 100644
--- a/src/functioncommandtolist.h
+++ b/src/functioncommandtolist.h
@@ -11,7 +11,7 @@ public:
11 FunctionCommandToList(); 11 FunctionCommandToList();
12 virtual ~FunctionCommandToList(); 12 virtual ~FunctionCommandToList();
13 13
14 virtual void execute( StringList &lInput, StringList &lOutput ); 14 virtual void execute( const StringList &lInput, StringList &lOutput );
15 15
16private: 16private:
17 17
diff --git a/src/functiondirectoriesin.cpp b/src/functiondirectoriesin.cpp
index a22e5d7..9452489 100644
--- a/src/functiondirectoriesin.cpp
+++ b/src/functiondirectoriesin.cpp
@@ -11,7 +11,7 @@ FunctionDirectoriesIn::~FunctionDirectoriesIn()
11{ 11{
12} 12}
13 13
14void FunctionDirectoriesIn::execute( StringList &lInput, StringList &lOutput ) 14void FunctionDirectoriesIn::execute( const StringList &lInput, StringList &lOutput )
15{ 15{
16} 16}
17 17
diff --git a/src/functiondirectoriesin.h b/src/functiondirectoriesin.h
index d769a0d..ba1b2e4 100644
--- a/src/functiondirectoriesin.h
+++ b/src/functiondirectoriesin.h
@@ -11,7 +11,7 @@ public:
11 FunctionDirectoriesIn(); 11 FunctionDirectoriesIn();
12 virtual ~FunctionDirectoriesIn(); 12 virtual ~FunctionDirectoriesIn();
13 13
14 virtual void execute( StringList &lInput, StringList &lOutput ); 14 virtual void execute( const StringList &lInput, StringList &lOutput );
15 15
16private: 16private:
17 17
diff --git a/src/functionfilesin.cpp b/src/functionfilesin.cpp
index 7dc073b..0d65c13 100644
--- a/src/functionfilesin.cpp
+++ b/src/functionfilesin.cpp
@@ -11,7 +11,7 @@ FunctionFilesIn::~FunctionFilesIn()
11{ 11{
12} 12}
13 13
14void FunctionFilesIn::execute( StringList &lInput, StringList &lOutput ) 14void FunctionFilesIn::execute( const StringList &lInput, StringList &lOutput )
15{ 15{
16} 16}
17 17
diff --git a/src/functionfilesin.h b/src/functionfilesin.h
index 2ad23f9..b660301 100644
--- a/src/functionfilesin.h
+++ b/src/functionfilesin.h
@@ -11,7 +11,7 @@ public:
11 FunctionFilesIn(); 11 FunctionFilesIn();
12 virtual ~FunctionFilesIn(); 12 virtual ~FunctionFilesIn();
13 13
14 virtual void execute( StringList &lInput, StringList &lOutput ); 14 virtual void execute( const StringList &lInput, StringList &lOutput );
15 15
16private: 16private:
17 17
diff --git a/src/functionregexp.cpp b/src/functionregexp.cpp
index 045f745..462e93c 100644
--- a/src/functionregexp.cpp
+++ b/src/functionregexp.cpp
@@ -11,7 +11,7 @@ FunctionRegexp::~FunctionRegexp()
11{ 11{
12} 12}
13 13
14void FunctionRegexp::execute( StringList &lInput, StringList &lOutput ) 14void FunctionRegexp::execute( const StringList &lInput, StringList &lOutput )
15{ 15{
16} 16}
17 17
diff --git a/src/functionregexp.h b/src/functionregexp.h
index 80a8220..9fa2eb4 100644
--- a/src/functionregexp.h
+++ b/src/functionregexp.h
@@ -11,7 +11,7 @@ public:
11 FunctionRegexp(); 11 FunctionRegexp();
12 virtual ~FunctionRegexp(); 12 virtual ~FunctionRegexp();
13 13
14 virtual void execute( StringList &lInput, StringList &lOutput ); 14 virtual void execute( const StringList &lInput, StringList &lOutput );
15 15
16private: 16private:
17 17
diff --git a/src/functiontostring.cpp b/src/functiontostring.cpp
index f5f43b2..a76705a 100644
--- a/src/functiontostring.cpp
+++ b/src/functiontostring.cpp
@@ -11,7 +11,7 @@ FunctionToString::~FunctionToString()
11{ 11{
12} 12}
13 13
14void FunctionToString::execute( StringList &lInput, StringList &lOutput ) 14void FunctionToString::execute( const StringList &lInput, StringList &lOutput )
15{ 15{
16} 16}
17 17
diff --git a/src/functiontostring.h b/src/functiontostring.h
index 93bc20f..5e64256 100644
--- a/src/functiontostring.h
+++ b/src/functiontostring.h
@@ -11,7 +11,7 @@ public:
11 FunctionToString(); 11 FunctionToString();
12 virtual ~FunctionToString(); 12 virtual ~FunctionToString();
13 13
14 virtual void execute( StringList &lInput, StringList &lOutput ); 14 virtual void execute( const StringList &lInput, StringList &lOutput );
15 15
16private: 16private:
17 17
diff --git a/src/main.cpp b/src/main.cpp
index 97c2708..be95f07 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -4,6 +4,7 @@
4//#include "viewermake.h" 4//#include "viewermake.h"
5#include "paramproc.h" 5#include "paramproc.h"
6#include "staticstring.h" 6#include "staticstring.h"
7#include "build.h"
7 8
8class Param : public ParamProc 9class Param : public ParamProc
9{ 10{
@@ -76,7 +77,7 @@ int main( int argc, char *argv[] )
76 //bld.setCache( prm.sCache ); 77 //bld.setCache( prm.sCache );
77 //try 78 //try
78 //{ 79 //{
79 bld.load( prm.sFile.c_str() ); 80 Build *pBuild = bld.load( prm.sFile.c_str() );
80 //} 81 //}
81 //catch( BuildException &e ) 82 //catch( BuildException &e )
82 //{ 83 //{
@@ -90,6 +91,8 @@ int main( int argc, char *argv[] )
90 printf("\n\n----------\nDebug dump\n----------\n"); 91 printf("\n\n----------\nDebug dump\n----------\n");
91 bld.debugDump(); 92 bld.debugDump();
92 } 93 }
94 printf("\n\n----------\nDebug dump\n----------\n");
95 pBuild->debugDump();
93 //else 96 //else
94 { 97 {
95 //if( prm.sAction > 0 ) 98 //if( prm.sAction > 0 )
diff --git a/src/perform.cpp b/src/perform.cpp
index 937a76c..4e4a78e 100644
--- a/src/perform.cpp
+++ b/src/perform.cpp
@@ -7,3 +7,9 @@ Perform::Perform()
7Perform::~Perform() 7Perform::~Perform()
8{ 8{
9} 9}
10
11void Perform::addParam( const char *sParam )
12{
13 lParam.push_back( sParam );
14}
15
diff --git a/src/perform.h b/src/perform.h
index 0b6a16d..020af42 100644
--- a/src/perform.h
+++ b/src/perform.h
@@ -2,7 +2,8 @@
2#define PERFORM_H 2#define PERFORM_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5 5#include <list>
6#include <string>
6 7
7class Perform 8class Perform
8{ 9{
@@ -10,7 +11,10 @@ public:
10 Perform(); 11 Perform();
11 virtual ~Perform(); 12 virtual ~Perform();
12 13
14 void addParam( const char *sParam );
15
13private: 16private:
17 std::list<std::string> lParam;
14 18
15}; 19};
16 20
diff --git a/src/rule.cpp b/src/rule.cpp
new file mode 100644
index 0000000..22af322
--- /dev/null
+++ b/src/rule.cpp
@@ -0,0 +1,9 @@
1#include "rule.h"
2
3Rule::Rule()
4{
5}
6
7Rule::~Rule()
8{
9}
diff --git a/src/rule.h b/src/rule.h
new file mode 100644
index 0000000..065ab9e
--- /dev/null
+++ b/src/rule.h
@@ -0,0 +1,17 @@
1#ifndef RULE_H
2#define RULE_H
3
4#include <stdint.h>
5
6
7class Rule
8{
9public:
10 Rule();
11 virtual ~Rule();
12
13private:
14
15};
16
17#endif
diff --git a/src/target.cpp b/src/target.cpp
index f22bc54..834dbaa 100644
--- a/src/target.cpp
+++ b/src/target.cpp
@@ -7,3 +7,4 @@ Target::Target()
7Target::~Target() 7Target::~Target()
8{ 8{
9} 9}
10
diff --git a/src/target.h b/src/target.h
index b7bee83..75fcb50 100644
--- a/src/target.h
+++ b/src/target.h
@@ -3,6 +3,10 @@
3 3
4#include <stdint.h> 4#include <stdint.h>
5 5
6#include <string>
7#include <list>
8
9typedef std::list<std::string> StringList;
6 10
7class Target 11class Target
8{ 12{
@@ -10,8 +14,35 @@ public:
10 Target(); 14 Target();
11 virtual ~Target(); 15 virtual ~Target();
12 16
13private: 17 void setName( const std::string &sName )
18 {
19 this->sName = sName;
20 }
21
22 std::string getName()
23 {
24 return sName;
25 }
26
27 void setRule( const std::string &sRule )
28 {
29 this->sRule = sRule;
30 }
14 31
32 std::string getRule()
33 {
34 return sRule;
35 }
36
37 StringList &getInput()
38 {
39 return lInput;
40 }
41
42private:
43 std::string sName;
44 std::string sRule;
45 StringList lInput;
15}; 46};
16 47
17#endif 48#endif