inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/config
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_config
00005 #define inlib_config
00006 
00007 // Used in the xxx-config programs.
00008 
00009 #include "sep"
00010 #include "smanip"
00011 #include "system"
00012 #include "file"
00013 
00014 namespace inlib {
00015 namespace config {
00016 
00017 inline std::string remove_versions(const std::string& aString) {
00018   std::vector<std::string> words = inlib::words(aString," ");
00019   unsigned int wordn = words.size();
00020   std::string snew;
00021   for(unsigned int index=0;index<wordn;index++) {
00022     const std::string& word = words[index];
00023     if(word.find("@@top@@")!=std::string::npos) {
00024       std::string s = remove_version(word);
00025       if(snew.size()) snew += " ";
00026       snew += s;
00027     } else {
00028       if(snew.size()) snew += " ";
00029       snew += word;
00030     }
00031   }
00032   return snew;
00033 }
00034 
00035 inline bool osc_home_dir(std::string& a_dir) {
00036   if(!getenv("OSC_HOME_DIR",a_dir)) {
00037     ::fprintf(stderr," Environment variable OSC_HOME_DIR not defined.\n");
00038     ::fprintf(stderr," You have to setup the kit by sourcing \n");
00039     ::fprintf(stderr," the setup script found in the distribution.\n");
00040     a_dir.clear();
00041     return false;
00042   }
00043   return true;
00044 }
00045 
00046 inline bool find_resource(
00047  const std::string& aFile
00048 ,const std::string& aWhat
00049 ,std::string& a_value
00050 ) {
00051   std::vector<std::string> txt;
00052   if(!inlib::file::read(aFile,txt)) {
00053     ::fprintf(stderr,"Can't read the file :\n");
00054     ::fprintf(stderr,"%s\n",aFile.c_str());
00055     ::fprintf(stderr,
00056               "containing the platform dependant incs and libs infos.\n");
00057     a_value.clear();
00058     return false;
00059   }
00060   if(!txt.size()) {
00061     ::fprintf(stderr,"The file :\n");
00062     ::fprintf(stderr,"%s\n",aFile.c_str());
00063     ::fprintf(stderr,"is empty. We expect to find in it\n");
00064     ::fprintf(stderr,"the platform dependant incs and libs infos.\n");
00065     a_value.clear();
00066     return false;
00067   }
00068  {unsigned int number = txt.size();
00069   for(unsigned int index=0;index<number;index++){
00070     const std::string& line = txt[index];
00071     std::string::size_type pos = line.find('=');
00072     if(pos==std::string::npos) {
00073       ::fprintf(stderr,"Syntax error in file :\n");
00074       ::fprintf(stderr,"%s\n",aFile.c_str());
00075       ::fprintf(stderr,"for line :\n");
00076       ::fprintf(stderr,"%s\n",line.c_str());
00077       ::fprintf(stderr,"We expect line with : <key>=<value>\n");
00078       a_value.clear();
00079       return false;
00080     }
00081     if(aWhat==line.substr(0,pos)) {
00082       a_value = line.substr(pos+1,line.size()-(pos+1));
00083       return true;
00084     }
00085   }}
00086   ::fprintf(stderr,"The file :\n");
00087   ::fprintf(stderr,"%s\n",aFile.c_str());
00088   ::fprintf(stderr,"does not contain the %s infos.\n",aWhat.c_str());
00089   a_value.clear();
00090   return false;
00091 }
00092 
00096 
00097 inline bool find_cxx(const std::string&,const std::string& aFile,std::string& a_value) {
00098   std::string home_dir;
00099   if(!osc_home_dir(home_dir)) {a_value.clear();return false;}
00100   std::string file = home_dir+sep()+"bin"+sep()+aFile;
00101   return find_resource(file,"obuild_cxx_command",a_value);
00102 }
00103 
00104 inline bool find_incs(const std::string&,const std::string& aFile,std::string& a_value) {
00105   std::string home_dir;
00106   if(!osc_home_dir(home_dir)) {a_value.clear();return false;}
00107   std::string file = home_dir+sep()+"bin"+sep()+aFile;
00108   if(!find_resource(file,"obuild_cxx_includes",a_value)) return false;
00109   a_value = remove_versions(a_value);
00110   replace(a_value,"@@top@@",home_dir+sep()+"Resources");
00111   return true;
00112 }
00113 
00114 inline bool find_flags(const std::string&,const std::string& aFile,std::string& a_value) {
00115   std::string home_dir;
00116   if(!osc_home_dir(home_dir)) {a_value.clear();return false;}
00117   std::string file = home_dir+sep()+"bin"+sep()+aFile;
00118 
00119   std::string opts;
00120   if(!find_resource(file,"obuild_cxx_options",opts)) {
00121     a_value.clear();
00122     return false;
00123   }
00124 
00125   std::string macs;
00126   if(!find_resource(file,"obuild_cxx_macros",macs)) {
00127     a_value.clear();
00128     return false;
00129   }
00130 
00131   std::string incs;
00132   if(!find_resource(file,"obuild_cxx_includes",incs)) {
00133     a_value.clear();
00134     return false;
00135   }
00136 
00137   incs = remove_versions(incs);
00138   replace(incs,"@@top@@",home_dir+sep()+"Resources");
00139 
00140   //if(home_dir.find(" ")==std::string::npos) {
00141   //  replace(incs,"\"","");
00142   //}
00143 
00144   a_value= opts+" "+macs+" "+incs;
00145   return true;
00146 }
00147 
00148 inline bool find_libs(const std::string&,const std::string& aFile,std::string& a_value) {
00149   std::string home_dir;
00150   if(!osc_home_dir(home_dir)) {a_value.clear();return false;}
00151   std::string file = home_dir+sep()+"bin"+sep()+aFile;
00152 
00153   std::string spaths;
00154 #ifdef WIN32
00155   spaths = "/LIBPATH:\""+home_dir+"\\lib\"";
00156 #else
00157   spaths = "-L\""+home_dir+"/lib\"";
00158 #endif
00159 
00160   std::string slibs;
00161   if(!find_resource(file,"obuild_linked_libraries",slibs)) {
00162     a_value.clear();
00163     return false;
00164   }
00165 
00166   //if(home_dir.find(" ")==std::string::npos) {
00167   //  replace(spaths,"\"","");
00168   //}
00169 
00170   a_value = spaths+" "+slibs;
00171 
00172   return true;
00173 }
00174 
00175 inline bool find_incdir(const std::string&,const std::string& aFile,std::string& a_value) {
00176   std::string home_dir;
00177   if(!osc_home_dir(home_dir)) {a_value.clear();return false;}
00178   std::string file = home_dir+sep()+"bin"+sep()+aFile;
00179 
00180   std::string package;
00181   if(!find_resource(file,"obuild_package",package)) {
00182     a_value.clear();
00183     return false;
00184   }
00185 
00186   std::string version;
00187   if(!find_resource(file,"obuild_version",version)) {
00188     a_value.clear();
00189     return false;
00190   }
00191 
00192   a_value = home_dir+sep()+"Resources"+sep()+package+sep()+"include";
00193 
00194   return true;
00195 }
00196 
00197 }}
00198 
00199 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines