source: CMT/HEAD/source/cmt_generator.cxx @ 561

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

See C.L. 444

  • Property svn:eol-style set to native
File size: 30.0 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 <errno.h>
8#include <stdio.h>
9
10#ifndef WIN32
11#include <unistd.h>
12#endif
13
14#include "cmt_generator.h"
15#include "cmt_use.h"
16#include "cmt_symbol.h"
17
18#include "cmt_generators.h"
19#include "cmt_log.h"
20#include "cmt_error.h"
21
22//------------------------------------------------------------------------
23void SourceFile::set (const cmt_string name, Language& language, const cmt_string output)
24{
25  m_name = name;
26  m_language = &language;
27  m_output = output;
28 
29  CmtSystem::reduce_file_separators (m_name);
30}
31
32cmt_string SourceFile::name () const
33{
34  return (m_name);
35}
36
37Language& SourceFile::language () const
38{
39  return (*m_language);
40}
41
42cmt_string SourceFile::output () const
43{
44  return (m_output);
45}
46//------------------------------------------------------------------------
47
48//--------------------------------------------------
49CmtGenerator::CmtGenerator ()
50{
51  m_CONSTITUENT.set ("CONSTITUENT");
52  m_LINKMACRO.set ("LINKMACRO");
53  m_DEPENDENCIESOPTS.set ("DEPENDENCIESOPTS");
54  m_DOCPATH.set ("DOCPATH");
55  m_PACKAGEPATH.set ("PACKAGEPATH");
56  m_PACKAGEPREFIX.set ("PACKAGEPREFIX");
57  m_PACKAGE.set ("PACKAGE");
58  m_VERSION.set ("VERSION");
59  m_MGRSTYLE.set ("MGRSTYLE");
60  m_TITLE.set ("TITLE");
61  m_GROUP.set ("GROUP");
62  m_CONSTITUENTSUFFIX.set ("CONSTITUENTSUFFIX");
63  m_LIBRARYSUFFIX.set ("LIBRARYSUFFIX");
64  m_USER.set ("USER");
65  m_DATE.set ("DATE");
66  m_PROTOTARGET.set ("PROTOTARGET");
67  m_OBJS.set ("OBJS");
68  m_CLASSES.set ("CLASSES");
69  m_PROTOSTAMPS.set ("PROTOSTAMPS");
70  m_NAME.set ("NAME");
71  m_FILEPATH.set ("FILEPATH");
72  m_FILESUFFIX.set ("FILESUFFIX");
73  m_SUFFIX.set ("SUFFIX");
74  m_FILENAME.set ("FILENAME");
75  m_LINE.set ("LINE");
76  m_ADDINCLUDE.set ("ADDINCLUDE");
77  m_FULLNAME.set ("FULLNAME");
78  m_DIRNAME.set ("DIRNAME");
79  m_OUTPUTNAME.set ("OUTPUTNAME");
80  m_ALLOS9SOURCES.set ("ALLOS9SOURCES");
81  m_NODEBUGUSELINKOPTS.set ("NODEBUGUSELINKOPTS");
82  m_DEBUGUSELINKOPTS.set ("DEBUGUSELINKOPTS");
83  m_USEINCLUDES.set ("USEINCLUDES");
84  m_HASTARGETTAG.set ("HASTARGETTAG");
85  m_HASDEPENDENCIES.set ("HASDEPENDENCIES");
86}
87
88//--------------------------------------------------
89void CmtGenerator::reset ()
90{
91  m_CONSTITUENT = "";
92  m_LINKMACRO = "";
93  m_DEPENDENCIESOPTS = "";
94  m_DOCPATH = "";
95  m_PACKAGEPATH = "";
96  m_PACKAGEPREFIX = "";
97  m_PACKAGE = "";
98  m_VERSION = "";
99  m_MGRSTYLE = "";
100  m_TITLE = "";
101  m_GROUP = "";
102  m_CONSTITUENTSUFFIX = "";
103  m_LIBRARYSUFFIX = "";
104  m_USER = "";
105  m_DATE = "";
106  m_PROTOTARGET = "";
107  m_OBJS = "";
108  m_CLASSES = "";
109  m_PROTOSTAMPS = "";
110  m_NAME = "";
111  m_FILEPATH = "";
112  m_FILESUFFIX = "";
113  m_SUFFIX = "";
114  m_FILENAME = "";
115  m_LINE = "";
116  m_ADDINCLUDE = "";
117  m_FULLNAME = "";
118  m_OUTPUTNAME = "";
119  m_ALLOS9SOURCES = "";
120  m_NODEBUGUSELINKOPTS = "";
121  m_DEBUGUSELINKOPTS = "";
122  m_USEINCLUDES = "";
123  m_HASTARGETTAG = "";
124  m_HASDEPENDENCIES = "";
125  m_PACKINCLUDES = "";
126  m_PACKOS9      = false;
127  m_GENERATOR    = "";
128
129  is_library     = false;
130  is_application = false;
131  srcdir       = "";
132  docdir       = "";
133  cmtdir       = "";
134  incdir       = "";
135  src          = "$(src)";
136  doc          = "$(doc)";
137  inc          = "$(inc)";
138  mgr          = "$(mgr)";
139  cmt          = "$(cmt)";
140  protos       = "";
141  protonames   = "";
142  os9sources   = "";
143
144  m_source_files.clear ();
145
146  Language::setup_all_fragments ();
147
148  CmtSystem::cd (Cmt::get_current_dir ());
149
150  cmt_string branch = CmtSystem::current_branch ();
151
152  if ((branch == "mgr") || (branch == "cmt"))
153    {
154      if (CmtSystem::test_directory ("../src"))
155        {
156          srcdir = "..";
157          srcdir += CmtSystem::file_separator ();
158          srcdir += "src";
159          srcdir += CmtSystem::file_separator ();
160        }
161      else
162        {
163          srcdir = "";
164        }
165
166      if (CmtSystem::test_directory ("../doc"))
167        {
168          docdir = "..";
169          docdir += CmtSystem::file_separator ();
170          docdir += "doc";
171          docdir += CmtSystem::file_separator ();
172        }
173      else
174        {
175          docdir = "";
176        }
177
178      if (CmtSystem::test_directory ("../cmt"))
179        {
180          cmtdir = "..";
181          cmtdir += CmtSystem::file_separator ();
182          cmtdir += "cmt";
183          cmtdir += CmtSystem::file_separator ();
184        }
185      else if (CmtSystem::test_directory ("../mgr"))
186        {
187          cmtdir = "..";
188          cmtdir += CmtSystem::file_separator ();
189          cmtdir += "mgr";
190          cmtdir += CmtSystem::file_separator ();
191        }
192      else
193        {
194          cmtdir = CmtSystem::pwd ();
195          cmtdir += CmtSystem::file_separator ();
196        }
197
198      if (CmtSystem::test_directory ("../src"))
199        {
200          incdir = "..";
201          incdir += CmtSystem::file_separator ();
202          incdir += "src";
203          incdir += CmtSystem::file_separator ();
204        }
205      else
206        {
207          incdir = "";
208        }
209    }
210  else
211    {
212      srcdir = ".";
213      srcdir += CmtSystem::file_separator ();
214      docdir = ".";
215      docdir += CmtSystem::file_separator ();
216      cmtdir = CmtSystem::pwd ();
217      cmtdir += CmtSystem::file_separator ();
218      incdir = ".";
219      incdir += CmtSystem::file_separator ();
220    }
221}
222
223//--------------------------------------------------
224bool CmtGenerator::prepare_output (const cmt_string& package,
225                                   const Constituent& constituent,
226                                   const cmt_string& file)
227{
228  m_PACKAGE = package;
229  m_CONSTITUENT = constituent.name;
230  m_CONSTITUENTSUFFIX = constituent.suffix;
231
232  m_PACKOS9 = constituent.need_OS9;
233
234  m_output_file_name = cmtdir + m_CONSTITUENT + ".";
235
236  if (Cmt::build_nmake ())
237    {
238      m_output_file_name += "nmake";
239    }
240  else
241    {
242      m_output_file_name += "make";
243    }
244 
245  if (file != "") m_output_file_name = file;
246
247  m_output_file_name += "new";
248
249
250  m_output_file = fopen (m_output_file_name.c_str (), "wb");
251  if (m_output_file != NULL)
252    {
253      return (true);
254    }
255  else
256    {
257      return (false);
258    }
259}
260
261//--------------------------------------------------
262void CmtGenerator::check (const cmt_string& name)
263{
264  static cmt_string old;
265  static cmt_string backup;
266
267  old = name;
268
269  int pos = old.find_last_of ("new");
270  old.erase (pos);
271
272  if (!CmtSystem::compare_files (old, name))
273    {
274      backup = old;
275      backup += "sav";
276
277      unlink (backup.c_str ());
278      rename (old.c_str (), backup.c_str ());
279      rename (name.c_str (), old.c_str ());
280    }
281  else
282    {
283      unlink (name);
284    }
285}
286
287//--------------------------------------------------
288void CmtGenerator::commit (const cmt_string& name)
289{
290  static cmt_string old;
291  static cmt_string backup;
292
293  old = name;
294
295  int pos = old.find_last_of ("new");
296  old.erase (pos);
297
298  if (CmtSystem::test_file (old))
299    {
300      backup = old;
301      backup += "sav";
302
303      unlink (backup.c_str ());
304      rename (old.c_str (), backup.c_str ());
305    }
306
307  rename (name.c_str (), old.c_str ());
308}
309
310//--------------------------------------------------
311void CmtGenerator::terminate ()
312{
313  CmtSystem::close_ostream (m_output_file, m_output_file_name);
314  //  fclose (m_output_file);
315
316  //--- Complete the operation --------------
317
318  commit (m_output_file_name);
319}
320
321//--------------------------------------------------
322void CmtGenerator::fill_names_outputs ()
323{
324  bool first = true;
325
326  m_LINE = "";
327  m_OBJS = "";
328
329  for (int i = 0; i < m_source_files.size (); i++)
330    {
331      const SourceFile& file = m_source_files[i];
332      const cmt_string name = file.name ();
333      const cmt_string output = file.output ();
334
335      if (output != "")
336        {
337          if (first)
338            {
339              first = false;
340            }
341          else
342            {
343              m_LINE += " ";
344              m_OBJS += " ";
345            }
346          m_LINE += name;
347          m_OBJS += output;
348        }
349
350      if (Cmt::get_debug ())
351        {
352          cout << "CmtGenerator::fill_names_ outputs>" << endl;
353          cout << "name=" << name << " LINE=" << m_LINE << endl;
354          cout << "output=" << output << " OBJS=" << m_OBJS << endl;
355        }
356    }
357
358  filter_path (m_LINE.value);
359}
360
361//--------------------------------------------------
362void CmtGenerator::fill_outputs ()
363{
364  bool first = true;
365
366  m_OBJS = "";
367
368  for (int i = 0; i < m_source_files.size (); i++)
369    {
370      const SourceFile& file = m_source_files[i];
371      const cmt_string output = file.output ();
372
373      if (output != "")
374        {
375          if (first)
376            {
377              first = false;
378            }
379          else
380            {
381              m_OBJS += " ";
382            }
383
384          m_OBJS += output;
385        }
386
387      if (Cmt::get_debug ())
388        {
389          cout << "CmtGenerator::fill_outputs> output=" << output << " OBJS=" << m_OBJS << endl;
390        }
391
392    }
393
394  if (Cmt::get_debug ())
395    {
396      cout << "CmtGenerator::fill_outputs> OBJS=" << m_OBJS << endl;
397    }
398
399}
400
401//--------------------------------------------------
402void CmtGenerator::prepare_use_context ()
403{
404  cmt_string path;
405  cmt_string substitution;
406
407  Use* use = &Use::current ();
408
409  m_deps_builder.clear ();
410
411  if (use->include_path != "none")
412    {
413      if (use->include_path == "")
414        {
415          m_deps_builder.add (incdir, "$(src)");
416        }
417      else
418        {
419          substitution = use->include_path;
420         
421          path = substitution;
422          Symbol::expand (path);
423         
424          CmtSystem::reduce_file_separators (path);
425
426          m_deps_builder.add (path, substitution);
427        }
428    }
429
430  m_deps_builder.add_includes (*use);
431
432  Use::UsePtrVector& uses = Use::get_ordered_uses ();
433
434  if (uses.size () > 0)
435    {
436      int number;
437
438      for (number = 0; number < uses.size (); number++)
439        {
440          use = uses[number];
441          if (use->discarded) continue;
442
443          if (use->real_path != "")
444            {
445              if (use->include_path != "none")
446                {
447                  if (use->include_path == "")
448                    {
449                      use->get_full_path (path);
450                      path += CmtSystem::file_separator ();
451                      path += "src";
452
453                      substitution = "$(";
454                      substitution += use->prefix;
455                      substitution += "ROOT)";
456                      substitution += CmtSystem::file_separator ();
457                      substitution += "src";
458                      substitution += CmtSystem::file_separator ();
459                    }
460                  else
461                    {
462                      substitution = use->include_path;
463
464                      path = substitution;
465                      Symbol::expand (path);
466
467                      CmtSystem::reduce_file_separators (path);
468                    }
469
470                  m_deps_builder.add (path, substitution);
471                }
472
473              m_deps_builder.add_includes (*use);
474            }
475        }
476    }
477}
478
479//--------------------------------------------------
480void CmtGenerator::filter_path (cmt_string& text)
481{
482  CmtSystem::compress_path (text);
483
484  text.replace_all ("./../src/../", "../");
485  text.replace_all ("./../src/", "$(src)");
486
487  text.replace_all (".\\..\\src\\..\\", "..\\");
488  text.replace_all (".\\..\\src\\", "$(src)");
489
490  text.replace_all ("../src/../", "../");
491  text.replace_all ("../src/", "$(src)");
492
493  text.replace_all ("..\\src\\..\\", "..\\");
494  text.replace_all ("..\\src\\", "$(src)");
495
496  text.replace_all ("../doc/../", "../");
497  text.replace_all ("../doc/", "$(doc)");
498
499  text.replace_all ("..\\doc\\..\\", "..\\");
500  text.replace_all ("..\\doc\\", "$(doc)");
501
502  text.replace_all ("$(src)$(src)", "$(src)");
503}
504
505/**
506   Scan a complete file spec (with possibly wild cards and directory)
507   given in full_name ad fill in a vector of found file names.
508
509   Result of the scan is filtered against matching suffixes
510
511   Returns the count of non empty file names really found.
512
513*/
514int CmtGenerator::get_all_files (const cmt_string& full_name,
515                                 const cmt_vector<cmt_regexp>& exclude_exprs,
516                                 const cmt_vector<cmt_regexp>& select_exprs,
517                                 CmtSystem::cmt_string_vector& files)
518{
519  static cmt_string suffix;
520  static cmt_string name;
521
522  bool has_excludes = false;
523  bool has_selects = false;
524
525  suffix = "";
526  name = "";
527
528  files.clear ();
529
530  has_excludes = (exclude_exprs.size () > 0);
531  has_selects = (select_exprs.size () > 0);
532
533  CmtSystem::get_dot_suffix (full_name, suffix);
534
535  bool wilcarded_suffix = false;
536
537  if (suffix == ".*") wilcarded_suffix = true;
538
539  int count = 0;
540
541  if (full_name.find ('*') != cmt_string::npos)
542    {
543      CmtSystem::scan_dir (full_name, files);
544
545      if (Cmt::get_debug ())
546        {
547          cout << "CMT::get_all_files> full_name=" << full_name <<
548            " pwd=" << CmtSystem::pwd () << endl;
549          cout << "CMT::get_all_files> files.size=" <<  files.size () << endl;
550        }
551
552      /**
553
554      We have to treat patterns of the form *.xxx (ie with a
555      suffix) thus we filter out everything that could have been
556      collected with a different suffix because the
557      CmtSystem::scan_dir function only handles patterns of the
558      form xxx* (ie with trailing *)
559
560      [If the original suffix was empty (ie files specified using
561      xx*) this means getting files without any dot-suffix. This
562      may be incorrect??]
563
564      */
565
566      for (int j = 0; j < files.size (); j++)
567        {
568          cmt_string& n = files[j];
569
570          bool rejected = false;
571
572          if (n == "")
573            {
574              rejected = true;
575            }
576
577          if (!rejected && has_selects)
578            {
579              rejected = true;
580
581              for (int k = 0; k < select_exprs.size (); k++)
582                {
583                  const cmt_regexp& exp = select_exprs[k];
584                  if (exp.match (n))
585                    {
586                      rejected = false;
587                      break;
588                    }
589                }
590            }
591
592          if (!rejected && has_excludes)
593            {
594              for (int k = 0; k < exclude_exprs.size (); k++)
595                {
596                  const cmt_regexp& exp = exclude_exprs[k];
597                  if (exp.match (n))
598                    {
599                      rejected = true;
600                      break;
601                    }
602                }
603            }
604
605          if (!rejected)
606            {
607              static cmt_string s;
608
609              CmtSystem::get_dot_suffix (n, s);
610              if (!wilcarded_suffix && (s != suffix)) 
611                {
612                  rejected = true;
613                }
614              else
615                {
616                  count++;
617                }
618            }
619
620          if (Cmt::get_debug ())
621            {
622              if (rejected)
623                {
624                  cout << "CMT::get_all_files> reject " <<  n << endl;
625                }
626              else
627                {
628                  cout << "CMT::get_all_files> keep " <<  n << endl;
629                }
630            }
631
632          if (rejected)
633            {
634              n = "";
635            }
636        }
637    }
638  else
639    {
640      if (full_name != "")
641        {
642          bool rejected = false;
643
644          if (has_excludes)
645            {
646              for (int k = 0; k < exclude_exprs.size (); k++)
647                {
648                  const cmt_regexp& exp = exclude_exprs[k];
649                  if (exp.match (full_name))
650                    {
651                      rejected = true;
652                      break;
653                    }
654                }
655            }
656
657          if (!rejected)
658            {
659              cmt_string& n = files.add ();
660
661              n = full_name;
662
663              count++;
664            }
665        }
666    }
667
668  return (count);
669}
670
671//--------------------------------------------------
672void CmtGenerator::set_full_name (cmt_string& full_name, cmt_string& file)
673{
674  full_name = "";
675
676  Symbol::expand (file);
677
678  if (file == "") return;
679 
680  if (!CmtSystem::absolute_path (file))
681    {
682      full_name = srcdir;
683      if (full_name != "") full_name += CmtSystem::file_separator ();
684    }
685 
686  full_name += file;
687
688  CmtSystem::reduce_file_separators (full_name);
689}
690
691//------------------------------------------------------------------------
692//static ApplicationGenerator ApplicationContext;
693static LibraryGenerator LibraryContext;
694static DocumentGenerator DocumentContext;
695static ReadmeGenerator ReadmeContext;
696static PrototypeGenerator PrototypeContext;
697static DefaultMakefileGenerator DefaultMakefileContext;
698static MSDEVGenerator MSDEVContext;
699static VSNETGenerator VSNETContext;
700static MakeSetupGenerator MakeSetupContext;
701static ConstituentsMakefileGenerator ConstituentsMakefileContext;
702static DependencyGenerator DependencyContext;
703
704//--------------------------------------------------
705int Generator::build_msdev_workspace (const Constituent::ConstituentVector& constituents)
706{
707  return (MSDEVContext.build_workspace (constituents));
708}
709
710//--------------------------------------------------
711int Generator::build_msdev (const Constituent& constituent)
712{
713  return (MSDEVContext.build_project (constituent));
714}
715
716//--------------------------------------------------
717int Generator::build_vsnet_workspace (const Constituent::ConstituentVector& constituents)
718{
719  return (VSNETContext.build_workspace (constituents));
720}
721
722//--------------------------------------------------   
723int Generator::build_vsnet (const Constituent& constituent)
724{
725  return (VSNETContext.build_project (constituent));
726}
727
728//--------------------------------------------------
729void Generator::build_make_setup (const cmt_string& package)
730{
731  MakeSetupContext.build (package);
732}
733
734//--------------------------------------------------
735void Generator::build_constituents_makefile (const cmt_string& package,
736                                             const cmt_string& file)
737//                                           const CmtSystem::cmt_string_vector& arguments)
738{
739  ConstituentsMakefileContext.build (package, file);
740  //  ConstituentsMakefileContext.build (package, arguments);
741}
742
743//--------------------------------------------------
744int Generator::build_constituent_infile (const Constituent& constituent,
745                                         const cmt_string& outdir,
746                                         bool usecmt)
747{
748  cmt_string file (constituent.name + ".in");
749  if (outdir != "")
750    {
751      if (outdir [outdir.size () - 1] != CmtSystem::file_separator ())
752        file = outdir + CmtSystem::file_separator () + file;
753      else
754        file = outdir + file;
755    }
756
757  static InGenerator InGen (usecmt);
758
759  bool gen (true);
760  ostringstream os;
761  ofstream s;
762  //  s.open (file);
763  s.open (file, ios::in);
764  if (s) // file already exists
765    {
766      InGen.build (constituent, os);
767      ostringstream osn;
768      osn << s.rdbuf ();
769      if (os.str () == osn.str ())
770        {
771          //      cerr << file << " up-to-date" << endl;
772          gen = false;
773        }
774    }
775  s.clear ();
776  s.close ();
777  s.clear ();
778  if (gen)
779    {
780      s.open (file);
781      if (!s)
782        {
783          CmtError::set (CmtError::file_access_error, file);
784          return -1;
785        }
786      s.exceptions (ios::failbit | ios::badbit);
787      try
788        {
789          if (os.str ().size () != 0)
790            {
791              //  cerr << file << " contents already generated" << endl;
792              s << os.str ();
793            }
794          else
795            {
796              InGen.build (constituent, s);
797            }
798          s.close (); // ios_base::failbit
799        }
800      catch (const ios::failure& e)
801        {
802          CmtSystem::close_ostream (NULL, file + ": " + cmt_string (e.what ()));
803          return -1;
804        }
805    }
806
807      //  InGen.build (constituent, s);
808
809  //  s.close (); // ios_base::failbit
810
811  return 0;
812}
813
814//--------------------------------------------------
815int Generator::build_constituent_makefile (const Constituent& constituent,
816                                           const cmt_string& file)
817{
818  const cmt_string& package = Cmt::get_current_package ();
819
820  switch (constituent.type)
821    {
822    case Application:
823      //ApplicationContext.build (package, constituent, file);
824      //break;
825    case Library:
826      LibraryContext.build (package, constituent, file);
827      break;
828    case Document:
829      DocumentContext.build (package, constituent, file);
830      break;
831    }
832
833  return (0);
834}
835
836//--------------------------------------------------
837void Generator::build_constituent_makefile (const CmtSystem::cmt_string_vector& arguments)
838{
839  cmt_string name;
840  cmt_string file;
841
842  if (arguments.size () == 1)
843    {
844      file = "";
845      name = arguments[0];
846    }
847  else if (arguments.size () == 2) // arguments[0].substr (0, 5) == "-out="
848    {
849      cmt_string arg = arguments[0];
850      arg.erase (0, 5);
851      file = arg;
852      name = arguments[1];
853    }
854  else
855    {
856      CmtMessage::error ("build constituent_makefile : wrong arguments");
857      //      cerr << "#CMT> build constituent_makefile : wrong arguments" << endl;
858      return;
859    }
860
861  const Constituent* constituent = Constituent::find (name);
862  if (constituent != 0) build_constituent_makefile (*constituent, file);
863}
864
865//--------------------------------------------------
866void Generator::build_default_makefile ()
867{
868  DefaultMakefileContext.build ();
869}
870
871//--------------------------------------------------
872void Generator::build_dependencies (const CmtSystem::cmt_string_vector& arguments)
873{
874  DependencyContext.build (arguments);
875}
876
877//--------------------------------------------------
878void Generator::build_prototype (const cmt_string& file_name)
879{
880  PrototypeContext.build (file_name);
881}
882
883//--------------------------------------------------
884void Generator::build_readme (const CmtSystem::cmt_string_vector& arguments)
885{
886  ReadmeContext.build (arguments);
887}
888
889class WinDefAwk : public PAwk
890{
891public :
892  WinDefAwk (const cmt_string& library_name)
893  {
894    m_name = library_name;
895  }
896
897  void begin ()
898  {
899    cout << "LIBRARY " << m_name << endl;
900    cout << "EXPORTS" << endl;
901  }
902
903  void filter (const cmt_string& line)
904  {
905    if (line.find ("External") == cmt_string::npos) return;
906    if (line.find ("??_") != cmt_string::npos)
907      {
908        if (line.find ("operator/=") == cmt_string::npos) return;
909        // Keep operator /= .
910      }
911
912    CmtSystem::cmt_string_vector words;
913    CmtSystem::split (line, " \t", words);
914    if (words.size () >= 7)
915      {
916        int pos = 7;
917
918        cmt_string& fifth_word = words[4];
919        if (fifth_word == "()") pos = 7;
920        else if (fifth_word == "External") pos = 6;
921        else return;
922
923        cmt_string& symbol = words[pos];
924        if (symbol[0] == '_') symbol.erase (0, 1);
925        symbol.replace_all ("\r", "");
926        symbol.replace_all ("\n", "");
927
928        if ((pos == 6) && 
929            ((line.find(": static") != cmt_string::npos) ||
930             (line.find("(class") != cmt_string::npos)) )
931          {
932            // static data members are not DATA :
933            // extern objects are not DATA :
934            cout << " " << symbol << " " << endl;
935          } 
936        else if (pos == 6)
937          {
938            // DATA :
939            cout << " " << symbol << "\tDATA" << endl;
940          } 
941        else
942          {
943            // code :
944            cout << " " << symbol << " " << endl;
945          } 
946      }
947  }
948
949  void end ()
950  {
951  }
952
953private:
954  cmt_string m_name;
955};
956
957//--------------------------------------------------
958//void Generator::build_windefs (const cmt_string& library_name)
959void Generator::build_windefs (const CmtSystem::cmt_string_vector& arguments)
960{
961  cmt_string name;
962  //  CmtSystem::cmt_string_vector files;
963  cmt_string files;
964
965  for (int i = 0; i < arguments.size (); i++)
966    {
967      const cmt_string& w = arguments[i];
968      if (w.substr (0, 6) == "-name=" || w.substr (0, 6) == "-name:" ||
969          w.substr (0, 6) == "/name:" || w.substr (0, 6) == "/name=")
970        w.substr (6, name);
971      else if (w.substr (0, 1) == "@" && w.size () > 1)
972        {
973          cmt_string commandfile;
974          w.substr (1, commandfile);
975          if (!CmtSystem::test_file (commandfile))
976            {
977              CmtMessage::warning ("No such file `" + commandfile + "'.");
978              continue;
979            }
980          cmt_string text;
981          if (!text.read (commandfile))
982            {
983              CmtMessage::warning ("Could not read `" + commandfile + "'.");
984              continue;
985            }
986          text.replace_all ("\r", " ");
987          text.replace_all ("\n", " ");
988          files += " " + text;
989          /*
990          CmtSystem::cmt_string_vector words;
991          CmtSystem::split (text, " \t", words);
992          for (int i = 0; i < words.size (); i++)
993            {
994              files.push_back (words[i]);
995            }
996          */
997        }
998      else
999        files += " " + w;
1000      //        files.push_back (w);
1001    }
1002
1003  if (files.size () == 0)
1004    {
1005      CmtMessage::error ("build_windefs: no files specified");
1006      return;
1007    }
1008  if (name == "")
1009    {
1010      CmtSystem::cmt_string_vector words;
1011      CmtSystem::split (files, " \t", words);
1012      if (words.size () == 0)
1013        {
1014          CmtMessage::error ("build_windefs: no files specified");
1015          return;
1016        }
1017      cmt_string suffix;
1018      CmtSystem::get_dot_suffix (words[0], suffix);
1019      CmtSystem::basename (words[0], suffix, name);
1020    }
1021  if (name == "")
1022    {
1023      CmtMessage::error ("build_windefs: cannot determine library name");
1024      return;
1025    }
1026
1027  //  cmt_string bin;
1028
1029  //  CmtSystem::dirname (library_name, bin);
1030  //  CmtSystem::get_dot_suffix (library_name, suffix);
1031  //  CmtSystem::basename (library_name, suffix, name);
1032 
1033  //  if (!CmtSystem::cd (bin)) return;
1034 
1035  //  cmt_string command;
1036 
1037  cmt_string command ("dumpbin /symbols");
1038  //  command += library_name;
1039  /*
1040  for (int i = 0; i < files.size (); i++)
1041    {
1042      command += " " + files[i];
1043    }
1044  */
1045  command += " " + files;
1046       
1047  WinDefAwk filter (name);
1048 
1049  filter.run (command, "SECT");
1050}
1051
1052//--------------------------------------------------
1053void Packager::begin ()
1054{
1055  m_package_name = "";
1056}
1057
1058void Packager::filter (const cmt_string& line)
1059{
1060  CmtSystem::cmt_string_vector words;
1061
1062  CmtSystem::split (line, " ", words);
1063  if (words.size () > 1)
1064    {
1065      cmt_string& w = words[0];
1066
1067      if (w == "package")
1068        {
1069          m_package_name = words[1];
1070
1071          int pos = m_package_name.find (";");
1072          if (pos != cmt_string::npos) m_package_name.erase (pos);
1073          m_package_name.replace_all (".", CmtSystem::file_separator ());
1074        }
1075    }
1076}
1077
1078cmt_string& Packager::package_name ()
1079{
1080  return (m_package_name);
1081}
1082
1083//------------------------------------------------------------------------
1084InGenerator::Buffer::Buffer ()
1085  : m_initialized (false), m_usecmt (true)
1086{ }
1087
1088//------------------------------------------------------------------------
1089void InGenerator::Buffer::set_names (const CmtSystem::cmt_string_vector& names)
1090{
1091  m_names = names;
1092}
1093
1094//------------------------------------------------------------------------
1095int InGenerator::Buffer::print (ostream& s)
1096{
1097  initialize ();
1098  s << m_buffer.str ();
1099  return 0;
1100}
1101
1102//------------------------------------------------------------------------
1103void InGenerator::Buffer::set_uses (bool usecmt)
1104{
1105  m_usecmt = usecmt;
1106}
1107
1108//------------------------------------------------------------------------
1109int InGenerator::Languages::initialize ()
1110{
1111  int errors (0);
1112  if (m_initialized) return - errors;
1113  m_initialized = true;
1114  for (int i = 0; i < m_names.size (); i++)
1115    {
1116      const cmt_string& name = m_names[i];
1117      Language& p (Language::find (name));
1118      if (Language::null () == p) { errors += 1; continue; }
1119      p.show (Requirements, m_buffer);
1120      /*
1121      if (!p->use->get_package ()->is_cmt ())
1122        p->print (Requirements, m_buffer);
1123      */
1124    }
1125  //  cerr << "Languages::initialize: " << m_buffer.str ();
1126  return - errors;
1127}
1128
1129//------------------------------------------------------------------------
1130int InGenerator::Fragments::initialize ()
1131{
1132  int errors (0);
1133  if (m_initialized) return - errors;
1134  m_initialized = true;
1135  for (int i = 0; i < m_names.size (); i++)
1136    {
1137      const cmt_string& name = m_names[i];
1138      Fragment* fragment (Fragment::find (name));
1139      if (0 == fragment) { errors += 1; continue; }
1140      if (m_usecmt || !fragment->use->get_package ()->is_cmt ())
1141        fragment->print (Requirements, m_buffer);
1142    }
1143  //  cerr << "initialize: " << m_buffer.str ();
1144  return - errors;
1145}
1146
1147//------------------------------------------------------------------------
1148InGenerator::InGenerator (bool usecmt)
1149  : m_usecmt (usecmt)
1150{
1151  CmtSystem::cmt_string_vector common;
1152  common.push_back ("make_header");
1153  common.push_back ("dependencies");
1154  common.push_back ("cleanup_header");
1155  m_common.set_names (common);
1156  m_common.set_uses (usecmt);
1157
1158  CmtSystem::cmt_string_vector application;
1159  application.push_back ("java_header");
1160  application.push_back ("application_header");
1161  application.push_back ("application");
1162  application.push_back ("check_java");
1163  application.push_back ("cleanup_application");
1164  application.push_back ("cleanup_objects");
1165  application.push_back ("check_application");
1166
1167  CmtSystem::cmt_string_vector application_library;
1168  application_library.push_back ("protos_header");
1169  application_library.push_back ("buildproto");
1170  application_library.push_back ("dependencies_and_triggers");
1171  application_library.push_back ("java");
1172  application_library.push_back ("java_copy");
1173  application_library.push_back ("cleanup");
1174  application_library.push_back ("cleanup_java");
1175  m_application_library.set_names (application_library);
1176  m_application_library.set_uses (usecmt);
1177
1178  CmtSystem::cmt_string_vector library;
1179  library.push_back ("jar_header");
1180  library.push_back ("library_header");
1181  library.push_back ("jar");
1182  library.push_back ("library_no_share");
1183  library.push_back ("library_no_static");
1184  library.push_back ("library");
1185  library.push_back ("cleanup_library");
1186
1187  CmtSystem::cmt_string_vector languages;
1188  Language::LanguageVector& Languages = Language::languages ();
1189  for (int n = 0; n < Languages.size (); n++)
1190    {
1191      Language& language = Languages[n];
1192      //language.setup_fragments ();
1193      application.push_back (language.fragment_name); //application.name ();
1194      library.push_back (language.fragment_name + "_library"); //library.name ();
1195      if (m_usecmt || !language.m_use->get_package ()->is_cmt ())
1196//       if (!language.m_use->get_package ()->is_cmt ())
1197        {
1198          languages.push_back (language.m_name);
1199        }
1200      else if (language.dependencies_options () !=
1201          language.dependencies_options_expanded ())
1202        {
1203          languages.push_back (language.m_name);
1204        }
1205    }
1206  m_languages.set_names (languages);
1207  m_languages.set_uses (usecmt);
1208  m_application.set_names (application);
1209  m_application.set_uses (usecmt);
1210  m_library.set_names (library);
1211  m_library.set_uses (usecmt);
1212 
1213  CmtSystem::cmt_string_vector document;
1214  document.push_back ("document_header");
1215  m_document.set_names (document);
1216  m_document.set_uses (usecmt);
1217}
1218
1219//------------------------------------------------------------------------
1220int InGenerator::build (const Constituent& constituent, ostream& s)
1221{
1222  constituent.show (s);
1223  m_common.print (s);
1224
1225  switch (constituent.type)
1226    {
1227    case Application:
1228      m_application.print (s);
1229      m_application_library.print (s);
1230      m_languages.print (s);
1231      break;
1232    case Library:
1233      m_application_library.print (s);
1234      m_library.print (s);
1235      m_languages.print (s);
1236      break;
1237    case Document:
1238      Fragment* fragment (Fragment::find (constituent.generator));
1239      if (0 == fragment) return -1;
1240      if (m_usecmt || !fragment->use->get_package ()->is_cmt ())
1241        fragment->print (Requirements, s);
1242      if ("" != fragment->header)
1243        {
1244          Fragment* header (Fragment::find (fragment->header));
1245          if (0 == header) return -1;
1246          //      if (header->use != fragment->use &&
1247          if (m_usecmt || !header->use->get_package ()->is_cmt ())
1248            header->print (Requirements, s);
1249        }
1250      if ("" != fragment->trailer)
1251        {
1252          Fragment* trailer (Fragment::find (fragment->trailer));
1253          if (0 == trailer) return -1;
1254          //      if (trailer->use != fragment->use &&
1255          if (m_usecmt || !trailer->use->get_package ()->is_cmt ())
1256            trailer->print (Requirements, s);
1257        }
1258      m_document.print (s);
1259      break;
1260    }
1261
1262  return 0;
1263}
1264//------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.