Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 47 → Rev 48

/trunk/C-CPP-utils/supermakemake/dirlist.h
19,6 → 19,7
 
#include <set>
#include <map>
#include <dirent.h>
 
using namespace std;
 
49,6 → 50,7
 
enum FileType { C, CPP, H, ARCHIVE, PREASSEMBLY, ASSEMBLY, M4_H, M4_CPP, OTHER }; // file type
DirList( ); //Scan the current directory and all sub directories
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
96,6 → 98,13
map<string, set<string> > _includeFiles;
map<string, set<string> > _dependencies;
 
private:
//Scan the dir and all subdirs
void scan_dirs( DIR* dir );
 
//Scan only our current directory
void scan_single_dir( DIR* dir, int ac = 0 );
 
}; // DirList
 
#endif
/trunk/C-CPP-utils/supermakemake/MakefileObject.cpp
84,54 → 84,90
cerr << "ERROR: Couldn't open file " << makefile << endl;
}
 
string* lastUsedVariable = NULL;
set<string>* lastUsedList = NULL;
bool append = false;
while( theFile.good() ){
theFile.getline( buffer, 300 );
 
//if the append variable is set, we have not reached the end of our line
if( append ){
if( lastUsedVariable != NULL ){
//append to our string variable
lastUsedVariable->append( parseList( buffer ) );
}else if( lastUsedList != NULL ){
//append to our set variable
parseFileList( buffer, lastUsedList );
}
 
//if we still haven't reached the end of our line,
//loop again
if( theFile.gcount() >= 300 ){
continue;
}
 
lastUsedVariable = NULL;
lastUsedList = NULL;
append = false;
}
 
if( theFile.gcount() >= 300 ){
cerr << "ERROR: More than 300 characters in a single line of your Makefile. Split the lines up!" << endl;
append = true;
}
 
if( memcmp( buffer, "CPP_FILES", 9 ) == 0 ){
parseFileList( buffer, &cpp_files );
lastUsedList = &cpp_files;
}
 
if( memcmp( buffer, "H_FILES", 7 ) == 0 ){
parseFileList( buffer, &h_files );
lastUsedList = &h_files;
}
 
if( memcmp( buffer, "C_FILES", 7 ) == 0 ){
parseFileList( buffer, &c_files );
lastUsedList = &c_files;
}
 
if( memcmp( buffer, "PS_FILES", 8 ) == 0 ){
parseFileList( buffer, &ps_files );
lastUsedList = &ps_files;
}
 
if( memcmp( buffer, "S_FILES", 7 ) == 0 ){
parseFileList( buffer, &s_files );
lastUsedList = &s_files;
}
 
if( memcmp( buffer, "CPPFLAGS", 8 ) == 0 ){
cpp_flags = parseList( buffer );
lastUsedVariable = &cpp_flags;
}
 
if( memcmp( buffer, "CFLAGS", 6 ) == 0 ){
c_flags = parseList( buffer );
lastUsedVariable = &c_flags;
}
 
if( memcmp( buffer, "CXXFLAGS", 8 ) == 0 ){
cxx_flags = parseList( buffer );
lastUsedVariable = &cxx_flags;
}
 
if( memcmp( buffer, "CLIBFLAGS", 9 ) == 0 ){
clib_flags = parseList( buffer );
lastUsedVariable = &clib_flags;
}
if( memcmp( buffer, "CCLIBFLAGS", 10 ) == 0 ){
cxxlib_flags = parseList( buffer );
lastUsedVariable = &cxxlib_flags;
}
 
if( memcmp( buffer, "CPPFLAGS", 8 ) == 0 ){
cpp_flags = parseList( buffer );
lastUsedVariable = &cpp_flags;
}
if( memcmp( buffer, "CC =", 4 ) == 0 ){
149,6 → 185,8
 
free( buffer );
 
remove_old_files();
 
}
 
Makefile::Makefile( std::map<string, string>* conf ){
163,6 → 201,7
write_lists();
write_main_targets();
write_dependencies();
write_trailer( (*configuration)["c_compiler"] == "gcc" );
}
 
/*Write::Write( DirList &dirlist, map<string, string> * conf ){
665,8 → 704,8
cout << "\n\n" ;
}
 
/*
void Write::write_trailer( DirList &dirlist, bool useGCC ){
 
void Makefile::write_trailer( bool useGCC ){
cout << "#\n";
cout << "# Housekeeping\n";
cout << "#\n";
679,14 → 718,14
 
cout << "clean:\n"
<< "\t-/bin/rm $(OBJFILES)";
if( !dirlist.cpp_main.empty() ){
cout << " " << FileListInserter( dirlist.cpp_main, ".o" );
if( !cpp_main.empty() ){
cout << " " << FileListInserter( cpp_main, ".o" );
}
if( !dirlist.c_main.empty() ){
cout << " " << FileListInserter( dirlist.c_main, ".o" );
if( !c_main.empty() ){
cout << " " << FileListInserter( c_main, ".o" );
}
if( !dirlist.ass_main.empty() ){
cout << " " << FileListInserter( dirlist.ass_main, ".o" );
if( !s_main.empty() ){
cout << " " << FileListInserter( s_main, ".o" );
}
if(useGCC) {
cout << " core 2> /dev/null\n";
698,27 → 737,27
cout << "\t-/bin/rm -rf ";
if(products.empty()) {
#ifdef WINDOWS
cout << FileListInserter( dirlist.cpp_main, ".exe" );
cout << FileListInserter( cpp_main, ".exe" );
#else
cout << FileListInserter( dirlist.cpp_main, "" );
cout << FileListInserter( cpp_main, "" );
#endif
if( !dirlist.cpp_main.empty() ) {
if( !cpp_main.empty() ) {
cout << " ";
}
#ifdef WINDOWS
cout << FileListInserter( dirlist.c_main, ".exe" );
cout << FileListInserter( c_main, ".exe" );
#else
cout << FileListInserter( dirlist.c_main, "" );
cout << FileListInserter( c_main, "" );
#endif
if( !dirlist.c_main.empty() ) {
if( !c_main.empty() ) {
cout << " ";
}
#ifdef WINDOWS
cout << FileListInserter( dirlist.ass_main, ".exe" );
cout << FileListInserter( s_main, ".exe" );
#else
cout << FileListInserter( dirlist.ass_main, "" );
cout << FileListInserter( s_main, "" );
#endif
if( !dirlist.ass_main.empty() ) {
if( !s_main.empty() ) {
cout << " ";
}
} else {
730,8 → 769,8
}
cout << endl; // to flush buffer
}
*/
 
 
void Makefile::findMainPrograms(){
 
//First, let's check all of our C files
762,3 → 801,34
}
 
}
 
void Makefile::remove_old_files(){
FILE* theFile;
 
for( set<string>::iterator it = c_files.begin(); it != c_files.end(); it++ ){
theFile = fopen( (*it).c_str(), "r" );
if( theFile == NULL ){
c_files.erase( it );
}else{
fclose( theFile );
}
}
 
for( set<string>::iterator it = cpp_files.begin(); it != cpp_files.end(); it++ ){
theFile = fopen( (*it).c_str(), "r" );
if( theFile == NULL ){
cpp_files.erase( it );
}else{
fclose( theFile );
}
}
 
for( set<string>::iterator it = h_files.begin(); it != h_files.end(); it++ ){
theFile = fopen( (*it).c_str(), "r" );
if( theFile == NULL ){
h_files.erase( it );
}else{
fclose( theFile );
}
}
}
/trunk/C-CPP-utils/supermakemake/MakefileObject.h
44,6 → 44,10
 
void write_install_targets();
 
void remove_old_files();
 
void write_trailer( bool );
 
private:
 
//Lists of files
/trunk/C-CPP-utils/supermakemake/dirlist.cpp
60,6 → 60,20
return os;
}
 
/**
* The default constructor goes through the default directory,
* and all subdirectories to find files.
*/
DirList::DirList(){
DIR* dir;
 
dir = opendir( "." );
if( dir != NULL ){
scan_dirs( dir );
}
closedir( dir );
}
 
