#include "pch.h" #include "tasks.h" #include "../core/process.h" namespace mob::tasks { openssl::openssl() : basic_task("openssl") { } std::string openssl::version() { return conf::version_by_name("openssl"); } bool openssl::prebuilt() { return conf().prebuilt().use_prebuilt("openssl"); } fs::path openssl::source_path() { return conf().paths().build() / ("openssl-" + version()); } fs::path openssl::build_path() { return source_path() / "build"; } fs::path openssl::bin_path() { return build_path() / "bin"; } void openssl::do_clean(clean c) { instrument([&] { if (prebuilt()) { if (is_set(c, clean::redownload)) run_tool(downloader(prebuilt_url(), downloader::clean)); } else { if (is_set(c, clean::redownload)) run_tool(downloader(source_url(), downloader::clean)); } if (is_any_set(c, clean::reextract|clean::reconfigure|clean::rebuild)) { cx().trace(context::reextract, "deleting {}", source_path()); op::delete_directory(cx(), source_path(), op::optional); return; } }); } void openssl::do_fetch() { if (prebuilt()) fetch_prebuilt(); else fetch_from_source(); } void openssl::do_build_and_install() { if (prebuilt()) build_and_install_prebuilt(); else build_and_install_from_source(); } void openssl::fetch_prebuilt() { cx().trace(context::generic, "using prebuilt openssl"); const auto file = instrument([&] { return run_tool(downloader(prebuilt_url())); }); instrument([&] { run_tool(extractor() .file(file) .output(source_path())); }); } void openssl::fetch_from_source() { const auto file = instrument([&] { return run_tool(downloader(source_url())); }); instrument([&] { run_tool(extractor() .file(file) .output(source_path())); }); } void openssl::build_and_install_prebuilt() { instrument([&] { copy_files(); }); } void openssl::build_and_install_from_source() { instrument([&] { if (fs::exists(source_path() / "makefile")) cx().trace(context::bypass, "openssl already configured"); else configure(); }); instrument([&] { install_engines(); }); instrument([&] { op::copy_file_to_dir_if_better(cx(), source_path() / "ms" / "applink.c", include_path()); copy_files(); }); } void openssl::configure() { run_tool(process_runner(process() .binary(perl::binary()) .arg("Configure") .arg("VC-WIN64A") .arg("--openssldir=", build_path()) .arg("--prefix=", build_path()) .arg("-FS") .arg("-MP1") .arg("-wd4566") .cwd(source_path()) .env(env::vs(arch::x64)))); } void openssl::install_engines() { const int max_tries = 3; for (int tries=0; tries openssl::output_names() { return { "libcrypto-" + version_no_patch_underscores() + "-x64", "libssl-" + version_no_patch_underscores() + "-x64" }; } openssl::version_info openssl::parsed_version() { // 1.2.3d // everything but 1 is optional std::regex re( "(\\d+)" // 1 "(?:" "\\.(\\d+)" // .2 "(?:" "\\.(\\d+)([a-zA-Z]+)?" // .3d ")?" ")?"); std::smatch m; const auto s = version(); if (!std::regex_match(s, m, re)) gcx().bail_out(context::generic, "bad openssl version '{}'", s); return {m[1], m[2], m[3]}; } std::string openssl::version_no_patch_underscores() { auto v = parsed_version(); std::string s = v.major; if (v.minor != "") s += "_" + v.minor; return s; } } // namespace