aboutsummaryrefslogtreecommitdiff
path: root/src/builder.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-07-31 08:07:12 +0000
committerMike Buland <eichlan@xagasoft.com>2006-07-31 08:07:12 +0000
commit9139f1df4cda80b91ab68e5de27e85eaa4c54682 (patch)
tree87fadb2618ee8228f7184aa14bfa2b21741e3f49 /src/builder.cpp
parent113fc467a7170a8a564049c64d1036dd10e6abac (diff)
downloadbuild-9139f1df4cda80b91ab68e5de27e85eaa4c54682.tar.gz
build-9139f1df4cda80b91ab68e5de27e85eaa4c54682.tar.bz2
build-9139f1df4cda80b91ab68e5de27e85eaa4c54682.tar.xz
build-9139f1df4cda80b91ab68e5de27e85eaa4c54682.zip
I still can't get the pymake file to auto-make the bison and flex .c files, but
besides that everything is looking great. There's only one thing left to parse and interpret before we can try actually building something.
Diffstat (limited to 'src/builder.cpp')
-rw-r--r--src/builder.cpp152
1 files changed, 151 insertions, 1 deletions
diff --git a/src/builder.cpp b/src/builder.cpp
index 2de6f5c..e5017e2 100644
--- a/src/builder.cpp
+++ b/src/builder.cpp
@@ -3,13 +3,17 @@
3#include "builder.h" 3#include "builder.h"
4#include "action.h" 4#include "action.h"
5#include "command.h" 5#include "command.h"
6#include "target.h"
6#include "build.tab.h" 7#include "build.tab.h"
8#include "rule.h"
7 9
8subExceptionDef( BuildException ) 10subExceptionDef( BuildException )
9 11
10Builder::Builder() : 12Builder::Builder() :
11 pDefaultAction( NULL ), 13 pDefaultAction( NULL ),
12 pLastAddedAction( NULL ) 14 pLastAddedAction( NULL ),
15 sTmp(""),
16 sContext("")
13{ 17{
14} 18}
15 19
@@ -51,13 +55,159 @@ void Builder::add( Command *pCmd )
51 } 55 }
52} 56}
53 57
58void Builder::add( Rule *pRule )
59{
60 pLastAddedRule = pRule;
61 mRule[pRule->getName()] = pRule;
62}
63
64void Builder::add( Target *pTarg )
65{
66 pLastAddedTarget = pTarg;
67 mTarget[pTarg->getName()] = pTarg;
68}
69
54void Builder::debug() 70void Builder::debug()
55{ 71{
72 printf("Actions:\n");
56 pDefaultAction->debug(); 73 pDefaultAction->debug();
57 for( std::map<const char *, Action *, ltstr>::iterator i = mAction.begin(); 74 for( std::map<const char *, Action *, ltstr>::iterator i = mAction.begin();
58 i != mAction.end(); i++ ) 75 i != mAction.end(); i++ )
59 { 76 {
60 (*i).second->debug(); 77 (*i).second->debug();
61 } 78 }
79
80 printf("Targets:\n");
81 for( std::map<const char *, Target *, ltstr>::iterator i = mTarget.begin();
82 i != mTarget.end(); i++ )
83 {
84 (*i).second->debug();
85 }
86
87 printf("Rules:\n");
88 for( std::map<const char *, Rule *, ltstr>::iterator i = mRule.begin();
89 i != mRule.end(); i++ )
90 {
91 (*i).second->debug();
92 }
93
94 printf("Variables:\n");
95 for( varmap::iterator i = mVar.begin(); i != mVar.end(); i++ )
96 {
97 printf(" %s = \"%s\"\n", (*i).first.c_str(), (*i).second.c_str() );
98 }
99
100 printf("Variables (by context):\n");
101 for( std::map<std::string, varmap>::iterator j = mContVar.begin();
102 j != mContVar.end(); j++ )
103 {
104 printf(" %s:\n", (*j).first.c_str() );
105 for( varmap::iterator i = (*j).second.begin();
106 i != (*j).second.end(); i++ )
107 {
108 printf(" %s = \"%s\"\n",
109 (*i).first.c_str(), (*i).second.c_str() );
110 }
111 }
112
113 printf("Additional dependancies:\n");
114 for( std::map<std::string, std::list<std::string> *>::iterator i =
115 mRequires.begin(); i != mRequires.end(); i++ )
116 {
117 printf(" %s: ", (*i).first.c_str() );
118 std::list<std::string> *pList = (*i).second;
119 for( std::list<std::string>::iterator j = pList->begin();
120 j != pList->end(); j++ )
121 {
122 if( j != pList->begin() )
123 printf(", ");
124 printf("%s", (*j).c_str() );
125 }
126 printf("\n");
127 }
128}
129
130void Builder::checkVar( const char *cont, const char *sName )
131{
132 if( cont[0] != '\0' )
133 {
134 varmap &mmVar = mContVar[cont];
135 if( mmVar.find( sName ) == mmVar.end() )
136 {
137 checkVar( "", sName );
138 mmVar[sName] = mVar[sName];
139 }
140 }
141 else
142 {
143 if( mVar.find( sName ) == mVar.end() )
144 {
145 char *env = getenv( sName );
146 if( env )
147 mVar[sName] = env;
148 else
149 mVar[sName] = "";
150 }
151 }
152}
153
154void Builder::varSet( const char *sName, const char *sValue )
155{
156 checkVar( sContext, sName );
157
158 if( sContext[0] == '\0' )
159 {
160 mVar[sName] = sValue;
161 }
162 else
163 {
164 mContVar[sContext.getString()][sName] = sValue;
165 }
166}
167
168void Builder::varAddSet( const char *sName, const char *sValue )
169{
170 checkVar( sContext, sName );
171
172 if( sContext[0] == '\0' )
173 {
174 std::string s = mVar[sName];
175 s += " ";
176 s += sValue;
177 mVar[sName] = s;
178 }
179 else
180 {
181 std::string s = mContVar[sContext.getString()][sName];
182 s += " ";
183 s += sValue;
184 mContVar[sContext.getString()][sName] = s;
185 }
186}
187
188void Builder::requires( const char *sBase, const char *sReq )
189{
190 std::list<std::string> *pList = NULL;
191 if( mRequires.find(sBase) == mRequires.end() )
192 {
193 pList = new std::list<std::string>;
194 mRequires[sBase] = pList;
195 }
196 else
197 {
198 pList = mRequires[sBase];
199 }
200
201 pList->push_back( sReq );
202}
203
204void Builder::setContext( const char *sCont )
205{
206 sContext = sCont;
207}
208
209void Builder::setContext()
210{
211 setContext("");
62} 212}
63 213