source: CMT/v1r20p20081118/source/cmt_generator.cxx @ 597

Last change on this file since 597 was 474, checked in by rybkin, 16 years ago

See C.L. 375

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