| std::vector<std::string> CompileStep::getPublicLDFlags(const std::string &outDir) { | std::vector<std::string> CompileStep::getPublicLDFlags(const std::string &outDir) { | ||||
| BBVariables &vars = variables(); | BBVariables &vars = variables(); | ||||
| auto it = vars.find("ldflags"); | |||||
| if (it == vars.end()) { | |||||
| return {}; | |||||
| } else { | |||||
| return it->second; | |||||
| } | |||||
| std::vector<std::string> flags; | |||||
| toolchain::getLDFlags(vars, flags); | |||||
| return flags; | |||||
| } | } | ||||
| std::vector<std::string> CompileStep::getPublicLDLibs(const std::string &outDir) { | std::vector<std::string> CompileStep::getPublicLDLibs(const std::string &outDir) { | ||||
| std::vector<std::string> libs; | |||||
| BBVariables &vars = variables(); | BBVariables &vars = variables(); | ||||
| auto pkgsIt = vars.find("pkgs"); | |||||
| if (pkgsIt != vars.end()) { | |||||
| toolchain::getPkgConfigLDLibs(pkgsIt->second, libs); | |||||
| } | |||||
| auto libsIt = vars.find("ldlibs"); | |||||
| if (libsIt != vars.end()) { | |||||
| for (auto &lib: libsIt->second) { | |||||
| libs.push_back(lib); | |||||
| } | |||||
| } | |||||
| std::vector<std::string> libs; | |||||
| toolchain::getLDLibs(vars, libs); | |||||
| return libs; | return libs; | ||||
| } | } | ||||
| BBVariables &vars = variables(); | BBVariables &vars = variables(); | ||||
| auto pkgsIt = vars.find("pkgs"); | |||||
| if (pkgsIt != vars.end()) { | |||||
| toolchain::getPkgConfigFlags(pkgsIt->second, flags_); | |||||
| } | |||||
| std::string cflagsName; | |||||
| switch (type_) { | |||||
| case toolchain::FileType::C: | |||||
| cflagsName = "cflags"; | |||||
| break; | |||||
| case toolchain::FileType::CXX: | |||||
| cflagsName = "cxxflags"; | |||||
| break; | |||||
| } | |||||
| auto cflagsIt = vars.find(cflagsName); | |||||
| if (cflagsIt != vars.end()) { | |||||
| for (auto &flag: cflagsIt->second) { | |||||
| flags_.push_back(flag); | |||||
| } | |||||
| } | |||||
| toolchain::getFlags(vars, type_, flags_); | |||||
| hasFlags_ = true; | hasFlags_ = true; | ||||
| return flags_; | return flags_; | ||||
| } | } |
| //#bb ldlibs := -lpthread | |||||
| //#bb ldlibs := pthread | |||||
| #include <getopt.h> | #include <getopt.h> | ||||
| #include <string.h> | #include <string.h> |
| abort(); | abort(); | ||||
| } | } | ||||
| void getFlags(const BBVariables &vars, FileType type, std::vector<std::string> &flags) { | |||||
| auto std = vars.find("std"); | |||||
| if (std != vars.end() && std->second.size() > 0) { | |||||
| flags.push_back("-std=" + std->second[1]); | |||||
| } | |||||
| auto pkgs = vars.find("pkgs"); | |||||
| if (pkgs != vars.end()) { | |||||
| std::vector<std::string> argv; | |||||
| argv.push_back(getPkgConfig()); | |||||
| argv.push_back("--cflags"); | |||||
| for (auto &pkg: pkgs->second) { | |||||
| argv.push_back(pkg); | |||||
| } | |||||
| // Execute $(PKG_CONFIG) --cflags $(PKGS) | |||||
| std::string output; | |||||
| sys::execute(argv, &output, global::verbose >= 2); | |||||
| parseWhitespaceSeparated(output, flags); | |||||
| } | |||||
| auto warnings = vars.find("warnings"); | |||||
| if (warnings != vars.end()) { | |||||
| for (auto &w: warnings->second) { | |||||
| flags.push_back("-W" + w); | |||||
| } | |||||
| } | |||||
| auto includes = vars.find("includes"); | |||||
| if (includes != vars.end()) { | |||||
| for (auto &i: includes->second) { | |||||
| flags.push_back("-I" + i); | |||||
| } | |||||
| } | |||||
| auto sanitize = vars.find("sanitize"); | |||||
| if (sanitize != vars.end()) { | |||||
| for (auto &s: sanitize->second) { | |||||
| flags.push_back("-fsanitize=" + s); | |||||
| } | |||||
| } | |||||
| auto cflags = vars.find( | |||||
| type == FileType::C ? "cflags" : | |||||
| type == FileType::CXX ? "cxxflags" : | |||||
| nullptr); | |||||
| if (cflags != vars.end()) { | |||||
| for (auto &f: cflags->second) { | |||||
| flags.push_back(f); | |||||
| } | |||||
| } | |||||
| } | |||||
| void getLDLibs(const BBVariables &vars, std::vector<std::string> &flags) { | |||||
| auto pkgs = vars.find("pkgs"); | |||||
| if (pkgs != vars.end()) { | |||||
| std::vector<std::string> argv; | |||||
| argv.push_back(getPkgConfig()); | |||||
| argv.push_back("--libs"); | |||||
| for (auto &pkg: pkgs->second) { | |||||
| argv.push_back(pkg); | |||||
| } | |||||
| // Execute $(PKG_CONFIG) --cflags $(PKGS) | |||||
| std::string output; | |||||
| sys::execute(argv, &output, global::verbose >= 2); | |||||
| parseWhitespaceSeparated(output, flags); | |||||
| } | |||||
| auto ldlibs = vars.find("ldlibs"); | |||||
| if (ldlibs != vars.end()) { | |||||
| for (auto &l: ldlibs->second) { | |||||
| flags.push_back("-l" + l); | |||||
| } | |||||
| } | |||||
| } | |||||
| void getLDFlags(const BBVariables &vars, std::vector<std::string> &flags) { | |||||
| auto sanitize = vars.find("sanitize"); | |||||
| if (sanitize != vars.end()) { | |||||
| for (auto &s: sanitize->second) { | |||||
| flags.push_back("-fsanitize=" + s); | |||||
| } | |||||
| } | |||||
| auto ldflags = vars.find("ldflags"); | |||||
| if (ldflags != vars.end()) { | |||||
| for (auto &f: ldflags->second) { | |||||
| flags.push_back(f); | |||||
| } | |||||
| } | |||||
| } | |||||
| void getPkgConfigFlags(const std::vector<std::string> &pkgs, std::vector<std::string> &flags) { | void getPkgConfigFlags(const std::vector<std::string> &pkgs, std::vector<std::string> &flags) { | ||||
| std::vector<std::string> argv; | std::vector<std::string> argv; | ||||
| argv.push_back(getPkgConfig()); | argv.push_back(getPkgConfig()); |
| #include <vector> | #include <vector> | ||||
| #include <string> | #include <string> | ||||
| #include "BBParser.h" | |||||
| namespace toolchain { | namespace toolchain { | ||||
| enum FileType { | |||||
| enum class FileType { | |||||
| C, CXX, | C, CXX, | ||||
| }; | }; | ||||
| enum TargetType { | |||||
| enum class TargetType { | |||||
| BINARY, | BINARY, | ||||
| SHARED_LIBRARY, | SHARED_LIBRARY, | ||||
| STATIC_LIBRARY, | STATIC_LIBRARY, | ||||
| const std::string &path, | const std::string &path, | ||||
| const std::string &outDir); | const std::string &outDir); | ||||
| void getPkgConfigFlags(const std::vector<std::string> &pkgs, std::vector<std::string> &flags); | |||||
| void getPkgConfigLDLibs(const std::vector<std::string> &pkgs, std::vector<std::string> &flags); | |||||
| void getFlags(const BBVariables &vars, FileType type, std::vector<std::string> &flags); | |||||
| void getLDLibs(const BBVariables &vars, std::vector<std::string> &flags); | |||||
| void getLDFlags(const BBVariables &vars, std::vector<std::string> &flags); | |||||
| std::vector<std::string> getDependencies( | std::vector<std::string> getDependencies( | ||||
| const std::vector<std::string> &flags, | const std::vector<std::string> &flags, |