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

Last change on this file since 488 was 488, checked in by rybkin, 15 years ago

See C.L. 383

  • Property svn:eol-style set to native
File size: 22.7 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
21//------------------------------------------------------------------------
22void SourceFile::set (const cmt_string name, Language& language, const cmt_string output)
23{
24  m_name = name;
25  m_language = &language;
26  m_output = output;
27 
28  CmtSystem::reduce_file_separators (m_name);
29}
30
31cmt_string SourceFile::name () const
32{
33  return (m_name);
34}
35
36Language& SourceFile::language () const
37{
38  return (*m_language);
39}
40
41cmt_string SourceFile::output () const
42{
43  return (m_output);
44}
45//------------------------------------------------------------------------
46
47//--------------------------------------------------
48CmtGenerator::CmtGenerator ()
49{
50  m_CONSTITUENT.set ("CONSTITUENT");
51  m_LINKMACRO.set ("LINKMACRO");
52  m_DEPENDENCIESOPTS.set ("DEPENDENCIESOPTS");
53  m_DOCPATH.set ("DOCPATH");
54  m_PACKAGEPATH.set ("PACKAGEPATH");
55  m_PACKAGEPREFIX.set ("PACKAGEPREFIX");
56  m_PACKAGE.set ("PACKAGE");
57  m_VERSION.set ("VERSION");
58  m_MGRSTYLE.set ("MGRSTYLE");
59  m_TITLE.set ("TITLE");
60  m_GROUP.set ("GROUP");
61  m_CONSTITUENT.set ("CONSTITUENT");
62  m_CONSTITUENTSUFFIX.set ("CONSTITUENTSUFFIX");
63  m_LIBRARYSUFFIX.set ("LIBRARYSUFFIX");
64  m_USER.set ("USER");
65  m_DATE.set ("DATE");
66  m_PROTOTARGET.set ("PROTOTARGET");
67  m_OBJS.set ("OBJS");
68  m_CLASSES.set ("CLASSES");
69  m_PROTOSTAMPS.set ("PROTOSTAMPS");
70  m_NAME.set ("NAME");
71  m_FILEPATH.set ("FILEPATH");
72  m_FILESUFFIX.set ("FILESUFFIX");
73  m_SUFFIX.set ("SUFFIX");
74  m_FILENAME.set ("FILENAME");
75  //  m_LINKMACRO.set ("LINKMACRO");
76  m_LINE.set ("LINE");
77  m_ADDINCLUDE.set ("ADDINCLUDE");
78  m_FULLNAME.set ("FULLNAME");
79  m_DIRNAME.set ("DIRNAME");
80  m_OUTPUTNAME.set ("OUTPUTNAME");
81  m_ALLOS9SOURCES.set ("ALLOS9SOURCES");
82  m_NODEBUGUSELINKOPTS.set ("NODEBUGUSELINKOPTS");
83  m_DEBUGUSELINKOPTS.set ("DEBUGUSELINKOPTS");
84  m_USEINCLUDES.set ("USEINCLUDES");
85  m_HASTARGETTAG.set ("HASTARGETTAG");
86  m_HASDEPENDENCIES.set ("HASDEPENDENCIES");
87}
88
89//--------------------------------------------------
90void CmtGenerator::reset ()
91{
92  m_CONSTITUENT = "";
93  m_LINKMACRO = "";
94  m_DEPENDENCIESOPTS = "";
95  m_DOCPATH = "";
96  m_PACKAGEPATH = "";
97  m_PACKAGEPREFIX = "";
98  m_PACKAGE = "";
99  m_VERSION = "";
100  m_MGRSTYLE = "";
101  m_TITLE = "";
102  m_GROUP = "";
103  m_CONSTITUENTSUFFIX = "";
104  m_LIBRARYSUFFIX = "";
105  m_USER = "";
106  m_DATE = "";
107  m_PROTOTARGET = "";
108  m_OBJS = "";
109  m_CLASSES = "";
110  m_PROTOSTAMPS = "";
111  m_NAME = "";
112  m_FILEPATH = "";
113  m_FILESUFFIX = "";
114  m_SUFFIX = "";
115  m_FILENAME = "";
116  m_LINE = "";
117  m_ADDINCLUDE = "";
118  m_FULLNAME = "";
119  m_OUTPUTNAME = "";
120  m_ALLOS9SOURCES = "";
121  m_NODEBUGUSELINKOPTS = "";
122  m_DEBUGUSELINKOPTS = "";
123  m_USEINCLUDES = "";
124  m_HASTARGETTAG = "";
125  m_HASDEPENDENCIES = "";
126  m_PACKINCLUDES = "";
127  m_PACKOS9      = false;
128  m_GENERATOR    = "";
129
130  is_library     = false;
131  is_application = false;
132  srcdir       = "";
133  docdir       = "";
134  cmtdir       = "";
135  incdir       = "";
136  src          = "$(src)";
137  doc          = "$(doc)";
138  inc          = "$(inc)";
139  mgr          = "$(mgr)";
140  cmt          = "$(cmt)";
141  protos       = "";
142  protonames   = "";
143  os9sources   = "";
144
145  m_source_files.clear ();
146
147  Language::setup_all_fragments ();
148
149  CmtSystem::cd (Cmt::get_current_dir ());
150
151  cmt_string branch = CmtSystem::current_branch ();
152
153  if ((branch == "mgr") || (branch == "cmt"))
154    {
155      if (CmtSystem::test_directory ("../src"))
156        {
157          srcdir = "..";
158          srcdir += CmtSystem::file_separator ();
159          srcdir += "src";
160          srcdir += CmtSystem::file_separator ();
161        }
162      else
163        {
164          srcdir = "";
165        }
166
167      if (CmtSystem::test_directory ("../doc"))
168        {
169          docdir = "..";
170          docdir += CmtSystem::file_separator ();
171          docdir += "doc";
172          docdir += CmtSystem::file_separator ();
173        }
174      else
175        {
176          docdir = "";
177        }
178
179      if (CmtSystem::test_directory ("../cmt"))
180        {
181          cmtdir = "..";
182          cmtdir += CmtSystem::file_separator ();
183          cmtdir += "cmt";
184          cmtdir += CmtSystem::file_separator ();
185        }
186      else if (CmtSystem::test_directory ("../mgr"))
187        {
188          cmtdir = "..";
189          cmtdir += CmtSystem::file_separator ();
190          cmtdir += "mgr";
191          cmtdir += CmtSystem::file_separator ();
192        }
193      else
194        {
195          cmtdir = CmtSystem::pwd ();
196          cmtdir += CmtSystem::file_separator ();
197        }
198
199      if (CmtSystem::test_directory ("../src"))
200        {
201          incdir = "..";
202          incdir += CmtSystem::file_separator ();
203          incdir += "src";
204          incdir += CmtSystem::file_separator ();
205        }
206      else
207        {
208          incdir = "";
209        }
210    }
211  else
212    {
213      srcdir = ".";
214      srcdir += CmtSystem::file_separator ();
215      docdir = ".";
216      docdir += CmtSystem::file_separator ();
217      cmtdir = CmtSystem::pwd ();
218      cmtdir += CmtSystem::file_separator ();
219      incdir = ".";
220      incdir += CmtSystem::file_separator ();
221    }
222}
223
224//--------------------------------------------------
225bool CmtGenerator::prepare_output (const cmt_string& package,
226                                   const Constituent& constituent,
227                                   const cmt_string& file)
228{
229  m_PACKAGE = package;
230  m_CONSTITUENT = constituent.name;
231  m_CONSTITUENTSUFFIX = constituent.suffix;
232
233  m_PACKOS9 = constituent.need_OS9;
234
235  m_output_file_name = cmtdir + m_CONSTITUENT + ".";
236
237  if (Cmt::build_nmake ())
238    {
239      m_output_file_name += "nmake";
240    }
241  else
242    {
243      m_output_file_name += "make";
244    }
245 
246  if (file != "") m_output_file_name = file;
247
248  m_output_file_name += "new";
249
250
251  m_output_file = fopen (m_output_file_name.c_str (), "wb");
252  if (m_output_file != NULL)
253    {
254      return (true);
255    }
256  else
257    {
258      return (false);
259    }
260}
261
262//--------------------------------------------------
263void CmtGenerator::check (const cmt_string& name)
264{
265  static cmt_string old;
266  static cmt_string backup;
267
268  old = name;
269
270  int pos = old.find_last_of ("new");
271  old.erase (pos);
272
273  if (!CmtSystem::compare_files (old, name))
274    {
275      backup = old;
276      backup += "sav";
277
278      unlink (backup.c_str ());
279      rename (old.c_str (), backup.c_str ());
280      rename (name.c_str (), old.c_str ());
281    }
282  else
283    {
284      unlink (name);
285    }
286}
287
288//--------------------------------------------------
289void CmtGenerator::commit (const cmt_string& name)
290{
291  static cmt_string old;
292  static cmt_string backup;
293
294  old = name;
295
296  int pos = old.find_last_of ("new");
297  old.erase (pos);
298
299  if (CmtSystem::test_file (old))
300    {
301      backup = old;
302      backup += "sav";
303
304      unlink (backup.c_str ());
305      rename (old.c_str (), backup.c_str ());
306    }
307
308  rename (name.c_str (), old.c_str ());
309}
310
311//--------------------------------------------------
312void CmtGenerator::terminate ()
313{
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//------------------------------------------------------------------------
692static 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 CmtSystem::cmt_string_vector& arguments)
737{
738  ConstituentsMakefileContext.build (package, arguments);
739}
740
741//--------------------------------------------------
742int Generator::build_constituent_makefile (const Constituent& constituent,
743                                           const cmt_string& file)
744{
745  const cmt_string& package = Cmt::get_current_package ();
746
747  switch (constituent.type)
748    {
749    case Application:
750      ApplicationContext.build (package, constituent, file);
751      break;
752    case Library:
753      LibraryContext.build (package, constituent, file);
754      break;
755    case Document:
756      DocumentContext.build (package, constituent, file);
757      break;
758    }
759
760  return (0);
761}
762
763//--------------------------------------------------
764void Generator::build_constituent_makefile (const CmtSystem::cmt_string_vector& arguments)
765{
766  cmt_string name;
767  cmt_string file;
768
769  if (arguments.size () == 1)
770    {
771      file = "";
772      name = arguments[0];
773    }
774  else if (arguments.size () == 2) // arguments[0].substr (0, 5) == "-out="
775    {
776      cmt_string arg = arguments[0];
777      arg.erase (0, 5);
778      file = arg;
779      name = arguments[1];
780    }
781  else
782    {
783      CmtMessage::error ("build constituent_makefile : wrong arguments");
784      //      cerr << "#CMT> build constituent_makefile : wrong arguments" << endl;
785      return;
786    }
787
788  const Constituent* constituent = Constituent::find (name);
789  if (constituent != 0) build_constituent_makefile (*constituent, file);
790}
791
792//--------------------------------------------------
793void Generator::build_default_makefile ()
794{
795  DefaultMakefileContext.build ();
796}
797
798//--------------------------------------------------
799void Generator::build_dependencies (const CmtSystem::cmt_string_vector& arguments)
800{
801  DependencyContext.build (arguments);
802}
803
804//--------------------------------------------------
805void Generator::build_prototype (const cmt_string& file_name)
806{
807  PrototypeContext.build (file_name);
808}
809
810//--------------------------------------------------
811void Generator::build_readme (const CmtSystem::cmt_string_vector& arguments)
812{
813  ReadmeContext.build (arguments);
814}
815
816class WinDefAwk : public PAwk
817{
818public :
819  WinDefAwk (const cmt_string& library_name)
820  {
821    m_name = library_name;
822  }
823
824  void begin ()
825  {
826    cout << "LIBRARY " << m_name << endl;
827    cout << "EXPORTS" << endl;
828  }
829
830  void filter (const cmt_string& line)
831  {
832    if (line.find ("External") == cmt_string::npos) return;
833    if (line.find ("??_") != cmt_string::npos)
834      {
835        if (line.find ("operator/=") == cmt_string::npos) return;
836        // Keep operator /= .
837      }
838
839    CmtSystem::cmt_string_vector words;
840    CmtSystem::split (line, " \t", words);
841    if (words.size () >= 7)
842      {
843        int pos = 7;
844
845        cmt_string& fifth_word = words[4];
846        if (fifth_word == "()") pos = 7;
847        else if (fifth_word == "External") pos = 6;
848        else return;
849
850        cmt_string& symbol = words[pos];
851        if (symbol[0] == '_') symbol.erase (0, 1);
852        symbol.replace_all ("\r", "");
853        symbol.replace_all ("\n", "");
854
855        if ((pos == 6) && 
856            ((line.find(": static") != cmt_string::npos) ||
857             (line.find("(class") != cmt_string::npos)) )
858          {
859            // static data members are not DATA :
860            // extern objects are not DATA :
861            cout << " " << symbol << " " << endl;
862          } 
863        else if (pos == 6)
864          {
865            // DATA :
866            cout << " " << symbol << "\tDATA" << endl;
867          } 
868        else
869          {
870            // code :
871            cout << " " << symbol << " " << endl;
872          } 
873      }
874  }
875
876  void end ()
877  {
878  }
879
880private:
881  cmt_string m_name;
882};
883
884//--------------------------------------------------
885//void Generator::build_windefs (const cmt_string& library_name)
886void Generator::build_windefs (const CmtSystem::cmt_string_vector& arguments)
887{
888  cmt_string name;
889  //  CmtSystem::cmt_string_vector files;
890  cmt_string files;
891
892  for (int i = 0; i < arguments.size (); i++)
893    {
894      const cmt_string& w = arguments[i];
895      if (w.substr (0, 6) == "-name=" || w.substr (0, 6) == "-name:" ||
896          w.substr (0, 6) == "/name:" || w.substr (0, 6) == "/name=")
897        w.substr (6, name);
898      else if (w.substr (0, 1) == "@" && w.size () > 1)
899        {
900          cmt_string commandfile;
901          w.substr (1, commandfile);
902          if (!CmtSystem::test_file (commandfile))
903            {
904              CmtMessage::warning ("No such file `" + commandfile + "'.");
905              continue;
906            }
907          cmt_string text;
908          if (!text.read (commandfile))
909            {
910              CmtMessage::warning ("Could not read `" + commandfile + "'.");
911              continue;
912            }
913          text.replace_all ("\r", " ");
914          text.replace_all ("\n", " ");
915          files += " " + text;
916          /*
917          CmtSystem::cmt_string_vector words;
918          CmtSystem::split (text, " \t", words);
919          for (int i = 0; i < words.size (); i++)
920            {
921              files.push_back (words[i]);
922            }
923          */
924        }
925      else
926        files += " " + w;
927      //        files.push_back (w);
928    }
929
930  if (files.size () == 0)
931    {
932      CmtMessage::error ("build_windefs: no files specified");
933      return;
934    }
935  if (name == "")
936    {
937      CmtSystem::cmt_string_vector words;
938      CmtSystem::split (files, " \t", words);
939      if (words.size () == 0)
940        {
941          CmtMessage::error ("build_windefs: no files specified");
942          return;
943        }
944      cmt_string suffix;
945      CmtSystem::get_dot_suffix (words[0], suffix);
946      CmtSystem::basename (words[0], suffix, name);
947    }
948  if (name == "")
949    {
950      CmtMessage::error ("build_windefs: cannot determine library name");
951      return;
952    }
953
954  //  cmt_string bin;
955
956  //  CmtSystem::dirname (library_name, bin);
957  //  CmtSystem::get_dot_suffix (library_name, suffix);
958  //  CmtSystem::basename (library_name, suffix, name);
959 
960  //  if (!CmtSystem::cd (bin)) return;
961 
962  //  cmt_string command;
963 
964  cmt_string command ("dumpbin /symbols");
965  //  command += library_name;
966  /*
967  for (int i = 0; i < files.size (); i++)
968    {
969      command += " " + files[i];
970    }
971  */
972  command += " " + files;
973       
974  WinDefAwk filter (name);
975 
976  filter.run (command, "SECT");
977}
978
979//--------------------------------------------------
980void Packager::begin ()
981{
982  m_package_name = "";
983}
984
985void Packager::filter (const cmt_string& line)
986{
987  CmtSystem::cmt_string_vector words;
988
989  CmtSystem::split (line, " ", words);
990  if (words.size () > 1)
991    {
992      cmt_string& w = words[0];
993
994      if (w == "package")
995        {
996          m_package_name = words[1];
997
998          int pos = m_package_name.find (";");
999          if (pos != cmt_string::npos) m_package_name.erase (pos);
1000          m_package_name.replace_all (".", CmtSystem::file_separator ());
1001        }
1002    }
1003}
1004
1005cmt_string& Packager::package_name ()
1006{
1007  return (m_package_name);
1008}
1009
Note: See TracBrowser for help on using the repository browser.