source: CMT/v1r23/source/cmt_generators.cxx @ 693

Last change on this file since 693 was 561, checked in by rybkin, 13 years ago

See C.L. 444

  • Property svn:eol-style set to native
File size: 82.8 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 "cmt_generators.h"
8#include "cmt_awk.h"
9#include "cmt_use.h"
10#include "cmt_symbol.h"
11#include "cmt_log.h"
12#include "cmt_error.h"
13#include <assert.h>
14
15//--------------------------------------------------
16AnyDocumentGenerator::AnyDocumentGenerator ()
17{
18  m_TITLE.set ("TITLE");
19  m_STRUCTURED_OUTPUT.set ("STRUCTURED_OUTPUT");
20
21  make_header_fragment.set ("make_header");
22  cleanup_header_fragment.set ("cleanup_header");
23  cleanup_fragment.set ("cleanup");
24  dependencies_fragment.set ("dependencies");
25  dependencies_and_triggers_fragment.set ("dependencies_and_triggers");
26}
27
28void AnyDocumentGenerator::reset ()
29{
30  CmtGenerator::reset ();
31  m_TITLE = "";
32
33  make_header_fragment.reset ();
34  cleanup_header_fragment.reset ();
35  cleanup_fragment.reset ();
36  dependencies_fragment.reset ();
37  dependencies_and_triggers_fragment.reset ();
38}
39
40//--------------------------------------------------
41LibraryGenerator::LibraryGenerator ()
42{
43  library_header_fragment.set ("library_header");
44  application_header_fragment.set ("application_header");
45  java_header_fragment.set ("java_header");
46  jar_header_fragment.set ("jar_header");
47  protos_header_fragment.set ("protos_header");
48  library_fragment.set ("library");
49  library_no_share_fragment.set ("library_no_share");
50  library_no_static_fragment.set ("library_no_static");
51  application_fragment.set ("application");
52  jar_fragment.set ("jar");
53  java_fragment.set ("java");
54  java_copy_fragment.set ("java_copy");
55  cleanup_library_fragment.set ("cleanup_library");
56  cleanup_application_fragment.set ("cleanup_application");
57  cleanup_java_fragment.set ("cleanup_java");
58  cleanup_objects_fragment.set ("cleanup_objects");
59  buildproto_fragment.set ("buildproto");
60  check_application_fragment.set ("check_application");
61  check_java_fragment.set ("check_java");
62}
63
64//--------------------------------------------------
65void LibraryGenerator::reset ()
66{
67  AnyDocumentGenerator::reset ();
68  library_header_fragment.reset ();
69  application_header_fragment.reset ();
70  java_header_fragment.reset ();
71  jar_header_fragment.reset ();
72  protos_header_fragment.reset ();
73  library_fragment.reset ();
74  library_no_share_fragment.reset ();
75  library_no_static_fragment.reset ();
76  jar_fragment.reset ();
77  application_fragment.reset ();
78  java_fragment.reset ();
79  java_copy_fragment.reset ();
80  cleanup_library_fragment.reset ();
81  cleanup_application_fragment.reset ();
82  cleanup_java_fragment.reset ();
83  cleanup_objects_fragment.reset ();
84  buildproto_fragment.reset ();
85  check_application_fragment.reset ();
86  check_java_fragment.reset ();
87}
88
89//--------------------------------------------------
90bool LibraryGenerator::analyze_file (const Constituent& constituent,
91                                     const cmt_string& file)
92{
93  static cmt_string suffix;
94  static cmt_string name;
95  static cmt_string obj;
96
97  bool file_not_found = false;
98  bool can_build = true;
99
100  obj = file;
101
102  if (Cmt::get_debug ())
103    {
104      cout << "CmtGenerator::analyze_file> constituent=" << 
105        constituent.name <<
106        " file=" << file << endl;
107    }
108
109  if (!CmtSystem::test_file (file) && !CmtSystem::test_directory (file))
110    {
111      file_not_found = true;
112      CmtMessage::warning ("Source file " + file + " not found");
113      //      cerr << "#CMT> Warning: Source file " << file << " not found" << endl;
114    }
115
116  CmtSystem::get_suffix (file, suffix);
117  CmtSystem::basename (file, suffix, name);
118
119  Language& language = Language::find_with_suffix (suffix);
120
121  if (m_LINKMACRO == "")
122    {
123      m_LINKMACRO = language.linker;
124    }
125
126  if (language == "java")
127    {
128      static Packager packager;
129     
130      obj  = "$(javabin)";
131      obj +=  m_CONSTITUENT;
132      obj +=  CmtSystem::file_separator ();
133
134      cmt_regexp exp ("^package[ \t][ \t]*[a-zA-Z0-9_.][a-zA-Z0-9_.][ \t]*;");
135     
136      packager.run (file, exp);
137      if (packager.package_name () != "")
138        {
139          obj += packager.package_name ();
140          obj += CmtSystem::file_separator ();
141        }
142     
143      obj += name;
144      obj += ".class";
145    }
146  else if (language != Language::null ())
147    {
148      obj  = "$(bin)";     
149
150      if (CmtSystem::getenv("STRUCTURED_OUTPUT")!="" || Cmt::build_nmake ())
151        {
152          obj +=  m_CONSTITUENT;
153          obj +=  CmtSystem::file_separator ();
154        }
155
156      obj += name;
157      obj += language.output_suffix;
158      obj += constituent.suffix;
159      if (Cmt::build_nmake ()) obj += ".obj";
160      else obj += ".o";
161 
162      for (int i = 0; i < language.extra_output_suffixes.size (); i++)
163        {
164          cmt_string& extra_suffix = language.extra_output_suffixes[i];
165
166          obj += " $(bin)";
167          obj += name;
168          obj += extra_suffix;
169          obj += language.output_suffix;
170          obj += constituent.suffix;
171          if (Cmt::build_nmake ()) obj += ".obj";
172          else obj += ".o";
173        }
174    }
175  else
176    {
177      if (m_LINKMACRO == "java")
178        {
179          obj  = "$(javabin)";
180          obj +=  m_CONSTITUENT;
181          obj +=  CmtSystem::file_separator ();
182          obj += file;
183         
184          obj.replace ("../src/", "");
185          obj.replace ("..\\src\\", "");
186        }
187      else if (file_not_found)
188        {
189          can_build = false;
190          obj  = "";
191          CmtMessage::warning ("Source file " + name + " cannot be rebuilt");
192          //      cerr << "#CMT> Warning: Source file " << name << " cannot be rebuilt" << endl;
193        }
194      else
195        {
196          obj  = "";
197        }
198    }
199
200  if (Cmt::get_debug ())
201    {
202      cout << "CmtGenerator::analyze_file> constituent=" << 
203        constituent.name <<
204        " obj=" << obj << endl;
205    }
206
207  if (can_build)
208    {
209      SourceFile& source = m_source_files.add ();
210      source.set (file, language, obj);
211      return (true);
212    }
213  else
214    {
215      return (false);
216    }
217}
218
219//--------------------------------------------------
220void LibraryGenerator::java_file_action (SourceFile& file, const Constituent& constituent)
221{
222  static cmt_string suffix;
223
224  m_FULLNAME = file.name ();
225  m_OUTPUTNAME = file.output ();
226
227  CmtSystem::get_dot_suffix (m_FULLNAME, suffix);
228 
229  CmtSystem::basename (m_FULLNAME, suffix, m_NAME.value);
230  CmtSystem::basename (m_FULLNAME, m_FILENAME.value);
231 
232  //  if (CmtSystem::test_file (m_FULLNAME))
233  //    {
234      java_fragment.copy (m_output_file, constituent.variables, 5,
235                          &m_NAME,
236                          &m_FULLNAME,
237                          &m_OUTPUTNAME,
238                          &m_CONSTITUENT, 
239                          &m_CONSTITUENTSUFFIX);
240      /*
241    }
242  else
243    {
244      CmtMessage::warning ("file " + m_FULLNAME + " not found");
245      //      cerr << "#CMT> Warning: file " << m_FULLNAME << " not found" << endl;
246    }
247      */
248}
249
250//--------------------------------------------------
251void LibraryGenerator::proto_file_action (const cmt_string& file, const Constituent& constituent)
252{
253  static cmt_string suffix;
254
255  CmtSystem::dirname (file, m_FILEPATH.value);
256  if (m_FILEPATH.value != "") m_FILEPATH.value += CmtSystem::file_separator ();
257
258  filter_path (m_FILEPATH.value);
259
260  CmtSystem::basename (file, m_FILENAME.value);
261  CmtSystem::get_dot_suffix (m_FILENAME, suffix);
262
263  CmtSystem::basename (m_FILENAME, suffix, m_NAME.value);
264
265  buildproto_fragment.copy (m_output_file, constituent.variables, 3, 
266                            &m_NAME, 
267                            &m_FILEPATH, 
268                            &m_FILENAME);
269}
270
271//--------------------------------------------------
272void LibraryGenerator::prepare_proto_file (const cmt_string& file)
273{
274  static cmt_string name;
275  static cmt_string pp;
276
277  CmtSystem::name (file, name);
278
279  if (CmtSystem::test_file (file))
280    {
281      pp  = incdir;
282      pp += name;
283      pp += ".pp";
284
285      if (!CmtSystem::test_file (pp))
286        {
287          //Generator::build_prototype (file);
288        }
289    }
290
291  protos += " ";
292  protos += inc;
293  protos += name;
294  protos += ".ph";
295
296  protonames += " ";
297  protonames += name;
298  protonames += ".ph";
299
300  m_PROTOSTAMPS += " ";
301  m_PROTOSTAMPS += inc;
302  m_PROTOSTAMPS += name;
303  m_PROTOSTAMPS += ".pp";
304}
305
306//--------------------------------------------------
307void LibraryGenerator::module_file_action (SourceFile& file, const Constituent& constituent)
308{
309  cmt_string name = file.name ();
310  Language& language = file.language ();
311
312  static cmt_string suffix;
313  static cmt_string prefix;
314  static cmt_string preproc;
315
316  m_FULLNAME = name;
317
318  CmtSystem::get_dot_suffix (name, suffix);
319
320  CmtSystem::basename (name, suffix, m_NAME.value);
321
322  CmtSystem::dirname (name, prefix);
323  CmtSystem::basename (name, m_FILENAME.value);
324
325  FragmentHandle* fragment;
326
327  if (language != Language::null ())
328    {
329      preproc = language.preprocessor_command;
330      fragment = (is_library) ? &(language.library) : &(language.application);
331      m_DEPENDENCIESOPTS = language.dependencies_options ();
332    }
333  else
334    {
335      //
336      // What happens when the language is not known???
337      //
338      //
339      preproc = "-I";
340      fragment = 0;
341    }
342
343  if ((prefix == "../src") || (prefix == "..\\src"))
344    {
345      m_ADDINCLUDE = "";
346    }
347  else if (prefix != "")
348    {
349      m_ADDINCLUDE  = preproc;
350      m_ADDINCLUDE += prefix;
351    }
352
353  m_FILEPATH = prefix;
354  if (m_FILEPATH.value != "") m_FILEPATH.value += CmtSystem::file_separator ();
355  filter_path (m_FILEPATH.value);
356
357  /*
358  m_LINE = m_FULLNAME.value;
359  m_LINE += " ";
360  */
361
362  filter_path (m_FULLNAME.value);
363
364  CmtSystem::get_suffix (name, m_FILESUFFIX.value);
365
366  if (fragment != 0)
367    {
368      //      fragment->copy (m_output_file, constituent.variables, 10,
369      fragment->copy (m_output_file, constituent.variables, 11,
370                      &m_CONSTITUENT, 
371                      &m_CONSTITUENTSUFFIX, 
372                      &m_FILENAME, 
373                      &m_NAME, 
374                      &m_LINE,
375                      &m_ADDINCLUDE, 
376                      &m_FULLNAME, 
377                      &m_FILEPATH, 
378                      &m_FILESUFFIX, 
379                      &m_PACKAGE,
380                      &m_DEPENDENCIESOPTS);
381    }
382  else if (file.output () != "")
383    {
384      m_OUTPUTNAME = file.output ();
385      CmtSystem::dirname (m_OUTPUTNAME.value, m_FILEPATH.value);
386
387      java_copy_fragment.copy (m_output_file, constituent.variables, 11,
388                               &m_CONSTITUENT, 
389                               &m_CONSTITUENTSUFFIX, 
390                               &m_FILENAME, 
391                               &m_NAME, 
392                               &m_LINE,
393                               &m_ADDINCLUDE, 
394                               &m_FULLNAME, 
395                               &m_FILEPATH, 
396                               &m_FILESUFFIX, 
397                               &m_PACKAGE, 
398                               &m_OUTPUTNAME);
399    }
400
401  if (m_PACKOS9)
402    {
403      //      os9sources += m_LINE;
404      os9sources += m_FULLNAME.value;
405      os9sources += " ";
406    }
407}
408
409//--------------------------------------------------
410void LibraryGenerator::build (const cmt_string& package,
411                              const Constituent& constituent,
412                              const cmt_string& file_name)
413{
414  static cmt_string lib;
415  static cmt_string allsources;
416  static cmt_string file;
417  static cmt_string full_name;
418  static cmt_string compressed_name;
419  static cmt_string suffix;
420  int i;
421  bool need_prototypes;
422
423  reset ();
424
425  if (!prepare_output (package, constituent, file_name)) return;
426
427  switch (constituent.type)
428    {
429    case Application:
430      is_library = false;
431      is_application = true;
432      m_TITLE = "Application";
433      break;
434    case Library:
435      is_library = true;
436      is_application = false;
437      m_TITLE = "Library";
438      break;
439    }
440
441  m_source_files.clear ();
442
443  need_prototypes = constituent.need_prototypes;
444
445  //  cout << m_TITLE << " " << m_CONSTITUENT << endl;
446  CmtMessage::info (m_TITLE + " " + m_CONSTITUENT);
447
448  lib  = "$(";
449  lib += m_CONSTITUENT;
450  lib += "lib)";
451
452  //
453  // Prepare the include paths
454  //
455
456  const CmtSystem::cmt_string_vector& includes = constituent.includes;
457
458  for (i = 0; i < includes.size (); i++)
459    {
460      const cmt_string& subdir = includes[i];
461
462      m_PACKINCLUDES += " -I";
463      m_PACKINCLUDES += subdir;
464    }
465
466  //
467  // Scan the sources.
468  //
469
470  const CmtSystem::cmt_string_vector& sources = constituent.modules;
471  const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs;
472  const cmt_vector<cmt_regexp>& selects = constituent.select_exprs;
473
474  //  m_LINE = "";
475
476  for (i = 0; i < sources.size (); i++)
477    {
478      file = sources[i];
479
480      set_full_name (full_name, file);
481      if (full_name == "") continue;
482
483      CmtSystem::compress_path (full_name, compressed_name);
484      full_name = compressed_name;
485
486      static CmtSystem::cmt_string_vector files;
487
488      int count = get_all_files (full_name, excludes, selects, files);
489
490      filter_path (full_name);
491
492      for (int j = 0; j < files.size (); j++)
493        {
494          const cmt_string& name = files[j];
495
496          if (name != "") 
497            {
498              if (!analyze_file (constituent, name)) 
499                {
500                  count = 0;
501                  break;
502                }
503            }
504        }
505
506      /*
507      if (count > 0)
508        {
509          m_LINE += full_name;
510          m_LINE += " ";
511        }
512      */
513    }
514
515  fill_names_outputs ();
516  //fill_outputs ();
517
518  //prepare_use_context ();
519
520  m_DATE = CmtSystem::now ();
521  m_USER = CmtSystem::user ();
522  m_PACKAGE = package;
523
524  if (constituent.has_target_tag)
525    {
526      m_HASTARGETTAG = "has_target_tag";
527    }
528  else
529    {
530      m_HASTARGETTAG = "has_no_target_tag";
531    }
532   
533  m_HASDEPENDENCIES = "has_dependencies";
534
535  m_STRUCTURED_OUTPUT = "STRUCTURED_OUTPUT";
536
537  make_header_fragment.copy (m_output_file, constituent.variables, 9, 
538                             &m_TITLE,
539                             &m_CONSTITUENT,
540                             &m_CONSTITUENTSUFFIX,
541                             &m_USER,
542                             &m_DATE,
543                             &m_PACKAGE,
544                             &m_HASTARGETTAG,
545                             &m_HASDEPENDENCIES,
546                             &m_STRUCTURED_OUTPUT
547                             );
548
549  if (need_prototypes)
550    {
551      need_prototypes = false;
552
553      for (i = 0; i < m_source_files.size (); i++)
554        {
555          const SourceFile& file = m_source_files[i];
556          Language& language = file.language ();
557          if (language.prototypes)
558            {
559              need_prototypes = true;
560              break;
561            }
562        }
563    }
564
565  //-------------------------------------------
566  //
567  // Specific targets (application, library or java)
568  // Prepare in case prototype files are needed
569  //
570  //-------------------------------------------
571
572  m_PROTOTARGET = "";
573
574  //if ((Cmt::current_build_strategy & PrototypesMask) == Prototypes)
575  if (need_prototypes)
576    {
577      m_PROTOTARGET = m_CONSTITUENT;
578      m_PROTOTARGET += "PROTOS";
579    }
580
581  if (m_LINKMACRO == "java")
582    {
583      if (is_library)
584        {
585          jar_header_fragment.copy (m_output_file, constituent.variables, 3, 
586                                    &m_CONSTITUENT, 
587                                    &m_CONSTITUENTSUFFIX,
588                                    &m_OBJS);
589        }
590      else
591        {
592          java_header_fragment.copy (m_output_file, constituent.variables, 3, 
593                                     &m_CONSTITUENT,
594                                     &m_CONSTITUENTSUFFIX,
595                                     &m_OBJS);
596        }
597    }
598  else
599    {
600      if (is_library)
601        {
602          library_header_fragment.copy (m_output_file, constituent.variables, 3,
603                                        &m_CONSTITUENT,
604                                        &m_CONSTITUENTSUFFIX,
605                                        &m_PROTOTARGET);
606        }
607      else
608        {
609          application_header_fragment.copy (m_output_file, constituent.variables, 3,
610                                            &m_CONSTITUENT, 
611                                            &m_CONSTITUENTSUFFIX, 
612                                            &m_PROTOTARGET);
613        }
614    }
615
616
617  //----------------------------------------------------
618  //
619  // Preparing prototype files.
620  //
621  //----------------------------------------------------
622
623  //if ((Cmt::current_build_strategy & PrototypesMask) == Prototypes)
624  if (need_prototypes)
625    {
626      for (i = 0; i < m_source_files.size (); i++)
627        {
628          const SourceFile& file = m_source_files[i];
629          Language& language = file.language ();
630          if (language.prototypes)
631            {
632              prepare_proto_file (file.name ());
633            }
634        }
635
636      if (m_PROTOSTAMPS != "")
637        {
638          protos_header_fragment.copy (m_output_file, constituent.variables, 3, 
639                                       &m_CONSTITUENT,
640                                       &m_CONSTITUENTSUFFIX,
641                                       &m_PROTOSTAMPS);
642        }
643
644      if (protonames != "")
645        {
646          for (i = 0; i < m_source_files.size (); i++)
647            {
648              const SourceFile& file = m_source_files[i];
649              Language& language = file.language ();
650              if (language.prototypes)
651                {
652                  proto_file_action (file.name (), constituent);
653                }
654            }
655        }
656    }
657
658  //----------------------------------------------------
659  //
660  // Preparing the library.
661  //
662  //----------------------------------------------------
663
664  if (m_OBJS != "")
665    {
666      if (m_LINKMACRO == "java")
667        {
668          if (is_library)
669            {
670              cmt_string classes = m_OBJS.value;
671
672              classes.replace_all ("$(javabin)", "");
673              classes.replace_all (srcdir.c_str (), "");
674
675              m_CLASSES = classes;
676
677              jar_fragment.copy (m_output_file, constituent.variables, 4, 
678                                 &m_CONSTITUENT,
679                                 &m_CONSTITUENTSUFFIX,
680                                 &m_OBJS,
681                                 &m_CLASSES);
682            }
683        }
684      else
685        {
686          if (is_library)
687            {
688              if (constituent.no_share && constituent.no_static)
689                {
690                  CmtMessage::warning (constituent.name + ": No shared or static library");
691                }
692              else if (constituent.no_share)
693                {
694                  library_no_share_fragment.copy (m_output_file, constituent.variables, 3, 
695                                                  &m_CONSTITUENT,
696                                                  &m_CONSTITUENTSUFFIX,
697                                                  &m_OBJS);
698                }
699              else if (constituent.no_static)
700                {
701                  library_no_static_fragment.copy (m_output_file, constituent.variables, 3, 
702                                                  &m_CONSTITUENT,
703                                                  &m_CONSTITUENTSUFFIX,
704                                                  &m_OBJS);
705                }
706              else
707                {
708                  library_fragment.copy (m_output_file, constituent.variables, 3, 
709                                         &m_CONSTITUENT,
710                                         &m_CONSTITUENTSUFFIX,
711                                         &m_OBJS);
712                }
713            }
714          else
715            {
716              application_fragment.copy (m_output_file, constituent.variables, 4,
717                                         &m_CONSTITUENT,
718                                         &m_CONSTITUENTSUFFIX, 
719                                         &m_OBJS,
720                                         &m_LINKMACRO);
721            }
722        }
723    }
724
725  bool need_dependencies = false;
726 
727  for (i = 0; i < m_source_files.size (); i++)
728    {
729      const SourceFile& file = m_source_files[i];
730      Language& language = file.language ();
731      if (language == Language::null () || !language.native_dependencies ())
732        {
733          need_dependencies = true;
734          break;
735        }
736    }
737
738  if (constituent.build_triggers)
739    {
740      dependencies_and_triggers_fragment.copy (m_output_file, 
741                                               constituent.variables, 3,
742                                               &m_CONSTITUENT, 
743                                               &m_CONSTITUENTSUFFIX, 
744                                               &m_LINE);
745    }
746  else
747    {
748      if (need_dependencies)
749        {
750      dependencies_fragment.copy (m_output_file, 
751                                  constituent.variables, 3,
752                                  &m_CONSTITUENT, 
753                                  &m_CONSTITUENTSUFFIX, 
754                                  &m_LINE);
755        }
756    }
757
758  //----------------------------------------------------
759  //
760  // Building actual individual targets.
761  //
762  //----------------------------------------------------
763
764  for (i = 0; i < m_source_files.size (); i++)
765    {
766      SourceFile& file = m_source_files[i];
767      Language& language = file.language ();
768
769      if (language == "java")
770        {
771          java_file_action (file, constituent);
772        }
773      else
774        {
775          module_file_action (file, constituent);
776        }
777    }
778
779  if (m_PACKOS9)
780    {
781      if (os9sources != "")
782        {
783          //
784          // Generate transfers to the OS9 area.
785          //
786
787          m_ALLOS9SOURCES = "";
788          allsources = "";
789        }
790    }
791
792  /*
793    for file in `cmt_sort_line.csh ${os9sources}` ; do
794    if test `echo ${file} | grep '$(src)'` ; then
795    name=`echo ${file} | sed 's#$(src)##'`
796    ALLOS9SOURCES="${ALLOS9SOURCES} ../OS9/${name}"
797    allsources="${allsources} ${file}"
798    elif test `echo ${file} | grep '$(inc)'` ; then
799    name=`echo ${file} | sed 's#$(inc)##'`
800    ALLOS9SOURCES="${ALLOS9SOURCES} ../OS9/${name}"
801    allsources="${allsources} ${file}"
802    fi
803    done
804
805    if test ! "${ALLOS9SOURCES}" = "" ; then
806
807    sed -e "`subs_vars ALLOS9SOURCES`" \
808    ${os9_header_fragment} \
809    >>${output}
810
811    for FULLNAME in ${allsources} ; do
812
813    NAME=`echo ${FULLNAME} | sed -e 's#$(src)##' -e 's#$(inc)##'`
814
815    sed -e "`subs_vars NAME FULLNAME`" \
816    ${os9_fragment} \
817    >>${output}
818
819    done
820    fi
821    fi
822    fi
823  */
824
825  //
826  //  Generate package cleanup operations.
827  //
828
829  cleanup_header_fragment.copy (m_output_file, constituent.variables, 2, 
830                                &m_CONSTITUENT,
831                                &m_CONSTITUENTSUFFIX);
832
833  //if ((Cmt::current_build_strategy & PrototypesMask) == Prototypes)
834  if (need_prototypes)
835    {
836      if (protos != "")
837        {
838          m_FULLNAME = protos;
839          cleanup_fragment.copy (m_output_file, constituent.variables, 1, &m_FULLNAME);
840          m_FULLNAME = m_PROTOSTAMPS;
841          cleanup_fragment.copy (m_output_file, constituent.variables, 1, &m_FULLNAME);
842        }
843    }
844
845  if (m_LINKMACRO == "java")
846    {
847      cleanup_java_fragment.copy (m_output_file, constituent.variables, 1, &m_OBJS);
848
849      if (!is_library)
850        {
851          if (constituent.need_check)
852            {
853              check_java_fragment.copy (m_output_file, constituent.variables, 2, 
854                                        &m_CONSTITUENT,
855                                        &m_CONSTITUENTSUFFIX);
856            }
857        }
858    }
859  else
860    {
861      if (is_library)
862        {
863          cleanup_library_fragment.copy (m_output_file, constituent.variables, 2, 
864                                         &m_CONSTITUENT,
865                                         &m_CONSTITUENTSUFFIX);
866        }
867      else
868        {
869          cleanup_application_fragment.copy (m_output_file, constituent.variables, 2, 
870                                             &m_CONSTITUENT,
871                                             &m_CONSTITUENTSUFFIX);
872          if (m_OBJS != "")
873            {
874              cleanup_objects_fragment.copy (m_output_file, constituent.variables, 3, 
875                                             &m_OBJS,
876                                             &m_CONSTITUENT,
877                                             &m_CONSTITUENTSUFFIX);
878            }
879
880          if (constituent.need_check)
881            {
882              check_application_fragment.copy (m_output_file, constituent.variables, 2, 
883                                               &m_CONSTITUENT,
884                                               &m_CONSTITUENTSUFFIX);
885            }
886        }
887    }
888
889  terminate ();
890}
891
892//--------------------------------------------------
893DocumentGenerator::DocumentGenerator ()
894{
895  document_header_fragment.set ("document_header");
896}
897
898//--------------------------------------------------
899void DocumentGenerator::reset ()
900{
901  AnyDocumentGenerator::reset ();
902  document_header_fragment.reset ();
903}
904
905//--------------------------------------------------
906void DocumentGenerator::build (const cmt_string& package,
907                               const Constituent& constituent,
908                               const cmt_string& file_name)
909{
910  static cmt_string names;
911  static cmt_string output_dir;
912  static cmt_string name;
913  static cmt_string full_name;
914  static cmt_string compressed_name;
915  static cmt_string suffix;
916  static cmt_string output_suffix;
917  static cmt_string fragment_suffix;
918
919  reset ();
920
921  if (!prepare_output (package, constituent, file_name)) return;
922
923  is_library = false;
924  is_application = false;
925  m_GENERATOR = constituent.generator;
926  m_TITLE = "Document";
927
928  int i;
929
930  //  cout << m_TITLE << " " << m_CONSTITUENT << endl;
931  CmtMessage::info (m_TITLE + " " + m_CONSTITUENT);
932
933  //
934  // Prepare the include paths.
935  //
936
937  const CmtSystem::cmt_string_vector& includes = constituent.includes;
938
939  for (i = 0; i < includes.size (); i++)
940    {
941      const cmt_string& subdir = includes[i];
942
943      m_PACKINCLUDES += " -I";
944      m_PACKINCLUDES += subdir;
945    }
946
947  //
948  // Get the fragment associated with the document style
949  //
950
951  FragmentHandle fragment (m_GENERATOR);
952
953  fragment_suffix = fragment.suffix ();
954
955  output_suffix = ".";
956
957  if (fragment_suffix == "")
958    {
959      output_suffix += fragment.name ();
960    }
961  else
962    {
963      output_suffix += fragment_suffix;
964    }
965
966  //
967  // Scan the sources.
968  //
969
970  const CmtSystem::cmt_string_vector& sources = constituent.modules;
971  const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs;
972  const cmt_vector<cmt_regexp>& selects = constituent.select_exprs;
973
974  //  m_LINE = "";
975
976  for (i = 0; i < sources.size (); i++)
977    {
978      cmt_string& file = sources[i];
979
980      set_full_name (full_name, file);
981      if (full_name == "") continue;
982
983      CmtSystem::compress_path (full_name, compressed_name);
984      full_name = compressed_name;
985
986      static CmtSystem::cmt_string_vector files;
987
988      int count = get_all_files (full_name, excludes, selects, files);
989
990      //      filter_path (full_name);
991
992      /*
993      if (count > 0)
994        {
995          m_LINE += full_name;
996          m_LINE += " ";
997        }
998      */
999
1000      for (int j = 0; j < files.size (); j++)
1001        {
1002          const cmt_string& name = files[j];
1003
1004          if (name != "") 
1005            {
1006              analyze_file (name, constituent.name, output_suffix);
1007            }
1008        }
1009    }
1010
1011  fill_names_outputs ();
1012  //  fill_outputs ();
1013
1014  //  prepare_use_context ();
1015
1016  m_DATE = CmtSystem::now ();
1017  m_USER = CmtSystem::user ();
1018  m_PACKAGE = package;
1019
1020  if (constituent.has_target_tag)
1021    {
1022      m_HASTARGETTAG = "has_target_tag";
1023    }
1024  else
1025    {
1026      m_HASTARGETTAG = "has_no_target_tag";
1027    }
1028
1029  m_HASDEPENDENCIES = fragment.need_dependencies () ? "has_dependencies" : "has_no_dependencies" ;
1030
1031  make_header_fragment.copy (m_output_file, constituent.variables, 8,
1032                             &m_TITLE, 
1033                             &m_CONSTITUENT,
1034                             &m_CONSTITUENTSUFFIX,
1035                             &m_USER,
1036                             &m_DATE,
1037                             &m_PACKAGE,
1038                             &m_HASTARGETTAG,
1039                             &m_HASDEPENDENCIES
1040                             );
1041
1042  const cmt_string& header = fragment.header ();
1043
1044  //
1045  // If the document type specifies a header, use it .
1046  // otherwise, use the default document header fragment.
1047  //
1048  if (header != "")
1049    {
1050      FragmentHandle header_fragment (header);
1051      header_fragment.copy (m_output_file, constituent.variables, 3, 
1052                            &m_CONSTITUENT,
1053                            &m_CONSTITUENTSUFFIX,
1054                            &m_OBJS);
1055    }
1056  else
1057    {
1058      document_header_fragment.copy (m_output_file, constituent.variables, 3, 
1059                                     &m_CONSTITUENT,
1060                                     &m_CONSTITUENTSUFFIX,
1061                                     &m_OBJS);
1062    }
1063
1064  if (fragment.need_dependencies ())
1065    {
1066      dependencies_fragment.copy (m_output_file, constituent.variables, 3, 
1067                                  &m_CONSTITUENT,
1068                                  &m_CONSTITUENTSUFFIX,
1069                                  &m_LINE);
1070    }
1071  else
1072    {
1073      /*
1074      for (i = 0; i < sources.size (); i++)
1075        {
1076          cmt_string& file = sources[i];
1077         
1078          set_full_name (full_name, file);
1079          if (full_name == "") continue;
1080         
1081          CmtSystem::compress_path (full_name, compressed_name);
1082          full_name = compressed_name;
1083
1084          static CmtSystem::cmt_string_vector files;
1085         
1086          get_all_files (full_name, excludes, selects, files);
1087         
1088          for (int j = 0; j < files.size (); j++)
1089            {
1090              const cmt_string& name = files[j];
1091      */             
1092      for (i = 0; i < m_source_files.size (); i++)
1093        {
1094          SourceFile& file = m_source_files[i];
1095          const cmt_string& name = file.name ();
1096              if (name != "") 
1097                {
1098                  static cmt_string s;
1099                  static cmt_string n;
1100                 
1101                  CmtSystem::get_dot_suffix (name, s);
1102                  CmtSystem::basename (name, s, n);
1103                  CmtSystem::get_suffix (name, s);
1104                 
1105                  fprintf (m_output_file, "%s_%s_dependencies = %s\n",
1106                           n.c_str (),
1107                           s.c_str (),
1108                           name.c_str ());
1109                }
1110              //            }
1111        }
1112    }
1113 
1114  m_SUFFIX = fragment_suffix;
1115  for (i = 0; i < m_source_files.size (); i++)
1116    {
1117      SourceFile& file = m_source_files[i];
1118      const cmt_string& file_name = file.name ();
1119      m_FULLNAME = file_name;
1120      CmtSystem::get_dot_suffix (file_name, suffix);
1121      CmtSystem::basename (file_name, suffix, m_NAME.value);
1122      CmtSystem::dirname (file_name, m_FILEPATH.value);
1123      if (m_FILEPATH.value != "") m_FILEPATH.value += CmtSystem::file_separator ();
1124      filter_path (m_FILEPATH.value);
1125      CmtSystem::basename (file_name, m_FILENAME.value);
1126      CmtSystem::get_dot_suffix (m_FILENAME.value, m_FILESUFFIX.value);
1127      /*
1128      if (!CmtSystem::test_file (file_name) && !CmtSystem::test_directory (file_name))
1129        {
1130          CmtMessage::warning ("Source file " + file_name + " not found");
1131        }
1132      */
1133      filter_path (m_FULLNAME.value);
1134
1135      fragment.copy (m_output_file, constituent.variables, 8,
1136                     &m_FILEPATH,
1137                     &m_SUFFIX,
1138                     &m_CONSTITUENT,
1139                     &m_CONSTITUENTSUFFIX,
1140                     &m_FILENAME,
1141                     &m_NAME,
1142                     &m_FULLNAME,
1143                     &m_FILESUFFIX);
1144    }
1145
1146  const cmt_string& trailer = fragment.trailer ();
1147  if (trailer != "")
1148    {
1149      FragmentHandle trailer_fragment (trailer);
1150      trailer_fragment.copy (m_output_file, constituent.variables, 3, 
1151                             &m_CONSTITUENT,
1152                             &m_CONSTITUENTSUFFIX,
1153                             &m_OBJS);
1154    }
1155
1156  //
1157  //  Generate package cleanup operations.
1158  //
1159
1160  cleanup_header_fragment.copy (m_output_file, constituent.variables, 2, 
1161                                &m_CONSTITUENT,
1162                                &m_CONSTITUENTSUFFIX);
1163
1164  terminate ();
1165}
1166
1167//--------------------------------------------------
1168bool DocumentGenerator::analyze_file (const cmt_string& file,
1169                                      const cmt_string& constituent_name,
1170                                      const cmt_string& output_suffix)
1171{
1172  //static cmt_string output_dir;
1173  static cmt_string suffix;
1174  static cmt_string name;
1175  static cmt_string obj;
1176
1177  if (!CmtSystem::test_file (file) && !CmtSystem::test_directory (file))
1178    {
1179      CmtMessage::warning ("Source file " + file + " not found");
1180    }
1181
1182  //CmtSystem::dirname (file, output_dir);
1183  //output_dir += CmtSystem::file_separator ();
1184
1185  //filter_path (output_dir);
1186
1187  CmtSystem::get_suffix (file, suffix);
1188  CmtSystem::basename (file, suffix, name);
1189
1190  //obj = output_dir;
1191  obj = "$(";
1192  obj += constituent_name;
1193  obj += "_output)";
1194  obj += name;
1195  obj += output_suffix;
1196
1197  SourceFile& source = m_source_files.add ();
1198  source.set (file, Language::null (), obj);
1199
1200  return (true);
1201}
1202
1203ReadmeGenerator::ReadmeGenerator ()
1204{
1205  readme_header_fragment.set ("readme_header");
1206  readme_fragment.set ("readme");
1207  readme_doc_fragment.set ("readme_doc");
1208  readme_use_fragment.set ("readme_use");
1209  readme_trailer_fragment.set ("readme_trailer");
1210}
1211
1212void ReadmeGenerator::reset ()
1213{
1214  CmtGenerator::reset ();
1215
1216  readme_header_fragment.reset ();
1217  readme_fragment.reset ();
1218  readme_doc_fragment.reset ();
1219  readme_use_fragment.reset ();
1220  readme_trailer_fragment.reset ();
1221}
1222
1223//--------------------------------------------------
1224void ReadmeGenerator::build (const CmtSystem::cmt_string_vector& arguments)
1225{
1226  reset ();
1227
1228  m_PACKAGE = Cmt::get_current_package ();
1229  m_VERSION = Cmt::get_current_version ();
1230  m_DATE = CmtSystem::now ();
1231  m_USER = CmtSystem::user ();
1232
1233  cmt_string url;
1234  cmt_string doc;
1235
1236  for (int i = 0; i < arguments.size (); i++)
1237    {
1238      cmt_string arg = arguments[i];
1239
1240      if (arg.substr (0, 5) == "-url=")
1241        {
1242          arg.substr (5, url);
1243        }
1244      else if (arg.substr (0, 5) == "-doc=")
1245        {
1246          arg.substr (5, doc);
1247        }
1248    }
1249
1250  m_output_file_name = cmtdir + "README.html";
1251
1252  m_output_file = fopen (m_output_file_name.c_str (), "wb");
1253  if (m_output_file != NULL)
1254    {
1255      readme_header_fragment.copy (m_output_file, 2, 
1256                                   &m_PACKAGE, &m_VERSION);
1257
1258      if (doc != "")
1259        {
1260          m_DOCPATH = doc;
1261          readme_doc_fragment.copy (m_output_file, 3,
1262                                    &m_PACKAGE,
1263                                    &m_VERSION,
1264                                    &m_DOCPATH);
1265        }
1266
1267      readme_fragment.copy (m_output_file, 2,
1268                            &m_PACKAGE,
1269                            &m_VERSION);
1270
1271      int number;
1272      const Use::UsePtrVector& uses = Use::get_ordered_uses ();
1273
1274      for (number = 0; number < uses.size (); number++)
1275        {
1276          const Use* use = uses[number];
1277
1278          if (use == 0) continue;
1279          if (use->discarded) continue;
1280
1281          Package* p = use->get_package ();
1282          if (p->is_cmt ()) continue;
1283
1284          cmt_string selected_path;
1285
1286          if (url == "")
1287            {
1288              selected_path = use->real_path;
1289             
1290              if (use->specified_path != "")
1291                {
1292                  int pos = selected_path.find_last_of (use->specified_path);
1293                  if (pos != cmt_string::npos)
1294                    {
1295                      selected_path.erase (pos);
1296                    }
1297                }
1298            }
1299          else
1300            {
1301              selected_path = url;
1302             
1303              if (use->specified_path != "")
1304                {
1305                  selected_path += CmtSystem::file_separator ();
1306                }
1307            }
1308         
1309          m_PACKAGEPATH = selected_path;
1310          m_PACKAGEPREFIX = use->specified_path;
1311          m_PACKAGE = use->get_package_name ();
1312          m_VERSION = use->version;
1313          m_MGRSTYLE = (use->style == mgr_style) ? "mgr" : "cmt";
1314          readme_use_fragment.copy (m_output_file, 5,
1315                                    &m_PACKAGEPATH,
1316                                    &m_PACKAGEPREFIX,
1317                                    &m_PACKAGE,
1318                                    &m_VERSION,
1319                                    &m_MGRSTYLE);
1320        }
1321
1322      m_PACKAGE = Cmt::get_current_package ();
1323      m_VERSION = Cmt::get_current_version ();
1324      readme_trailer_fragment.copy (m_output_file, 4, 
1325                                    &m_PACKAGE, 
1326                                    &m_VERSION, 
1327                                    &m_DATE, 
1328                                    &m_USER);
1329
1330      terminate ();
1331    }
1332  else
1333    {
1334      CmtError::set (CmtError::file_access_error, m_output_file_name);
1335    }
1336}
1337
1338//--------------------------------------------------
1339class Prototyper : public FAwk
1340{
1341public:
1342  Prototyper (bool static_functions = false) :
1343    m_static_functions(static_functions)
1344  {
1345    if (m_static_functions)
1346      {
1347        m_suffix = "_static.phnew";
1348        m_define_suffix = "_static_ph";
1349      }
1350    else
1351      {
1352        m_suffix = ".phnew";
1353        m_define_suffix = "_ph";
1354      }
1355  }
1356
1357  void begin ()
1358  {
1359    m_running = false;
1360
1361    static cmt_string suffix;
1362    static cmt_string name;
1363
1364    CmtSystem::get_dot_suffix (m_file_name, suffix);
1365    CmtSystem::basename (m_file_name, suffix, name);
1366
1367    m_out_file_name  = "";
1368
1369    if (m_dir_name != "")
1370      {
1371        m_out_file_name  = m_dir_name;
1372        m_out_file_name += CmtSystem::file_separator ();
1373      }
1374
1375    m_out_file_name += name;
1376    m_out_file_name += m_suffix;
1377
1378    CmtSystem::basename (m_file_name, suffix, m_file_name);
1379
1380    m_output = fopen (m_out_file_name.c_str (), "wb");
1381
1382    if (m_output != 0)
1383      {
1384        fprintf (m_output, "#ifndef __%s%s__\n", m_file_name.c_str (),
1385                 m_define_suffix.c_str ());
1386        fprintf (m_output, "#define __%s%s__\n", m_file_name.c_str (),
1387                 m_define_suffix.c_str ());
1388
1389        fprintf (m_output, "\n");
1390        fprintf (m_output, "#ifdef __cplusplus\n");
1391        fprintf (m_output, "extern \"C\" {\n");
1392        fprintf (m_output, "#endif\n");
1393        fprintf (m_output, "\n");
1394      }
1395    else
1396      {
1397        stop ();
1398      }
1399  }
1400
1401  void filter (const cmt_string& line)
1402  {
1403    char c = line[0];
1404
1405    if (!m_running)
1406      {
1407        if ((c == ' ') ||
1408            (c == '/') ||
1409            (c == '|') ||
1410            (c == '\t') ||
1411            (c == '#')) return;
1412        if (line.find ('(') == cmt_string::npos)
1413          {
1414            m_prev_line = line;
1415            return;
1416          }
1417
1418        m_running = true;
1419        m_full_line = line;
1420        m_full_line.replace ("(", " (");
1421
1422        static CmtSystem::cmt_string_vector words;
1423
1424        CmtSystem::split (m_full_line, " \t", words);
1425
1426        const cmt_string& second = words[1];
1427        if (second[0] == '(')
1428          {
1429            m_full_line = m_prev_line;
1430            m_full_line += " ";
1431            m_full_line += line;
1432
1433            m_prev_line = "";
1434          }
1435      }
1436    else
1437      {
1438        m_full_line += line;
1439      }
1440    if (line.find (')') == cmt_string::npos) return;
1441    m_running = false;
1442
1443    if (m_full_line.find (';') != cmt_string::npos) return;
1444    if (m_full_line.find ("::") != cmt_string::npos) return;
1445    if (m_full_line.find ('<') != cmt_string::npos) return;
1446    if (m_full_line.find ('>') != cmt_string::npos) return;
1447    if (m_full_line.find ('{') != cmt_string::npos) return;
1448    if (m_full_line.find ('}') != cmt_string::npos) return;
1449    if (m_full_line.find ("typedef") != cmt_string::npos) return;
1450    if (m_full_line.find ("yy") != cmt_string::npos) return;
1451    if (m_full_line.find ("YY") != cmt_string::npos) return;
1452    if (m_static_functions)
1453      {
1454        if (m_full_line.find ("static") == cmt_string::npos) return;
1455      }
1456    else
1457      {
1458        if (m_full_line.find ("static") != cmt_string::npos) return;
1459      }
1460
1461    m_full_line += ";";
1462
1463    if (m_output != 0)
1464      {
1465        fprintf (m_output, "%s\n", m_full_line.c_str ());
1466      }
1467  }
1468
1469  void end ()
1470  {
1471    if (m_output != 0)
1472      {
1473        fprintf (m_output, "\n");
1474        fprintf (m_output, "#ifdef __cplusplus\n");
1475        fprintf (m_output, "}\n");
1476        fprintf (m_output, "#endif\n");
1477        fprintf (m_output, "\n");
1478        fprintf (m_output, "#endif\n");
1479        fprintf (m_output, "\n");
1480
1481        fclose (m_output);
1482      }
1483
1484    CmtGenerator::check (m_out_file_name);
1485  }
1486
1487private:
1488  bool m_running;
1489  cmt_string m_out_file_name;
1490  FILE* m_output;
1491  bool m_static_functions;
1492  cmt_string m_full_line;
1493  cmt_string m_prev_line;
1494  cmt_string m_suffix;
1495  cmt_string m_define_suffix;
1496};
1497//--------------------------------------------------
1498
1499//--------------------------------------------------
1500void PrototypeGenerator::build (const cmt_string& file_name)
1501{
1502  Prototyper prototyper;
1503
1504  reset ();
1505
1506  prototyper.run (file_name);
1507}
1508
1509//--------------------------------------------------
1510void DefaultMakefileGenerator::build ()
1511{
1512  cmt_string makefile;
1513
1514  //reset ();
1515
1516  //--- Build a simple Makefile if none is installed
1517
1518#ifndef WIN32
1519
1520  bool need_makefile = false;
1521
1522  makefile = cmtdir + "Makefile";
1523
1524  if (!CmtSystem::test_file (makefile))
1525    {
1526      need_makefile = true;
1527    }
1528  else
1529    {
1530      static cmt_string s;
1531
1532      s.read (makefile);
1533      if ((s.find ("METHODSROOT") != cmt_string::npos) ||
1534          (s.find ("$(CMTROOT)/src/constituents.make") == cmt_string::npos))
1535        {
1536          static cmt_string backup = makefile;
1537          backup += "_backup";
1538
1539          makefile += ".cmt";
1540
1541          if (!CmtSystem::test_file (makefile))
1542            {
1543              FILE* file = fopen (backup.c_str (), "wb");
1544              if (file != NULL)
1545                {
1546                  CmtMessage::warning ("\n"
1547                                       "# A Makefile already exists "
1548                                       "but it does not provide\n"
1549                                       "# the recommended features "
1550                                       "for a full benefit of CMT\n"
1551                                       "#\n"
1552                                       "# CMT is now building "
1553                                       "a new 'Makefile.cmt' which you can use\n"
1554                                       "# to upgrade your current one.");
1555                  /*
1556                  cerr << "# " << endl;
1557                  cerr << "#CMT> Warning: " << endl;
1558                  cerr << "# A Makefile already exists "
1559                    "but it does not provides " << endl;
1560                  cerr << "# the recommended features "
1561                    "for a full benefit of CMT" << endl;
1562                  cerr << "# " << endl;
1563                  cerr << "# CMT is now building "
1564                    "a new 'Makefile.cmt' which you can use" << endl;
1565                  cerr << "# to upgrade your current one." << endl;
1566                  cerr << "# " << endl;
1567                  */
1568                  s.write (file);
1569                  CmtSystem::close_ostream (file, backup);
1570                  //  fclose (file);
1571
1572                  need_makefile = true;
1573                }
1574              else
1575                {
1576                  CmtError::set (CmtError::file_access_error, backup);
1577                }
1578            }
1579        }
1580    }
1581
1582  if (need_makefile)
1583    {
1584      FILE* file = fopen (makefile.c_str (), "wb");
1585      if (file != NULL)
1586        {
1587          fprintf (file,
1588                   "include $(CMTROOT)/src/Makefile.header\n"
1589                   "\n"
1590                   "include $(CMTROOT)/src/constituents.make\n"
1591                   "\n");
1592          CmtSystem::close_ostream (file, makefile);
1593          //          fclose (file);
1594        }
1595      else
1596        {
1597          CmtError::set (CmtError::file_access_error, makefile);
1598        }
1599    }
1600
1601#endif
1602
1603#ifdef WIN32
1604
1605  makefile = cmtdir + "NMake";
1606
1607  if (Cmt::get_debug ())
1608    {
1609      cout << "DefaultMakefileGenerator::build> pwd=" << CmtSystem::pwd () << " cmtdir=" << cmtdir << endl;
1610    }
1611
1612  if (!CmtSystem::test_file (makefile))
1613    {
1614      FILE* file = fopen (makefile.c_str (), "wb");
1615      if (file != NULL)
1616        {
1617          fprintf (file,
1618                   "!include $(CMTROOT)\\src\\NMakefile.header\n"
1619                   "\n"
1620                   "!include $(CMTROOT)\\src\\constituents.nmake\n"
1621                   "\n");
1622          CmtSystem::close_ostream (file, makefile);
1623          //          fclose (file);
1624        }
1625      else
1626        {
1627          CmtError::set (CmtError::file_access_error, makefile);
1628        }
1629    }
1630
1631#endif
1632
1633}
1634
1635MSDEVGenerator::MSDEVGenerator ()
1636{
1637  dsw_header_fragment.set ("dsw_header");
1638  dsw_project_fragment.set ("dsw_project");
1639  dsw_all_project_header_fragment.set ("dsw_all_project_header");
1640  dsw_all_project_dependency_fragment.set ("dsw_all_project_dependency");
1641  dsw_all_project_trailer_fragment.set ("dsw_all_project_trailer");
1642  dsw_trailer_fragment.set ("dsw_trailer");
1643
1644  dsp_all_fragment.set ("dsp_all");
1645  dsp_library_header_fragment.set ("dsp_library_header");
1646  dsp_application_header_fragment.set ("dsp_application_header");
1647  dsp_windows_header_fragment.set ("dsp_windows_header");
1648  dsp_contents_fragment.set ("dsp_contents");
1649  dsp_trailer_fragment.set ("dsp_trailer");
1650}
1651
1652void MSDEVGenerator::reset ()
1653{
1654  CmtGenerator::reset ();
1655
1656  dsw_header_fragment.reset ();
1657  dsw_project_fragment.reset ();
1658  dsw_all_project_header_fragment.reset ();
1659  dsw_all_project_dependency_fragment.reset ();
1660  dsw_all_project_trailer_fragment.reset ();
1661  dsw_trailer_fragment.reset ();
1662
1663  dsp_all_fragment.reset ();
1664  dsp_library_header_fragment.reset ();
1665  dsp_application_header_fragment.reset ();
1666  dsp_windows_header_fragment.reset ();
1667  dsp_contents_fragment.reset ();
1668  dsp_trailer_fragment.reset ();
1669
1670  CmtSystem::cd (Cmt::get_current_dir ());
1671
1672  cmt_string branch = CmtSystem::current_branch ();
1673
1674  if ((branch == "mgr") || (branch == "cmt"))
1675    {
1676#ifdef WIN32
1677      msdevdir = "..";
1678      msdevdir += CmtSystem::file_separator ();
1679      msdevdir += "Visual";
1680     
1681      if (!CmtSystem::test_directory (msdevdir))
1682        {
1683          CmtSystem::mkdir (msdevdir);
1684        }
1685     
1686      msdevdir += CmtSystem::file_separator ();
1687#endif
1688    }
1689  else
1690    {
1691#ifdef WIN32
1692      msdevdir = ".";
1693      msdevdir += CmtSystem::file_separator ();
1694#endif
1695    }
1696
1697}
1698
1699int MSDEVGenerator::build_workspace (const Constituent::ConstituentVector& constituents)
1700{
1701  reset ();
1702
1703  const cmt_string& package = Cmt::get_current_package ();
1704
1705  m_output_file_name = msdevdir + package + ".dswnew";
1706
1707  m_output_file = fopen (m_output_file_name.c_str (), "wb");
1708  if (m_output_file != NULL)
1709    {
1710      m_PACKAGE = package;
1711      dsw_header_fragment.wincopy (m_output_file, 1,
1712                                   &m_PACKAGE);
1713
1714      int i;
1715
1716      dsw_all_project_header_fragment.wincopy (m_output_file, 1, 
1717                                               &m_PACKAGE);
1718
1719      for (i = 0; i < constituents.size (); i++)
1720        {
1721          const Constituent& constituent = constituents[i];
1722
1723          if (constituent.type == Library)
1724            {
1725              m_CONSTITUENT = constituent.name;
1726              m_CONSTITUENTSUFFIX = constituent.suffix;
1727              dsw_all_project_dependency_fragment.wincopy (m_output_file, constituent.variables, 3,
1728                                                           &m_PACKAGE,
1729                                                           &m_CONSTITUENT, 
1730                                                           &m_CONSTITUENTSUFFIX);
1731            }
1732          else
1733            {
1734              m_CONSTITUENT = constituent.name;
1735              m_CONSTITUENTSUFFIX = constituent.suffix;
1736              dsw_all_project_dependency_fragment.wincopy (m_output_file, constituent.variables, 3,
1737                                                           &m_PACKAGE,
1738                                                           &m_CONSTITUENT, 
1739                                                           &m_CONSTITUENTSUFFIX);
1740            }
1741
1742        }
1743
1744      dsw_all_project_trailer_fragment.wincopy (m_output_file,
1745                                                1, &m_PACKAGE);
1746
1747      for (i = 0; i < constituents.size (); i++)
1748        {
1749          const Constituent& constituent = constituents[i];
1750
1751          if (constituent.type == Library)
1752            {
1753              m_CONSTITUENT = constituent.name;
1754              m_CONSTITUENTSUFFIX = constituent.suffix;
1755              dsw_project_fragment.wincopy (m_output_file,
1756                                            constituent.variables, 3,
1757                                            &m_PACKAGE,
1758                                            &m_CONSTITUENT, 
1759                                            &m_CONSTITUENTSUFFIX);
1760            }
1761          else
1762            {
1763              m_CONSTITUENT = constituent.name;
1764              m_CONSTITUENTSUFFIX = constituent.suffix;
1765              dsw_project_fragment.wincopy (m_output_file, constituent.variables, 3, 
1766                                            &m_PACKAGE,
1767                                            &m_CONSTITUENT, 
1768                                            &m_CONSTITUENTSUFFIX);
1769            }
1770        }
1771
1772      dsw_trailer_fragment.wincopy (m_output_file, 1, &m_PACKAGE);
1773
1774      terminate ();
1775    }
1776  else
1777    {
1778      CmtError::set (CmtError::file_access_error, m_output_file_name);
1779    }
1780
1781  m_output_file_name = msdevdir + "all.dspnew";
1782
1783  m_output_file = fopen (m_output_file_name.c_str (), "wb");
1784  if (m_output_file != NULL)
1785    {
1786      dsp_all_fragment.wincopy (m_output_file, 1, &m_PACKAGE);
1787      terminate ();
1788    }
1789  else
1790    {
1791      CmtError::set (CmtError::file_access_error, m_output_file_name);
1792    }
1793
1794  return (0);
1795}
1796
1797//--------------------------------------------------
1798int MSDEVGenerator::build_project (const Constituent& constituent)
1799{
1800  reset ();
1801
1802  const cmt_string& package = Cmt::get_current_package ();
1803  static cmt_string file;
1804  static cmt_string full_name;
1805  static cmt_string suffix;
1806
1807  int i;
1808
1809  m_CONSTITUENT = constituent.name;
1810  m_CONSTITUENTSUFFIX = constituent.suffix;
1811
1812  for (i = 0; i < constituent.includes.size (); i++)
1813    {
1814      const cmt_string& include = constituent.includes[i];
1815      m_PACKINCLUDES += " -I" + include;
1816    }
1817
1818  switch (constituent.type)
1819    {
1820    case Application:
1821      is_application = true;
1822      m_TITLE = "Application";
1823      break;
1824    case Library:
1825      is_library = true;
1826      m_TITLE = "Library";
1827      break;
1828    case Document:
1829      m_GENERATOR = constituent.generator;
1830      m_TITLE = "Document";
1831      break;
1832    }
1833
1834  m_PACKOS9 = constituent.need_OS9;
1835
1836  const CmtSystem::cmt_string_vector& sources = constituent.modules;
1837  const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs;
1838  const cmt_vector<cmt_regexp>& selects = constituent.select_exprs;
1839
1840  //--- Build the constituents fragment -----
1841
1842  m_output_file_name = msdevdir + m_CONSTITUENT + ".dspnew";
1843  m_output_file = fopen (m_output_file_name.c_str (), "wb");
1844
1845  if (m_output_file == NULL) return (0);
1846
1847  m_PACKAGE = package;
1848
1849  if (is_library)
1850    {
1851      if (constituent.no_share)
1852        {
1853          m_LIBRARYSUFFIX = "lib";
1854        }
1855      else
1856        {
1857          m_LIBRARYSUFFIX = "arc";
1858        }
1859
1860      dsp_library_header_fragment.wincopy (m_output_file, constituent.variables, 4,
1861                                           &m_PACKAGE,
1862                                           &m_CONSTITUENT, 
1863                                           &m_CONSTITUENTSUFFIX, 
1864                                           &m_LIBRARYSUFFIX);
1865    }
1866  else
1867    {
1868      if (constituent.windows)
1869        {
1870          dsp_windows_header_fragment.wincopy (m_output_file, constituent.variables, 3,
1871                                               &m_PACKAGE,
1872                                               &m_CONSTITUENT, 
1873                                               &m_CONSTITUENTSUFFIX);
1874        }
1875      else
1876        {
1877          dsp_application_header_fragment.wincopy (m_output_file, constituent.variables, 3,
1878                                                   &m_PACKAGE,
1879                                                   &m_CONSTITUENT, 
1880                                                   &m_CONSTITUENTSUFFIX);
1881        }
1882    }
1883
1884  for (i = 0; i < sources.size (); i++)
1885    {
1886      file = sources[i];
1887
1888      set_full_name (full_name, file);
1889      if (full_name == "") continue;
1890
1891      static CmtSystem::cmt_string_vector files;
1892
1893      get_all_files (full_name, excludes, selects, files);
1894
1895      for (int j = 0; j < files.size (); j++)
1896        {
1897          const cmt_string& name = files[j];
1898
1899          if (name != "") 
1900            {
1901              m_FULLNAME = name;
1902
1903              if (m_output_file != NULL)
1904                {
1905                  dsp_contents_fragment.wincopy (m_output_file, constituent.variables, 2, 
1906                                                 &m_PACKAGE, 
1907                                                 &m_FULLNAME);
1908                }
1909            }
1910        }
1911    }
1912
1913  if (m_output_file != NULL)
1914    {
1915      dsp_trailer_fragment.wincopy (m_output_file, constituent.variables, 3,
1916                                    &m_PACKAGE,
1917                                    &m_CONSTITUENT, 
1918                                    &m_CONSTITUENTSUFFIX);
1919
1920      terminate ();
1921    }
1922
1923  return (0);
1924}
1925
1926
1927VSNETGenerator::VSNETGenerator ()
1928{
1929  sln_header_fragment.set ("sln_header");
1930  sln_project_fragment.set ("sln_project");
1931  sln_dependency_header_fragment.set ("sln_dependency_header");
1932  sln_dependency_project_fragment.set ("sln_dependency_project");
1933  sln_dependency_trailer_fragment.set ("sln_dependency_trailer");
1934  sln_project_config_fragment.set ("sln_project_config");
1935  sln_trailer_fragment.set ("sln_trailer");
1936
1937  vcproj_all_fragment.set ("vcproj_all");
1938  vcproj_library_header_fragment.set ("vcproj_library_header");
1939  vcproj_application_header_fragment.set ("vcproj_application_header");
1940  vcproj_windows_header_fragment.set ("vcproj_windows_header");
1941  vcproj_contents_fragment.set ("vcproj_contents");
1942  vcproj_directory_header_fragment.set ("vcproj_directory_header");
1943  vcproj_directory_trailer_fragment.set ("vcproj_directory_trailer");
1944  vcproj_trailer_fragment.set ("vcproj_trailer");
1945}
1946
1947void VSNETGenerator::reset ()
1948{
1949  CmtGenerator::reset ();
1950
1951  CmtSystem::cd (Cmt::get_current_dir ());
1952
1953  cmt_string branch = CmtSystem::current_branch ();
1954
1955  if ((branch == "mgr") || (branch == "cmt"))
1956    {
1957#ifdef WIN32
1958      vsnetdir = "..";
1959      vsnetdir += CmtSystem::file_separator ();
1960      vsnetdir += "Visual";
1961     
1962      if (!CmtSystem::test_directory (vsnetdir))
1963        {
1964          CmtSystem::mkdir (vsnetdir);
1965        }
1966     
1967      vsnetdir += CmtSystem::file_separator ();
1968#endif
1969    }
1970  else
1971    {
1972#ifdef WIN32
1973      vsnetdir = ".";
1974      vsnetdir += CmtSystem::file_separator ();
1975#endif
1976    }
1977}
1978
1979void VSNETGenerator::pseudoGUID (const cmt_string& a, 
1980                                 const cmt_string& b, 
1981                                 const cmt_string& c, 
1982                                 cmt_string& d)
1983{
1984  char buf[64]; // make the guid in here
1985  static char hex[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
1986  int k = 0;
1987  int i;
1988
1989  for (i = 0; (i < c.size()) && (k < sizeof(buf)); ++i, ++k) buf[k] = c[i];
1990  for (i = 0; (i < a.size()) && (k < sizeof(buf)); ++i, ++k) buf[k] = a[i];
1991  for (i = 0; (i < b.size()) && (k < sizeof(buf)); ++i, ++k) buf[k] = b[i];
1992  for (; k < sizeof(buf); ++k) buf[k] = 0;
1993
1994  // now use the buffer to format the output string
1995  // example: {3FE091FC-3738-4F2E-9723-E846B43F77AB}
1996  d = '{';
1997  k = 0;
1998
1999  for (i = 0; i < 4; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '-';
2000  for (i = 0; i < 2; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '-';
2001  for (i = 0; i < 2; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '-';
2002  for (i = 0; i < 2; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '-';
2003  for (i = 0; i < 6; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '}';
2004}
2005
2006int VSNETGenerator::build_workspace (const Constituent::ConstituentVector& constituents)
2007{
2008  reset ();
2009
2010  const cmt_string& package = Cmt::get_current_package ();
2011 
2012  m_output_file_name = vsnetdir + package + ".slnnew";
2013 
2014  Variable PACKAGE_GUID ("PACKAGE_GUID");
2015  Variable CONSTITUENT_GUID ("CONSTITUENT_GUID");
2016  Variable NUMBER ("NUMBER");
2017 
2018  cmt_string guid;
2019  pseudoGUID (package, Cmt::get_current_version(), "", guid);
2020  PACKAGE_GUID = guid;
2021 
2022  m_output_file = fopen (m_output_file_name.c_str (), "wb");
2023 
2024  if (m_output_file != NULL)
2025    {
2026      m_PACKAGE = package;
2027      sln_header_fragment.wincopy (m_output_file, 2, 
2028                                   &m_PACKAGE,
2029                                   &PACKAGE_GUID);
2030     
2031      int i;
2032     
2033      for (i = 0; i < constituents.size (); i++)
2034        {
2035          const Constituent& constituent = constituents[i];
2036         
2037          pseudoGUID (package, Cmt::get_current_version(), constituent.name, guid);
2038          CONSTITUENT_GUID = guid;
2039         
2040          if (constituent.type == Library)
2041            {
2042              m_CONSTITUENT = constituent.name;
2043              m_CONSTITUENTSUFFIX = constituent.suffix;
2044              sln_project_fragment.wincopy (m_output_file,
2045                                            constituent.variables, 4,
2046                                            &m_PACKAGE,
2047                                            &m_CONSTITUENT,
2048                                            &PACKAGE_GUID,
2049                                            &CONSTITUENT_GUID);
2050            }
2051          else
2052            {
2053              m_CONSTITUENT = constituent.name;
2054              m_CONSTITUENTSUFFIX = constituent.suffix;
2055              sln_project_fragment.wincopy (m_output_file, constituent.variables, 4,
2056                                            &m_PACKAGE,
2057                                            &m_CONSTITUENT,
2058                                            &PACKAGE_GUID,
2059                                            &CONSTITUENT_GUID);
2060            }
2061        }
2062     
2063      sln_dependency_header_fragment.wincopy (m_output_file,
2064                                              1, &m_PACKAGE);
2065     
2066      for (i = 0; i < constituents.size (); i++)
2067        {
2068          const Constituent& constituent = constituents[i];
2069          pseudoGUID (package, Cmt::get_current_version(), constituent.name, guid);
2070          CONSTITUENT_GUID = guid;
2071         
2072          cmt_string num;
2073          num = (char)('0' + i);
2074          NUMBER = num;
2075          if (constituent.type == Library)
2076            {
2077              m_CONSTITUENT = constituent.name;
2078              m_CONSTITUENTSUFFIX = constituent.suffix;
2079             
2080              sln_dependency_project_fragment.wincopy (m_output_file, constituent.variables, 5,
2081                                                       &m_PACKAGE,
2082                                                       &m_CONSTITUENT,
2083                                                       &PACKAGE_GUID,
2084                                                       &CONSTITUENT_GUID,
2085                                                       &NUMBER);
2086            }
2087          else
2088            {
2089              m_CONSTITUENT = constituent.name;
2090              m_CONSTITUENTSUFFIX = constituent.suffix;
2091              sln_dependency_project_fragment.wincopy (m_output_file, constituent.variables, 5,
2092                                                       &m_PACKAGE,
2093                                                       &m_CONSTITUENT,
2094                                                       &PACKAGE_GUID,
2095                                                       &CONSTITUENT_GUID, 
2096                                                       &NUMBER);
2097            }
2098        }
2099     
2100      sln_dependency_trailer_fragment.wincopy (m_output_file,
2101                                               1, &m_PACKAGE);
2102     
2103      for (i = 0; i < constituents.size (); i++)
2104        {
2105          const Constituent& constituent = constituents[i];
2106          pseudoGUID (package, Cmt::get_current_version(), constituent.name, guid);
2107          CONSTITUENT_GUID = guid;
2108         
2109          if (constituent.type == Library)
2110            {
2111              m_CONSTITUENT = constituent.name;
2112              m_CONSTITUENTSUFFIX = constituent.suffix;
2113              sln_project_config_fragment.wincopy (m_output_file,
2114                                                   constituent.variables, 3,
2115                                                   &m_PACKAGE,
2116                                                   &m_CONSTITUENT,
2117                                                   &CONSTITUENT_GUID);
2118            }
2119          else
2120            {
2121              m_CONSTITUENT = constituent.name;
2122              m_CONSTITUENTSUFFIX = constituent.suffix;
2123              sln_project_config_fragment.wincopy (m_output_file, constituent.variables, 3,
2124                                                   &m_PACKAGE,
2125                                                   &m_CONSTITUENT,
2126                                                   &CONSTITUENT_GUID);
2127            }
2128        }
2129     
2130      sln_trailer_fragment.wincopy (m_output_file, 1, &m_PACKAGE);
2131
2132      terminate ();
2133    }
2134 
2135  m_output_file_name = vsnetdir + "all.vcprojnew";
2136 
2137  m_output_file = fopen (m_output_file_name.c_str (), "wb");
2138  if (m_output_file != NULL)
2139    {
2140      vcproj_all_fragment.wincopy (m_output_file, 1, &m_PACKAGE);
2141
2142      terminate ();
2143    }
2144 
2145  return (0);
2146}
2147
2148int VSNETGenerator::build_project (const Constituent& constituent)
2149{
2150  reset ();
2151 
2152  const cmt_string& package = Cmt::get_current_package();
2153  static cmt_string file;
2154  static cmt_string full_name;
2155  static cmt_string suffix;
2156 
2157  static Variable GUID("GUID");
2158  int i;
2159 
2160  // Directory Support
2161  int dir_pos;
2162  int file_pos;
2163  int src_pos;
2164  int iSFFilter = 0;
2165  cmt_string directory;
2166  cmt_string new_dir;
2167  bool need_trailer = false;
2168
2169  m_CONSTITUENT = constituent.name;
2170  // make up a pseudo-GUID from the constituent-pacakge-version combination
2171 
2172  cmt_string guid;
2173  pseudoGUID (package, Cmt::get_current_version(), constituent.name, guid);
2174 
2175  GUID = guid;
2176 
2177  for (i = 0; i < constituent.includes.size (); i++)
2178    {
2179      const cmt_string& include = constituent.includes[i];
2180      m_PACKINCLUDES += " -I" + include;
2181    }
2182 
2183  switch (constituent.type)
2184    {
2185    case Application:
2186      is_application = true;
2187      m_TITLE = "Application";
2188      break;
2189    case Library:
2190      is_library = true;
2191      m_TITLE = "Library";
2192      break;
2193    case Document:
2194      m_GENERATOR = constituent.generator;
2195      m_TITLE = "Document";
2196      break;
2197    }
2198 
2199  m_PACKOS9 = constituent.need_OS9;
2200 
2201  const CmtSystem::cmt_string_vector& sources = constituent.modules;
2202  const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs;
2203  const cmt_vector<cmt_regexp>& selects = constituent.select_exprs;
2204 
2205  //--- Build the constituents fragment -----
2206  cmt_string output;
2207 
2208  m_output_file_name = vsnetdir + m_CONSTITUENT + ".vcprojnew";
2209  m_output_file = fopen (m_output_file_name.c_str (), "wb");
2210 
2211  if (m_output_file == NULL) return (0);
2212 
2213  m_PACKAGE = package;
2214 
2215  if (is_library)
2216    {
2217      if (constituent.no_share)
2218        {
2219          m_LIBRARYSUFFIX = "lib";
2220        }
2221      else
2222        {
2223          m_LIBRARYSUFFIX = "arc";
2224        }
2225     
2226      vcproj_library_header_fragment.wincopy (m_output_file, constituent.variables, 4,
2227                                              &m_PACKAGE,
2228                                              &m_CONSTITUENT,
2229                                              &GUID,
2230                                              &m_LIBRARYSUFFIX);
2231    }
2232  else
2233    {
2234      if (constituent.windows)
2235        {
2236          vcproj_windows_header_fragment.wincopy (m_output_file, constituent.variables, 3,
2237                                                  &m_PACKAGE,
2238                                                  &m_CONSTITUENT,
2239                                                  &GUID);
2240        }
2241      else
2242        {
2243          vcproj_application_header_fragment.wincopy (m_output_file, constituent.variables, 3,
2244                                                      &m_PACKAGE,
2245                                                      &m_CONSTITUENT,
2246                                                      &GUID);
2247        }
2248    }
2249 
2250  for (i = 0; i < sources.size (); i++)
2251    {
2252      file = sources[i];
2253     
2254      set_full_name (full_name, file);
2255      if (full_name == "") continue;
2256     
2257      static CmtSystem::cmt_string_vector files;
2258     
2259      get_all_files (full_name, excludes, selects, files);
2260     
2261      for (int j = 0; j < files.size (); j++)
2262        {
2263          const cmt_string& name = files[j];
2264         
2265          if (name != "")
2266            {
2267              m_FULLNAME = name;
2268
2269              // Add Directory Support here
2270              // Step 1: Parse into "..\src\" "directory" "\filename.cxx"
2271
2272              // find ..\ ;
2273              src_pos = name.find('\\');
2274              // Finds ..\src\ ;
2275              dir_pos = name.find(src_pos+1, '\\') + 1;
2276              // Finds ..\src\..\astro\ ;
2277              file_pos = name.find_last_of('\\');
2278             
2279              // Debug only
2280              //printf("%40s, %i, %i, %i;\n", name src_pos, dir_pos, file_pos);
2281              // If dir_pos == file_pos, then we have ../src/filename.cxx
2282              // If dir_pos >  file_pos, then we have ../filename.cxx or something odd.
2283                           
2284              // Step 2: see if it is or is not a ../src/ directory.
2285              if ((dir_pos < file_pos) && (dir_pos > src_pos))
2286                {
2287                  new_dir = name.substr (dir_pos, file_pos-dir_pos);
2288                  new_dir.replace( "..\\", ""); // All names are relative to package/Visual,
2289                                                // so we want to ditch the prevailing ..\ ;
2290                                                // which all of them have.
2291                }
2292              else
2293                {
2294                  new_dir = "Source Files NN";
2295                }
2296
2297              // Step 3: Add directory structure to vcproj file.
2298              if (new_dir != directory) // Detects a change in directory
2299                {
2300                  directory = new_dir;
2301                  // Step 3a: Add a </Filter> when neccessary.
2302                  if (need_trailer == false)
2303                    {
2304                      // Ensure that no trailing </Filter> is placed incorrectly.
2305                      need_trailer = true;
2306                    }
2307                  else
2308                    {
2309                      vcproj_directory_trailer_fragment.wincopy (m_output_file,
2310                                                                 constituent.variables, 1,
2311                                                                 &m_PACKAGE);
2312                    }
2313
2314                  // Step 3b: Add a <Filter> when neccessary.
2315                  if ((dir_pos < file_pos) && (dir_pos > src_pos))
2316                    {
2317                      // Add <Filter Name="directory">
2318                      m_DIRNAME = new_dir;
2319                      vcproj_directory_header_fragment.wincopy (m_output_file, constituent.variables, 2,
2320                                                                &m_PACKAGE,
2321                                                                &m_DIRNAME);
2322                    }
2323                  else
2324                    {
2325                      // Ensure that no </Filter> is placed incorrectly.
2326                      // This is the case of the file being in ../src
2327                      // which requires no directory. Thus no filter start or end tag is needed.
2328
2329                      need_trailer = false;
2330                    }
2331                }
2332
2333              if (m_output_file != NULL)
2334                {
2335                  vcproj_contents_fragment.wincopy (m_output_file, constituent.variables, 2,
2336                                                    &m_PACKAGE,
2337                                                    &m_FULLNAME);
2338                }
2339            }
2340        }
2341    }
2342
2343  if (need_trailer == true)
2344    {
2345      // Add a trailing </Filter> for directory support.
2346      vcproj_directory_trailer_fragment.wincopy (m_output_file, constituent.variables, 1,
2347                                                 &m_PACKAGE);
2348    }
2349
2350  if (m_output_file != NULL)
2351    {
2352      vcproj_trailer_fragment.wincopy (m_output_file, constituent.variables, 3,
2353                                       &m_PACKAGE,
2354                                       &m_CONSTITUENT,
2355                                       &m_CONSTITUENTSUFFIX);
2356
2357      terminate ();
2358    }
2359
2360  return (0);
2361}
2362
2363MakeSetupGenerator::MakeSetupGenerator ()
2364{
2365  make_setup_header_fragment.set ("make_setup_header");
2366  make_setup_fragment.set ("make_setup");
2367}
2368
2369void MakeSetupGenerator::reset ()
2370{
2371  CmtGenerator::reset ();
2372
2373  make_setup_header_fragment.reset ();
2374  make_setup_fragment.reset ();
2375}
2376
2377void MakeSetupGenerator::build (const cmt_string& package)
2378{
2379  reset ();
2380
2381  m_PACKAGE = package;
2382
2383  cmt_string file_name = "setup.";
2384
2385  if (Cmt::build_nmake ())
2386    {
2387      file_name += "nmake";
2388    }
2389  else
2390    {
2391      file_name += "make";
2392    }
2393 
2394  cmt_string new_file_name = file_name;
2395  new_file_name += "new";
2396
2397  m_output_file = fopen (new_file_name, "wb");
2398
2399  if (m_output_file != NULL)
2400    {
2401      int number;
2402
2403      const Use::UsePtrVector& uses = Use::get_ordered_uses ();
2404
2405      const Constituent::ConstituentVector& constituents =
2406        Constituent::constituents ();
2407
2408      cmt_string temp;
2409
2410      make_setup_header_fragment.copy (m_output_file, 1, &m_PACKAGE);
2411
2412      for (number = 0; number < uses.size (); number++)
2413        {
2414          const Use* use = uses[number];
2415
2416          if (use->discarded) continue;
2417
2418          if (use->real_path != "")
2419            {
2420              temp  = use->prefix;
2421              temp += "ROOT = ";
2422              temp += use->get_full_path ();
2423
2424              fprintf (m_output_file, "%s\n", temp.c_str());
2425            }
2426        }
2427
2428      temp  = "use_requirements = ";
2429      temp += "requirements ";
2430
2431      for (number = 0; number < uses.size (); number++)
2432        {
2433          const Use* use = uses[number];
2434
2435          if (use->discarded) continue;
2436
2437          if (use->real_path != "")
2438            {
2439              temp += "$(";
2440              temp += use->prefix;
2441              temp += "ROOT)";
2442              temp += CmtSystem::file_separator ();
2443              switch (use->style)
2444                {
2445                case cmt_style:
2446                  temp += "cmt";
2447                  break;
2448                case mgr_style:
2449                  temp += "mgr";
2450                  break;
2451                }
2452              temp += CmtSystem::file_separator ();
2453              temp += "requirements ";
2454            }
2455        }
2456
2457      fprintf (m_output_file, "%s\n", temp.c_str());
2458
2459      temp  = "constituents = $(constituents)";
2460      Symbol::expand (temp);
2461
2462      fprintf (m_output_file, "%s\n", temp.c_str());
2463
2464      make_setup_fragment.copy (m_output_file, 1, &m_PACKAGE);
2465
2466      CmtSystem::close_ostream (m_output_file, new_file_name);
2467      //  fclose (m_output_file);
2468
2469      //--- Complete the operation --------------
2470
2471      commit (new_file_name);
2472    }
2473  else
2474    {
2475      CmtError::set (CmtError::file_access_error, new_file_name);
2476    }
2477
2478  /*
2479    for option in $*
2480    do
2481    case ${option} in
2482    args-tag=*)
2483    tag=${option}
2484    tag=`echo "${tag}" | sed -e 's/args.tag=//'`
2485    ;;
2486    -tag=*)
2487    tag=args${option}
2488    tag=`echo "${tag}" | sed -e 's/args.tag=//'`
2489    ;;
2490    esac
2491    done
2492
2493    if test "${tag}" = "" ; then
2494    tag=${CMTCONFIG}
2495    fi
2496
2497    build_shell_setup_files ${tag}
2498
2499    now=`date`
2500
2501  */
2502}
2503
2504ConstituentsMakefileGenerator::ConstituentsMakefileGenerator ()
2505{
2506  constituents_header_fragment.set ("constituents_header");
2507  constituents_trailer_fragment.set ("constituents_trailer");
2508  group_fragment.set ("group");
2509  constituent_fragment.set ("constituent");
2510  constituent_lock_fragment.set ("constituent_lock");
2511  check_application_header_fragment.set ("check_application_header");
2512}
2513
2514void ConstituentsMakefileGenerator::reset ()
2515{
2516  CmtGenerator::reset ();
2517  constituents_header_fragment.reset ();
2518  constituents_trailer_fragment.reset ();
2519  group_fragment.reset ();
2520  constituent_fragment.reset ();
2521  constituent_lock_fragment.reset ();
2522  check_application_header_fragment.reset ();
2523}
2524
2525//--------------------------------------------------
2526void ConstituentsMakefileGenerator::build (const cmt_string& package,
2527                                           const cmt_string& file)
2528//                                         const CmtSystem::cmt_string_vector& arguments)
2529{
2530  reset ();
2531
2532  cmt_string file_name (file);
2533    //, dir_name;
2534
2535//   if (arguments.size () > 0)
2536//     {
2537//       cmt_string arg = arguments[0];
2538//       if (arg.substr (0, 5) == "-out=")
2539//      {
2540//        arg.erase (0, 5);
2541//        file_name = arg;
2542//      }
2543//       else if (arg.substr (0, 8) == "-outdir=")
2544//      {
2545//        arg.erase (0, 8);
2546//        dir_name = arg;
2547//      }
2548//     }
2549
2550  if (file_name == "")
2551    {
2552      file_name = "constituents.";
2553
2554      //--- Build the constituents fragment -----
2555
2556      if (Cmt::build_nmake ())
2557        {
2558          file_name += "nmake";
2559        }
2560      else
2561        {
2562          file_name += "make";
2563        }
2564    }
2565
2566//   if (dir_name != "")
2567//     {
2568//       if (dir_name [dir_name.size () - 1] != CmtSystem::file_separator ())
2569//      dir_name += CmtSystem::file_separator ();
2570//       file_name = dir_name + file_name;
2571//     }
2572
2573  cmt_string save_file_name = file_name;
2574  save_file_name += "cmtsave";
2575
2576  if (CmtSystem::test_file (file_name))
2577    {
2578      rename (file_name, save_file_name);
2579    }
2580
2581  cmt_string new_file_name = file_name;
2582  new_file_name += "new";
2583
2584  m_output_file = fopen (new_file_name, "wb");
2585  if (m_output_file != NULL)
2586    {
2587      int number;
2588      const Constituent::ConstituentVector&
2589        constituents = Constituent::constituents ();
2590
2591      m_PACKAGE = package;
2592
2593      constituents_header_fragment.copy (m_output_file, 1, &m_PACKAGE);
2594
2595      m_GROUP = "all";
2596      group_fragment.copy (m_output_file, 1, &m_GROUP);
2597
2598      const Group::GroupVector& groups = Group::groups ();
2599
2600      for (number = 0; number < groups.size (); number++)
2601        {
2602          const Group& group = groups[number];
2603
2604          m_GROUP = group.name ();
2605
2606          group_fragment.copy (m_output_file, 1, &m_GROUP);
2607        }
2608     
2609      bool lock = false;
2610      Symbol* lock_command_macro = Symbol::find ("lock_command");
2611      if (lock_command_macro != 0)
2612        {
2613          cmt_string lock_command = lock_command_macro->resolve_macro_value ();
2614          if (lock_command != "")
2615            {
2616              Symbol* unlock_command_macro = Symbol::find ("unlock_command");
2617              if (unlock_command_macro != 0)
2618                {
2619                  cmt_string unlock_command = unlock_command_macro->resolve_macro_value ();
2620                  if (unlock_command != "")
2621                    {
2622                      lock = true;
2623                    }
2624                }
2625            }
2626        }
2627      for (number = 0; number < constituents.size (); number++)
2628        {
2629          const Constituent& constituent = constituents[number];
2630
2631          m_CONSTITUENT = constituent.name;
2632          m_CONSTITUENTSUFFIX = constituent.suffix;
2633
2634          m_LINE = "";
2635
2636          if (constituent.has_target_tag)
2637            {
2638              m_HASTARGETTAG = "has_target_tag";
2639            }
2640          else
2641            {
2642              m_HASTARGETTAG = "has_no_target_tag";
2643            }
2644
2645          switch (constituent.type)
2646            {
2647            case Application:
2648              m_HASDEPENDENCIES = "has_dependencies";
2649              break;
2650            case Library:
2651              m_HASDEPENDENCIES = "has_dependencies";
2652              break;
2653            case Document:
2654              m_HASDEPENDENCIES = FragmentHandle (constituent.generator).need_dependencies () ? "has_dependencies" : "has_no_dependencies" ;
2655              break;
2656            }
2657
2658          if (constituent.type == Document && lock == true)
2659            {
2660              constituent_lock_fragment.copy (m_output_file, constituent.variables,
2661                                              6,
2662                                              &m_PACKAGE,
2663                                              &m_CONSTITUENT, 
2664                                              &m_CONSTITUENTSUFFIX,
2665                                              &m_LINE,
2666                                              &m_HASDEPENDENCIES,
2667                                              &m_HASTARGETTAG);
2668            }
2669          else
2670            {
2671              constituent_fragment.copy (m_output_file, constituent.variables,
2672                                         6,
2673                                         &m_PACKAGE,
2674                                         &m_CONSTITUENT, 
2675                                         &m_CONSTITUENTSUFFIX,
2676                                         &m_LINE,
2677                                         &m_HASDEPENDENCIES,
2678                                         &m_HASTARGETTAG);
2679            }
2680
2681          if (constituent.need_check)
2682            {
2683              check_application_header_fragment.copy (m_output_file, 
2684                                                      constituent.variables, 3,
2685                                                      &m_PACKAGE,
2686                                                      &m_CONSTITUENT,
2687                                                      &m_CONSTITUENTSUFFIX);
2688            }
2689        }
2690
2691      constituents_trailer_fragment.copy (m_output_file, 0);
2692
2693      CmtSystem::close_ostream (m_output_file, new_file_name);
2694      //  fclose (m_output_file);
2695
2696      commit (new_file_name);
2697    }
2698  else
2699    {
2700      CmtError::set (CmtError::file_access_error, new_file_name);
2701    }
2702}
2703
2704
2705
2706
2707/**
2708   With this Awk filter, we analyze an existing dependency file.
2709   We get the source name in each line
2710   The list of sources is maintained in m_sources
2711   A source is stored in the form <name>_<suffix> (instead of <name>.<suffix>)
2712*/
2713class DependencyFilter : public Awk
2714{
2715public:
2716  DependencyFilter ()
2717  {
2718  }
2719
2720  void begin ()
2721  {
2722    m_sources = "";
2723  }
2724
2725  void filter (const cmt_string& line)
2726  {
2727    int pos = line.find ("_dependencies = ");
2728    if (pos == cmt_string::npos) return;
2729
2730    cmt_string s = line;
2731    s.erase (pos);
2732
2733    m_sources += " ";
2734    m_sources += s;
2735    m_sources += " ";
2736
2737    //pos = s.find_last_of ("_");
2738    //if (pos != cmt_string::npos) s[pos] = "."
2739  }
2740
2741  void add_source (const cmt_string& file_name)
2742  {
2743    static cmt_string suffix;
2744    static cmt_string name;
2745
2746    CmtSystem::get_dot_suffix (file_name, suffix);
2747    CmtSystem::basename (file_name, suffix, name);
2748    CmtSystem::get_suffix (file_name, suffix);
2749
2750    cmt_string s = " ";
2751    s += name;
2752    s += "_";
2753    s += suffix;
2754    s += " ";
2755
2756    if (m_sources.find (s) == cmt_string::npos)
2757      {
2758        m_sources += s;
2759      }       
2760  }
2761
2762  bool has_source (const cmt_string& file_name) const
2763  {
2764    static cmt_string suffix;
2765    static cmt_string name;
2766
2767    CmtSystem::get_dot_suffix (file_name, suffix);
2768    CmtSystem::basename (file_name, suffix, name);
2769    CmtSystem::get_suffix (file_name, suffix);
2770
2771    cmt_string s = " ";
2772    s += name;
2773    s += "_";
2774    s += suffix;
2775    s += " ";
2776
2777    if (m_sources.find (s) == cmt_string::npos)
2778      {
2779        return (false);
2780      }
2781    else
2782      {
2783        return (true);
2784      }
2785  }
2786
2787  cmt_string& get_sources ()
2788  {
2789    return (m_sources);
2790  }
2791
2792private:
2793  cmt_string m_sources;
2794};
2795
2796void DependencyGenerator::build (const CmtSystem::cmt_string_vector& arguments)
2797{
2798  reset ();
2799  prepare_use_context ();
2800
2801  prepare_header_file_filters ();
2802
2803  const cmt_string& name = arguments[0];
2804
2805  m_constituent = Constituent::find (name);
2806  if (m_constituent == 0)
2807    {
2808      // Error : wrong constituent name...
2809      return;
2810    }
2811
2812  const Constituent& constituent = *m_constituent;
2813
2814  cmt_string file_name;
2815  cmt_string full_name;
2816  cmt_string compressed_name;
2817  //  cmt_string suffix;
2818  cmt_string dependencies;
2819
2820  //
2821  // Scan the sources.
2822  //
2823
2824  //
2825  //  We have to rebuild the dependencies for :
2826  //
2827  //   o all sources if the parameter -all_sources has been received
2828  //   o otherwise,
2829  //      + all source names provided in the argument list (if any)
2830  //      + all source names missing from the existing dependency file (if any)
2831  //
2832
2833  const CmtSystem::cmt_string_vector& sources = constituent.modules;
2834  const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs;
2835  const cmt_vector<cmt_regexp>& selects = constituent.select_exprs;
2836
2837  m_stamps = true;
2838  bool all_sources = false;
2839
2840  int source_number = arguments.size ();
2841  int i;
2842
2843  //cerr << "source_number=" << source_number << endl;
2844
2845  for (i = source_number-1; i >= 0; i--)
2846    {
2847      file_name = arguments[i];
2848
2849      //cerr << "file_name=" << file_name << endl;
2850
2851      // Get rid of files that may come from the makefile fragment
2852      if (file_name.find ("requirements") != cmt_string::npos) source_number--;
2853      else if (file_name.substr (0, 5) == "-out=" ||
2854               file_name.substr (0, 5) == "-out:" ||
2855               file_name.substr (0, 5) == "/out:" ||
2856               file_name.substr (0, 5) == "/out=")
2857        {
2858          source_number--;
2859          file_name.erase (0, 5);
2860          m_output_file_name = file_name;
2861        }
2862      else if (file_name.find (".make") != cmt_string::npos) source_number--;
2863      else if (file_name == "-all_sources" ||
2864               file_name == "/all_sources") 
2865        {
2866          source_number = sources.size ();
2867          all_sources = true;
2868        }
2869      else if (file_name == "-no_stamps" ||
2870               file_name == "/no_stamps") 
2871        {
2872          source_number--;
2873          m_stamps = false;
2874        }
2875    }
2876
2877  //
2878  // Now prepare the output file names
2879  //
2880  cmt_string branch = CmtSystem::current_branch ();
2881
2882  if ((branch == "mgr") || (branch == "cmt"))
2883    {
2884      Use& current_use = Use::current ();
2885
2886      Package* p = current_use.get_package ();
2887
2888      if (p->is_cmt ())
2889        {
2890          //          m_bin = "../";
2891          m_bin = "..";
2892          m_bin += CmtSystem::file_separator ();
2893          m_bin += CmtSystem::getenv ("CMTBIN");
2894          m_bin += CmtSystem::file_separator ();
2895        }
2896      else if (m_output_file_name != "")
2897        {
2898          CmtSystem::dirname (m_output_file_name, m_bin);
2899          if (m_bin == "")
2900            {
2901              m_bin = ".";
2902            }
2903          m_bin += CmtSystem::file_separator ();
2904        }
2905      else
2906        {
2907          m_bin = "${bin}";
2908        }
2909
2910      Symbol::expand (m_bin);
2911
2912      //cerr << "m_output_file_name=" << m_output_file_name << endl;
2913      //cerr << "current_tag=" << Cmt::current_tag << endl;
2914    }
2915  else
2916    {
2917      m_bin = ".";
2918      m_bin += CmtSystem::file_separator ();
2919    }
2920
2921  if (m_output_file_name == "")
2922    {
2923      m_output_file_name = m_bin;
2924      m_output_file_name += name;
2925      m_output_file_name += "_";
2926      m_output_file_name += "dependencies.";
2927      if (Cmt::build_nmake ())
2928        {
2929          m_output_file_name += "nmake";
2930        }
2931      else
2932        {
2933          m_output_file_name += "make";
2934        }
2935    }
2936
2937  if (all_sources)
2938    {
2939      for (i = 0; i < sources.size (); i++)
2940        {
2941          file_name = sources[i];
2942         
2943          set_full_name (full_name, file_name);
2944          if (full_name == "") continue;
2945
2946          CmtSystem::compress_path (full_name, compressed_name);
2947          full_name = compressed_name;
2948         
2949          static CmtSystem::cmt_string_vector files;
2950
2951          get_all_files (full_name, excludes, selects, files);
2952
2953          for (int j = 0; j < files.size (); j++)
2954            {
2955              const cmt_string& name = files[j];
2956             
2957              if (name != "") 
2958                {
2959                  const cmt_string& line = build (name);
2960                 
2961                  add_line_to_text (line, dependencies);
2962                }
2963            }
2964        }
2965    }
2966  else
2967    {
2968      //
2969      // New read the existing dependency file if any and filter it to
2970      // extract the source names
2971      //
2972      static DependencyFilter filter;
2973      dependencies.read (m_output_file_name);
2974      filter.run (dependencies);
2975     
2976      for (i = 1; i < source_number; i++)
2977        {
2978          file_name = arguments[i];
2979
2980          set_full_name (full_name, file_name);
2981          if (full_name == "") continue;
2982
2983          CmtSystem::compress_path (full_name, compressed_name);
2984          full_name = compressed_name;
2985         
2986          const cmt_string& line = build (full_name);
2987                 
2988          add_line_to_text (line, dependencies);
2989
2990          filter.add_source (full_name);
2991
2992        }
2993
2994      // Now : are there still any missing source file in dependencies??
2995
2996      for (i = 0; i < sources.size (); i++)
2997        {
2998          file_name = sources[i];
2999         
3000          set_full_name (full_name, file_name);
3001          if (full_name == "") continue;
3002         
3003          CmtSystem::compress_path (full_name, compressed_name);
3004          full_name = compressed_name;
3005         
3006          static CmtSystem::cmt_string_vector files;
3007         
3008          get_all_files (full_name, excludes, selects, files);
3009
3010          for (int j = 0; j < files.size (); j++)
3011            {
3012              const cmt_string& name = files[j];
3013              if (name != "") 
3014                {
3015                  if (!filter.has_source (name))
3016                    {
3017                      const cmt_string& line = build (name);
3018                 
3019                      add_line_to_text (line, dependencies);
3020                    }
3021                }
3022            }
3023        }
3024    }
3025
3026  FILE* f = fopen (m_output_file_name.c_str (), "wb");
3027
3028  if (f != 0)
3029    {
3030      dependencies.write (f);
3031      CmtSystem::close_ostream (f, m_output_file_name);
3032      //          fclose (f);
3033    }
3034  else
3035    {
3036      CmtError::set (CmtError::file_access_error, m_output_file_name);
3037      //      CmtMessage::error ("Cannot open " + m_output_file_name + " for write");
3038    }
3039
3040//  m_deps_builder.clear ();
3041}
3042
3043//--------------------------------------------------
3044//  o text contains lines with a pattern like :
3045//      key = xxxxx
3046//
3047//  o line follows the same pattern
3048//
3049//   This function appends <line> to <text> only if the key found in
3050//  <line> is not found in <text>
3051//--------------------------------------------------
3052void DependencyGenerator::add_line_to_text (const cmt_string& line, cmt_string& text)
3053{
3054  static const cmt_string empty;
3055
3056  int pos = line.find (" = ");
3057  if (pos != cmt_string::npos)
3058    {
3059      static cmt_string key;
3060      line.substr (0, pos + 3, key);
3061      pos = text.find (key);
3062      if (pos != cmt_string::npos)
3063        {
3064          // The key in line exists in text.
3065          // Now check if the key is exactly the same.
3066
3067          if ((pos == 0) || (text[pos -1] == '\n'))
3068            {
3069              // The key is either in the first line or
3070              // exactly matches '^key = ...'
3071
3072              int nl = text.find (pos, "\n");
3073              if (nl != cmt_string::npos)
3074                {
3075                  static cmt_string old;
3076                  text.substr (pos, nl - pos + 1, old);
3077                  text.replace (old, empty);
3078                }
3079              else
3080                {
3081                  text.erase (pos);
3082                }
3083            }
3084        }
3085    }
3086  if (line != "")
3087    {
3088      text += line;
3089      text += "\n";
3090    }
3091}
3092
3093cmt_string DependencyGenerator::build (const cmt_string& file_name)
3094{
3095  Log;
3096
3097  const Constituent& constituent = *m_constituent;
3098
3099  static cmt_string full_name;
3100  static cmt_string suffix;
3101  static cmt_string name;
3102  static cmt_string line;
3103
3104  full_name = "";
3105  line = "";
3106
3107  if (!CmtSystem::absolute_path (file_name))
3108    {
3109      full_name = srcdir;
3110    }
3111
3112  full_name += file_name;
3113
3114  CmtSystem::get_dot_suffix (full_name, suffix);
3115  CmtSystem::basename (full_name, suffix, name);
3116  CmtSystem::get_suffix (full_name, suffix);
3117
3118  if (name == "requirements") return (line);
3119
3120  const CmtSystem::cmt_string_vector& deps = m_deps_builder.run (full_name);
3121
3122  line  = name;
3123  line += "_";
3124  line += suffix;
3125  line += "_dependencies = ";
3126
3127  filter_path (full_name);
3128
3129#ifdef WIN32
3130  static const char quote = '\"';
3131#else
3132  static const char quote = ' ';
3133#endif
3134
3135  line += quote;
3136  line += full_name;
3137  line += quote;
3138
3139  for (int j = 0; j < deps.size (); j++)
3140    {
3141      cmt_string d = deps[j];
3142
3143      log << "dep line = " << d << log_endl;
3144
3145      filter_path (d);
3146
3147      log << "filtered dep line = " << d << log_endl;
3148
3149      line += " ";
3150      line += quote;
3151      line += d;
3152      line += quote;
3153    }
3154
3155  Symbol::expand (line);
3156
3157  if (m_stamps)
3158    {
3159      cmt_string stamp_output_base = constituent.name;
3160      stamp_output_base += "_deps";
3161
3162      cmt_string stamp_output = m_bin;
3163      stamp_output += stamp_output_base;
3164
3165      if (!CmtSystem::mkdir (stamp_output))
3166        {
3167          CmtMessage::error ("Cannot create the binary output directory for this constituent " + stamp_output);
3168          //      cerr << "Cannot create the binary output directory for this constituent" << endl;
3169        }
3170
3171      stamp_output_base += CmtSystem::file_separator ();
3172      stamp_output_base += name;
3173      stamp_output_base += "_";
3174      stamp_output_base += suffix;
3175      stamp_output_base += ".stamp";
3176
3177      stamp_output = m_bin;
3178      stamp_output += stamp_output_base;
3179     
3180      line += " $(bin)";
3181      line += stamp_output_base;
3182     
3183      cmt_string old_stamp;
3184     
3185      if (CmtSystem::test_file (stamp_output))
3186        {
3187          old_stamp.read (stamp_output);
3188        }
3189
3190      if (line != old_stamp)
3191        {
3192          line.write (stamp_output);
3193        }
3194    }
3195
3196  return (line);
3197}
3198
3199//--------------------------------------------------
3200void DependencyGenerator::prepare_header_file_filters ()
3201{
3202//   Use::UsePtrVector& uses = Use::get_ordered_uses ();
3203  Use::UsePtrVector uses (Use::get_ordered_uses ());
3204  uses.push_back (&Use::current ());
3205  for (int i = uses.size () - 1; i >= 0; i--)
3206    {
3207      Use* use = uses[i];
3208      if (use->discarded) continue;
3209      if (use->m_hidden) continue;
3210      if (!use->located ()) continue;
3211
3212      cmt_string package_name = use->get_package_name ();
3213      if (package_name == "CMT") continue;
3214
3215      Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter");
3216      if (filter_macro == 0) continue;
3217
3218      Symbol* stamp_macro = Symbol::find (package_name + "_header_file_stamp");
3219      cmt_string stamp;
3220      if (stamp_macro != 0)
3221        {
3222          stamp = stamp_macro->resolve_macro_value ();
3223        }
3224      else
3225        {
3226          use->get_full_path (stamp);
3227          stamp += CmtSystem::file_separator ();
3228          if (use->style == mgr_style) stamp += "mgr";
3229          else stamp += "cmt";
3230          stamp += CmtSystem::file_separator ();
3231          stamp += "cmt_header_file.stamp";
3232          //stamp += "cmt_all_headers.stamp";
3233          //<package>/cmt/cmt_all_headers.stamp
3234        }
3235      if (!CmtSystem::test_file (stamp)) continue;
3236
3237      cmt_regexp* filter = new cmt_regexp (filter_macro->resolve_macro_value ());
3238      assert (filter != 0);
3239
3240      m_deps_builder.add_header_filter (use, filter, stamp);
3241    }
3242}
Note: See TracBrowser for help on using the repository browser.