summaryrefslogtreecommitdiff
path: root/modules/crypto
diff options
context:
space:
mode:
authorClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-16 15:09:57 +0200
committerClaudius 'keldu' Holeksa <mail@keldu.de>2024-07-16 15:09:57 +0200
commitf619c4093e564562ce2d48f8cf9b8bcac859009c (patch)
tree3dbc67f328bdd657c9b1e7cc870db52aa6cedf48 /modules/crypto
parent3908c79fa4696bf5d1b7fa717e19a9192f4b29c3 (diff)
Minor changes and setting up crypto module
Diffstat (limited to 'modules/crypto')
-rw-r--r--modules/crypto/.nix/derivation.nix34
-rw-r--r--modules/crypto/SConstruct67
-rw-r--r--modules/crypto/c++/SConscript38
-rw-r--r--modules/crypto/tests/SConscript31
4 files changed, 170 insertions, 0 deletions
diff --git a/modules/crypto/.nix/derivation.nix b/modules/crypto/.nix/derivation.nix
new file mode 100644
index 0000000..dd7d36b
--- /dev/null
+++ b/modules/crypto/.nix/derivation.nix
@@ -0,0 +1,34 @@
+{ lib
+, stdenv
+, scons
+, clang-tools
+, version
+, forstio
+}:
+
+let
+
+in stdenv.mkDerivation {
+ pname = "forstio-crypto";
+ inherit version;
+ src = ./..;
+
+ enableParallelBuilding = true;
+
+ nativeBuildInputs = [
+ scons
+ clang-tools
+ ];
+
+ buildInputs = [
+ forstio.core
+ ];
+
+ doCheck = true;
+ checkPhase = ''
+ scons test
+ ./bin/tests
+ '';
+
+ outputs = ["out" "dev"];
+}
diff --git a/modules/crypto/SConstruct b/modules/crypto/SConstruct
new file mode 100644
index 0000000..f71db5a
--- /dev/null
+++ b/modules/crypto/SConstruct
@@ -0,0 +1,67 @@
+#!/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=[],
+ CPPDEFINES=['SAW_UNIX'],
+ CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'],
+ LIBS=['forstio-core'])
+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/modules/crypto/c++/SConscript b/modules/crypto/c++/SConscript
new file mode 100644
index 0000000..6c5dc44
--- /dev/null
+++ b/modules/crypto/c++/SConscript
@@ -0,0 +1,38 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+crypto_env = env.Clone();
+
+crypto_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+crypto_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += crypto_env.sources;
+env.headers += crypto_env.headers;
+
+## Shared lib
+objects_shared = []
+crypto_env.add_source_files(objects_shared, crypto_env.sources, shared=True);
+env.library_shared = crypto_env.SharedLibrary('#build/forstio-crypto', [objects_shared]);
+
+## Static lib
+objects_static = []
+crypto_env.add_source_files(objects_static, crypto_env.sources, shared=False);
+env.library_static = crypto_env.StaticLibrary('#build/forstio-crypto', [objects_static]);
+
+# Set Alias
+env.Alias('library_crypto', [env.library_shared, env.library_static]);
+
+env.targets += ['library_crypto'];
+
+# Install
+env.Install('$prefix/lib/', [env.library_shared, env.library_static]);
+env.Install('$prefix/include/forstio/crypto/', [crypto_env.headers]);
diff --git a/modules/crypto/tests/SConscript b/modules/crypto/tests/SConscript
new file mode 100644
index 0000000..f8ffc92
--- /dev/null
+++ b/modules/crypto/tests/SConscript
@@ -0,0 +1,31 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+test_cases_env = env.Clone();
+
+test_cases_env.Append(LIBS=['forstio-test']);
+
+test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+test_cases_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += test_cases_env.sources;
+env.headers += test_cases_env.headers;
+
+objects_static = []
+test_cases_env.add_source_files(objects_static, test_cases_env.sources, shared=False);
+test_cases_env.program = test_cases_env.Program('#bin/tests', [objects_static, env.library_static]);
+
+# Set Alias
+env.Alias('test', test_cases_env.program);
+env.Alias('check', test_cases_env.program);
+
+env.targets += ['test','check'];