From a45e660211b0e262a53047ac09426fd736d6ef9c Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 20 Jun 2024 09:35:40 +0200 Subject: buildme: initial commit. Signed-off-by: Amlal El Mahrouss --- buildme/main.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'buildme/main.cpp') diff --git a/buildme/main.cpp b/buildme/main.cpp index a328171..b91bd98 100644 --- a/buildme/main.cpp +++ b/buildme/main.cpp @@ -6,9 +6,63 @@ // #include +#include -int main(int argc, const char * argv[]) { - // insert code here... - std::cout << "Hello, World!\n"; +#include "json.hpp" + +using json = nlohmann::json; + +int main(int argc, const char * argv[]) +{ + std::cout << "buildme: "; + std::string path; + + if (argc == 1) + { + std::cout << "no files, defaulting to build.json\n"; + path = "./build.json"; + } + else + { + path = argv[1]; + } + + try + { + std::ifstream fJson(path); + json buildme = json::parse(fJson); + + std::string compiler = buildme["compiler_path"].get(); + std::cout << "choose toolchain: " << compiler << std::endl; + + json headerSearchPath = buildme["headers_path"]; + std::cout << "search path: " << headerSearchPath.dump() << std::endl; + + json sourceFiles = buildme["sources_path"]; + std::cout << "source files: " << sourceFiles.dump() << std::endl; + + std::string cmdLine = compiler + " "; + + for (auto sources : sourceFiles) + { + cmdLine += sources.get() + " "; + } + + for (auto sources : sourceFiles) + { + cmdLine += "-include=" + sources.get() + " "; + } + + cmdLine += "-std=" + buildme["compiler_std"].get() + " "; + + std::cout << "running: " << cmdLine << std::endl; + + std::system(cmdLine.c_str()); + } + catch (...) + { + return 1; + } + return 0; } -- cgit v1.2.3