source: CMT/v1r20b1/source/cmt_constituent.cxx@ 327

Last change on this file since 327 was 11, checked in by arnault, 21 years ago

Changing eol-style property

  • Property svn:eol-style set to native
File size: 15.3 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// See the complete license in cmt_license.txt "http://www.cecill.info".
5//-----------------------------------------------------------
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <ctype.h>
11
12#include "cmt_constituent.h"
13#include "cmt_generator.h"
14#include "cmt_system.h"
15#include "cmt_database.h"
16
17/*----------------------------------------------------------*/
18/* */
19/* Operations on Constituent */
20/* */
21/*----------------------------------------------------------*/
22
23//----------------------------------------------------------
24void Constituent::show (const cmt_string& name)
25{
26 Constituent* cptr = find (name);
27 if (cptr == 0) return;
28
29 const Constituent& constituent = *cptr;
30
31 constituent.show ();
32}
33
34//----------------------------------------------------------
35void Constituent::parse_all ()
36{
37 static ConstituentVector& Constituents = constituents ();
38
39 int number;
40
41 for (number = 0; number < Symbol::symbol_number (); number++)
42 {
43 Symbol& symbol = Symbol::symbol (number);
44
45 if (symbol.type != Symbol::SymbolAction) continue;
46
47 if (symbol.value_lists.size () < 1) continue;
48
49 cmt_string value = symbol.build_macro_value ();
50
51 if (value != "")
52 {
53 add_for_action (symbol.name);
54 }
55 }
56
57 for (number = 0; number < Constituents.size (); number++)
58 {
59 Constituent& constituent = Constituents[number];
60
61 constituent.parse ();
62 }
63}
64
65//----------------------------------------------------------
66void Constituent::show_all ()
67{
68 static ConstituentVector& Constituents = constituents ();
69
70 int number;
71
72 for (number = 0; number < Constituents.size (); number++)
73 {
74 const Constituent& constituent = Constituents[number];
75
76 constituent.show ();
77 }
78}
79
80//----------------------------------------------------------
81void Constituent::show_names ()
82{
83 static ConstituentVector& Constituents = constituents ();
84
85 int number;
86
87 for (number = 0; number < Constituents.size (); number++)
88 {
89 Constituent& constituent = Constituents[number];
90 cout << constituent.name << endl;
91 }
92}
93
94//----------------------------------------------------------
95Constituent* Constituent::find (const cmt_string& name)
96{
97 static ConstituentVector& Constituents = constituents ();
98
99 int constituent_index;
100
101 if (Constituents.size () == 0) return (0);
102
103 for (constituent_index = 0;
104 constituent_index < Constituents.size ();
105 constituent_index++)
106 {
107 Constituent& constituent = Constituents[constituent_index];
108
109 if (constituent.name == name)
110 {
111 return (&constituent);
112 }
113 }
114
115 return (0);
116}
117
118class constituents_action_iterator
119{
120public:
121 typedef enum
122 {
123 ready,
124 need_include
125 } states;
126
127 constituents_action_iterator (Constituent& c) : m_constituent (c)
128 {
129 m_state = ready;
130 }
131
132 void set (const cmt_string& w)
133 {
134 int equal;
135
136 if (w == "") return;
137
138 if (m_state == need_include)
139 {
140 m_state = ready;
141
142 cmt_string& include = m_constituent.includes.add ();
143 include = w;
144 }
145
146 if (w == "-OS9")
147 {
148 m_constituent.need_OS9 = true;
149 }
150 else if ((w == "-Windows") ||
151 (w == "-windows"))
152 {
153 m_constituent.windows = true;
154 }
155 else if (w == "-no_share")
156 {
157 m_constituent.no_share = true;
158 }
159 else if (w == "-no_static")
160 {
161 m_constituent.no_static = true;
162 }
163 else if (w == "-prototypes")
164 {
165 m_constituent.need_prototypes = true;
166 }
167 else if (w == "-no_prototypes")
168 {
169 m_constituent.need_prototypes = false;
170 }
171 else if (w == "-check")
172 {
173 m_constituent.need_check = true;
174 }
175 else if (w == "-triggers")
176 {
177 if (m_constituent.type == Library)
178 {
179 //m_constituent.build_triggers = true;
180 }
181 }
182 else if (w == "-no_triggers")
183 {
184 if (m_constituent.type == Library)
185 {
186 m_constituent.build_triggers = false;
187 }
188 }
189 else if (w == "-I")
190 {
191 m_state = need_include;
192 }
193 else if (w.substr (0, 3) == "-s=")
194 {
195 w.substr (3, m_subdir);
196 }
197 else if (w.substr (0, 3) == "-x=")
198 {
199 cmt_string& exclude = m_constituent.excludes.add ();
200 w.substr (3, exclude);
201 cmt_regexp& exp = m_constituent.exclude_exprs.add ();
202 exp.set (exclude);
203 }
204 else if (w.substr (0, 3) == "-k=")
205 {
206 cmt_string& select = m_constituent.selects.add ();
207 w.substr (3, select);
208 cmt_regexp& exp = m_constituent.select_exprs.add ();
209 exp.set (select);
210 }
211 else if (w.substr (0, 8) == "-import=")
212 {
213 cmt_string& import = m_constituent.imports.add ();
214 w.substr (8, import);
215 }
216 else if (w.substr (0, 7) == "-group=")
217 {
218 cmt_string group_name = "";
219
220 w.substr (7, group_name);
221
222 if (group_name != "")
223 {
224 m_constituent.group = Group::add (group_name);
225 }
226 }
227 else if (w.substr (0, 8) == "-suffix=")
228 {
229 w.substr (8, m_constituent.suffix);
230 }
231 else if (w == "-target_tag")
232 {
233 m_constituent.has_target_tag = true;
234 }
235 else if (w.substr (0, 1) == "-")
236 {
237 if (!Cmt::get_quiet ())
238 {
239 cerr << "#CMT> Warning: bad option "
240 << w << " in constituent " << m_constituent.name << endl;
241 //CmtError::set (CmtError::execution_error, cmd);
242 }
243 }
244 else if ((equal = w.find ("=")) != cmt_string::npos)
245 {
246 cmt_string variable_name;
247 cmt_string variable_value;
248
249 w.substr (0, equal, variable_name);
250 w.substr (equal + 1, variable_value);
251
252 Variable* v = Variable::find (m_constituent.variables, variable_name);
253 if (v == 0)
254 {
255 v = &(m_constituent.variables.add ());
256 v->set (variable_name);
257 }
258
259 (*v) = variable_value;
260 }
261 else
262 {
263 // We have a normal source module
264
265 cmt_string& module = m_constituent.modules.add ();
266
267 module.erase (0);
268
269 //
270 // The prefix explicitly provided in (w) has priority
271 // over the currently specified (m_subdir) when it is an
272 // absolute path
273 //
274 if (CmtSystem::absolute_path (w))
275 {
276 module += w;
277 }
278 else
279 {
280 cmt_string prefix;
281 cmt_string name = w;
282
283 CmtSystem::dirname (name, prefix);
284 if (prefix == "../src") CmtSystem::basename (name, name);
285
286 module += m_subdir;
287
288 if (module != "")
289 {
290 module += CmtSystem::file_separator ();
291 }
292
293 module += name;
294 }
295 }
296 }
297
298 Constituent& m_constituent;
299 cmt_string m_subdir;
300 states m_state;
301};
302
303//----------------------------------------------------------
304void Constituent::action (ConstituentType type,
305 const CmtSystem::cmt_string_vector& words)
306{
307 cmt_string generator;
308 cmt_string name;
309 Constituent* constituent;
310
311 int i = 1;
312
313 if (type == Document)
314 {
315 generator = words[i];
316 if (generator == "") return;
317 i++;
318 }
319
320 name = words[i];
321 if (name == "") return;
322 i++;
323
324 constituent = add (type, name, generator);
325
326 for (;i < words.size (); i++)
327 {
328 const cmt_string& w = words[i];
329 cmt_string& parameter = constituent->parameters.add ();
330 parameter = w;
331 }
332}
333
334//----------------------------------------------------------
335void Constituent::parse ()
336{
337 if (parameters.size () == 0) return;
338
339 Constituent& me = *this;
340
341 modules.clear ();
342
343 constituents_action_iterator it (me);
344
345 for (int i = 0; i < parameters.size (); i++)
346 {
347 const cmt_string& w = parameters[i];
348 cmt_string ew = w;
349
350 Symbol::expand (ew);
351
352 CmtSystem::cmt_string_vector ws;
353
354 //cerr << "Constituent " << name << " Analyzing module " << ew << endl;
355
356 if (ew.substr (0, 13) == "action_value=")
357 {
358 it.set (ew);
359 }
360 else
361 {
362 CmtSystem::split (ew, " \t", ws);
363
364 for (int j = 0; j < ws.size (); ++j)
365 {
366 const cmt_string& w = ws[j];
367
368 //cerr << "Constituent " << name << " Setting module " << w << endl;
369 it.set (w);
370 }
371 }
372 }
373
374 parameters.clear ();
375}
376
377//----------------------------------------------------------
378Constituent* Constituent::add (ConstituentType type,
379 const cmt_string& name,
380 const cmt_string& generator)
381{
382 static ConstituentVector& Constituents = constituents ();
383
384 {
385 Constituent* constituent;
386
387 if (name == "") return (0);
388
389 constituent = find (name);
390 if (constituent != 0) return (constituent);
391 }
392
393 Constituent& constituent = Constituents.add ();
394 constituent.clear ();
395
396 constituent.name = name;
397 constituent.generator = generator;
398 constituent.type = type;
399 constituent.need_prototypes = Cmt::need_prototypes ();
400
401 return (&constituent);
402}
403
404//----------------------------------------------------------
405Constituent* Constituent::add_for_action (const cmt_string& name)
406{
407 Constituent* constituent;
408
409 constituent = add (Document, name, "cmt_action_runner");
410
411 constituent->group = Group::add ("cmt_actions");
412 constituent->has_target_tag = true;
413
414 cmt_string& p1 = constituent->parameters.add ();
415 p1 = "action_value=";
416 p1 += "$(";
417 p1 += name;
418 p1 += ")";
419
420 return (constituent);
421}
422
423//----------------------------------------------------------
424void Constituent::clear_all ()
425{
426 static ConstituentVector& Constituents = constituents ();
427
428 for (int i = 0; i < Constituents.size (); i++)
429 {
430 Constituent& c = Constituents[i];
431 c.clear ();
432 }
433 Constituents.clear ();
434}
435
436//----------------------------------------------------------
437Constituent::ConstituentVector& Constituent::constituents ()
438{
439 static Database& db = Database::instance ();
440 static ConstituentVector& Constituents = db.constituents ();
441
442 return (Constituents);
443}
444
445//----------------------------------------------------------
446Constituent::Constituent ()
447{
448 clear ();
449}
450
451//----------------------------------------------------------
452Constituent::~Constituent ()
453{
454}
455
456//----------------------------------------------------------
457void Constituent::clear ()
458{
459 name = "";
460 generator = "";
461 type = Document;
462 group = 0;
463 modules.clear ();
464 parameters.clear ();
465 need_OS9 = false;
466 windows = false;
467 no_static = false;
468 no_share = false;
469 need_prototypes = false;
470 need_check = false;
471 build_triggers = false;
472 has_target_tag = false;
473 excludes.clear ();
474 exclude_exprs.clear ();
475 selects.clear ();
476 select_exprs.clear ();
477 includes.clear ();
478 imports.clear ();
479 variables.clear ();
480}
481
482//----------------------------------------------------------
483void Constituent::build_all_makefiles (bool simulation)
484{
485 static ConstituentVector& Constituents = constituents ();
486
487 int i;
488
489 for (i = 0; i < Constituents.size (); i++)
490 {
491 Constituent& constituent = Constituents[i];
492
493 constituent.build_makefile (simulation);
494 }
495}
496
497//----------------------------------------------------------
498void Constituent::build_all_msdev_files (bool simulation)
499{
500 static ConstituentVector& Constituents = constituents ();
501
502 int i;
503
504 Generator::build_msdev_workspace (Constituents);
505
506 for (i = 0; i < Constituents.size (); i++)
507 {
508 Constituent& constituent = Constituents[i];
509
510 constituent.build_msdev_file (simulation);
511 }
512}
513
514// Visual Studio.Net Support
515//----------------------------------------------------------
516void Constituent::build_all_vsnet_files (bool simulation)
517{
518 static ConstituentVector& Constituents = constituents ();
519
520 int i;
521
522 Generator::build_vsnet_workspace (Constituents);
523
524 for (i = 0; i < Constituents.size (); i++)
525 {
526 Constituent& constituent = Constituents[i];
527
528 constituent.build_vsnet_file (simulation);
529 }
530}
531
532//----------------------------------------------------------
533void Constituent::build_makefile (bool simulation) const
534{
535 if (!simulation)
536 {
537 Generator::build_constituent_makefile (*this);
538 }
539}
540
541//----------------------------------------------------------
542void Constituent::build_msdev_file (bool simulation) const
543{
544 if (!simulation)
545 {
546 Generator::build_msdev (*this);
547 }
548}
549
550// Visual Studio.net Support
551//----------------------------------------------------------
552void Constituent::build_vsnet_file (bool simulation) const
553{
554 if (!simulation)
555 {
556 Generator::build_vsnet (*this);
557 }
558}
559
560//----------------------------------------------------------
561void Constituent::show () const
562{
563 int i;
564
565 switch (type)
566 {
567 case Library:
568 cout << "library";
569 break;
570 case Application:
571 cout << "application";
572 break;
573 case Document:
574 cout << "document " << generator;
575 break;
576 }
577
578 cout << " " << name;
579
580 if (group != 0)
581 {
582 cout << " -group=" << group->name ();
583 }
584
585 if (suffix != 0)
586 {
587 cout << " -suffix=" << suffix;
588 }
589
590 if ((type == Application) && need_check)
591 {
592 cout << " -check";
593 }
594
595 if ((type == Library) && no_share)
596 {
597 cout << " -no_share";
598 }
599
600 if ((type == Library) && no_static)
601 {
602 cout << " -no_static";
603 }
604
605 if ((type == Library) && build_triggers)
606 {
607 cout << " -triggers";
608 }
609
610 if (has_target_tag)
611 {
612 cout << " -target_tag";
613 }
614
615 for (i = 0; i < (imports.size ()); i++)
616 {
617 const cmt_string& import_name = imports[i];
618
619 cout << " -import=" << import_name;
620 }
621
622 for (i = 0; i < (excludes.size ()); i++)
623 {
624 const cmt_string& exclude = excludes[i];
625
626 cout << " -x=" << exclude;
627 }
628
629 for (i = 0; i < (selects.size ()); i++)
630 {
631 const cmt_string& select = selects[i];
632
633 cout << " -k=" << select;
634 }
635
636 for (i = 0; i < (modules.size ()); i++)
637 {
638 const cmt_string& module_name = modules[i];
639
640 cout << " " << module_name;
641 }
642
643 for (i = 0; i < (variables.size ()); i++)
644 {
645 const Variable& v = variables[i];
646
647 cout << " " << v.name << "=" << v.value;
648 }
649
650 cout << endl;
651}
Note: See TracBrowser for help on using the repository browser.