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(); |
|