proj home

Files   Classes   Functions   Hierarchy  

createmakefile< CFC > Class Template Reference

Create a makeilfe in the current directory. Assumes the flat directory structure. More...

#include <createmakefile.h>

Collaboration diagram for createmakefile< CFC >:

List of all members.

Public Member Functions

void pathsbuild ()
 Build the paths.
 createmakefile (int argc, char **argv)
 Creates the data structure.
stringc pathsstring () const
 Iterate over paths returning a string.
stringc objsstring ()
 Iterate over objs returning a string.
void eval ()
 Write Makefile to current directory.

Public Attributes

makestate< CFC > ms
 The state and makefile processing machine.
set< string > paths
 List of paths.
string makefile
 Name of makefile generated in local directory.
string lib
 Name of libraries file.
string corrupt
 Support for corrupt compilation, expecting <targ>.o.


Detailed Description

template<typename CFC>
class createmakefile< CFC >

Create a makeilfe in the current directory. Assumes the flat directory structure.

Definition at line 19 of file createmakefile.h.


Constructor & Destructor Documentation

template<typename CFC >
createmakefile< CFC >::createmakefile ( int  argc,
char **  argv 
) [inline]

Creates the data structure.

Definition at line 83 of file createmakefile.h.

References createmakefile< CFC >::corrupt, createmakefile< CFC >::lib, createmakefile< CFC >::makefile, commandline::mapvar(), createmakefile< CFC >::ms, and createmakefile< CFC >::pathsbuild().

00084 {
00085   commandline cmd(argc,argv);
00086   cmd.mapvar(ms.driver,"driver");
00087 
00088   makefile="Makefile";
00089   cmd.mapvar(makefile,"makefile");
00090 
00091   lib="libraries";
00092   cmd.mapvar(lib,"lib");
00093 
00094   corrupt="";
00095   cmd.mapvar(corrupt,"corrupt");
00096 
00097   //processqueuebuild<cfcontainervec> pq(ms);
00098   processqueuebuild<CFC> pq(ms);
00099   for ( ; !pq; ++pq );
00100 
00101   ms.objsdependenciesPass1();
00102   ms.objsdependenciesPass2();
00103 
00104   pathsbuild();
00105 
00106 
00107   // NOTE:  I have a bud that I could not track.
00108   //
00109   // Problem:  main.h in main.o includes for cfcontainerhash,
00110   //   but not for cfcontainervec
00111   //
00112   // Solution: remove header.  Not ideal, but until the bug
00113   //           can be found this is best.
00114 
00115   // driver.o had driver.h in includes!
00116   {
00117     compilationfile* x1 = ms.proj.files[ms.proj.driverh()]; 
00118     assert(x1);
00119     compilationfile* x2 = ms.objs[ms.proj.drivero()]; 
00120     assert(x2);
00121     
00122     string str;
00123     for (ms.objs.reset(); !ms.objs; ++ms.objs)
00124     {
00125       if (ms.objs() != x2)
00126         continue;
00127 
00128       //ms.objs()->print();
00129 
00130       vector<compilationfile*>& includes(ms.objs()->includes);
00131       vector<compilationfile*>::iterator f = find(includes.begin(),includes.end(),x1);
00132       if (f!=includes.end())
00133       {
00134         //cout << "found" << endl;
00135         includes.erase(f);
00136       }
00137     }    
00138   }
00139 
00140 } 


Member Function Documentation

template<typename CFC >
void createmakefile< CFC >::eval (  )  [inline]

Write Makefile to current directory.

Definition at line 161 of file createmakefile.h.

References createmakefile< CFC >::corrupt, createmakefile< CFC >::lib, createmakefile< CFC >::makefile, createmakefile< CFC >::ms, createmakefile< CFC >::objsstring(), and createmakefile< CFC >::pathsstring().

Referenced by createmakefiletest::test02(), and createmakefiletest::test03().

