diff --git a/main.cpp b/main.cpp index c385b8c..ce2300a 100644 --- a/main.cpp +++ b/main.cpp @@ -4,11 +4,28 @@ #include #include #include +#include +#include using namespace std; const int MAX_PROCESSES = 4; const char* const COMPILER = "g++"; +const string help_header = "\ +KTPuild\n\ + An application that makes the compiling of large projects easier. The\n\ + intended use for EECS 280 students attending the University of \n\ + Michigan. Built and maintained by Kappa Theta Pi Alpha Chapter. For reporting\n\ + bugs or requesting features please visit: https://github.com/ktp-dev/KTPuild\n"; + +const string help_msg = "\n\ +Usages:\n\ + KTPuild\n\ + KTPuild -h | --help\n\ + \n\ +Options:\n\ + -h | --help: display help information\n\n"; + void run_command(const vector& command) { //To run a command, we have to call execvp. execvp expects a char** (C style array) that is null terminated. Thus, convert our nice C++ array of strings to a C array of C strings. Also, print them out so the user knows what we are running. @@ -92,18 +109,67 @@ void link_executable(const Buildfile& buildfile, const vector& cpp_files } } -int main() { +bool is_created(const string &filename){ + + // tests for the existence of the file with success being a 0 + if(access(filename.c_str(), F_OK) == 0) + { + return true; + } + return false; +} + +bool parse_commandline_args(int argc, char** &argv) +{ + struct option longOpts[] = { + { "help", no_argument, nullptr, 'h' }, + { nullptr, 0, nullptr, '\0' } + }; + + int option; + + while((option = getopt_long(argc, argv, "h", longOpts, nullptr))!= -1) + { + switch(option) + { + case 'h': + { + std::cout<<(help_header + help_msg); + return false; + } + default: + { + throw std::runtime_error(help_msg); + } + } + } + return true; +} + +int main(int argc, char ** argv) { /* - * 1) get the cpp files - * 2) determine what cpp files to recompile + * 1) parse for commandline arguments + * 2) get the cpp files + * 3) determine what cpp files to recompile * - need to recompile if no obj file we have to create it, or if there is an obj file, * but the cpp file has been modified more recently than the obj file - * 3) if none, we are done - * 4) else, recompile them (done!) - * 5) relink everything - * 6) done! + * - need to check to see if there is an executable created + * 4) if none, we are done + * 5) else, recompile them (done!) + * 6) relink everything + * 7) done! */ try { + + /* + parse command line arguments, if we get false back we encountered either a help or invalid + option and should exit the program while displaying the help message. + */ + if(!parse_commandline_args(argc, argv)) + { + return 1; + } + Buildfile buildfile; vector cpp_filename = buildfile.get_cpp_files(); //1 vector changed; @@ -111,10 +177,25 @@ int main() { if (has_changed(file)) changed.push_back(file); } - //now we know what cpp files have changed - if (changed.empty()) //TODO: also ensure exe exists + // if there is nothing to recompile and the executable has been created we are done + if (changed.empty() && is_created(buildfile.get_executable_name())) return 0; //3 +int main() +{ + +} + +int main() +{ + +} + +int main() +{ + +} + compile_object_files(buildfile, changed); //4 link_executable(buildfile, cpp_filename); //4