Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 77 → Rev 78

/trunk/C-CPP-utils/supermakemake/dirlist.h
34,7 → 34,7
const set<string> &files;
const char * suffix;
 
FileListInserter( const set<string> &f, const char *suf = 0 );
FileListInserter( const set<string> &f, const char *suf = 0);
};
 
/* Insertion operator for the previous inserter object. Writes a
52,7 → 52,7
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
DirList( const char **av ); // Use the following files to construct our list of files, NULL terminated
static const string basename( const string &name ); // get basename of name
 
// File name lists, publically accessible for traversals etc.
/trunk/C-CPP-utils/supermakemake/MakefileObject.cpp
235,9 → 235,12
 
}
 
Makefile::Makefile( std::map<string, string>* conf ){
Makefile::Makefile( std::map<string, string>* conf, DirList* dirList ){
configuration = conf;
initializeMakefileVariables();
 
//Copy everything from the DirList to our object
cpp_files = dirList->cpp;
}
 
Makefile::~Makefile(){
354,6 → 357,7
 
//Write out our compiler variables
//C compiler
/*
iter = makefileVariables.find( "CC" );
cout << "CC = \t\t" << makefileVariables[ "CC" ] << "\n";
makefileVariables.erase( iter );
390,6 → 394,7
iter = makefileVariables.find( "COMPILE.cc" );
cout << "COMPILE.cc = " << makefileVariables[ "COMPILE.cc" ] << "\n";
makefileVariables.erase( iter );
*/
 
cout << '\n';
 
/trunk/C-CPP-utils/supermakemake/MakefileObject.h
21,7 → 21,7
/**
* Create a new Makefile
*/
Makefile( std::map<std::string, std::string>* conf );
Makefile( std::map<std::string, std::string>* conf, DirList* dirList );
 
~Makefile();
 