00162 {
00163   ofstream file(makefile.c_str()); 
00164 
00165   file << "# This makefile was generated using the build tool found at" << endl;
00166   file << "# http://www.fluxionsdividebyzero.com/p1/misc/makefilebuildtool.html" << endl << endl;
00167   file << "CC=g++ -Wall" << endl;
00168   file << "INC=" << pathsstring() << endl;
00169   file << "OBJ=" << objsstring() << endl;
00170 
00171   // Look for libraries file, echo its contents after LIB=
00172   ifstream filelibraries(lib.c_str());
00173 //cout << SHOW(libraries) << endl;
00174   string lib2;
00175   if (filelibraries.eof()==false)
00176     getline(filelibraries,lib2);
00177   file << "LIB=" << lib2 << endl << endl << endl;
00178 
00179 //cout << SHOW(corrupt) << endl;
00180 
00181   if (corrupt.empty())
00182     file << ms.driver << ": $(OBJ)" << endl;
00183   else
00184   {
00185     compilationfile* x;
00186     bool found=false;
00187     for (ms.objs.reset(); !ms.objs; ++ms.objs)
00188     {
00189       x=ms.objs();
00190       assert(x);
00191 //cout << SHOW(x->filename) << endl;
00192       if (x->filename == corrupt)
00193         found=true;
00194     }      
00195     if (found==false)
00196     {
00197       cout << "error:  " << corrupt << " not a dependency" << endl;
00198       return;
00199     }
00200       
00201     file << ms.driver << ": " << corrupt << endl;
00202   }
00203 
00204   
00205   file << " $(CC) $(INC) -o " << ms.driver << " $(OBJ) $(LIB)" << endl;
00206 
00207   compilationfile* x;
00208   for (ms.objs.reset(); !ms.objs; ++ms.objs)
00209   {
00210     x=ms.objs();
00211     assert(x);
00212 
00213     file << x->filename << ":";
00214 
00215     for (uint i=0; i<x->includes.size(); ++i)
00216     {
00217       if (x->includes[i]->isobj())
00218         file << " " << x->includes[i]->filename;
00219       else
00220         file << " " << x->includes[i]->filenamefull();
00221     }  
00222     file << endl;
00223     file << " $(CC) $(INC) -c " << x->linksource->filenamefull() << endl;
00224   }
00225 
00226   file << endl;
00227   file << "clean:" << endl;
00228   file << " rm *.o *.order *.out gmon.* " << ms.driver <<  endl;
00229   file << endl;
00230 
00231   file << endl;
00232   file << "# Re-compile specific parts of the program. e.g." << endl;
00233   file << "#   $ make del targ=windowscale" << endl;
00234   file << "targ=__nopattern__" << endl;
00235   file << "del:" << endl;
00236   file << " rm *${targ}*.o; make" <<  endl;
00237   file << endl;
00238 
00239 
00240 //  system("if [ -e tempheaders.txt ]; then rm tempheaders.txt; fi");
00241   string arg("if [ -e "+makefilebtglobals::tempheaders+" ]; then rm "
00242     + makefilebtglobals::tempheaders+"; fi");
00243   system(arg.c_str());
00244   system("if [ -e tempcpp.txt ]; then rm tempcpp.txt; fi");
00245 }

template<typename CFC >
stringc createmakefile< CFC >::objsstring (  )  [inline]

Iterate over objs returning a string.

Definition at line 58 of file createmakefile.h.

References createmakefile< CFC >::ms.

Referenced by createmakefile< CFC >::eval().

00059 {
00060   string str;
00061   for (ms.objs.reset(); !ms.objs; ++ms.objs)
00062   {
00063     str += (ms.objs()->filename + " ");
00064   }
00065 
00066   return str;
00067 }

template<typename CFC >
void createmakefile< CFC >::pathsbuild (  )  [inline]

Build the paths.

Definition at line 144 of file createmakefile.h.

References compilationfile::includes, createmakefile< CFC >::ms, and createmakefile< CFC >::paths.

Referenced by createmakefile< CFC >::createmakefile().

00145 {
00146   compilationfile* x;
00147   for ( ms.objs.reset(); !ms.objs; ++ms.objs )
00148   {
00149     x = ms.objs();
00150     assert(x);
00151     uint kmax=x->includes.size();
00152     for (uint k=0; k<kmax; ++k)
00153     {
00154       assert(x->includes[k]);
00155       paths.insert( x->includes[k]->path );
00156     }
00157   }
00158 }

template<typename CFC >
stringc createmakefile< CFC >::pathsstring (  )  const [inline]

Iterate over paths returning a string.

Definition at line 70 of file createmakefile.h.

References createmakefile< CFC >::paths.

Referenced by createmakefile< CFC >::eval(), and createmakefiletest::test01().

00071 {
00072   string str;
00073 
00074   set<string>::const_iterator i=paths.begin();
00075   set<string>::const_iterator iend=paths.end();
00076   for ( ; i!=iend; ++i)
00077     str += ("-I" + *i + " ");
00078 
00079   return str;  
00080 }


Member Data Documentation

template<typename CFC>
string createmakefile< CFC >::corrupt

Support for corrupt compilation, expecting <targ>.o.

Definition at line 36 of file createmakefile.h.

Referenced by createmakefile< CFC >::createmakefile(), and createmakefile< CFC >::eval().

template<typename CFC>
string createmakefile< CFC >::lib

Name of libraries file.

Definition at line 33 of file createmakefile.h.

Referenced by createmakefile< CFC >::createmakefile(), and createmakefile< CFC >::eval().

template<typename CFC>
string createmakefile< CFC >::makefile

Name of makefile generated in local directory.

Definition at line 30 of file createmakefile.h.

Referenced by createmakefile< CFC >::createmakefile(), and createmakefile< CFC >::eval().

template<typename CFC>
makestate<CFC> createmakefile< CFC >::ms

template<typename CFC>
set<string> createmakefile< CFC >::paths

List of paths.

Definition at line 27 of file createmakefile.h.

Referenced by createmakefile< CFC >::pathsbuild(), and createmakefile< CFC >::pathsstring().


The documentation for this class was generated from the following file:

Generated on Fri Mar 4 00:49:52 2011 for Chelton Evans Source by  doxygen 1.5.8