Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 5 → Rev 6

/C-CPP-utils/supermakemake/dirlist.h
47,13 → 47,11
class DirList {
public: // Constructors
 
enum FileType { C, CPP, H, ARCHIVE, ASSEMBLY, OTHER }; // file type
enum FileType { C, CPP, H, ARCHIVE, PREASSEMBLY, ASSEMBLY, M4_H, M4_CPP, OTHER }; // file type
DirList( map<string,string>& config ); //Auto-scan directories in "dirs" config
DirList( int ac, char **av ); // Constructor to initialize sets
static const string basename( const string &name ); // get basename of name
set<string> includeFiles( const string &name ); // get include files
set<string> dependencies( const string &name ); // recursive dependencies
 
// File name lists, publically accessible for traversals etc.
 
63,11 → 61,16
set<string> c; // All C files
set<string> c_main; // All C files with main
set<string> c_other; // Non-main C files
set<string> preass; //all preassembly files
set<string> preass_main; //all main preassembly
set<string> preass_other; //all other preassembly
set<string> ass; // All assembly files
set<string> ass_main; // All assembly files with main
set<string> ass_other; // Non-main assembly files
set<string> h; // All .H and .h files
set<string> archive; // All .a files
set<string> h_m4; // All .h.m4 .H.m4 files
set<string> cpp_m4; // All .cpp.m4 .cc.m4 .C.m4 files
 
public: // file scanning functions
 
/C-CPP-utils/supermakemake/dirlist.cpp
54,11 → 54,8
*/
DirList::DirList(map<string,string>& config){
//
// Read the directory and store all the files we find there,
// EXCEPT if arguments were given, those are the only .C, .c, .cpp, and .s
// files we're interested in, so skip any found here.
// Read the directory and store all the files we find there
//
 
vector<string> tokens;
char modified_string[ config["dirs"].size() + 1];
memcpy( modified_string, config["dirs"].c_str(), config["dirs"].size() + 1 );
90,6 → 87,10
insert_source( hasMainLabel, name, ass, ass_main, ass_other );
break;
 
case PREASSEMBLY:
insert_source( hasMainLabel, name, preass, preass_main, preass_other );
break;
 
case H:
h.insert( name );
break;
98,6 → 99,10
archive.insert( name );
break;
 
case M4_H:
 
case M4_CPP:
 
default:;
// nothing to do
}
153,6 → 158,12
}
break;
 
case PREASSEMBLY:
if( ac <= 0 ){
insert_source( hasMainLabel, name, preass, preass_main, preass_other );
}
break;
 
case H:
h.insert( name );
break;
225,45 → 236,6
return name.substr( 0, pos );
}
 
/* includeFiles
*
* Get a list of include files mentioned in file name. Cache the result
* so successive calls do no work.
*/
set<string> DirList::includeFiles( const string &name ) {
map<string,set<string> >::const_iterator it( _includeFiles.find( name ) );
if( it != _includeFiles.end() ) {
return it->second;
} else {
return _includeFiles[ name ] = getIncludeFiles( name );
}
}
 
/*dependencies
*
* Do a transitive closure of include files included by file name.
* Cache the result so successive calls do no work.
*/
set<string> DirList::dependencies( const string &name ) {
map<string, set<string> >::iterator it = _dependencies.find( name );
if( it != _dependencies.end() ) {
return it->second;
} else {
set<string> todo( getIncludeFiles( name ) );
set<string> closure;
while( !todo.empty() ) {
string s = *todo.begin();
todo.erase( todo.begin() );
if( closure.insert( s ).second ) {
set<string> newfiles( getIncludeFiles( s ) );
todo.insert( newfiles.begin(), newfiles.end() );
}
}
_dependencies[ name ] = closure;
return closure;
}
}
 
