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