/trunk/C-CPP-utils/supermakemake/dirlist.cpp
33,6 → 33,8
* space-separated list of file names in f.
*/
ostream & operator<<( ostream &os, const FileListInserter &ins ) {
int current_line_len = 0;
 
for( set<string>::const_iterator it = ins.files.begin();
it != ins.files.end();
++it ) {
41,20 → 43,22
}
 
if( ins.suffix ) {
if( ( DirList::basename( *it ).size() + os.tellp() ) >= 80 ){
//if this would put us over 80 characters on the line,
//put a newline
os << "\n";
if( ( DirList::basename( *it ).size() + current_line_len ) >= 60 ){
//if this would put us over 60 characters on the line,
//put a newline. can't use tellp when redirecting to file
os << "\\\n";
}
os << DirList::basename( *it ) << ins.suffix;
} else {
if( ( ( *it ).size() + os.tellp() ) >= 80 ){
//if this would put us over 80 characters on the line,
if( ( ( *it ).size() + current_line_len ) >= 60 ){
//if this would put us over 60 characters on the line,
//put a newline
os << "\n";
os << "\\\n";
}
os << *it;
}
current_line_len += ( *it ).size();
 
}
return os;
111,7 → 115,7
* .C, .cpp, .c, and .s files, and ignore those found in the directory.
* We always read .h files.
*/
DirList::DirList( int ac, char **av ){
DirList::DirList( const char **av ){
//
// 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
118,18 → 122,20
// files we're interested in, so skip any found here.
//
DIR *dir( opendir( "." ) );
unsigned int ac = 0;
 
if( dir != 0 ){
scan_single_dir( dir, ac );
} else {
cerr << "Error opening current directory\n";
return;
}
 
//
// Copy the names from the argument list into their vector.
//
while( ac-- > 0 ) {
string name( *av++ );
while( av[ ac ] != NULL ){
string name( av[ ac++ ] );
 
switch( fileType( name ) ) {
case CPP:
/trunk/C-CPP-utils/supermakemake/makemake.cpp
17,6 → 17,8
 
#include <fstream>
 
#include <popt.h>
 
#include "dirlist.h"
#include "write.h"
#include "MakefileObject.h"
24,32 → 26,69
bool debug( false );
 
//Method prototype
void printHelp(char*);
void printHelp( const char*);
 
void printHelp(char* progName){
const char* UPDATE_OPTION_DESC =
"Let makemake update the list of files that it compiles. "
"Any new files will be added to the makefile. "
"This will also remove files if makemake cannot find them. "
"All custom targets and flags from the old makefile are kept. "
"Implies --depends";
 
const char* DEPENDS_OPTION_DESC =
"Update only the dependencies that the makefile keeps track of. "
"All targets and flags from the old makefile are kept";
 
const char* HEADER_OPTION_DESC =
"Use the specified file instead of header.mak. "
"See the manual for more information.";
 
const char* NO_HEADER_OPTION_DESC =
"Do not open header.mak even if it exists";
 
const char* PROGRAM_OPTION_DESC =
"Use the specified file instead of programs.mak. "
"See the manual for more information on the programs.mak file";
 
const char* NO_PROGRAM_MAK_OPTION_DESC =
"Do not open programs.mak even if it exists";
const char* NO_DEBUG_OPTION_DESC =
"Do not output compiler debugging flags";
 
const char* AR_OPTION_DESC =
"Explicitly make a static archive. "
"Made automatically if a source file starts with 'ar'";
 
const char* SO_OPTION_DESC =
"Explicitly make a shared library file. "
"Made automatically if a source file starts with 'lib'";
 
const char* INSTALL_OPTION_DESC =
"Generate a 'install' target to install this program. "
"By default, this will install to /usr/local/bin";
 
const char* PREFIX_OPTION_DESC =
"Generate an install target, but install to PREFIX instead "
"of /usr/local/bin. Implies --install";
 
const char* DIRS_OPTION_DESC =
"Look through the specified colon-separated directories for files to compile";
 
const char* RECURSIVE_OPTION_DESC =
"Recursively search through all directories for files to compile.";
 
const char* FILES_OPTION_DESC =
"The files to create the makefile from. If no files are specified, "
"makemake will look through the current directory.";
 
const char* MAKEFILE_OPTION_DESC =
"The makefile to open in order to parse. If no arg given, will attempt to open file 'Makefile'";
 
void printHelp( const 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"
76,14 → 115,86
}
 
int main( int argc, char **argv ){
int main( int argc, const char **argv ){
bool search_dirs = false;
bool recursive_search = false;
char* progName;
char *exename = argv[0];
const char* progName;
const char *exename = argv[0];
char c;
Makefile* makefile;
poptContext pc;
int poptVal;
 
//update variables
bool update = false;
bool depends = false;
 
//header option variables
char* header_mak = NULL;
bool ignore_header_mak = false;
//programs option variables
char* programs_mak = NULL;
bool ignore_programs_mak = false;
 
//debug option variable
bool no_debug = false;
 
//file option variable
char* open_makefile = NULL;
 
//update help table
struct poptOption update_options[] = {
{ "update", 0, POPT_ARG_NONE, &update, 0, UPDATE_OPTION_DESC, NULL },
{ "depends", 0, POPT_ARG_NONE, &depends, 0, DEPENDS_OPTION_DESC, NULL },
{ "file", 'f', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &open_makefile, 'f', MAKEFILE_OPTION_DESC, NULL },
POPT_TABLEEND
};
 
struct poptOption generation_options[] = {
{ "header", 0, POPT_ARG_STRING, &header_mak, 'h', HEADER_OPTION_DESC, NULL },
{ "no-header", 0, POPT_ARG_NONE, &ignore_header_mak, 'h', NO_HEADER_OPTION_DESC, NULL },
{ "programs", 0, POPT_ARG_STRING, &programs_mak, 'p', PROGRAM_OPTION_DESC, NULL },
{ "no-programs", 0, POPT_ARG_NONE, &ignore_programs_mak, 'p', NO_PROGRAM_MAK_OPTION_DESC, NULL },
{ "no-debug", 0, POPT_ARG_NONE, &no_debug, 0, NO_DEBUG_OPTION_DESC, NULL },
POPT_TABLEEND
};
 
struct poptOption main_options[] = {
{ NULL, 0, POPT_ARG_INCLUDE_TABLE, &update_options, 0, "Makefile update options(makefile must already exist): ", NULL },
{ NULL, 0, POPT_ARG_INCLUDE_TABLE, &generation_options, 0, "Makefile generation options(any existing makefile will be overwritten): ", NULL },
POPT_AUTOHELP
POPT_TABLEEND
};
 
pc = poptGetContext( NULL, argc, argv, main_options, 0 );
 
while( ( poptVal = poptGetNextOpt( pc ) ) >= 0 ){
switch( poptVal ){
case 'h':
if( header_mak != NULL && ignore_header_mak == true ){
std::cerr << "ERROR: Unable to have both --no-header and --header, mutually exclusive!" << std::endl;
return 1;
}
break;
case 'p':
if( programs_mak != NULL && ignore_programs_mak == true ){
std::cerr << "ERROR: Unable to have both --no-programs and --programs, mutually exclusive!" << std::endl;
return 1;
}
break;
default: ;
}
}
 
std::cout << open_makefile << std::endl;
return 1;
 
if( poptVal != -1 ){
std::cerr << "Unable to parse options: " << poptStrerror( poptVal ) << std::endl;
return 1;
}
 
map<string, string> config;
config["c_compiler"] = "cc";
config["cpp_compiler"] = "CC";
175,12 → 286,12
// file names.
//
DirList* dirlist;
if( search_dirs ){
dirlist = new DirList( config );
}else if( recursive_search ){
if( recursive_search ){
dirlist = new DirList();
}else if( poptPeekArg( pc ) != NULL ){
dirlist = new DirList( poptGetArgs( pc ) );
}else{
dirlist = new DirList( argc, argv );
dirlist = new DirList( config );
}
 
//
188,8 → 299,8
//
//Write write( *dirlist, &config );
 
makefile = new Makefile( "Makefile.wevp", &config );
// makefile = new Makefile( &config );
//makefile = new Makefile( "Makefile", &config );
makefile = new Makefile( &config, dirlist );
// makefile->addFiles( dirlist );
makefile->writeMakefile();
 
/trunk/C-CPP-utils/supermakemake/Makefile
43,7 → 43,7
CXXFLAGS = -ggdb
CFLAGS = -ggdb
CLIBFLAGS = -lm
CCLIBFLAGS = -lpthread
CCLIBFLAGS = -lpthread -lpopt
########## End of default flags