/* DirList
*
*
78,55 → 92,15
}
 
for( unsigned int x = 0; x < tokens.size(); x++ ){
DIR *dir( opendir( tokens[x].c_str() ) );
DIR *dir( opendir( tokens[x].c_str() ) );
 
if( dir != 0 ){
struct dirent *dirent;
 
while( ( dirent = readdir( dir ) ) != 0 ) {
string name( dirent->d_name );
 
switch( fileType( name ) ) {
case CPP:
insert_source( hasMainFunction, name, cpp, cpp_main, cpp_other );
break;
 
case C:
insert_source( hasMainFunction, name, c, c_main, c_other );
break;
 
case ASSEMBLY:
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;
 
case ARCHIVE:
archive.insert( name );
break;
 
case M4_H:
 
case M4_CPP:
 
default:;
// nothing to do
}
 
if( dir != NULL ){
scan_single_dir( dir );
closedir( dir );
} else {
cerr << "Error opening directory " << tokens[x] << "\n";
}
closedir( dir );
} else {
cerr << "Error opening directory " << tokens[x] << "\n";
}
}
 
 
}
 
/* DirList
146,50 → 120,7
DIR *dir( opendir( "." ) );
 
if( dir != 0 ){
struct dirent *dirent;
 
while( ( dirent = readdir( dir ) ) != 0 ) {
string name( dirent->d_name );
 
switch( fileType( name ) ) {
case CPP:
if( ac <= 0 ) {
insert_source( hasMainFunction, name, cpp, cpp_main, cpp_other );
}
break;
 
case C:
if( ac <= 0 ) {
insert_source( hasMainFunction, name, c, c_main, c_other );
}
break;
 
case ASSEMBLY:
if( ac <= 0 ) {
insert_source( hasMainLabel, name, ass, ass_main, ass_other );
}
break;
 
case PREASSEMBLY:
if( ac <= 0 ){
insert_source( hasMainLabel, name, preass, preass_main, preass_other );
}
break;
 
case H:
h.insert( name );
break;
 
case ARCHIVE:
archive.insert( name );
break;
 
default:;
// nothing to do
}
 
}
closedir( dir );
scan_single_dir( dir, ac );
} else {
cerr << "Error opening current directory\n";
}
466,3 → 397,70
}
return list;
}
 
void DirList::scan_dirs( DIR* dir ){
struct dirent* dirent;
DIR* newDir;
 
if( dir == NULL ) return;
 
while( ( dirent = readdir( dir ) ) != NULL ){
switch( dirent->d_type ){
case DT_DIR:
newDir = opendir( dirent->d_name );
scan_dirs( newDir );
closedir( newDir );
break;
case DT_REG:
//These are the files that we care about
scan_single_dir( dir );
}
}
 
}
 
void DirList::scan_single_dir( DIR* dir, int ac ){
struct dirent *dirent;
 
while( ( dirent = readdir( dir ) ) != 0 ) {
string name( dirent->d_name );
 
switch( fileType( name ) ) {
case CPP:
if( ac <= 0 ) {
insert_source( hasMainFunction, name, cpp, cpp_main, cpp_other );
}
break;
 
case C:
if( ac <= 0 ) {
insert_source( hasMainFunction, name, c, c_main, c_other );
}
break;
 
case ASSEMBLY:
if( ac <= 0 ) {
insert_source( hasMainLabel, name, ass, ass_main, ass_other );
}
break;
 
case PREASSEMBLY:
if( ac <= 0 ){
insert_source( hasMainLabel, name, preass, preass_main, preass_other );
}
break;
 
case H:
h.insert( name );
break;
 
case ARCHIVE:
archive.insert( name );
break;
 
default:;
// nothing to do
}
 
}
}
/trunk/C-CPP-utils/supermakemake/makemake.cpp
15,6 → 15,8
#include <cstdlib>
#include <cstring>
 
#include <fstream>
 
#include "dirlist.h"
#include "write.h"
 
24,45 → 26,63
void printHelp(char*);
 
void printHelp(char* progName){
//This line is 80 characters long
//------------------------------------------------------------------------------
const char* HELP_TEXT =
" -update Let makemake update the list of files that it compiles\n"
" Any new files will be added to the makefile\n"
" This will also remove files if makemake cannot find them\n"
" All custom targets and flags from the old makefile are kept\n"
" -depends Update the dependencies that the makefile keeps track of.\n"
" All targets and flags from the old makefile are kept\n"
" -header HEADER Use the specified file instead of header.mak\n"
" See the manual for more information\n"
" -no-header Do not open header.mak even if it exists\n"
" -programs PROGRAMS Use the specified file instead of programs.mak\n"
" See the manual for more information\n"
" -no-programs Do not open programs.mak even if it exists\n"
" -no-debug Do not output compiler debugging flags\n"
" -ar NAME Explicity make a static archive. Made automatically\n"
" if a source file starts with 'ar'\n"
" -so NAME Explicity make a shared object file. Made automatically\n"
" if a source file starts with 'lib'\n"
" -install Generate a 'make install' target to install this program\n"
" By default, this will install to /usr/bin\n"
" --prefix=PREFIX Generate a 'make install' target, but install to PREFIX\n"
" instead of /usr/bin. -install is implied\n"
" --dirs=DIR Look through the specified colon-separated directores\n"
" for files to compile\n"
" -r Recursively search through all directories for files\n"
" files The files to create the makefile from. If no files are\n"
" specified, makemake will look through the current\n"
" directory\n"
"\n"
"SuperMakemake v1.0\n"
"Based off of code by Prof. Sidney Marshall,\n"
"Rochester Institute of Technology Department of Computer Science\n"
"Original source code may be found at http://cs.rit.edu/~swm/makemake\n"
"Currently maintained by rm5248 @ www.programming.rm5248.com\n";
 
cout << "Usage: " << progName << " [-update] [-depends] [-header headerfile | -no-header] [-programs programsfile | -no-programs] ";
cout << "[-no-debug] [-ar name] [-so name] [-install] [-prefix=PREFIX] [-dirs=DIRS] [files] " << endl;
cout << "[-no-debug] [-ar name] [-so name] [-install] [--prefix=PREFIX] [--dirs=DIRS | -r] [files] " << endl;
cout << endl;
cout << "Note that " << progName << " outputs the makefile to STDOUT; it is typically invoked as " << progName << " > Makefile" << endl;
cout << endl;
 
cout << HELP_TEXT << endl;
cout << "" << endl;
cout << " -update \t\tLet " << progName << " update the list of files that it compiles. Any new files will be added to the makefile. ";
cout << "This will also remove files if " << progName << " cannot find them anymore. All targets and flags from the old makefile are kept." << endl;
cout << " -depends \t\tUpdate the dependencies that the makefile keeps track of. All targets and flags from the old makefile are kept." << endl;
cout << " -header HEADER\t\tUse the specified file instead of header.mak(see man makemake for more information)" << endl;
cout << " -no-header \t\tDo not open header.mak even if it exists" << endl;
cout << " -programs PROGRAMS\t\tUse the specified file instead of programs.mak(see man makemake for more information)" << endl;
cout << " -no-programs \t\tDo not open programs.mak even if it exists" << endl;
cout << " -no-debug \t\tDo not output compiler instructions to insert debugging information" << endl;
cout << " -ar NAME \t\tInstead of making an executable program, compile and link into an archive file with name NAME" << endl;
cout << " -so NAME \t\tInstead of making an executable program, compile and link into a shared object file with name NAME" << endl;
cout << " -install \t\tGenerate a 'make install' target to install this program. By default, it will be installed to /usr/bin" << endl;
cout << " -prefix=PREFIX \t\tGenerate a 'make install' target, but install to PREFIX instead of /usr/bin. -install does not have to be specified" << endl;
cout << " -dirs=DIRS \t\tLook through the specified colon-separated directories for files to compile" << endl;
cout << " files \t\tThe files to create the makefile from. If no files are specified, " << progName << " will look through the current directory ";
cout << "for the files to create the makefile from" << endl;
cout << "" << endl;
cout << "SuperMakemake v1.0" << endl;
cout << "Based off of code by Prof. Sidney Marshall, Rochester Institute of Technology Department of Computer Science" << endl;
cout << "Original source code may be found at http://cs.rit.edu/~swm/makemake" << endl;
cout << "Currently maintained by rm5248 @ www.rm5248.com" << endl;
 
}
 
#include "MakefileObject.h"
int main( int argc, char **argv ){
Makefile m( "Makefile2" );
m.writeMakefile();
return 1;
 
bool search_dirs = false;
bool recursive_search = false;
char* progName;
char *exename = argv[0];
char c;
Makefile* makefile;
 
map<string, string> config;
config["c_compiler"] = "cc";
80,10 → 100,6
 
// check gnu compiler make or sun compiler make
// if first letter of executable is 'g' then gnu otherwise sun
 
char *exename = argv[0];
char c;
 
while((c = *exename++)) {
if(c == '/') {
argv[0] = exename;
126,17 → 142,21
cout << "make shared object file NOT YET IMPLEMENTED" << endl;
} else if( strcmp("-install", *argv) == 0 ){
config["install"] = "true";
} else if( strcmp("-prefix", *argv) == 0 ){
} else if( strcmp("--prefix", *argv) == 0 ){
if( argc != 0 ){
config["install"] = "true";
config["prefix"] = *++argv;
argc--;
}
} else if( strstr(*argv, "-dirs=") != NULL ){
search_dirs = true;
config["dirs"] = string( &((*argv)[6]) );
} else if( strstr(*argv, "--dirs=") != NULL ){
if( !search_dirs ){
search_dirs = true;
config["dirs"] = string( &((*argv)[6]) );
}
} else if( strcmp("-r", *argv) == 0 ){
search_dirs = false;
recursive_search = true;
//} else if( strcmp("-update", *argv) == 0 ){
//} else if( strcmp("-update", *argv) == 0 ){
}else {
switch( *++*argv ){
case 'd':
157,6 → 177,8
DirList* dirlist;
if( search_dirs ){
dirlist = new DirList( config );
}else if( recursive_search ){
dirlist = new DirList();
}else{
dirlist = new DirList( argc, argv );
}
164,7 → 186,7
//
// Now write the makefile
//
Write write( *dirlist, &config );
//Write write( *dirlist, &config );
 
return 0;
}