summaryrefslogtreecommitdiff
path: root/kel_rap
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-07-05 00:56:42 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-07-05 00:56:42 +0200
commit1b2029dbbbfdafb618aca3eccdbbba2512b5b49b (patch)
treee9729b2f6ece1819c6def1d736260cf234c3fe87 /kel_rap
parent0283191ec906adaa1cb0738b5cb20044b01bb572 (diff)
downloadapps-dev_tools-1b2029dbbbfdafb618aca3eccdbbba2512b5b49b.tar.gz
kel rap for running multiple simsHEADmain
Diffstat (limited to 'kel_rap')
-rw-r--r--kel_rap/.nix/derivation.nix19
-rw-r--r--kel_rap/SConstruct69
-rw-r--r--kel_rap/c++/SConscript32
-rw-r--r--kel_rap/c++/kel_rap.cpp51
4 files changed, 171 insertions, 0 deletions
diff --git a/kel_rap/.nix/derivation.nix b/kel_rap/.nix/derivation.nix
new file mode 100644
index 0000000..54c41fd
--- /dev/null
+++ b/kel_rap/.nix/derivation.nix
@@ -0,0 +1,19 @@
+{ stdenv
+, scons
+, clang-tools
+}:
+
+stdenv.mkDerivation {
+ pname = "kel_rap";
+ version = "0.0.0";
+
+ nativeBuildInputs = [
+ clang-tools
+ scons
+ ];
+
+ buildInputs = [
+ ];
+
+ src = ./..;
+}
diff --git a/kel_rap/SConstruct b/kel_rap/SConstruct
new file mode 100644
index 0000000..262dced
--- /dev/null
+++ b/kel_rap/SConstruct
@@ -0,0 +1,69 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+import os.path
+import glob
+import re
+
+if sys.version_info < (3,):
+ def isbasestring(s):
+ return isinstance(s,basestring)
+else:
+ def isbasestring(s):
+ return isinstance(s, (str,bytes))
+
+def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""):
+
+ if isbasestring(filetype):
+ dir_path = self.Dir('.').abspath
+ filetype = sorted(glob.glob(dir_path+"/"+filetype))
+
+ for path in filetype:
+ target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path )
+ if shared:
+ target_name+='.os'
+ sources.append( self.SharedObject( target=target_name, source=path ) )
+ else:
+ target_name+='.o'
+ sources.append( self.StaticObject( target=target_name, source=path ) )
+ pass
+
+def isAbsolutePath(key, dirname, env):
+ assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
+
+env_vars = Variables(
+ args=ARGUMENTS
+)
+
+env_vars.Add('prefix',
+ help='Installation target location of build results and headers',
+ default='/usr/local/',
+ validator=isAbsolutePath
+);
+
+env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
+ CXX=['c++'],
+ CPPDEFINES=['SAW_UNIX'],
+ CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'],
+ LIBS=[
+ ]
+)
+env.__class__.add_source_files = add_kel_source_files
+env.Tool('compilation_db');
+env.cdb = env.CompilationDatabase('compile_commands.json');
+
+env.objects = [];
+env.sources = [];
+env.headers = [];
+env.targets = [];
+
+Export('env')
+SConscript('c++/SConscript')
+#SConscript('tests/SConscript')
+
+env.Alias('cdb', env.cdb);
+env.Alias('all', [env.targets]);
+env.Default('all');
+
+env.Alias('install', '$prefix')
diff --git a/kel_rap/c++/SConscript b/kel_rap/c++/SConscript
new file mode 100644
index 0000000..bfcedae
--- /dev/null
+++ b/kel_rap/c++/SConscript
@@ -0,0 +1,32 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+program_env = env.Clone();
+
+program_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+program_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += program_env.sources;
+env.headers += program_env.headers;
+
+## Static lib
+objects_static = []
+program_env.add_source_files(objects_static, program_env.sources, shared=False);
+env.binary = program_env.Program('#build/kel_rap', [objects_static]);
+
+# Set Alias
+env.Alias('binary', [env.binary]);
+
+env.targets += ['binary'];
+
+# Install
+env.Install('$prefix/bin/', [env.binary]);
diff --git a/kel_rap/c++/kel_rap.cpp b/kel_rap/c++/kel_rap.cpp
new file mode 100644
index 0000000..d505125
--- /dev/null
+++ b/kel_rap/c++/kel_rap.cpp
@@ -0,0 +1,51 @@
+#include <array>
+#include <filesystem>
+#include <iostream>
+#include <string>
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+namespace fs = std::filesystem;
+
+int main(int argc, char* argv[]) {
+ if (argc != 2) {
+ std::cerr << "Usage: " << argv[0] << " <dir>\n";
+ return -1;
+ }
+
+ for (const auto& e : fs::directory_iterator(argv[1])) {
+ if (!e.is_regular_file())
+ continue;
+
+ std::string path = e.path().string();
+
+ pid_t pid = fork();
+ if (pid < 0) {
+ std::cerr << "fork failed\n";
+ return -1;
+ }
+
+ if (pid == 0) {
+ std::string path = e.path().string();
+ std::array<char*, 2> args{
+ path.data(),
+ nullptr
+ };
+
+ execvp(args[0], args.data());
+
+ std::cerr << "execvp failed: " << path << '\n';
+ return -1;
+ }
+
+ int status;
+ if (waitpid(pid, &status, 0) < 0) {
+ std::cerr << "waitpid failed\n";
+ return -1;
+ }
+ }
+
+ return 0;
+}