diff --git a/bob b/bob index d22c85e..15c6ab1 100755 Binary files a/bob and b/bob differ diff --git a/readme.md b/readme.md index 7bb10a9..57129ee 100644 --- a/readme.md +++ b/readme.md @@ -75,3 +75,21 @@ compile; ``` The `compile` line just tells Bob that it's time to compile your code. It will run the compiler with all the options. This is helpful as you don't have to type out your long command to compile everything any time you make a change. + +If you need to use a library, you can add a line like this in your Bobfile: + +``` +library "(library)"; +``` + +This will look in your system's default directory for libraries (usually `/usr/lib`). Specify a custom directory with + +``` +libdir "(libdir)"; +``` + +If you need to include a directory, do it like this: + +``` +include "(include)"; +``` diff --git a/src/main.cpp b/src/main.cpp index 68b1e99..5293114 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,8 +22,20 @@ void log(string input) { cout << "\033[37mInfo: \033[39m" << input << endl; } -int compile(string compiler, string source, string binary) { - string cmd = compiler + " " + source + " -o " + binary; +int compile(string compiler, string source, string binary, vector libVector, vector incVector, vector libDirVector) { + string libs; + for (int i = 0; i < libVector.size(); i++) { + libs += (" -l" + libVector[i]); + } + string includes; + for (int i = 0; i < incVector.size(); i++) { + libs += (" -I " + incVector[i]); + } + string libDir; + for (int i = 0; i < libDirVector.size(); i++) { + libs += (" -I " + libDirVector[i]); + } + string cmd = compiler + libs + " " + source + " -o " + binary; log("Compiling with command " + cmd); return system(cmd.c_str()); } @@ -99,9 +111,9 @@ int main(int argc, char* argv[]) { debug("Created source directory"); ofstream srcFile("src/main." + language); if (lang == "1") { - srcFile << "#include \nint main() {\nprintf(\"Hello, World!\\n\");\nreturn 0;\n}\n"; + srcFile << "#include \n\nint main() {\n printf(\"Hello, World!\\n\");\n return 0;\n}\n"; } else if (lang == "2") { - srcFile << "#include \nusing namespace std;\nint main() {\ncout << \"Hello, World!\" << endl;\nreturn 0;\n}\n"; + srcFile << "#include \n\nusing namespace std;\n\nint main() {\n cout << \"Hello, World!\" << endl;\n return 0;\n}\n"; } srcFile.close(); debug("Created source file"); @@ -179,6 +191,9 @@ int main(int argc, char* argv[]) { string compiler; string binary; string source; + vector libraries; + vector includes; + vector libdirs; string editingTarget; @@ -187,7 +202,7 @@ int main(int argc, char* argv[]) { debug("Token is " + parsed[i][j]); if (j == 0) { if (parsed[i][j] == "compile") { - compile(compiler, source, binary); + compile(compiler, source, binary, libraries, includes, libdirs); break; } editingTarget = parsed[i][j]; @@ -202,6 +217,15 @@ int main(int argc, char* argv[]) { } else if (editingTarget == "source") { debug("Setting source"); source = parsed[i][j]; + } else if (editingTarget == "library") { + debug("Adding library"); + libraries.push_back(parsed[i][j]); + } else if (editingTarget == "include") { + debug("Adding include"); + includes.push_back(parsed[i][j]); + } else if (editingTarget == "libdir") { + debug("Adding library directory"); + libdirs.push_back(parsed[i][j]); } } }