diff --git a/.gitignore b/.gitignore index 3815f04..691f43d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ bin/** *.dblite *.o *.a +*.pyc diff --git a/SConstruct b/SConstruct index 32b3970..182b3a0 100644 --- a/SConstruct +++ b/SConstruct @@ -71,6 +71,25 @@ env_base.msvc = False # avoid issues when building with different versions of python out of the same directory env_base.SConsignFile(".sconsign{0}.dblite".format(pickle.HIGHEST_PROTOCOL)) +database_list = [] + +for x in sorted(glob.glob("database/*")): + if not os.path.isdir(x) or not os.path.exists(x + "/detect.py"): + continue + tmppath = "./" + x + + sys.path.insert(0, tmppath) + import detect + + if detect.is_active() and detect.can_build(): + x = x.replace("database/", "") # rest of world + x = x.replace("database\\", "") # win32 + database_list += [x] + + sys.path.remove(tmppath) + sys.modules.pop("detect") + + # Build options opts = Variables([], ARGUMENTS) @@ -92,10 +111,34 @@ env_base.Prepend(CPPPATH=["#libs"]) env_base.Prepend(LINKFLAGS=["-lpthread"]) env_base.Append(CXX=["-o3"]) -#env_base.Append(CXX=["-g"]) +#env_base.Append(CXX=["-g2"]) env = env_base.Clone() +for d in database_list: + tmppath = "./database/" + d + sys.path.insert(0, tmppath) + + import detect + + env_db = env_base.Clone() + + # Compilation DB requires SCons 3.1.1+. + from SCons import __version__ as scons_raw_version + + scons_ver = env_db._get_major_minor_revision(scons_raw_version) + + if scons_ver >= (4, 0, 0): + env_db.Tool("compilation_db") + env_db.Alias("compiledb", env.CompilationDatabase()) + + detect.configure(env_db) + detect.configure(env) + + Export("env_db") + + SConscript("database/" + d + "/SCsub") + Export("env") SConscript("core/SCsub") diff --git a/core/database.cpp b/core/database.cpp new file mode 100644 index 0000000..e69de29 diff --git a/core/database.h b/core/database.h new file mode 100644 index 0000000..e69de29 diff --git a/core/database_manager.cpp b/core/database_manager.cpp new file mode 100644 index 0000000..e69de29 diff --git a/core/database_manager.h b/core/database_manager.h new file mode 100644 index 0000000..e69de29 diff --git a/database/mysql/SCsub b/database/mysql/SCsub new file mode 100644 index 0000000..91367d3 --- /dev/null +++ b/database/mysql/SCsub @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +Import("env_db") + +env_db.core_sources = [] + +env_db.add_source_files(env_db.core_sources, "*.cpp") + +# Build it all as a library +lib = env_db.add_library("database_mysql", env_db.core_sources) +env_db.Prepend(LIBS=[lib]) diff --git a/database/mysql/detect.py b/database/mysql/detect.py new file mode 100644 index 0000000..2508cc9 --- /dev/null +++ b/database/mysql/detect.py @@ -0,0 +1,59 @@ +import os +import platform +import sys + + +def is_active(): + return True + + +def get_name(): + return "mysql" + + +def can_build(): + + if os.name == "posix" or sys.platform == "darwin": + x11_error = os.system("pkg-config --version > /dev/null") + if x11_error: + return False + + mariadb_error = os.system("pkg-config mariadb --modversion --silence-errors > /dev/null ") + mysql_error = os.system("pkg-config mysql --modversion --silence-errors > /dev/null ") + + if mariadb_error and mysql_error: + #print("mysql and mariadb not found..") + return False + + return True + + #todo + return False + + +def get_opts(): + from SCons.Variables import BoolVariable, EnumVariable + + return [ + EnumVariable("debug_symbols", "Add debugging symbols to release/release_debug builds", "yes", ("yes", "no")), + ] + + +def get_flags(): + + return [] + + +def configure(env): + mariadb_error = os.system("pkg-config mariadb --modversion --silence-errors > /dev/null ") + mysql_error = os.system("pkg-config mysql --modversion --silence-errors > /dev/null ") + + if not mariadb_error: + env.ParseConfig("pkg-config mariadb --cflags --libs") + + if not mysql_error: + env.ParseConfig("pkg-config mysql --cflags --libs") + + # Link those statically for portability + #if env["use_static_cpp"]: + #env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"]) diff --git a/database/mysql/mysql_connection.cpp b/database/mysql/mysql_connection.cpp new file mode 100644 index 0000000..1f787d1 --- /dev/null +++ b/database/mysql/mysql_connection.cpp @@ -0,0 +1 @@ +#include "mysql_connection.h" \ No newline at end of file diff --git a/database/mysql/mysql_connection.h b/database/mysql/mysql_connection.h new file mode 100644 index 0000000..9a854e4 --- /dev/null +++ b/database/mysql/mysql_connection.h @@ -0,0 +1,27 @@ +#ifndef MYSQL_CONNECTION +#define MYSQL_CONNECTION + +//Brynet has it aswell, and because of using namespace it is defined here aswell +//later this will be fixed better +#ifdef IS_NUM +#undef IS_NUM +#endif + +#include + +class MysqlConnection { + public: + MysqlConnection() { + mysql = new MYSQL(); + } + ~MysqlConnection() + { + delete mysql; + } + + MYSQL *mysql; +}; + +#undef IS_NUM + +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index 0df776f..9549a88 100644 --- a/main.cpp +++ b/main.cpp @@ -7,6 +7,8 @@ #include "rdn_application.h" +#include "database/mysql/mysql_connection.h" + #define MAIN_CLASS RDNApplication int main(int argc, char **argv) { @@ -14,6 +16,9 @@ int main(int argc, char **argv) { file_cache->wwwroot = "./www"; file_cache->wwwroot_refresh_cache(); + //MysqlConnection *conn; + //conn = new MysqlConnection(); + Application *app = new MAIN_CLASS(); app->setup_routes(); @@ -28,6 +33,7 @@ int main(int argc, char **argv) { delete server; delete app; delete file_cache; + // delete conn; return 0; } \ No newline at end of file