Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
---
BasedOnStyle: Microsoft
AccessModifierOffset: '-4'
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: 'true'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'true'
BinPackParameters: 'false'
ColumnLimit: '0'
Language: Cpp
NamespaceIndentation: All
BasedOnStyle: Google
IndentWidth: 2
TabWidth: 2
UseTab: Never
ColumnLimit: 100
DerivePointerAlignment: false
PointerAlignment: Left
ReflowComments: 'true'
SortIncludes: 'false'
UseTab: Always
...
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
SortIncludes: true
IncludeBlocks: Preserve
SpaceAfterCStyleCast: true
SpaceBeforeParens: ControlStatements
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
BreakBeforeBraces: Attach
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: true
NamespaceIndentation: Inner
ReflowComments: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignTrailingComments: true
FixNamespaceComments: true
IncludeIsMainRegex: '(Test)?$'
SortUsingDeclarations: true
32 changes: 32 additions & 0 deletions BTBKit/IManifestBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ============================================================= //
// btb
// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
// ============================================================= //

#pragma once

#include <BTBKit/Includes.h>
#include <BTBKit/Macros.h>

#define BTB_MANIFEST_BUILDER : public BTB::IManifestBuilder

namespace BTB {
/// @brief Builder interface class.
/// @note This class is meant to be used as an interface.
class IManifestBuilder {
public:
IManifestBuilder() = default;
virtual ~IManifestBuilder() = default;

IManifestBuilder& operator=(const IManifestBuilder&) = default;
IManifestBuilder(const IManifestBuilder&) = default;

/// @brief Builds a target using the implemented laguage.
/// @param arg_sz filename size
/// @param arg_val filename path.
/// @retval true succeeded.
/// @retval false failed.
virtual bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) = 0;
virtual const char* buildSystem() = 0;
};
} // namespace BTB
10 changes: 5 additions & 5 deletions lib/Includes.h → BTBKit/Includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#ifndef BTB_INCLUDES_H
#define BTB_INCLUDES_H

#include <cstdio>
#include <cstddef>
#include <string>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <thread>
#include <sstream>
#include <fstream>
#include <string>
#include <thread>

#endif // BTB_INCLUDES_H
#endif // BTB_INCLUDES_H
30 changes: 30 additions & 0 deletions BTBKit/JSONManifestBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ============================================================= //
// btb
// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
// ============================================================= //

#pragma once

#include <BTBKit/IManifestBuilder.h>
#include <json.h>

namespace BTB {
/// @brief JSON builder
class JSONManifestBuilder final BTB_MANIFEST_BUILDER {
public:
JSONManifestBuilder() = default;
~JSONManifestBuilder() override = default;

JSONManifestBuilder& operator=(const JSONManifestBuilder&) = default;
JSONManifestBuilder(const JSONManifestBuilder&) = default;

public:
/// @brief Builds a JSON target.
/// @param arg_sz filename size
/// @param arg_val filename path.
/// @retval true build succeeded.
/// @retval false failed to build.
bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) override;
const char* buildSystem() override;
};
} // namespace BTB
34 changes: 34 additions & 0 deletions BTBKit/Macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ============================================================= //
// btb
// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
// ============================================================= //

#pragma once

extern "C" {
#include <assert.h>
}

#include <rang.h>

#define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0))
#define UNLIKELY(ARG) LIKELY(!(ARG))

#define LIBBTB_VERSION "v0.0.1-libBTB"

#define LIBBTB_VERSION_BCD 0x0001

#define LIBBTB_VERSION_MAJOR 1
#define LIBBTB_VERSION_MINOR 1
#define LIBBTB_VERSION_PATCH 0

#define LIBBTB_UNUSED(X) ((void) X)