/* fileType
*
* Return a member of the fileType enumeration corresponding to
275,8 → 247,21
if( pos == string::npos ) return OTHER;
string suffix( name.substr( pos+1, name.size() ) );
FileType ft = OTHER;
if( suffix == "C" || suffix == "cpp" ) ft = CPP;
 
if( suffix == "m4" ){
cout << "M4 SUFFIX\n";
string prefix( name.substr( 0, pos ) );
size_t pos2 = prefix.rfind('.');
if( pos2 == string::npos ) return OTHER;
string real_suffix( name.substr( pos2, pos ) );
if( real_suffix == "C" || real_suffix == "cpp" || real_suffix == "cc" ) ft = M4_CPP;
if( real_suffix == "H" || real_suffix == "h" ) ft = M4_H;
return ft;
}
 
if( suffix == "C" || suffix == "cpp" || suffix == "cc" ) ft = CPP;
if( suffix == "c" ) ft = C;
if( suffix == "S" ) ft = PREASSEMBLY;
if( suffix == "s" ) ft = ASSEMBLY;
if( suffix == "H" || suffix == "h" ) ft = H;
if( suffix == "a" ) ft = ARCHIVE;
/C-CPP-utils/supermakemake/write.cpp
34,6 → 34,10
using namespace std;
 
Write::Write( DirList &dirlist, map<string, string> * conf ){
if( dirlist.h_m4.size() > 0 || dirlist.cpp_m4.size() > 0 ){
(*configuration)["m4"] = "true";
}
 
configuration = conf;
write_header();
write_lists( dirlist );
97,15 → 101,20
cout << ".c.a:\n";
cout << "\t\t$(COMPILE.c) -o $% $<\n";
cout << "\t\t$(AR) $(ARFLAGS) $@ $%\n";
//cout << "\t\t$(RM) $%\n";
cout << ".C.a:\n";
cout << "\t\t$(COMPILE.cc) -o $% $<\n";
cout << "\t\t$(AR) $(ARFLAGS) $@ $%\n";
//cout << "\t\t$(RM) $%\n";
cout << ".cpp.a:\n";
cout << "\t\t$(COMPILE.cc) -o $% $<\n";
cout << "\t\t$(AR) $(ARFLAGS) $@ $%\n";
//cout << "\t\t$(RM) $%\n";
 
if( (*configuration)["m4"] == "true" ){
cout << "%.h: %.h.m4\n";
cout << "\t\tm4 $< > $@\n";
cout << "%.cpp: %.cpp.m4\n";
cout << "\t\tm4 $< > $@\n";
}
 
cout << "\n";
/*if(useGCC) {
cout << "CC =\t\tgcc\n";
167,7 → 176,14
cout << "PS_FILES = \t \n";
cout << "S_FILES =\t" << FileListInserter(dirlist.ass) << '\n';
cout << "H_FILES =\t" << FileListInserter(dirlist.h) << '\n';
cout << "SOURCEFILES =\t$(H_FILES) $(CPP_FILES) $(C_FILES) $(S_FILES)\n";
if( (*configuration)["m4"] == "true" ){
cout << "M4_FILES = \t" << FileListInserter(dirlist.h_m4) << FileListInserter(dirlist.cpp_m4);
}
cout << "SOURCEFILES =\t$(H_FILES) $(CPP_FILES) $(C_FILES) $(S_FILES)";
if( (*configuration)["m4"] == "true" ){
cout << "$(M4_FILES)";
}
cout << "\n";
cout << ".PRECIOUS:\t$(SOURCEFILES)\n";
 
cout << "OBJFILES =\t";
365,10 → 381,7
 
void doFork(int fileds, DirList& dirlist){
//Child process
cout << "fileds before dup is " << fileds << endl;
 
dup2( fileds, STDOUT_FILENO ); //make output go to pipe instead of STDOUT
cout << "fileds AFTER DUP2" << fileds << endl;
int totalElements = dirlist.cpp.size() + dirlist.c.size() + 3; //all c/cpp files, plus three for "gcc" "-MM" [args] NULL
char** argArray = (char**)malloc( sizeof(char*) * totalElements );
int currentArgSpot = 0;
408,12 → 421,12
// if( (*configuration)["c_compiler"].compare("gcc") ){
if( 1 ){
//Fork and read in the data from gcc
//command: gcc -MM *.cpp *.c
//command: gcc -MM *.cpp *.c $(CPPFLAGS)
// we aren't doing the $(CPPFLAGS) at the moment.
switch( fork() ){
case 0:
//Child process
//close( fileds[0] );
cout << "fileds 1 at fork is " << fileds[1] << endl;
doFork(fileds[1], dirlist);
case -1:
//bad error.
422,9 → 435,11
//parent process
close( fileds[1] );
}
char* read_buffer[100];
while( read( fileds[0], read_buffer, 100 ) > 0 ){
cout << "READ BUFFER: " << read_buffer;
char read_buffer[100];
int val;
while( val = read( fileds[0], read_buffer, 100 ), val > 0 ){
read_buffer[val] = '\0';
cout << read_buffer;
}
}