namespace global { | namespace global { | ||||
bool verbose = false; | |||||
int verbose = 0; | |||||
} | } |
namespace global { | namespace global { | ||||
extern bool verbose; | |||||
extern int verbose; | |||||
} | } |
return 0; | return 0; | ||||
case 'v': | case 'v': | ||||
global::verbose = true; | |||||
global::verbose += 1; | |||||
break; | break; | ||||
case 'o': | case 'o': | ||||
// Change directory? | // Change directory? | ||||
if (workDir.size() > 0) { | if (workDir.size() > 0) { | ||||
if (global::verbose) { | |||||
fprintf(stderr, "Entering directory '%s'\n", workDir.c_str()); | |||||
} | |||||
fprintf(stderr, "Entering directory '%s'\n", workDir.c_str()); | |||||
if (chdir(workDir.c_str()) < 0) { | if (chdir(workDir.c_str()) < 0) { | ||||
perror(workDir.c_str()); | perror(workDir.c_str()); | ||||
case Action::BUILD: | case Action::BUILD: | ||||
// TODO: Support more types than BINARY | // TODO: Support more types than BINARY | ||||
if (!compileAndLink(sources, outDir, jobs, target, toolchain::TargetType::BINARY)) { | if (!compileAndLink(sources, outDir, jobs, target, toolchain::TargetType::BINARY)) { | ||||
logger::log("Nothing to do.\n"); | |||||
logger::log("Nothing to do."); | |||||
} | } | ||||
break; | break; | ||||
#include <sys/wait.h> | #include <sys/wait.h> | ||||
#include <stdexcept> | #include <stdexcept> | ||||
#include "globals.h" | |||||
#include "logger.h" | #include "logger.h" | ||||
#include "globals.h" | |||||
namespace sys { | namespace sys { | ||||
argv.push_back("mkdir"); | argv.push_back("mkdir"); | ||||
argv.push_back("-p"); | argv.push_back("-p"); | ||||
argv.push_back(path.c_str()); | argv.push_back(path.c_str()); | ||||
execute(argv, nullptr); | |||||
execute(argv, nullptr, global::verbose >= 2); | |||||
} | } | ||||
void execute(std::vector<const char *> &args, std::string *output) { | |||||
if (global::verbose) { | |||||
void execute(std::vector<const char *> &args, std::string *output, bool print) { | |||||
if (print) { | |||||
std::string str; | std::string str; | ||||
for (size_t i = 0; i < args.size(); ++i) { | for (size_t i = 0; i < args.size(); ++i) { | ||||
if (i == 0) { | if (i == 0) { |
FileInfo fileInfo(const std::string &path); | FileInfo fileInfo(const std::string &path); | ||||
bool fileExists(const std::string &path); | bool fileExists(const std::string &path); | ||||
void mkdirp(const std::string &path); | void mkdirp(const std::string &path); | ||||
void execute(std::vector<const char *> &args, std::string *output); | |||||
void execute(std::vector<const char *> &args, std::string *output, bool print); | |||||
} | } |
#include <errno.h> | #include <errno.h> | ||||
#include "sys.h" | #include "sys.h" | ||||
#include "globals.h" | |||||
namespace toolchain { | namespace toolchain { | ||||
// Execute $(PKG_CONFIG) --cflags $(PKGS) | // Execute $(PKG_CONFIG) --cflags $(PKGS) | ||||
std::string output; | std::string output; | ||||
sys::execute(argv, &output); | |||||
sys::execute(argv, &output, global::verbose >= 2); | |||||
parseWhitespaceSeparated(output, flags); | parseWhitespaceSeparated(output, flags); | ||||
} | } | ||||
// Execute $(PKG_CONFIG) --libs $(PKGS) | // Execute $(PKG_CONFIG) --libs $(PKGS) | ||||
std::string output; | std::string output; | ||||
sys::execute(argv, &output); | |||||
sys::execute(argv, &output, global::verbose >= 2); | |||||
parseWhitespaceSeparated(output, flags); | parseWhitespaceSeparated(output, flags); | ||||
} | } | ||||
// Execute $(compiler) $(flags) -MM $< | // Execute $(compiler) $(flags) -MM $< | ||||
std::string output; | std::string output; | ||||
sys::execute(argv, &output); | |||||
sys::execute(argv, &output, global::verbose >= 2); | |||||
size_t idx = output.find(':'); | size_t idx = output.find(':'); | ||||
if (idx != std::string::npos) { | if (idx != std::string::npos) { | ||||
argv.push_back(sourcePath.c_str()); | argv.push_back(sourcePath.c_str()); | ||||
// Execute $(compiler) $(flags) -o $@ -c $< | // Execute $(compiler) $(flags) -o $@ -c $< | ||||
sys::execute(argv, nullptr); | |||||
sys::execute(argv, nullptr, global::verbose >= 1); | |||||
} | } | ||||
void link( | void link( | ||||
} | } | ||||
// Execute $(compiler) $(ldflags) -o $@ $(objs) $(ldlibs) | // Execute $(compiler) $(ldflags) -o $@ $(objs) $(ldlibs) | ||||
sys::execute(argv, nullptr); | |||||
sys::execute(argv, nullptr, global::verbose >= 1); | |||||
} | } | ||||
} | } |