summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--btbuild/compile_flags.txt2
-rw-r--r--btbuild/main.cxx24
-rw-r--r--inc/manifest_builder.hxx2
-rw-r--r--makefile7
-rw-r--r--src/compile_flags.txt2
-rw-r--r--src/manifest_builder.cxx101
-rw-r--r--tests/build.json6
-rw-r--r--tests/example.cxx8
-rw-r--r--tests/example.json6
10 files changed, 108 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore
index c0f6293..a98e0c5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,8 @@ syntax: glob
html/
latex/
+btb
+
.cmake/
.qtc_clangd/
CMakeCache.txt
diff --git a/btbuild/compile_flags.txt b/btbuild/compile_flags.txt
new file mode 100644
index 0000000..f6d73f3
--- /dev/null
+++ b/btbuild/compile_flags.txt
@@ -0,0 +1,2 @@
+-std=c++20
+-I../inc
diff --git a/btbuild/main.cxx b/btbuild/main.cxx
new file mode 100644
index 0000000..3c0840b
--- /dev/null
+++ b/btbuild/main.cxx
@@ -0,0 +1,24 @@
+#include <manifest_builder.hxx>
+#include <cstddef>
+#include <string>
+#include <iostream>
+
+int main(int argc, char** argv)
+{
+ ManifestBuilder builder;
+
+ for (size_t index = 1; index < argc; ++index)
+ {
+ std::string index_json = argv[index];
+
+ if (index_json == "-v")
+ {
+ std::cout << "btb: version 1.00\n";
+ continue;
+ }
+
+ builder.buildJson(index_json.size(), index_json.c_str());
+ }
+
+ return 0;
+}
diff --git a/inc/manifest_builder.hxx b/inc/manifest_builder.hxx
index 4276ee2..f66a7a8 100644
--- a/inc/manifest_builder.hxx
+++ b/inc/manifest_builder.hxx
@@ -12,6 +12,6 @@ public:
ManifestBuilder(const ManifestBuilder&) = default;
public:
- int buildJson(int argc, const char * argv[]);
+ bool buildJson(int arg_sz, const char * arg_val);
};
diff --git a/makefile b/makefile
index 69cfe1d..e04801f 100644
--- a/makefile
+++ b/makefile
@@ -1,3 +1,8 @@
.PHONY: build-zpt-core
build-zpt-core:
- g++ -I./inc $(wildcard src/*.cxx) -fPIC -shared -o libzpt-core.so
+ g++ -I./inc $(wildcard src/*.cxx) -std=c++20 -fPIC -shared -o libzpt-core.so
+ cp libzpt-core.so /usr/lib
+
+.PHONY: build-btbuild
+build-btbuild:
+ g++ -I./inc $(wildcard btbuild/*.cxx) -lzpt-core -o btb
diff --git a/src/compile_flags.txt b/src/compile_flags.txt
new file mode 100644
index 0000000..f6d73f3
--- /dev/null
+++ b/src/compile_flags.txt
@@ -0,0 +1,2 @@
+-std=c++20
+-I../inc
diff --git a/src/manifest_builder.cxx b/src/manifest_builder.cxx
index ec60028..a18dc72 100644
--- a/src/manifest_builder.cxx
+++ b/src/manifest_builder.cxx
@@ -5,67 +5,80 @@
// Created by Amlal on 6/20/24.
//
-#include <sstream>
+#include <cstdio>
+#include <json.hxx>
+#include <cstdlib>
#include <iostream>
#include <fstream>
-
#include <manifest_builder.hxx>
-#include <json.hxx>
-
using json = nlohmann::json;
-int ManifestBuilder::buildJson(int argc, const char * argv[])
+bool ManifestBuilder::buildJson(int arg_sz, const char* arg_val)
{
- std::cout << "buildme: ";
- std::string path;
+ std::cout << "buildme: ";
+ std::string path;
+
+ if (arg_sz < 0)
+ {
+ std::cout << "no files provided.\n";
+ return false;
+ }
+ else
+ {
+ path = arg_val;
+ }
+
+ try
+ {
+ std::ifstream json_obj(path);
+
+ if (!json_obj.good())
+ {
+ std::cout << "buildme: no files provided.\n";
+ perror("buildme");
+
+ return false;
+ }
+
+ json buildme = json::parse(json_obj);
- if (argc == 1)
- {
- std::cout << "no files, defaulting to build.json\n";
- path = "./build.json";
- }
- else
- {
- path = argv[1];
- }
+ std::string compiler = buildme["compiler_path"].get<std::string>();
+ std::cout << "choose toolchain: " << compiler << std::endl;
- try
- {
- std::ifstream fJson(path);
- json buildme = json::parse(fJson);
+ json headerSearchPath = buildme["headers_path"];
+ std::cout << "buildme: search path: " << headerSearchPath.dump() << std::endl;
- std::string compiler = buildme["compiler_path"].get<std::string>();
- std::cout << "choose toolchain: " << compiler << std::endl;
+ json sourceFiles = buildme["sources_path"];
+ std::cout << "buildme: source files: " << sourceFiles.dump() << std::endl;
- json headerSearchPath = buildme["headers_path"];
- std::cout << "search path: " << headerSearchPath.dump() << std::endl;
+ std::string cmdLine = compiler + " ";
- json sourceFiles = buildme["sources_path"];
- std::cout << "source files: " << sourceFiles.dump() << std::endl;
+ for (auto& sources : sourceFiles)
+ {
+ cmdLine += sources.get<std::string>() + " ";
+ }
- std::string cmdLine = compiler + " ";
+ for (auto& headers : headerSearchPath)
+ {
+ cmdLine += "-include=" + headers.get<std::string>() + " ";
+ }
- for (auto sources : sourceFiles)
- {
- cmdLine += sources.get<std::string>() + " ";
- }
+ cmdLine += "-std=" + buildme["compiler_std"].get<std::string>() + " ";
- for (auto sources : sourceFiles)
- {
- cmdLine += "-include=" + sources.get<std::string>() + " ";
- }
+ cmdLine += "-o " + buildme["output_name"].get<std::string>();
- cmdLine += "-std=" + buildme["compiler_std"].get<std::string>() + " ";
+ std::cout << "buildme: running: '" << cmdLine << "'" << std::endl;
- std::cout << "running: " << cmdLine << std::endl;
+ std::system(cmdLine.c_str());
+ }
+ catch (std::runtime_error& err)
+ {
+ perror("buildme");
+ std::cout << "buildme: error: " << err.what() << std::endl;
- std::system(cmdLine.c_str());
- }
- catch (...)
- {
- return 1;
- }
+ return false;
+ }
- return 0;
+ return true;
}
diff --git a/tests/build.json b/tests/build.json
deleted file mode 100644
index 8a1ee45..0000000
--- a/tests/build.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "compiler_path": "cplusplus",
- "compiler_std": "c++20",
- "headers_path": ["/App/Modules/", "/App/Headers/"],
- "sources_path": ["/App/Sources/*.cxx"]
-}
diff --git a/tests/example.cxx b/tests/example.cxx
new file mode 100644
index 0000000..dfef2e4
--- /dev/null
+++ b/tests/example.cxx
@@ -0,0 +1,8 @@
+#include <string>
+#include <iostream>
+
+int main(int argc, char** argv)
+{
+ std::cout << "hello, world!\n";
+ return 0;
+}
diff --git a/tests/example.json b/tests/example.json
new file mode 100644
index 0000000..12dd2a5
--- /dev/null
+++ b/tests/example.json
@@ -0,0 +1,6 @@
+{
+ "compiler_path": "g++",
+ "compiler_std": "c++20",
+ "sources_path": ["tests/example.cxx"],
+ "output_name": "example.elf"
+}