diff options
| -rw-r--r-- | btbuild/main.cxx | 39 | ||||
| -rw-r--r-- | makefile | 5 | ||||
| -rw-r--r-- | src/manifest_builder.cxx | 30 | ||||
| -rw-r--r-- | tests/example.json | 5 |
4 files changed, 59 insertions, 20 deletions
diff --git a/btbuild/main.cxx b/btbuild/main.cxx index 3c0840b..5e771cb 100644 --- a/btbuild/main.cxx +++ b/btbuild/main.cxx @@ -1,23 +1,52 @@ +#include <cstdio> #include <manifest_builder.hxx> #include <cstddef> #include <string> #include <iostream> +#include <thread> + +int job_index = 0; + int main(int argc, char** argv) { - ManifestBuilder builder; + job_index = argc-1; for (size_t index = 1; index < argc; ++index) { std::string index_json = argv[index]; - if (index_json == "-v") + if (index_json == "-v" || + index_json == "--version") { - std::cout << "btb: version 1.00\n"; - continue; + std::cout << "btb(uild): version 1.00\n"; + std::cout << "btb(uild): brought to you by Amlal El Mahrouss.\n"; + return 0; } - builder.buildJson(index_json.size(), index_json.c_str()); + std::thread job([] (std::string index_json) -> void { + std::cout << "building: " << index_json << std::endl; + + ManifestBuilder builder; + + if (!builder.buildJson(index_json.size(), index_json.c_str())) + { + std::string format = "btb "; + format += index_json; + + perror(format.c_str()); + } + + --job_index; + }, index_json); + + job.detach(); + } + + // wait for completion of all jobs. + while (job_index) + { + } return 0; @@ -7,3 +7,8 @@ build-zpt-core: build-btbuild: g++ -I./inc $(wildcard btbuild/*.cxx) -lzpt-core -o btb cp btb /usr/bin + +.PHONY: help +help: + @echo "=> build-zpt-core" + @echo "=> build-btbuild" diff --git a/src/manifest_builder.cxx b/src/manifest_builder.cxx index a18dc72..7a6ee2a 100644 --- a/src/manifest_builder.cxx +++ b/src/manifest_builder.cxx @@ -16,12 +16,10 @@ using json = nlohmann::json; bool ManifestBuilder::buildJson(int arg_sz, const char* arg_val) { - std::cout << "buildme: "; std::string path; if (arg_sz < 0) { - std::cout << "no files provided.\n"; return false; } else @@ -35,22 +33,15 @@ bool ManifestBuilder::buildJson(int arg_sz, const char* arg_val) if (!json_obj.good()) { - std::cout << "buildme: no files provided.\n"; - perror("buildme"); - return false; } json buildme = json::parse(json_obj); std::string compiler = buildme["compiler_path"].get<std::string>(); - std::cout << "choose toolchain: " << compiler << std::endl; json headerSearchPath = buildme["headers_path"]; - std::cout << "buildme: search path: " << headerSearchPath.dump() << std::endl; - json sourceFiles = buildme["sources_path"]; - std::cout << "buildme: source files: " << sourceFiles.dump() << std::endl; std::string cmdLine = compiler + " "; @@ -61,21 +52,32 @@ bool ManifestBuilder::buildJson(int arg_sz, const char* arg_val) for (auto& headers : headerSearchPath) { - cmdLine += "-include=" + headers.get<std::string>() + " "; + cmdLine += "-I" + headers.get<std::string>() + " "; } - cmdLine += "-std=" + buildme["compiler_std"].get<std::string>() + " "; + json macrosList = buildme["cpp_macros"]; - cmdLine += "-o " + buildme["output_name"].get<std::string>(); + for (auto& macro : macrosList) + { + cmdLine += "-D" + macro.get<std::string>() + " "; + } + + json compilerFlags = buildme["compiler_flags"]; - std::cout << "buildme: running: '" << cmdLine << "'" << std::endl; + for (auto& flag : compilerFlags) + { + cmdLine += flag.get<std::string>() + " "; + } + + cmdLine += "-std=" + buildme["compiler_std"].get<std::string>() + " "; + cmdLine += "-o " + buildme["output_name"].get<std::string>(); std::system(cmdLine.c_str()); } catch (std::runtime_error& err) { - perror("buildme"); std::cout << "buildme: error: " << err.what() << std::endl; + perror("buildme"); return false; } diff --git a/tests/example.json b/tests/example.json index 12dd2a5..6a14d63 100644 --- a/tests/example.json +++ b/tests/example.json @@ -1,6 +1,9 @@ { "compiler_path": "g++", "compiler_std": "c++20", + "headers_path": ["inc"], "sources_path": ["tests/example.cxx"], - "output_name": "example.elf" + "output_name": "example.elf", + "compiler_flags": ["-fPIC"], + "cpp_macros": ["FOO_MACRO"] } |
