aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.conf6
-rw-r--r--src/builder.cpp33
-rw-r--r--src/builder.h9
-rw-r--r--src/filetarget.cpp12
-rw-r--r--src/filetarget.h1
-rw-r--r--src/main.cpp4
-rw-r--r--src/perform.cpp3
-rw-r--r--src/perform.h8
-rw-r--r--src/performcmd.cpp9
-rw-r--r--src/performcmd.h1
-rw-r--r--src/rule.cpp103
-rw-r--r--src/rule.h5
12 files changed, 120 insertions, 74 deletions
diff --git a/build.conf b/build.conf
index 9f6f5ab..1d7c6a2 100644
--- a/build.conf
+++ b/build.conf
@@ -7,9 +7,11 @@ create file build from files in src using rule exe
7set CXXFLAGS += "-Ilibbu++/src" 7set CXXFLAGS += "-Ilibbu++/src"
8set LDFLAGS += "-Llibbu++ -lbu++" 8set LDFLAGS += "-Llibbu++ -lbu++"
9 9
10for build set LDFLAGS += -lreadline
11
10build requires src/libbu++/libbu++.a 12build requires src/libbu++/libbu++.a
11 13
12/(.*)\.o/ requires from command "g++ {CXXFLAGS} -M {re:1}.c*" 14/(.*)\.o$/ requires from command "g++ {CXXFLAGS} -M {re:1}.c*"
13 15
14rule exe matches all /(.*)\.o$/ perform command ... 16rule exe matches all /(.*)\.o$/ perform command ...
15 "g++ {match} {LDFLAGS} -o {target}" 17 "g++ {match} {LDFLAGS} -o {target}"
@@ -18,7 +20,7 @@ rule cpp matches one /(.*)\.c(pp)?$/ produces "{re:1}.o" perform command ...
18 "g++ {CXXFLAGS} -c -o {target} {match}" 20 "g++ {CXXFLAGS} -c -o {target} {match}"
19 21
20rule bison matches one /(.*)\.y$/ produces "{re:1}.tab.c", "{re:1}.tab.h" ... 22rule bison matches one /(.*)\.y$/ produces "{re:1}.tab.c", "{re:1}.tab.h" ...
21 perform command "bison {match}" 23 perform command "bison -v -b{re:1} {match}"
22 24
23rule flex matches one /(.*)\.l$/ produces "{re:1}.yy.c" perform ... 25rule flex matches one /(.*)\.l$/ produces "{re:1}.yy.c" perform ...
24 command "flex --bison-bridge --bison-locations -o {target} {match}" 26 command "flex --bison-bridge --bison-locations -o {target} {match}"
diff --git a/src/builder.cpp b/src/builder.cpp
index 852d70d..6bde1b4 100644
--- a/src/builder.cpp
+++ b/src/builder.cpp
@@ -248,9 +248,8 @@ void Builder::processRequires( std::list<std::string> &lInput )
248 if( re->execute( (*j).c_str() ) ) 248 if( re->execute( (*j).c_str() ) )
249 { 249 {
250 varmap *revars = regexVars( re ); 250 varmap *revars = regexVars( re );
251 FILE *fcmd = popen( 251 std::string s = varRepl( (*i).second.c_str(), "", revars );
252 varRepl( (*i).second.c_str(), "", revars ).c_str(), 252 FILE *fcmd = popen( s.c_str(), "r" );
253 "r" );
254 std::string rhs; 253 std::string rhs;
255 bool bHeader = true; 254 bool bHeader = true;
256 for(;;) 255 for(;;)
@@ -296,7 +295,7 @@ void Builder::processRequires( std::list<std::string> &lInput )
296 ); 295 );
297 rhs = ""; 296 rhs = "";
298 } 297 }
299 fclose( fcmd ); 298 pclose( fcmd );
300 delete revars; 299 delete revars;
301 } 300 }
302 } 301 }
@@ -407,17 +406,17 @@ std::string Builder::varRepl( const char *sSrc, const char *cont, varmap *mExtra
407 } 406 }
408 else if( *s == '}' && bVar ) 407 else if( *s == '}' && bVar )
409 { 408 {
410 if( hasVar( &mVar, var ) ) 409 if( hasVar( mExtra, var ) )
411 { 410 {
412 out += mVar[var]; 411 out += (*mExtra)[var];
413 } 412 }
414 else if( hasVar( mCont, var ) ) 413 else if( hasVar( mCont, var ) )
415 { 414 {
416 out += (*mCont)[var]; 415 out += (*mCont)[var];
417 } 416 }
418 else if( hasVar( mExtra, var ) ) 417 else if( hasVar( &mVar, var ) )
419 { 418 {
420 out += (*mExtra)[var]; 419 out += mVar[var];
421 } 420 }
422 var = ""; 421 var = "";
423 bVar = false; 422 bVar = false;
@@ -464,3 +463,21 @@ std::list<Rule *> Builder::findRuleChain( Rule *pRule )
464 return ret; 463 return ret;
465} 464}
466 465
466void cleanList( std::list<std::string> &lst )
467{
468 std::map<std::string, bool> m;
469
470 for( std::list<std::string>::iterator i = lst.begin(); i != lst.end(); i++ )
471 {
472 if( m.find( *i ) == m.end() )
473 m[ *i ] = true;
474 else
475 {
476 std::list<std::string>::iterator j = i;
477 j--;
478 lst.erase( i );
479 i = j;
480 }
481 }
482}
483
diff --git a/src/builder.h b/src/builder.h
index faa82c2..f21e411 100644
--- a/src/builder.h
+++ b/src/builder.h
@@ -100,11 +100,16 @@ public:
100 return mTarget[sName]; 100 return mTarget[sName];
101 } 101 }
102 102
103 std::list<std::string> getRequires( const char *sReq )
104 {
105 return mRequires[sReq];
106 }
107
103 typedef std::map<std::string, std::string> varmap; 108 typedef std::map<std::string, std::string> varmap;
104 varmap *regexVars( RegExp *re ); 109 varmap *regexVars( RegExp *re );
105 std::string varRepl( const char *sSrc, const char *cont, varmap *mExtra ); 110 std::string varRepl( const char *sSrc, const char *cont, varmap *mExtra );
106private:
107 111
112private:
108 void requiresNormal( const char *sBase, const char *sReq ); 113 void requiresNormal( const char *sBase, const char *sReq );
109 void requiresRegexp( const char *sBase, const char *sReq ); 114 void requiresRegexp( const char *sBase, const char *sReq );
110 void checkVar( const char *cont, const char *sName ); 115 void checkVar( const char *cont, const char *sName );
@@ -139,4 +144,6 @@ private:
139 bool bReqRegexp; 144 bool bReqRegexp;
140}; 145};
141 146
147void cleanList( std::list<std::string> &lst );
148
142#endif 149#endif
diff --git a/src/filetarget.cpp b/src/filetarget.cpp
index 3fefd9f..1880c35 100644
--- a/src/filetarget.cpp
+++ b/src/filetarget.cpp
@@ -70,10 +70,18 @@ void FileTarget::check( Builder &bld )
70{ 70{
71 Rule *pRule = bld.getRule( sRule ); 71 Rule *pRule = bld.getRule( sRule );
72 72
73 std::list<std::string> tmp = pRule->execute( bld, lInput, getName() ); 73 std::list<Perform *> perf;
74 std::list<std::string> tmp = pRule->execute( bld, lInput, perf, getName() );
74 lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); 75 lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() );
75 76
76 bld.processRequires( lInput ); 77 bld.processRequires( lOutput );
78
79 for( std::list<Perform *>::iterator i = perf.begin();
80 i != perf.end(); i++ )
81 {
82 std::list<std::string> lReqs = bld.getRequires( (*i)->getTarget() );
83
84 }
77} 85}
78 86
79void FileTarget::clean( Builder &bld ) 87void FileTarget::clean( Builder &bld )
diff --git a/src/filetarget.h b/src/filetarget.h
index 11dc180..c872c0a 100644
--- a/src/filetarget.h
+++ b/src/filetarget.h
@@ -18,6 +18,7 @@ public:
18 virtual void clean( class Builder &bld ); 18 virtual void clean( class Builder &bld );
19 19
20private: 20private:
21 // start here with the file time cache
21 22
22}; 23};
23 24
diff --git a/src/main.cpp b/src/main.cpp
index 2e13b16..ebf0cfd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,8 +7,8 @@ int main()
7 bld.load("build.conf"); 7 bld.load("build.conf");
8 8
9 bld.build(); 9 bld.build();
10 10/*
11 printf("\n\n----------\nDebug dump\n----------\n"); 11 printf("\n\n----------\nDebug dump\n----------\n");
12 bld.debug(); 12 bld.debug();*/
13} 13}
14 14
diff --git a/src/perform.cpp b/src/perform.cpp
index 937a76c..d7082a0 100644
--- a/src/perform.cpp
+++ b/src/perform.cpp
@@ -1,6 +1,7 @@
1#include "perform.h" 1#include "perform.h"
2 2
3Perform::Perform() 3Perform::Perform( const char *sTarget ) :
4 sTarget( sTarget )
4{ 5{
5} 6}
6 7
diff --git a/src/perform.h b/src/perform.h
index fefb05e..2eb8cb0 100644
--- a/src/perform.h
+++ b/src/perform.h
@@ -6,12 +6,18 @@
6class Perform 6class Perform
7{ 7{
8public: 8public:
9 Perform(); 9 Perform( const char *sTarget );
10 virtual ~Perform(); 10 virtual ~Perform();
11 11
12 virtual void execute( class Builder &bld ) = 0; 12 virtual void execute( class Builder &bld ) = 0;
13 13
14 const char *getTarget()
15 {
16 return sTarget;
17 }
18
14private: 19private:
20 StaticString sTarget;
15 21
16}; 22};
17 23
diff --git a/src/performcmd.cpp b/src/performcmd.cpp
index 21ba737..724f42b 100644
--- a/src/performcmd.cpp
+++ b/src/performcmd.cpp
@@ -2,8 +2,8 @@
2#include "builder.h" 2#include "builder.h"
3 3
4PerformCmd::PerformCmd( const char *sCmd, const char *sTarget ) : 4PerformCmd::PerformCmd( const char *sCmd, const char *sTarget ) :
5 Perform( sTarget ),
5 sCommand( sCmd ), 6 sCommand( sCmd ),
6 sTarget( sTarget )
7{ 7{
8} 8}
9 9
@@ -14,6 +14,11 @@ PerformCmd::~PerformCmd()
14void PerformCmd::execute( class Builder &bld ) 14void PerformCmd::execute( class Builder &bld )
15{ 15{
16 printf("%s\n", sCommand.getString() ); 16 printf("%s\n", sCommand.getString() );
17 system( sCommand.getString() ); 17 int ret;
18 if( (ret = system( sCommand.getString() )) != 0 )
19 {
20 printf("Error code: %d\n", WEXITSTATUS(ret) );
21 exit( WEXITSTATUS(ret) );
22 }
18} 23}
19 24
diff --git a/src/performcmd.h b/src/performcmd.h
index 3bc83aa..59510a6 100644
--- a/src/performcmd.h
+++ b/src/performcmd.h
@@ -16,7 +16,6 @@ public:
16 16
17private: 17private:
18 StaticString sCommand; 18 StaticString sCommand;
19 StaticString sTarget;
20}; 19};
21 20
22#endif 21#endif
diff --git a/src/rule.cpp b/src/rule.cpp
index 4425ea5..979075b 100644
--- a/src/rule.cpp
+++ b/src/rule.cpp
@@ -67,20 +67,48 @@ void Rule::setPerforms( ePerform pwhat, const char *sperfcmd )
67 sPerfCmd = sperfcmd; 67 sPerfCmd = sperfcmd;
68} 68}
69 69
70Perform *Rule::buildCommand( Builder &bld, const char *sCmd, const char *sTarget, const char *sMatches ) 70Perform *Rule::buildCommand( Builder &bld, const char *sCmd, Builder::varmap *vars )
71{ 71{
72 Builder::varmap vars; 72 return new PerformCmd(
73 vars["target"] = sTarget; 73 bld.varRepl( sCmd, (*vars)["target"].c_str(), vars ).c_str(),
74 vars["match"] = sMatches; 74 (*vars)["target"].c_str()
75 return new PerformCmd( bld.varRepl( sCmd, "", &vars ).c_str(), sTarget ); 75 );
76} 76}
77 77
78std::list<std::string> Rule::findTargets( Builder &bld, std::list<std::string> &lIn, std::string &sMatches, const char *sTarget ) 78std::list<std::string> Rule::execute( Builder &bld, std::list<std::string> lInput, std::list<Perform *> &lPerf, const char *sTarget )
79{ 79{
80 std::list<std::string> lTmp; 80 std::list<Rule *> lRule = bld.findRuleChain( this );
81 /*
82 if( !lRule.empty() )
83 {
84 printf("Rule %s chains to: ", sName.getString() );
85 for( std::list<Rule *>::iterator i = lRule.begin();
86 i != lRule.end(); i++ )
87 {
88 if( i != lRule.begin() )
89 printf(", ");
90 printf("%s", (*i)->sName.getString() );
91 }
92 printf("\n");
93 }*/
81 94
82 for( std::list<std::string>::iterator i = lIn.begin(); 95 std::list<std::string> lOutput;
83 i != lIn.end(); i++ ) 96 std::string sMatches;
97
98 for( std::list<Rule *>::iterator i = lRule.begin(); i != lRule.end(); i++ )
99 {
100 std::list<std::string> lTmp = (*i)->execute( bld, lInput, lPerf );
101 lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
102 }
103
104 std::list<std::string> lTest;
105 lTest.insert( lTest.end(), lInput.begin(), lInput.end() );
106 lTest.insert( lTest.end(), lOutput.begin(), lOutput.end() );
107
108 cleanList( lTest );
109
110 for( std::list<std::string>::iterator i = lTest.begin();
111 i != lTest.end(); i++ )
84 { 112 {
85 if( rWhat.execute( (*i).c_str() ) ) 113 if( rWhat.execute( (*i).c_str() ) )
86 { 114 {
@@ -90,21 +118,22 @@ std::list<std::string> Rule::findTargets( Builder &bld, std::list<std::string> &
90 { 118 {
91 if( mHow == matchOne ) 119 if( mHow == matchOne )
92 { 120 {
93 lTmp.push_back( 121 lOutput.push_back(
94 bld.varRepl( 122 bld.varRepl(
95 (*j).c_str(), 123 (*j).c_str(),
96 "", 124 "",
97 revars 125 revars
98 ) 126 )
99 ); 127 );
128 (*revars)["target"] = (sTarget==NULL)?
129 (lOutput.back().c_str()):(sTarget);
130 (*revars)["match"] = (*i).c_str();
100 Perform *p = buildCommand( 131 Perform *p = buildCommand(
101 bld, 132 bld,
102 sPerfCmd, 133 sPerfCmd,
103 (sTarget==NULL)?(lTmp.back().c_str()):(sTarget), 134 revars
104 (*i).c_str()
105 ); 135 );
106 p->execute( bld ); 136 lPerf.push_back( p );
107 delete p;
108 } 137 }
109 else if( mHow == matchAll ) 138 else if( mHow == matchAll )
110 { 139 {
@@ -115,57 +144,27 @@ std::list<std::string> Rule::findTargets( Builder &bld, std::list<std::string> &
115 delete revars; 144 delete revars;
116 } 145 }
117 } 146 }
118 147 //std::list<std::string> lTmp = findTargets( bld, lTest, sMatches, sTarget );
119 return lTmp; 148 //lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
120}
121
122std::list<std::string> Rule::execute( Builder &bld, std::list<std::string> lInput, const char *sTarget )
123{
124 std::list<Rule *> lRule = bld.findRuleChain( this );
125
126 if( !lRule.empty() )
127 {
128 printf("Rule %s chains to: ", sName.getString() );
129 for( std::list<Rule *>::iterator i = lRule.begin();
130 i != lRule.end(); i++ )
131 {
132 if( i != lRule.begin() )
133 printf(", ");
134 printf("%s", (*i)->sName.getString() );
135 }
136 printf("\n");
137 }
138
139 std::list<std::string> lOutput;
140 std::string sMatches;
141
142 for( std::list<Rule *>::iterator i = lRule.begin(); i != lRule.end(); i++ )
143 {
144 std::list<std::string> lTmp = (*i)->execute( bld, lInput );
145 lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
146 }
147
148 std::list<std::string> lTmp = findTargets( bld, lInput, sMatches, sTarget );
149 lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
150 lTmp = findTargets( bld, lOutput, sMatches, sTarget );
151 lOutput.insert( lOutput.end(), lTmp.begin(), lTmp.end() );
152 149
153 if( mHow == matchAll ) 150 if( mHow == matchAll )
154 { 151 {
155 lOutput.push_back( 152 lOutput.push_back(
156 bld.varRepl( 153 bld.varRepl(
157 sTarget, 154 sTarget,
158 "", 155 sTarget,
159 NULL 156 NULL
160 ) 157 )
161 ); 158 );
159 Builder::varmap vars;
160 vars["target"] = sTarget;
161 vars["match"] = sMatches;
162 Perform *p = buildCommand( 162 Perform *p = buildCommand(
163 bld, 163 bld,
164 sPerfCmd, 164 sPerfCmd,
165 sTarget, 165 &vars
166 sMatches.c_str()
167 ); 166 );
168 p->execute( bld ); 167 lPerf.push_back( p );
169 } 168 }
170 169
171 return lOutput; 170 return lOutput;
diff --git a/src/rule.h b/src/rule.h
index 8246cc9..b7c0049 100644
--- a/src/rule.h
+++ b/src/rule.h
@@ -6,6 +6,7 @@
6#include <stdint.h> 6#include <stdint.h>
7#include "regexp.h" 7#include "regexp.h"
8#include "staticstring.h" 8#include "staticstring.h"
9#include "builder.h"
9 10
10class Perform; 11class Perform;
11 12
@@ -40,10 +41,10 @@ public:
40 41
41 bool willChain( Rule *pRule ); 42 bool willChain( Rule *pRule );
42 43
43 std::list<std::string> execute( class Builder &bld, std::list<std::string> lInput, const char *sTarget=NULL ); 44 std::list<std::string> execute( class Builder &bld, std::list<std::string> lInput, std::list<Perform *> &lPerf, const char *sTarget=NULL );
44 45
45private: 46private:
46 class Perform *buildCommand( class Builder &bld, const char *sCmd, const char *sTarget, const char *sMatches ); 47 class Perform *buildCommand( class Builder &bld, const char *sCmd, Builder::varmap *vars );
47 std::list<std::string> findTargets( class Builder &bld, std::list<std::string> &lIn, std::string &sMatches, const char *sTarget ); 48 std::list<std::string> findTargets( class Builder &bld, std::list<std::string> &lIn, std::string &sMatches, const char *sTarget );
48 StaticString sName; 49 StaticString sName;
49 std::list<std::string> lProduces; 50 std::list<std::string> lProduces;