Ignore:
Timestamp:
Nov 27, 2011, 4:36:15 PM (13 years ago)
Author:
rybkin
Message:

See C.L. 465

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/source/cmt_generator.cxx

    r561 r588  
    1919#include "cmt_log.h"
    2020#include "cmt_error.h"
     21
     22#include "cmt_install_area.h"
    2123
    2224//------------------------------------------------------------------------
     
    143145
    144146  m_source_files.clear ();
     147  m_bin = "";
     148  m_output_file_name = "";
     149  m_output_file = 0;
     150  m_constituent = 0;
    145151
    146152  Language::setup_all_fragments ();
     
    350356      if (Cmt::get_debug ())
    351357        {
    352           cout << "CmtGenerator::fill_names_ outputs>" << endl;
     358          cout << "CmtGenerator::fill_names_outputs>" << endl;
    353359          cout << "name=" << name << " LINE=" << m_LINE << endl;
    354360          cout << "output=" << output << " OBJS=" << m_OBJS << endl;
     
    399405}
    400406
     407/*
    401408//--------------------------------------------------
    402409void CmtGenerator::prepare_use_context ()
     
    476483    }
    477484}
    478 
     485*/
    479486//--------------------------------------------------
    480487void CmtGenerator::filter_path (cmt_string& text)
     
    700707static MakeSetupGenerator MakeSetupContext;
    701708static ConstituentsMakefileGenerator ConstituentsMakefileContext;
     709static PackagesMakefileGenerator PackagesMakefileContext;
    702710static DependencyGenerator DependencyContext;
    703711
     
    813821
    814822//--------------------------------------------------
     823int Generator::build_library_links_infile (const cmt_string& outdir)
     824{
     825#ifndef WIN32
     826  cmt_string file ("library_links.in");
     827  if (outdir != "")
     828    {
     829      if (outdir [outdir.size () - 1] != CmtSystem::file_separator ())
     830        file = outdir + CmtSystem::file_separator () + file;
     831      else
     832        file = outdir + file;
     833    }
     834
     835  bool wrote (false);
     836  ostringstream ls;
     837
     838  Use::UsePtrVector& Uses = Use::get_ordered_uses ();
     839  Use& current_use = Use::current ();
     840  Use::UsePtrVector uses (Uses);
     841  uses.push_back (&Use::current ());
     842
     843  cmt_string shlibsuffix;
     844  {
     845    Symbol* macro = Symbol::find ("shlibsuffix");
     846    if (macro == 0)
     847      {
     848        CmtError::set(CmtError::configuration_error, "shlibsuffix undefined");
     849        return -1;
     850      }
     851    shlibsuffix = macro->build_macro_value ();
     852    Symbol::expand (shlibsuffix);
     853  }
     854
     855  for (int i = 0; i < uses.size (); i++)
     856    {
     857      Use* use = uses[i];
     858
     859      if (use == 0) continue;
     860      if (use->discarded) continue;
     861      if (use->m_hidden) continue;
     862
     863      if (use->get_package_name () == "CMT") continue;
     864      if (!use->located ()) continue;
     865      //use->remove_library_links (cmtinstallarea, tag, shlibsuffix, symunlinkcmd);
     866      cmt_string s (use->get_package_name ());
     867      s += "_libraries";
     868      const Symbol* libraries_macro = Symbol::find (s);
     869      if (libraries_macro == 0) continue;
     870      cmt_string libraries = libraries_macro->build_macro_value ();
     871      Symbol::expand (libraries);
     872      static CmtSystem::cmt_string_vector values;
     873     
     874      CmtSystem::split (libraries, " \t", values);
     875     
     876      for (int j = 0; j < values.size (); j++)
     877        {
     878          const cmt_string& library = values[j];
     879         
     880          static cmt_string libname;
     881          static cmt_string name;
     882         
     883          // Is it a simple name or a complete path?
     884         
     885          libname = library;
     886          Symbol::expand (libname);
     887          if (0 == libname.size ()) continue;
     888         
     889          CmtSystem::cmt_string_vector paths;
     890          use->absolute_library_path (libname,
     891                                      shlibsuffix,
     892                                      paths);
     893          for (int k = 0; k < paths.size (); k++)
     894            {
     895              cmt_string path (paths[k]);
     896              Symbol::expand (path);
     897              if (0 == path.size ()) continue;
     898              if (wrote) ls << " ";
     899              else wrote = true;
     900              ls << CmtSystem::quote (path, " \t");
     901            }
     902        }
     903    }
     904  ostringstream os;
     905  if (wrote)
     906    {
     907      os << "macro ";
     908      os << current_use.get_package_name () + "_libraries ";
     909      os << CmtSystem::quote (ls.str ().c_str (), " \t");
     910      os << "\n";
     911
     912      os << "macro shlibsuffix ";
     913      os << CmtSystem::quote (shlibsuffix, " \t");
     914      os << "\n";
     915
     916      cmt_string symlinkcmd;
     917      {
     918        Symbol* macro = Symbol::find ("library_install_command");
     919        if (macro != 0)
     920          {
     921            symlinkcmd = macro->build_macro_value ();
     922            Symbol::expand (symlinkcmd);
     923          }
     924      }
     925      os << "macro library_install_command ";
     926      os << CmtSystem::quote (symlinkcmd, " \t");
     927      os << "\n";
     928
     929      cmt_string symunlinkcmd;
     930      {
     931        Symbol* macro = Symbol::find ("symunlink");
     932        if (macro != 0)
     933          {
     934            symunlinkcmd = macro->build_macro_value ();
     935            Symbol::expand (symunlinkcmd);
     936          }
     937      }
     938      os << "macro symunlink ";
     939      os << CmtSystem::quote (symunlinkcmd, " \t");
     940      os << "\n";
     941
     942      if (current_use.get_strategy ("InstallArea"))
     943        {
     944          os << "build_strategy with_installarea\n";
     945
     946          const CmtInstallAreaMgr& ia_mgr = CmtInstallAreaMgr::instance ();
     947         
     948          cmt_string cmtinstallarea = ia_mgr.get_installarea ();
     949          {
     950            Symbol* symbol = Symbol::find ("CMTINSTALLAREA");
     951            if (symbol != 0)
     952              {
     953                cmtinstallarea = symbol->build_macro_value ();
     954                Symbol::expand (cmtinstallarea);
     955              }
     956          }
     957          os << "macro CMTINSTALLAREA ";
     958          os << CmtSystem::quote (cmtinstallarea, " \t");
     959          os << "\n";
     960
     961          cmt_string tag;
     962          {
     963            Symbol* macro = Symbol::find ("tag");
     964            if (macro != 0)
     965              {
     966                tag = macro->build_macro_value ();
     967                Symbol::expand (tag);
     968              }
     969          }
     970          os << "macro tag ";
     971          os << CmtSystem::quote (tag, " \t");
     972          os << "\n";
     973        }
     974      //      cerr << os.str ();
     975    }
     976
     977  // Write input requirements file
     978
     979  //  static InGenerator InGen (usecmt);
     980
     981  bool gen (true);
     982  //  ostringstream os;
     983  ofstream s;
     984  //  s.open (file);
     985  s.open (file, ios::in);
     986  if (s) // file already exists
     987    {
     988      //      InGen.build (constituent, os);
     989      ostringstream osn;
     990      osn << s.rdbuf ();
     991      if (os.str () == osn.str ())
     992        {
     993          //      cerr << file << " up-to-date" << endl;
     994          gen = false;
     995        }
     996    }
     997  s.clear ();
     998  s.close ();
     999  s.clear ();
     1000  if (gen)
     1001    {
     1002      s.open (file);
     1003      if (!s)
     1004        {
     1005          CmtError::set (CmtError::file_access_error, file);
     1006          return -1;
     1007        }
     1008      s.exceptions (ios::failbit | ios::badbit);
     1009      try
     1010        {
     1011          //      if (os.str ().size () != 0)
     1012          //        {
     1013              //  cerr << file << " contents already generated" << endl;
     1014              s << os.str ();
     1015              //            }
     1016              //          else
     1017              //            {
     1018              //              InGen.build (constituent, s);
     1019              //            }
     1020          s.close (); // ios_base::failbit
     1021        }
     1022      catch (const ios::failure& e)
     1023        {
     1024          CmtSystem::close_ostream (NULL, file + ": " + cmt_string (e.what ()));
     1025          return -1;
     1026        }
     1027    }
     1028
     1029#endif
     1030  return 0;
     1031}
     1032
     1033//--------------------------------------------------
     1034int Generator::build_dependencies_infile (const Constituent* pconstituent,
     1035                                          const cmt_string& outdir,
     1036                                          bool usecmt)
     1037{
     1038  cmt_string file ("dependencies");
     1039  if (0 != pconstituent)
     1040    file += "_" + pconstituent->name;
     1041  file += ".in";
     1042
     1043  if (outdir != "")
     1044    {
     1045      if (outdir [outdir.size () - 1] != CmtSystem::file_separator ())
     1046        file = outdir + CmtSystem::file_separator () + file;
     1047      else
     1048        file = outdir + file;
     1049    }
     1050
     1051  ostringstream os;
     1052 
     1053  cmt_string preprocessor;
     1054  Symbol* macro = Symbol::find ("preprocessor_command");
     1055  if (macro != 0)
     1056    {
     1057      preprocessor = macro->resolve_macro_value ();
     1058    }
     1059
     1060  if (preprocessor == "")
     1061    {
     1062      const Use* current_use = &Use::current ();
     1063      Use::UsePtrVector uses (Use::get_ordered_uses ());
     1064      uses.push_back (&Use::current ());
     1065     
     1066      if (current_use->include_path == "none")
     1067        os << "include_path none\n";
     1068
     1069      for (int i = uses.size () - 1; i >= 0; i--)
     1070        {
     1071          const Use* use = uses[i];
     1072          if (use->discarded) continue;
     1073          if (use->m_hidden) continue;
     1074          if (!use->located ()) continue;
     1075         
     1076          cmt_string package_name = use->get_package_name ();
     1077          if (package_name == "CMT") continue;
     1078         
     1079          const Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter");
     1080          if (filter_macro == 0) continue;
     1081         
     1082          const Symbol* stamp_macro = Symbol::find (package_name + "_header_file_stamp");
     1083          cmt_string stamp;
     1084          if (stamp_macro != 0)
     1085            {
     1086              stamp = stamp_macro->resolve_macro_value ();
     1087            }
     1088          else
     1089            {
     1090              use->get_full_path (stamp);
     1091              switch (use->style)
     1092                {
     1093                case cmt_style:
     1094                  stamp += CmtSystem::file_separator ();
     1095                  stamp += "cmt";
     1096                  break;
     1097                case mgr_style:
     1098                  stamp += CmtSystem::file_separator ();
     1099                  stamp += "mgr";
     1100                  break;
     1101                }
     1102              stamp += CmtSystem::file_separator ();
     1103              stamp += "cmt_header_file.stamp";
     1104            }
     1105          if (!CmtSystem::test_file (stamp)) continue;
     1106
     1107          os << "macro " + package_name + "_header_file_filter ";
     1108          os << CmtSystem::quote (filter_macro->resolve_macro_value (), " \t");
     1109          os << "\n";
     1110          os << "macro " + package_name + "_header_file_stamp ";
     1111          os << CmtSystem::quote (stamp, " \t");
     1112          os << "\n";
     1113        }
     1114    }
     1115  else
     1116    {
     1117      os << "macro preprocessor_command ";
     1118      os << CmtSystem::quote (preprocessor, " \t");
     1119      os << "\n";
     1120      macro = Symbol::find ("includes");
     1121      if (0 != macro)
     1122        {
     1123          os << "macro includes ";
     1124          os << CmtSystem::quote (macro->resolve_macro_value (), " \t");
     1125          os << "\n";
     1126        }
     1127      if (0 == pconstituent)
     1128        {
     1129          const Constituent::ConstituentVector& constituents =
     1130            Constituent::constituents ();
     1131          for (int n = 0; n < constituents.size (); n++)
     1132            {
     1133              const Constituent& constituent = constituents[n];
     1134              if (constituent.has_target_tag) continue;
     1135              if (constituent.type == Document) continue;
     1136              cmt_string prefix;
     1137              switch (constituent.type)
     1138                {
     1139                case Application:
     1140                  prefix = "app_";
     1141                  break;
     1142                case Library:
     1143                  prefix = "lib_";
     1144                  break;
     1145                }
     1146              cmt_string macro_name (prefix + constituent.name + "_cppflags");
     1147              macro = Symbol::find (macro_name);
     1148              if (0 != macro)
     1149                {
     1150                  os << "macro_append " + macro_name + " ";
     1151                  os << CmtSystem::quote (macro->resolve_macro_value (), " \t");
     1152                  os << "\n";
     1153                }
     1154            }
     1155        }
     1156      else if (pconstituent->type != Document)
     1157        {
     1158          const Constituent& constituent = *pconstituent;
     1159          cmt_string prefix;
     1160          switch (constituent.type)
     1161            {
     1162            case Application:
     1163              prefix = "app_";
     1164              break;
     1165            case Library:
     1166              prefix = "lib_";
     1167              break;
     1168            }
     1169          cmt_string macro_name (prefix + constituent.name + "_cppflags");
     1170          macro = Symbol::find (macro_name);
     1171          if (0 != macro)
     1172            {
     1173              os << "macro_append " + macro_name + " ";
     1174              os << CmtSystem::quote (macro->resolve_macro_value (), " \t");
     1175              os << "\n";
     1176            }
     1177        }
     1178    }
     1179
     1180  // Write input requirements file
     1181
     1182  bool gen (true);
     1183  //  ostringstream os;
     1184  ofstream s;
     1185  //  s.open (file);
     1186  s.open (file, ios::in);
     1187  if (s) // file already exists
     1188    {
     1189      //      InGen.build (constituent, os);
     1190      ostringstream osn;
     1191      osn << s.rdbuf ();
     1192      if (os.str () == osn.str ())
     1193        {
     1194          //      cerr << file << " up-to-date" << endl;
     1195          gen = false;
     1196        }
     1197    }
     1198  s.clear ();
     1199  s.close ();
     1200  s.clear ();
     1201  if (gen)
     1202    {
     1203      s.open (file);
     1204      if (!s)
     1205        {
     1206          CmtError::set (CmtError::file_access_error, file);
     1207          return -1;
     1208        }
     1209      s.exceptions (ios::failbit | ios::badbit);
     1210      try
     1211        {
     1212          //      if (os.str ().size () != 0)
     1213          //        {
     1214              //  cerr << file << " contents already generated" << endl;
     1215              s << os.str ();
     1216              //            }
     1217              //          else
     1218              //            {
     1219              //              InGen.build (constituent, s);
     1220              //            }
     1221          s.close (); // ios_base::failbit
     1222        }
     1223      catch (const ios::failure& e)
     1224        {
     1225          CmtSystem::close_ostream (NULL, file + ": " + cmt_string (e.what ()));
     1226          return -1;
     1227        }
     1228    }
     1229
     1230  return 0;
     1231}
     1232
     1233//--------------------------------------------------
    8151234int Generator::build_constituent_makefile (const Constituent& constituent,
     1235                                           bool& dependencies,
    8161236                                           const cmt_string& file)
    8171237{
     
    8241244      //break;
    8251245    case Library:
    826       LibraryContext.build (package, constituent, file);
     1246      LibraryContext.build (package, constituent, dependencies, file);
    8271247      break;
    8281248    case Document:
    829       DocumentContext.build (package, constituent, file);
     1249      DocumentContext.build (package, constituent, dependencies, file);
    8301250      break;
    8311251    }
     
    8601280
    8611281  const Constituent* constituent = Constituent::find (name);
    862   if (constituent != 0) build_constituent_makefile (*constituent, file);
     1282  if (constituent != 0)
     1283    {
     1284      bool dependencies (false);
     1285      build_constituent_makefile (*constituent, dependencies, file);
     1286    }
    8631287}
    8641288
     
    8671291{
    8681292  DefaultMakefileContext.build ();
     1293}
     1294
     1295//--------------------------------------------------
     1296void Generator::build_packages_makefile (const cmt_string& package,
     1297                                         const cmt_string& file)
     1298{
     1299  PackagesMakefileContext.build (package, file);
     1300  //  UsesMakefileContext.build (package, file);
    8691301}
    8701302
     
    12131645  CmtSystem::cmt_string_vector document;
    12141646  document.push_back ("document_header");
     1647  document.push_back ("dependency");
    12151648  m_document.set_names (document);
    12161649  m_document.set_uses (usecmt);
Note: See TracChangeset for help on using the changeset viewer.