namespace BTB::Logger {
/// @brief replacement for std::cout for BTB logging.
inline std::ostream& info() noexcept {
auto& out = std::cout;
out << rang::fg::red << "btb: " << rang::style::reset;
return out;
}
} // namespace BTB::Logger
2 changes: 1 addition & 1 deletion makefile → GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SUDO=sudo
GCC=g++
GCC_MINGW=x86_64-w64-mingw32-g++
CXXFLAGS=-I./lib -I./vendor
CXXFLAGS=-I./ -I./vendor
CXXSTD= -std=c++20
SRC=$(wildcard cli/*.cc) $(wildcard src/*.cc)
OUT=btb
Expand Down
145 changes: 66 additions & 79 deletions cli/CommandLine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,74 @@
// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
// ============================================================= //

#include <JSONManifestBuilder.h>
#include <Includes.h>
#include <BTBKit/Includes.h>
#include <BTBKit/JSONManifestBuilder.h>

static bool kFailed = false;
static bool kDryRun = false;

int main(int argc, char** argv)
{
if (argc <= 1)
return EXIT_FAILURE;

for (size_t index = 1; index < argc; ++index)
{
std::string index_path = argv[index];

if (index_path == "-v" ||
index_path == "--version")
{
BTB::Logger::info() << "Brought to you by Amlal El Mahrouss for the NeKernel project.\n";
BTB::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n";

BTB::Logger::info() << "Bugs, issues? Check out: https://github.com/nekernel-org/btb/issues\n";

return EXIT_SUCCESS;
}
else if (index_path == "--dry-run")
{
kDryRun = true;
continue;
}
else if (index_path == "-h" ||
index_path == "--help")
{
BTB::Logger::info() << "Usage: btb <file>\n";

return EXIT_SUCCESS;
}

if (index_path.starts_with("-"))
{
BTB::Logger::info() << "error: unknown option '" << index_path << "'\n";

return EXIT_FAILURE;
}

std::thread job_build_thread([](std::string index_path) -> void {
BTB::IManifestBuilder* builder = nullptr;

const auto kJsonExtension = ".json";

if (index_path.ends_with(kJsonExtension))
{
builder = new BTB::JSONManifestBuilder();

if (!builder)
{
kFailed = true;
return;
}
}
else
{
BTB::Logger::info() << "error: file '" << index_path << "' is not a JSON file!" << std::endl;
kFailed = true;
return;
}

BTB::Logger::info() << "building manifest: " << index_path << std::endl;

if (builder && !builder->buildTarget(index_path.size(), index_path.c_str(), kDryRun))
{
kFailed = true;
}

delete builder;
builder = nullptr;
},
index_path);

job_build_thread.join();
}

return kFailed ? EXIT_FAILURE : EXIT_SUCCESS;
int main(int argc, char** argv) {
if (argc <= 1) return EXIT_FAILURE;

for (size_t index = 1; index < argc; ++index) {
std::string index_path = argv[index];

if (index_path == "-v" || index_path == "--version") {
BTB::Logger::info() << "Brought to you by Amlal El Mahrouss for the NeKernel project.\n";
BTB::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n";

BTB::Logger::info()
<< "Bugs, issues? Check out: https://github.com/nekernel-org/btb/issues\n";

return EXIT_SUCCESS;
} else if (index_path == "--dry-run") {
kDryRun = true;
continue;
} else if (index_path == "-h" || index_path == "--help") {
BTB::Logger::info() << "Usage: btb <file>\n";

return EXIT_SUCCESS;
}

if (index_path.starts_with("-")) {
BTB::Logger::info() << "error: unknown option '" << index_path << "'\n";

return EXIT_FAILURE;
}

std::thread job_build_thread(
[](std::string index_path) -> void {
BTB::IManifestBuilder* builder = nullptr;

const auto kJsonExtension = ".json";

if (index_path.ends_with(kJsonExtension)) {
builder = new BTB::JSONManifestBuilder();

if (!builder) {
kFailed = true;
return;
}
} else {
BTB::Logger::info() << "error: file '" << index_path << "' is not a JSON file!"
<< std::endl;
kFailed = true;
return;
}

BTB::Logger::info() << "building manifest: " << index_path << std::endl;

if (builder && !builder->buildTarget(index_path.size(), index_path.c_str(), kDryRun)) {
kFailed = true;
}

delete builder;
builder = nullptr;
},
index_path);

job_build_thread.join();
}

return kFailed ? EXIT_FAILURE : EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion compile_flags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-std=c++20
-Ilib
-I./
-Ivendor
8 changes: 0 additions & 8 deletions examples/example_01/example.cc

This file was deleted.

7 changes: 7 additions & 0 deletions examples/example_01_hello_world/hello_world.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>
#include <string>

int main(int argc, char** argv) {
std::cout << "hello, world!\n";
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compiler_path": "g++",
"compiler_std": "c++20",
"headers_path": ["lib"],
"sources_path": ["example.cc"],
"output_name": "example.elf",
"sources_path": ["hello_world.cc"],
"output_name": "hello_world.elf",
"compiler_flags": ["-fPIC"],
"cpp_macros": ["FOO_MACRO"],
"run_after_build": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compiler_path": "x86_64-w64-mingw32-g++",
"compiler_std": "c++20",
"headers_path": ["lib"],
"sources_path": ["example.cc"],
"output_name": "example.elf",
"sources_path": ["hello_world.cc"],
"output_name": "hello_world.elf",
"compiler_flags": ["-fPIC"],
"cpp_macros": ["FOO_MACRO"],
"run_after_build": true
Expand Down
7 changes: 7 additions & 0 deletions examples/example_02_libbtb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Notice for Deployment.

In order to use libBTB, it shall live on the same directory,
<br/>
or within a directory recognized in the `$LD_LIBRARY_PATH` or `$DYLD_LIBRARY_PATH` variable.

## Thanks in advance.
12 changes: 12 additions & 0 deletions examples/example_02_libbtb/libbtb.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <BTBKit/JSONManifestBuilder.h>

#ifndef _WIN32
static auto kPath = "./posix.json";
#else
static auto kPath = ".\win64.json";
#endif

int main(int argc, char** argv) {
auto builder = new BTB::JSONManifestBuilder();
return builder->buildTarget(strlen(kPath), kPath);
}
Loading