libregexis024/building/main.cpp

152 lines
6.6 KiB
C++

#include <regexis024_build_system.h>
struct Libregexis024BuildSystem {
/* Building runlevel */
BuildUnitsArray runlevel_1;
/* Installation runlevel */
BuildUnitsArray runlevel_2;
/* "debug" or "release" */
std::string build_type;
bool build_tests = false;
std::vector<std::string> warning_flags = {"-Wall", "-Wno-unused-variable", "-Werror=return-type","-pedantic",
"-Wno-unused-but-set-variable", "-Wno-reorder"};
std::vector<std::string> version_flags = {"--std", "c++14", "-D", "_POSIX_C_SOURCE=200809L"};
std::vector<std::string> debug_defines_release = {};
std::vector<std::string> debug_defines_debug = {"_GLIBCXX_DEBUG", "LIBREGEXIS024_DEBUG", "LIBREGEXIS024_ALLOW_LOUD"};
std::vector<std::string> opt_flags_release = {"-g", "-O2"};
std::vector<std::string> opt_flags_debug = {"-g", "-ggdb", "-O0"};
std::vector<std::string> getSomeRadFlags() {
std::vector<std::string> 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;
}
Libregexis024BuildSystem(const std::string& build_type, const NormalCBuildSystemCommandMeaning& cmd)
:build_type(build_type)
{
ASSERT(build_type == "release" || build_type == "debug", "Unknown build type");
std::vector<ExternalLibraryTarget> ext_targets;
std::vector<CTarget> my_targets;
{
std::vector<std::string> compilation_units_release = {
"libregexis024vm/vm_errno.cpp",
"libregexis024vm/vm_opcodes_disassembly.cpp",
"libregexis024vm/libregexis024vm_interface.cpp",
"libregexis024vm/libregexis024vm_disassembly.cpp",
"libregexis024vm/libregexis024vm_context.cpp",
"libregexis024vm/instruction_implementation.cpp",
"libregexis024vm/libregex024opcodes_stringification.cpp",
"libregexis024fa/codeset.cpp",
"libregexis024fa/colored_codeset.cpp",
"libregexis024fa/fa_first_stage_fix.cpp",
"libregexis024fa/finite_automaton.cpp",
"libregexis024fa/misc_fa_funcs.cpp",
"libregexis024fa/selarr_priority_table.cpp",
"libregexis024fa/tracking_fa_nodes.cpp",
"libregexis024fa/fa_make_deterministic.cpp",
"libregexis024fa/graph_to_bytecode/natural_compiler_utils.cpp",
"libregexis024fa/graph_to_bytecode/writing_commands.cpp",
"libregexis024fa/graph_to_bytecode/filter.cpp",
"libregexis024fa/graph_to_bytecode/fa_compiler.cpp",
"libregexis024fa/graph_to_bytecode/core.cpp",
"libregexis024sol/utils.cpp",
"libregexis024sol/common_codesets.cpp",
"libregexis024sol/expr_compiler.cpp",
"libregexis024sol/square_bracket_expression.cpp",
"libregexis024sol/sol_misc_base.cpp",
"libregexis024sol/command_expression.cpp",
"libregexis024sol/backslash_expression.cpp",
"libregexis024sol/subexpr_fa_transformed.cpp",
"libregexis024sol/expr_parse_functions/tracking_units.cpp",
"libregexis024sol/expr_parse_functions/ep_sequence.cpp",
"libregexis024sol/expr_parse_functions/command_recognition.cpp",
"libregexis024tools/stringmatching.cpp",
"libregexis024tools/delayed_matching.cpp",
};
/* These are added to compilation_units_of_release */
std::vector<std::string> additional_compilation_units_debug = {
"debugging_regexis024/prettyprint/prettyprint_util.cpp",
"debugging_regexis024/vm/libregexis024vm_debug.cpp",
"debugging_regexis024/debug_through_graphviz.cpp",
};
/* Suitable forr both release and debug (even though you will pretty much never need to export headers of build of
* debug build type */
std::vector<std::string> exported_headers = {
"libregexis024vm/vm_errno.h",
"libregexis024vm/vm_opcodes_types.h",
"libregexis024vm/vm_opcodes.h",
"libregexis024vm/libregexis024vm_interface.h",
"libregexis024fa/tracking_variables.h",
"libregexis024sol/part_of_expr_that_tracks.h",
"libregexis024sol/expr_compiler.h",
"libregexis024tools/stringmatching.h",
"libregexis024tools/delayed_matching.h",
};
CTarget T{"libregexis024", "shared_library"};
T.additional_compilation_flags = getSomeRadFlags();
array_concat(T.units, compilation_units_release);
if (build_type == "debug")
array_concat(T.units, additional_compilation_units_debug);
T.include_pr = "";
T.include_ir = "";
T.exported_headers = exported_headers;
T.installation_dir = "";
T.pc_output_path = "libregexis024.pc";
my_targets.push_back(T);
}
if (build_tests) {
CTarget T{"libregexis024_test4", "executable"};
T.additional_compilation_flags = getSomeRadFlags();
T.proj_deps = {CTargetDependenceOnProjectsLibrary{"libregexis024"}};
T.units = {"libregexis024test/test4.cpp"};
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);
std::vector<std::string> 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);
Libregexis024BuildSystem bs("release", cmd);
if (cmd.need_to_build)
complete_tasks_of_build_units(bs.runlevel_1);
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());
}
}