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 <errno.h> |
---|
8 | #include <stdio.h> |
---|
9 | |
---|
10 | #ifndef WIN32 |
---|
11 | #include <unistd.h> |
---|
12 | #endif |
---|
13 | |
---|
14 | #include "cmt_generator.h" |
---|
15 | #include "cmt_use.h" |
---|
16 | #include "cmt_symbol.h" |
---|
17 | |
---|
18 | #include "cmt_generators.h" |
---|
19 | #include "cmt_log.h" |
---|
20 | |
---|
21 | //------------------------------------------------------------------------ |
---|
22 | void SourceFile::set (const cmt_string name, Language& language, const cmt_string output) |
---|
23 | { |
---|
24 | m_name = name; |
---|
25 | m_language = &language; |
---|
26 | m_output = output; |
---|
27 | |
---|
28 | CmtSystem::reduce_file_separators (m_name); |
---|
29 | } |
---|
30 | |
---|
31 | cmt_string SourceFile::name () const |
---|
32 | { |
---|
33 | return (m_name); |
---|
34 | } |
---|
35 | |
---|
36 | Language& SourceFile::language () const |
---|
37 | { |
---|
38 | return (*m_language); |
---|
39 | } |
---|
40 | |
---|
41 | cmt_string SourceFile::output () const |
---|
42 | { |
---|
43 | return (m_output); |
---|
44 | } |
---|
45 | //------------------------------------------------------------------------ |
---|
46 | |
---|
47 | //-------------------------------------------------- |
---|
48 | CmtGenerator::CmtGenerator () |
---|
49 | { |
---|
50 | m_CONSTITUENT.set ("CONSTITUENT"); |
---|
51 | m_LINKMACRO.set ("LINKMACRO"); |
---|
52 | m_DEPENDENCIESOPTS.set ("DEPENDENCIESOPTS"); |
---|
53 | m_DOCPATH.set ("DOCPATH"); |
---|
54 | m_PACKAGEPATH.set ("PACKAGEPATH"); |
---|
55 | m_PACKAGEPREFIX.set ("PACKAGEPREFIX"); |
---|
56 | m_PACKAGE.set ("PACKAGE"); |
---|
57 | m_VERSION.set ("VERSION"); |
---|
58 | m_MGRSTYLE.set ("MGRSTYLE"); |
---|
59 | m_TITLE.set ("TITLE"); |
---|
60 | m_GROUP.set ("GROUP"); |
---|
61 | m_CONSTITUENT.set ("CONSTITUENT"); |
---|
62 | m_CONSTITUENTSUFFIX.set ("CONSTITUENTSUFFIX"); |
---|
63 | m_LIBRARYSUFFIX.set ("LIBRARYSUFFIX"); |
---|
64 | m_USER.set ("USER"); |
---|
65 | m_DATE.set ("DATE"); |
---|
66 | m_PROTOTARGET.set ("PROTOTARGET"); |
---|
67 | m_OBJS.set ("OBJS"); |
---|
68 | m_CLASSES.set ("CLASSES"); |
---|
69 | m_PROTOSTAMPS.set ("PROTOSTAMPS"); |
---|
70 | m_NAME.set ("NAME"); |
---|
71 | m_FILEPATH.set ("FILEPATH"); |
---|
72 | m_FILESUFFIX.set ("FILESUFFIX"); |
---|
73 | m_SUFFIX.set ("SUFFIX"); |
---|
74 | m_FILENAME.set ("FILENAME"); |
---|
75 | // m_LINKMACRO.set ("LINKMACRO"); |
---|
76 | m_LINE.set ("LINE"); |
---|
77 | m_ADDINCLUDE.set ("ADDINCLUDE"); |
---|
78 | m_FULLNAME.set ("FULLNAME"); |
---|
79 | m_DIRNAME.set ("DIRNAME"); |
---|
80 | m_OUTPUTNAME.set ("OUTPUTNAME"); |
---|
81 | m_ALLOS9SOURCES.set ("ALLOS9SOURCES"); |
---|
82 | m_NODEBUGUSELINKOPTS.set ("NODEBUGUSELINKOPTS"); |
---|
83 | m_DEBUGUSELINKOPTS.set ("DEBUGUSELINKOPTS"); |
---|
84 | m_USEINCLUDES.set ("USEINCLUDES"); |
---|
85 | m_HASTARGETTAG.set ("HASTARGETTAG"); |
---|
86 | m_HASDEPENDENCIES.set ("HASDEPENDENCIES"); |
---|
87 | } |
---|
88 | |
---|
89 | //-------------------------------------------------- |
---|
90 | void CmtGenerator::reset () |
---|
91 | { |
---|
92 | m_CONSTITUENT = ""; |
---|
93 | m_LINKMACRO = ""; |
---|
94 | m_DEPENDENCIESOPTS = ""; |
---|
95 | m_DOCPATH = ""; |
---|
96 | m_PACKAGEPATH = ""; |
---|
97 | m_PACKAGEPREFIX = ""; |
---|
98 | m_PACKAGE = ""; |
---|
99 | m_VERSION = ""; |
---|
100 | m_MGRSTYLE = ""; |
---|
101 | m_TITLE = ""; |
---|
102 | m_GROUP = ""; |
---|
103 | m_CONSTITUENTSUFFIX = ""; |
---|
104 | m_LIBRARYSUFFIX = ""; |
---|
105 | m_USER = ""; |
---|
106 | m_DATE = ""; |
---|
107 | m_PROTOTARGET = ""; |
---|
108 | m_OBJS = ""; |
---|
109 | m_CLASSES = ""; |
---|
110 | m_PROTOSTAMPS = ""; |
---|
111 | m_NAME = ""; |
---|
112 | m_FILEPATH = ""; |
---|
113 | m_FILESUFFIX = ""; |
---|
114 | m_SUFFIX = ""; |
---|
115 | m_FILENAME = ""; |
---|
116 | m_LINE = ""; |
---|
117 | m_ADDINCLUDE = ""; |
---|
118 | m_FULLNAME = ""; |
---|
119 | m_OUTPUTNAME = ""; |
---|
120 | m_ALLOS9SOURCES = ""; |
---|
121 | m_NODEBUGUSELINKOPTS = ""; |
---|
122 | m_DEBUGUSELINKOPTS = ""; |
---|
123 | m_USEINCLUDES = ""; |
---|
124 | m_HASTARGETTAG = ""; |
---|
125 | m_HASDEPENDENCIES = ""; |
---|
126 | m_PACKINCLUDES = ""; |
---|
127 | m_PACKOS9 = false; |
---|
128 | m_GENERATOR = ""; |
---|
129 | |
---|
130 | is_library = false; |
---|
131 | is_application = false; |
---|
132 | srcdir = ""; |
---|
133 | docdir = ""; |
---|
134 | cmtdir = ""; |
---|
135 | incdir = ""; |
---|
136 | src = "$(src)"; |
---|
137 | doc = "$(doc)"; |
---|
138 | inc = "$(inc)"; |
---|
139 | mgr = "$(mgr)"; |
---|
140 | cmt = "$(cmt)"; |
---|
141 | protos = ""; |
---|
142 | protonames = ""; |
---|
143 | os9sources = ""; |
---|
144 | |
---|
145 | m_source_files.clear (); |
---|
146 | |
---|
147 | Language::setup_all_fragments (); |
---|
148 | |
---|
149 | CmtSystem::cd (Cmt::get_current_dir ()); |
---|
150 | |
---|
151 | cmt_string branch = CmtSystem::current_branch (); |
---|
152 | |
---|
153 | if ((branch == "mgr") || (branch == "cmt")) |
---|
154 | { |
---|
155 | if (CmtSystem::test_directory ("../src")) |
---|
156 | { |
---|
157 | srcdir = ".."; |
---|
158 | srcdir += CmtSystem::file_separator (); |
---|
159 | srcdir += "src"; |
---|
160 | srcdir += CmtSystem::file_separator (); |
---|
161 | } |
---|
162 | else |
---|
163 | { |
---|
164 | srcdir = ""; |
---|
165 | } |
---|
166 | |
---|
167 | if (CmtSystem::test_directory ("../doc")) |
---|
168 | { |
---|
169 | docdir = ".."; |
---|
170 | docdir += CmtSystem::file_separator (); |
---|
171 | docdir += "doc"; |
---|
172 | docdir += CmtSystem::file_separator (); |
---|
173 | } |
---|
174 | else |
---|
175 | { |
---|
176 | docdir = ""; |
---|
177 | } |
---|
178 | |
---|
179 | if (CmtSystem::test_directory ("../cmt")) |
---|
180 | { |
---|
181 | cmtdir = ".."; |
---|
182 | cmtdir += CmtSystem::file_separator (); |
---|
183 | cmtdir += "cmt"; |
---|
184 | cmtdir += CmtSystem::file_separator (); |
---|
185 | } |
---|
186 | else if (CmtSystem::test_directory ("../mgr")) |
---|
187 | { |
---|
188 | cmtdir = ".."; |
---|
189 | cmtdir += CmtSystem::file_separator (); |
---|
190 | cmtdir += "mgr"; |
---|
191 | cmtdir += CmtSystem::file_separator (); |
---|
192 | } |
---|
193 | else |
---|
194 | { |
---|
195 | cmtdir = CmtSystem::pwd (); |
---|
196 | cmtdir += CmtSystem::file_separator (); |
---|
197 | } |
---|
198 | |
---|
199 | if (CmtSystem::test_directory ("../src")) |
---|
200 | { |
---|
201 | incdir = ".."; |
---|
202 | incdir += CmtSystem::file_separator (); |
---|
203 | incdir += "src"; |
---|
204 | incdir += CmtSystem::file_separator (); |
---|
205 | } |
---|
206 | else |
---|
207 | { |
---|
208 | incdir = ""; |
---|
209 | } |
---|
210 | } |
---|
211 | else |
---|
212 | { |
---|
213 | srcdir = "."; |
---|
214 | srcdir += CmtSystem::file_separator (); |
---|
215 | docdir = "."; |
---|
216 | docdir += CmtSystem::file_separator (); |
---|
217 | cmtdir = CmtSystem::pwd (); |
---|
218 | cmtdir += CmtSystem::file_separator (); |
---|
219 | incdir = "."; |
---|
220 | incdir += CmtSystem::file_separator (); |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | //-------------------------------------------------- |
---|
225 | bool CmtGenerator::prepare_output (const cmt_string& package, |
---|
226 | const Constituent& constituent, |
---|
227 | const cmt_string& file) |
---|
228 | { |
---|
229 | m_PACKAGE = package; |
---|
230 | m_CONSTITUENT = constituent.name; |
---|
231 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
232 | |
---|
233 | m_PACKOS9 = constituent.need_OS9; |
---|
234 | |
---|
235 | m_output_file_name = cmtdir + m_CONSTITUENT + "."; |
---|
236 | |
---|
237 | if (Cmt::build_nmake ()) |
---|
238 | { |
---|
239 | m_output_file_name += "nmake"; |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | m_output_file_name += "make"; |
---|
244 | } |
---|
245 | |
---|
246 | if (file != "") m_output_file_name = file; |
---|
247 | |
---|
248 | m_output_file_name += "new"; |
---|
249 | |
---|
250 | |
---|
251 | m_output_file = fopen (m_output_file_name.c_str (), "wb"); |
---|
252 | if (m_output_file != NULL) |
---|
253 | { |
---|
254 | return (true); |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | return (false); |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | //-------------------------------------------------- |
---|
263 | void CmtGenerator::check (const cmt_string& name) |
---|
264 | { |
---|
265 | static cmt_string old; |
---|
266 | static cmt_string backup; |
---|
267 | |
---|
268 | old = name; |
---|
269 | |
---|
270 | int pos = old.find_last_of ("new"); |
---|
271 | old.erase (pos); |
---|
272 | |
---|
273 | if (!CmtSystem::compare_files (old, name)) |
---|
274 | { |
---|
275 | backup = old; |
---|
276 | backup += "sav"; |
---|
277 | |
---|
278 | unlink (backup.c_str ()); |
---|
279 | rename (old.c_str (), backup.c_str ()); |
---|
280 | rename (name.c_str (), old.c_str ()); |
---|
281 | } |
---|
282 | else |
---|
283 | { |
---|
284 | unlink (name); |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | //-------------------------------------------------- |
---|
289 | void CmtGenerator::commit (const cmt_string& name) |
---|
290 | { |
---|
291 | static cmt_string old; |
---|
292 | static cmt_string backup; |
---|
293 | |
---|
294 | old = name; |
---|
295 | |
---|
296 | int pos = old.find_last_of ("new"); |
---|
297 | old.erase (pos); |
---|
298 | |
---|
299 | if (CmtSystem::test_file (old)) |
---|
300 | { |
---|
301 | backup = old; |
---|
302 | backup += "sav"; |
---|
303 | |
---|
304 | unlink (backup.c_str ()); |
---|
305 | rename (old.c_str (), backup.c_str ()); |
---|
306 | } |
---|
307 | |
---|
308 | rename (name.c_str (), old.c_str ()); |
---|
309 | } |
---|
310 | |
---|
311 | //-------------------------------------------------- |
---|
312 | void CmtGenerator::terminate () |
---|
313 | { |
---|
314 | CmtSystem::close_ostream (m_output_file, m_output_file_name); |
---|
315 | // fclose (m_output_file); |
---|
316 | |
---|
317 | //--- Complete the operation -------------- |
---|
318 | |
---|
319 | commit (m_output_file_name); |
---|
320 | } |
---|
321 | |
---|
322 | //-------------------------------------------------- |
---|
323 | void CmtGenerator::fill_names_outputs () |
---|
324 | { |
---|
325 | bool first = true; |
---|
326 | |
---|
327 | m_LINE = ""; |
---|
328 | m_OBJS = ""; |
---|
329 | |
---|
330 | for (int i = 0; i < m_source_files.size (); i++) |
---|
331 | { |
---|
332 | const SourceFile& file = m_source_files[i]; |
---|
333 | const cmt_string name = file.name (); |
---|
334 | const cmt_string output = file.output (); |
---|
335 | |
---|
336 | if (output != "") |
---|
337 | { |
---|
338 | if (first) |
---|
339 | { |
---|
340 | first = false; |
---|
341 | } |
---|
342 | else |
---|
343 | { |
---|
344 | m_LINE += " "; |
---|
345 | m_OBJS += " "; |
---|
346 | } |
---|
347 | m_LINE += name; |
---|
348 | m_OBJS += output; |
---|
349 | } |
---|
350 | |
---|
351 | if (Cmt::get_debug ()) |
---|
352 | { |
---|
353 | cout << "CmtGenerator::fill_names_ outputs>" << endl; |
---|
354 | cout << "name=" << name << " LINE=" << m_LINE << endl; |
---|
355 | cout << "output=" << output << " OBJS=" << m_OBJS << endl; |
---|
356 | } |
---|
357 | } |
---|
358 | |
---|
359 | filter_path (m_LINE.value); |
---|
360 | } |
---|
361 | |
---|
362 | //-------------------------------------------------- |
---|
363 | void CmtGenerator::fill_outputs () |
---|
364 | { |
---|
365 | bool first = true; |
---|
366 | |
---|
367 | m_OBJS = ""; |
---|
368 | |
---|
369 | for (int i = 0; i < m_source_files.size (); i++) |
---|
370 | { |
---|
371 | const SourceFile& file = m_source_files[i]; |
---|
372 | const cmt_string output = file.output (); |
---|
373 | |
---|
374 | if (output != "") |
---|
375 | { |
---|
376 | if (first) |
---|
377 | { |
---|
378 | first = false; |
---|
379 | } |
---|
380 | else |
---|
381 | { |
---|
382 | m_OBJS += " "; |
---|
383 | } |
---|
384 | |
---|
385 | m_OBJS += output; |
---|
386 | } |
---|
387 | |
---|
388 | if (Cmt::get_debug ()) |
---|
389 | { |
---|
390 | cout << "CmtGenerator::fill_outputs> output=" << output << " OBJS=" << m_OBJS << endl; |
---|
391 | } |
---|
392 | |
---|
393 | } |
---|
394 | |
---|
395 | if (Cmt::get_debug ()) |
---|
396 | { |
---|
397 | cout << "CmtGenerator::fill_outputs> OBJS=" << m_OBJS << endl; |
---|
398 | } |
---|
399 | |
---|
400 | } |
---|
401 | |
---|
402 | //-------------------------------------------------- |
---|
403 | void CmtGenerator::prepare_use_context () |
---|
404 | { |
---|
405 | cmt_string path; |
---|
406 | cmt_string substitution; |
---|
407 | |
---|
408 | Use* use = &Use::current (); |
---|
409 | |
---|
410 | m_deps_builder.clear (); |
---|
411 | |
---|
412 | if (use->include_path != "none") |
---|
413 | { |
---|
414 | if (use->include_path == "") |
---|
415 | { |
---|
416 | m_deps_builder.add (incdir, "$(src)"); |
---|
417 | } |
---|
418 | else |
---|
419 | { |
---|
420 | substitution = use->include_path; |
---|
421 | |
---|
422 | path = substitution; |
---|
423 | Symbol::expand (path); |
---|
424 | |
---|
425 | CmtSystem::reduce_file_separators (path); |
---|
426 | |
---|
427 | m_deps_builder.add (path, substitution); |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | m_deps_builder.add_includes (*use); |
---|
432 | |
---|
433 | Use::UsePtrVector& uses = Use::get_ordered_uses (); |
---|
434 | |
---|
435 | if (uses.size () > 0) |
---|
436 | { |
---|
437 | int number; |
---|
438 | |
---|
439 | for (number = 0; number < uses.size (); number++) |
---|
440 | { |
---|
441 | use = uses[number]; |
---|
442 | if (use->discarded) continue; |
---|
443 | |
---|
444 | if (use->real_path != "") |
---|
445 | { |
---|
446 | if (use->include_path != "none") |
---|
447 | { |
---|
448 | if (use->include_path == "") |
---|
449 | { |
---|
450 | use->get_full_path (path); |
---|
451 | path += CmtSystem::file_separator (); |
---|
452 | path += "src"; |
---|
453 | |
---|
454 | substitution = "$("; |
---|
455 | substitution += use->prefix; |
---|
456 | substitution += "ROOT)"; |
---|
457 | substitution += CmtSystem::file_separator (); |
---|
458 | substitution += "src"; |
---|
459 | substitution += CmtSystem::file_separator (); |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | substitution = use->include_path; |
---|
464 | |
---|
465 | path = substitution; |
---|
466 | Symbol::expand (path); |
---|
467 | |
---|
468 | CmtSystem::reduce_file_separators (path); |
---|
469 | } |
---|
470 | |
---|
471 | m_deps_builder.add (path, substitution); |
---|
472 | } |
---|
473 | |
---|
474 | m_deps_builder.add_includes (*use); |
---|
475 | } |
---|
476 | } |
---|
477 | } |
---|
478 | } |
---|
479 | |
---|
480 | //-------------------------------------------------- |
---|
481 | void CmtGenerator::filter_path (cmt_string& text) |
---|
482 | { |
---|
483 | CmtSystem::compress_path (text); |
---|
484 | |
---|
485 | text.replace_all ("./../src/../", "../"); |
---|
486 | text.replace_all ("./../src/", "$(src)"); |
---|
487 | |
---|
488 | text.replace_all (".\\..\\src\\..\\", "..\\"); |
---|
489 | text.replace_all (".\\..\\src\\", "$(src)"); |
---|
490 | |
---|
491 | text.replace_all ("../src/../", "../"); |
---|
492 | text.replace_all ("../src/", "$(src)"); |
---|
493 | |
---|
494 | text.replace_all ("..\\src\\..\\", "..\\"); |
---|
495 | text.replace_all ("..\\src\\", "$(src)"); |
---|
496 | |
---|
497 | text.replace_all ("../doc/../", "../"); |
---|
498 | text.replace_all ("../doc/", "$(doc)"); |
---|
499 | |
---|
500 | text.replace_all ("..\\doc\\..\\", "..\\"); |
---|
501 | text.replace_all ("..\\doc\\", "$(doc)"); |
---|
502 | |
---|
503 | text.replace_all ("$(src)$(src)", "$(src)"); |
---|
504 | } |
---|
505 | |
---|
506 | /** |
---|
507 | Scan a complete file spec (with possibly wild cards and directory) |
---|
508 | given in full_name ad fill in a vector of found file names. |
---|
509 | |
---|
510 | Result of the scan is filtered against matching suffixes |
---|
511 | |
---|
512 | Returns the count of non empty file names really found. |
---|
513 | |
---|
514 | */ |
---|
515 | int CmtGenerator::get_all_files (const cmt_string& full_name, |
---|
516 | const cmt_vector<cmt_regexp>& exclude_exprs, |
---|
517 | const cmt_vector<cmt_regexp>& select_exprs, |
---|
518 | CmtSystem::cmt_string_vector& files) |
---|
519 | { |
---|
520 | static cmt_string suffix; |
---|
521 | static cmt_string name; |
---|
522 | |
---|
523 | bool has_excludes = false; |
---|
524 | bool has_selects = false; |
---|
525 | |
---|
526 | suffix = ""; |
---|
527 | name = ""; |
---|
528 | |
---|
529 | files.clear (); |
---|
530 | |
---|
531 | has_excludes = (exclude_exprs.size () > 0); |
---|
532 | has_selects = (select_exprs.size () > 0); |
---|
533 | |
---|
534 | CmtSystem::get_dot_suffix (full_name, suffix); |
---|
535 | |
---|
536 | bool wilcarded_suffix = false; |
---|
537 | |
---|
538 | if (suffix == ".*") wilcarded_suffix = true; |
---|
539 | |
---|
540 | int count = 0; |
---|
541 | |
---|
542 | if (full_name.find ('*') != cmt_string::npos) |
---|
543 | { |
---|
544 | CmtSystem::scan_dir (full_name, files); |
---|
545 | |
---|
546 | if (Cmt::get_debug ()) |
---|
547 | { |
---|
548 | cout << "CMT::get_all_files> full_name=" << full_name << |
---|
549 | " pwd=" << CmtSystem::pwd () << endl; |
---|
550 | cout << "CMT::get_all_files> files.size=" << files.size () << endl; |
---|
551 | } |
---|
552 | |
---|
553 | /** |
---|
554 | |
---|
555 | We have to treat patterns of the form *.xxx (ie with a |
---|
556 | suffix) thus we filter out everything that could have been |
---|
557 | collected with a different suffix because the |
---|
558 | CmtSystem::scan_dir function only handles patterns of the |
---|
559 | form xxx* (ie with trailing *) |
---|
560 | |
---|
561 | [If the original suffix was empty (ie files specified using |
---|
562 | xx*) this means getting files without any dot-suffix. This |
---|
563 | may be incorrect??] |
---|
564 | |
---|
565 | */ |
---|
566 | |
---|
567 | for (int j = 0; j < files.size (); j++) |
---|
568 | { |
---|
569 | cmt_string& n = files[j]; |
---|
570 | |
---|
571 | bool rejected = false; |
---|
572 | |
---|
573 | if (n == "") |
---|
574 | { |
---|
575 | rejected = true; |
---|
576 | } |
---|
577 | |
---|
578 | if (!rejected && has_selects) |
---|
579 | { |
---|
580 | rejected = true; |
---|
581 | |
---|
582 | for (int k = 0; k < select_exprs.size (); k++) |
---|
583 | { |
---|
584 | const cmt_regexp& exp = select_exprs[k]; |
---|
585 | if (exp.match (n)) |
---|
586 | { |
---|
587 | rejected = false; |
---|
588 | break; |
---|
589 | } |
---|
590 | } |
---|
591 | } |
---|
592 | |
---|
593 | if (!rejected && has_excludes) |
---|
594 | { |
---|
595 | for (int k = 0; k < exclude_exprs.size (); k++) |
---|
596 | { |
---|
597 | const cmt_regexp& exp = exclude_exprs[k]; |
---|
598 | if (exp.match (n)) |
---|
599 | { |
---|
600 | rejected = true; |
---|
601 | break; |
---|
602 | } |
---|
603 | } |
---|
604 | } |
---|
605 | |
---|
606 | if (!rejected) |
---|
607 | { |
---|
608 | static cmt_string s; |
---|
609 | |
---|
610 | CmtSystem::get_dot_suffix (n, s); |
---|
611 | if (!wilcarded_suffix && (s != suffix)) |
---|
612 | { |
---|
613 | rejected = true; |
---|
614 | } |
---|
615 | else |
---|
616 | { |
---|
617 | count++; |
---|
618 | } |
---|
619 | } |
---|
620 | |
---|
621 | if (Cmt::get_debug ()) |
---|
622 | { |
---|
623 | if (rejected) |
---|
624 | { |
---|
625 | cout << "CMT::get_all_files> reject " << n << endl; |
---|
626 | } |
---|
627 | else |
---|
628 | { |
---|
629 | cout << "CMT::get_all_files> keep " << n << endl; |
---|
630 | } |
---|
631 | } |
---|
632 | |
---|
633 | if (rejected) |
---|
634 | { |
---|
635 | n = ""; |
---|
636 | } |
---|
637 | } |
---|
638 | } |
---|
639 | else |
---|
640 | { |
---|
641 | if (full_name != "") |
---|
642 | { |
---|
643 | bool rejected = false; |
---|
644 | |
---|
645 | if (has_excludes) |
---|
646 | { |
---|
647 | for (int k = 0; k < exclude_exprs.size (); k++) |
---|
648 | { |
---|
649 | const cmt_regexp& exp = exclude_exprs[k]; |
---|
650 | if (exp.match (full_name)) |
---|
651 | { |
---|
652 | rejected = true; |
---|
653 | break; |
---|
654 | } |
---|
655 | } |
---|
656 | } |
---|
657 | |
---|
658 | if (!rejected) |
---|
659 | { |
---|
660 | cmt_string& n = files.add (); |
---|
661 | |
---|
662 | n = full_name; |
---|
663 | |
---|
664 | count++; |
---|
665 | } |
---|
666 | } |
---|
667 | } |
---|
668 | |
---|
669 | return (count); |
---|
670 | } |
---|
671 | |
---|
672 | //-------------------------------------------------- |
---|
673 | void CmtGenerator::set_full_name (cmt_string& full_name, cmt_string& file) |
---|
674 | { |
---|
675 | full_name = ""; |
---|
676 | |
---|
677 | Symbol::expand (file); |
---|
678 | |
---|
679 | if (file == "") return; |
---|
680 | |
---|
681 | if (!CmtSystem::absolute_path (file)) |
---|
682 | { |
---|
683 | full_name = srcdir; |
---|
684 | if (full_name != "") full_name += CmtSystem::file_separator (); |
---|
685 | } |
---|
686 | |
---|
687 | full_name += file; |
---|
688 | |
---|
689 | CmtSystem::reduce_file_separators (full_name); |
---|
690 | } |
---|
691 | |
---|
692 | //------------------------------------------------------------------------ |
---|
693 | static ApplicationGenerator ApplicationContext; |
---|
694 | static LibraryGenerator LibraryContext; |
---|
695 | static DocumentGenerator DocumentContext; |
---|
696 | static ReadmeGenerator ReadmeContext; |
---|
697 | static PrototypeGenerator PrototypeContext; |
---|
698 | static DefaultMakefileGenerator DefaultMakefileContext; |
---|
699 | static MSDEVGenerator MSDEVContext; |
---|
700 | static VSNETGenerator VSNETContext; |
---|
701 | static MakeSetupGenerator MakeSetupContext; |
---|
702 | static ConstituentsMakefileGenerator ConstituentsMakefileContext; |
---|
703 | static DependencyGenerator DependencyContext; |
---|
704 | |
---|
705 | //-------------------------------------------------- |
---|
706 | int Generator::build_msdev_workspace (const Constituent::ConstituentVector& constituents) |
---|
707 | { |
---|
708 | return (MSDEVContext.build_workspace (constituents)); |
---|
709 | } |
---|
710 | |
---|
711 | //-------------------------------------------------- |
---|
712 | int Generator::build_msdev (const Constituent& constituent) |
---|
713 | { |
---|
714 | return (MSDEVContext.build_project (constituent)); |
---|
715 | } |
---|
716 | |
---|
717 | //-------------------------------------------------- |
---|
718 | int Generator::build_vsnet_workspace (const Constituent::ConstituentVector& constituents) |
---|
719 | { |
---|
720 | return (VSNETContext.build_workspace (constituents)); |
---|
721 | } |
---|
722 | |
---|
723 | //-------------------------------------------------- |
---|
724 | int Generator::build_vsnet (const Constituent& constituent) |
---|
725 | { |
---|
726 | return (VSNETContext.build_project (constituent)); |
---|
727 | } |
---|
728 | |
---|
729 | //-------------------------------------------------- |
---|
730 | void Generator::build_make_setup (const cmt_string& package) |
---|
731 | { |
---|
732 | MakeSetupContext.build (package); |
---|
733 | } |
---|
734 | |
---|
735 | //-------------------------------------------------- |
---|
736 | void Generator::build_constituents_makefile (const cmt_string& package, |
---|
737 | const CmtSystem::cmt_string_vector& arguments) |
---|
738 | { |
---|
739 | ConstituentsMakefileContext.build (package, arguments); |
---|
740 | } |
---|
741 | |
---|
742 | //-------------------------------------------------- |
---|
743 | int Generator::build_constituent_makefile (const Constituent& constituent, |
---|
744 | const cmt_string& file) |
---|
745 | { |
---|
746 | const cmt_string& package = Cmt::get_current_package (); |
---|
747 | |
---|
748 | switch (constituent.type) |
---|
749 | { |
---|
750 | case Application: |
---|
751 | ApplicationContext.build (package, constituent, file); |
---|
752 | break; |
---|
753 | case Library: |
---|
754 | LibraryContext.build (package, constituent, file); |
---|
755 | break; |
---|
756 | case Document: |
---|
757 | DocumentContext.build (package, constituent, file); |
---|
758 | break; |
---|
759 | } |
---|
760 | |
---|
761 | return (0); |
---|
762 | } |
---|
763 | |
---|
764 | //-------------------------------------------------- |
---|
765 | void Generator::build_constituent_makefile (const CmtSystem::cmt_string_vector& arguments) |
---|
766 | { |
---|
767 | cmt_string name; |
---|
768 | cmt_string file; |
---|
769 | |
---|
770 | if (arguments.size () == 1) |
---|
771 | { |
---|
772 | file = ""; |
---|
773 | name = arguments[0]; |
---|
774 | } |
---|
775 | else if (arguments.size () == 2) // arguments[0].substr (0, 5) == "-out=" |
---|
776 | { |
---|
777 | cmt_string arg = arguments[0]; |
---|
778 | arg.erase (0, 5); |
---|
779 | file = arg; |
---|
780 | name = arguments[1]; |
---|
781 | } |
---|
782 | else |
---|
783 | { |
---|
784 | CmtMessage::error ("build constituent_makefile : wrong arguments"); |
---|
785 | // cerr << "#CMT> build constituent_makefile : wrong arguments" << endl; |
---|
786 | return; |
---|
787 | } |
---|
788 | |
---|
789 | const Constituent* constituent = Constituent::find (name); |
---|
790 | if (constituent != 0) build_constituent_makefile (*constituent, file); |
---|
791 | } |
---|
792 | |
---|
793 | //-------------------------------------------------- |
---|
794 | void Generator::build_default_makefile () |
---|
795 | { |
---|
796 | DefaultMakefileContext.build (); |
---|
797 | } |
---|
798 | |
---|
799 | //-------------------------------------------------- |
---|
800 | void Generator::build_dependencies (const CmtSystem::cmt_string_vector& arguments) |
---|
801 | { |
---|
802 | DependencyContext.build (arguments); |
---|
803 | } |
---|
804 | |
---|
805 | //-------------------------------------------------- |
---|
806 | void Generator::build_prototype (const cmt_string& file_name) |
---|
807 | { |
---|
808 | PrototypeContext.build (file_name); |
---|
809 | } |
---|
810 | |
---|
811 | //-------------------------------------------------- |
---|
812 | void Generator::build_readme (const CmtSystem::cmt_string_vector& arguments) |
---|
813 | { |
---|
814 | ReadmeContext.build (arguments); |
---|
815 | } |
---|
816 | |
---|
817 | class WinDefAwk : public PAwk |
---|
818 | { |
---|
819 | public : |
---|
820 | WinDefAwk (const cmt_string& library_name) |
---|
821 | { |
---|
822 | m_name = library_name; |
---|
823 | } |
---|
824 | |
---|
825 | void begin () |
---|
826 | { |
---|
827 | cout << "LIBRARY " << m_name << endl; |
---|
828 | cout << "EXPORTS" << endl; |
---|
829 | } |
---|
830 | |
---|
831 | void filter (const cmt_string& line) |
---|
832 | { |
---|
833 | if (line.find ("External") == cmt_string::npos) return; |
---|
834 | if (line.find ("??_") != cmt_string::npos) |
---|
835 | { |
---|
836 | if (line.find ("operator/=") == cmt_string::npos) return; |
---|
837 | // Keep operator /= . |
---|
838 | } |
---|
839 | |
---|
840 | CmtSystem::cmt_string_vector words; |
---|
841 | CmtSystem::split (line, " \t", words); |
---|
842 | if (words.size () >= 7) |
---|
843 | { |
---|
844 | int pos = 7; |
---|
845 | |
---|
846 | cmt_string& fifth_word = words[4]; |
---|
847 | if (fifth_word == "()") pos = 7; |
---|
848 | else if (fifth_word == "External") pos = 6; |
---|
849 | else return; |
---|
850 | |
---|
851 | cmt_string& symbol = words[pos]; |
---|
852 | if (symbol[0] == '_') symbol.erase (0, 1); |
---|
853 | symbol.replace_all ("\r", ""); |
---|
854 | symbol.replace_all ("\n", ""); |
---|
855 | |
---|
856 | if ((pos == 6) && |
---|
857 | ((line.find(": static") != cmt_string::npos) || |
---|
858 | (line.find("(class") != cmt_string::npos)) ) |
---|
859 | { |
---|
860 | // static data members are not DATA : |
---|
861 | // extern objects are not DATA : |
---|
862 | cout << " " << symbol << " " << endl; |
---|
863 | } |
---|
864 | else if (pos == 6) |
---|
865 | { |
---|
866 | // DATA : |
---|
867 | cout << " " << symbol << "\tDATA" << endl; |
---|
868 | } |
---|
869 | else |
---|
870 | { |
---|
871 | // code : |
---|
872 | cout << " " << symbol << " " << endl; |
---|
873 | } |
---|
874 | } |
---|
875 | } |
---|
876 | |
---|
877 | void end () |
---|
878 | { |
---|
879 | } |
---|
880 | |
---|
881 | private: |
---|
882 | cmt_string m_name; |
---|
883 | }; |
---|
884 | |
---|
885 | //-------------------------------------------------- |
---|
886 | //void Generator::build_windefs (const cmt_string& library_name) |
---|
887 | void Generator::build_windefs (const CmtSystem::cmt_string_vector& arguments) |
---|
888 | { |
---|
889 | cmt_string name; |
---|
890 | // CmtSystem::cmt_string_vector files; |
---|
891 | cmt_string files; |
---|
892 | |
---|
893 | for (int i = 0; i < arguments.size (); i++) |
---|
894 | { |
---|
895 | const cmt_string& w = arguments[i]; |
---|
896 | if (w.substr (0, 6) == "-name=" || w.substr (0, 6) == "-name:" || |
---|
897 | w.substr (0, 6) == "/name:" || w.substr (0, 6) == "/name=") |
---|
898 | w.substr (6, name); |
---|
899 | else if (w.substr (0, 1) == "@" && w.size () > 1) |
---|
900 | { |
---|
901 | cmt_string commandfile; |
---|
902 | w.substr (1, commandfile); |
---|
903 | if (!CmtSystem::test_file (commandfile)) |
---|
904 | { |
---|
905 | CmtMessage::warning ("No such file `" + commandfile + "'."); |
---|
906 | continue; |
---|
907 | } |
---|
908 | cmt_string text; |
---|
909 | if (!text.read (commandfile)) |
---|
910 | { |
---|
911 | CmtMessage::warning ("Could not read `" + commandfile + "'."); |
---|
912 | continue; |
---|
913 | } |
---|
914 | text.replace_all ("\r", " "); |
---|
915 | text.replace_all ("\n", " "); |
---|
916 | files += " " + text; |
---|
917 | /* |
---|
918 | CmtSystem::cmt_string_vector words; |
---|
919 | CmtSystem::split (text, " \t", words); |
---|
920 | for (int i = 0; i < words.size (); i++) |
---|
921 | { |
---|
922 | files.push_back (words[i]); |
---|
923 | } |
---|
924 | */ |
---|
925 | } |
---|
926 | else |
---|
927 | files += " " + w; |
---|
928 | // files.push_back (w); |
---|
929 | } |
---|
930 | |
---|
931 | if (files.size () == 0) |
---|
932 | { |
---|
933 | CmtMessage::error ("build_windefs: no files specified"); |
---|
934 | return; |
---|
935 | } |
---|
936 | if (name == "") |
---|
937 | { |
---|
938 | CmtSystem::cmt_string_vector words; |
---|
939 | CmtSystem::split (files, " \t", words); |
---|
940 | if (words.size () == 0) |
---|
941 | { |
---|
942 | CmtMessage::error ("build_windefs: no files specified"); |
---|
943 | return; |
---|
944 | } |
---|
945 | cmt_string suffix; |
---|
946 | CmtSystem::get_dot_suffix (words[0], suffix); |
---|
947 | CmtSystem::basename (words[0], suffix, name); |
---|
948 | } |
---|
949 | if (name == "") |
---|
950 | { |
---|
951 | CmtMessage::error ("build_windefs: cannot determine library name"); |
---|
952 | return; |
---|
953 | } |
---|
954 | |
---|
955 | // cmt_string bin; |
---|
956 | |
---|
957 | // CmtSystem::dirname (library_name, bin); |
---|
958 | // CmtSystem::get_dot_suffix (library_name, suffix); |
---|
959 | // CmtSystem::basename (library_name, suffix, name); |
---|
960 | |
---|
961 | // if (!CmtSystem::cd (bin)) return; |
---|
962 | |
---|
963 | // cmt_string command; |
---|
964 | |
---|
965 | cmt_string command ("dumpbin /symbols"); |
---|
966 | // command += library_name; |
---|
967 | /* |
---|
968 | for (int i = 0; i < files.size (); i++) |
---|
969 | { |
---|
970 | command += " " + files[i]; |
---|
971 | } |
---|
972 | */ |
---|
973 | command += " " + files; |
---|
974 | |
---|
975 | WinDefAwk filter (name); |
---|
976 | |
---|
977 | filter.run (command, "SECT"); |
---|
978 | } |
---|
979 | |
---|
980 | //-------------------------------------------------- |
---|
981 | void Packager::begin () |
---|
982 | { |
---|
983 | m_package_name = ""; |
---|
984 | } |
---|
985 | |
---|
986 | void Packager::filter (const cmt_string& line) |
---|
987 | { |
---|
988 | CmtSystem::cmt_string_vector words; |
---|
989 | |
---|
990 | CmtSystem::split (line, " ", words); |
---|
991 | if (words.size () > 1) |
---|
992 | { |
---|
993 | cmt_string& w = words[0]; |
---|
994 | |
---|
995 | if (w == "package") |
---|
996 | { |
---|
997 | m_package_name = words[1]; |
---|
998 | |
---|
999 | int pos = m_package_name.find (";"); |
---|
1000 | if (pos != cmt_string::npos) m_package_name.erase (pos); |
---|
1001 | m_package_name.replace_all (".", CmtSystem::file_separator ()); |
---|
1002 | } |
---|
1003 | } |
---|
1004 | } |
---|
1005 | |
---|
1006 | cmt_string& Packager::package_name () |
---|
1007 | { |
---|
1008 | return (m_package_name); |
---|
1009 | } |
---|
1010 | |
---|