#include #include "regexis024_build_system.h" std::vector getFromPkgConfig(const std::string& req, const std::string& name){ std::string pc_stdout, pc_stderr; CommandReturnCode rc = executeCommand_and_save_output({"pkg-config", "--" + req, name}, pc_stdout, pc_stderr); ASSERT(rc.isOk(), "failed to use pkg-config beacause of:\n" + pc_stderr); // todo: learn how pkg-config actually stores these options std::vector result; for (char ch: pc_stdout) { if (result.empty()) result.emplace_back(); if (ch == ' ') result.emplace_back(); else result.back() += ch; } return result; } ExternalLibraryTarget formExternalLibraryTargetWithNativeName(const std::string& name) { return {name, {getFromPkgConfig("cflags", name), getFromPkgConfig("libs", name)}}; } struct CAWebChat { /* Building runlevel */ BuildUnitsArray runlevel_1; /* Installation runlevel */ BuildUnitsArray runlevel_2; std::string build_type; std::vector warning_flags = {"-Wall", "-Wno-unused-variable", "-Werror=return-type","-pedantic", "-Wno-unused-but-set-variable", "-Wno-reorder"}; std::vector version_flags = {"--std", "c++14", "-D", "_POSIX_C_SOURCE=200809L"}; std::vector debug_defines_release = {"_GLIBCXX_DEBUG"}; std::vector debug_defines_debug = {"_GLIBCXX_DEBUG", "DEBUG_ALLOW_LOUD"}; std::vector opt_flags_release = {"-g", "-O2"}; std::vector opt_flags_debug = {"-g", "-ggdb", "-O0"}; std::vector getSomeRadFlags() const { std::vector my_flag_collection; gxx_add_cli_options(my_flag_collection, warning_flags); gxx_add_cli_options(my_flag_collection, version_flags); if (build_type == "release") { gxx_add_cli_defines(my_flag_collection, debug_defines_release); gxx_add_cli_options(my_flag_collection, opt_flags_release); } else if (build_type == "debug") { gxx_add_cli_defines(my_flag_collection, debug_defines_debug); gxx_add_cli_options(my_flag_collection, opt_flags_debug); } return my_flag_collection; } CAWebChat(std::string _build_type, const NormalCBuildSystemCommandMeaning& cmd) : build_type(std::move(_build_type)) { ASSERT(build_type == "release" || build_type == "debug", "Unknown build type"); std::vector ext_targets = { formExternalLibraryTargetWithNativeName("libjsonincpp"), formExternalLibraryTargetWithNativeName("sqlite3"), }; std::vector my_targets; { CTarget T("engine_engine_number_9", "shared_library"); T.additional_compilation_flags = getSomeRadFlags(); T.proj_deps = {}; T.units = { "baza.cpp", "thread_synchronization.cpp", "os_utils.cpp", "http_structures/client_request_parse.cpp", "http_structures/response_gen.cpp", "connecting_assets/static_asset_manager.cpp", "running_mainloop.cpp", }; for (std::string& u: T.units) u = "http_server/engine_engine_number_9/" + u; T.include_pr = "http_server"; T.include_ir = ""; T.exported_headers = { "baza.h", "baza_throw.h", "thread_synchronization.h", "os_utils.h", "connecting_assets/static_asset_manager.h", "http_structures/client_request.h", "http_structures/response_gen.h", "running_mainloop.h", }; for (std::string& u: T.exported_headers) u = "engine_engine_number_9/" + u; T.installation_dir = ""; my_targets.push_back(T); } { CTarget T("iu9-ca-web-chat", "executable"); T.additional_compilation_flags = getSomeRadFlags(); T.proj_deps = {CTargetDependenceOnProjectsLibrary("engine_engine_number_9")}; T.units = {"main.cpp"}; for (std::string& u: T.units) u = "web_chat/" + u; T.include_pr = "web_chat"; T.installation_dir = ""; my_targets.push_back(T); } regular_ctargets_to_2bus_conversion(ext_targets, my_targets, runlevel_1, runlevel_2, cmd.project_root, cmd.installation_root); } }; int main(int argc, char** argv) { try { ASSERT_pl(argc > 0); assert(argc > 0); std::vector args(argc - 1); for (int i = 0; i + 1 < argc; i++) { args[i] = argv[i + 1]; } NormalCBuildSystemCommandMeaning cmd; regular_bs_cli_cmd_interpret(args, cmd); CAWebChat bs("debug", cmd); // std::string map = "Runlevel 1\n"; // draw_bu_arr_in_dot(bs.runlevel_1, map); // map += "Runlevel 2\n"; // draw_bu_arr_in_dot(bs.runlevel_2, map); // printf("%s", map.c_str()); if (cmd.need_to_build) complete_tasks_of_build_units(bs.runlevel_1); umask(~0755); if (cmd.need_to_install) complete_tasks_of_build_units(bs.runlevel_2); } catch (const buildSystemFailure& e) { printf("Build system failure\n""%s\n", e.toString().c_str()); } }