@@ -105,30 +105,15 @@ void CompileStep::doWriteCompDB(const std::string &outDir, compdb::Writer &w) { | |||
std::vector<std::string> CompileStep::getPublicLDFlags(const std::string &outDir) { | |||
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> libs; | |||
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; | |||
} | |||
@@ -163,28 +148,7 @@ std::vector<std::string> &CompileStep::flags() { | |||
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; | |||
return flags_; | |||
} |
@@ -1,4 +1,4 @@ | |||
//#bb ldlibs := -lpthread | |||
//#bb ldlibs := pthread | |||
#include <getopt.h> | |||
#include <string.h> |
@@ -122,6 +122,99 @@ std::string targetFilePath( | |||
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) { | |||
std::vector<std::string> argv; | |||
argv.push_back(getPkgConfig()); |
@@ -3,13 +3,15 @@ | |||
#include <vector> | |||
#include <string> | |||
#include "BBParser.h" | |||
namespace toolchain { | |||
enum FileType { | |||
enum class FileType { | |||
C, CXX, | |||
}; | |||
enum TargetType { | |||
enum class TargetType { | |||
BINARY, | |||
SHARED_LIBRARY, | |||
STATIC_LIBRARY, | |||
@@ -21,8 +23,9 @@ std::string targetFilePath( | |||
const std::string &path, | |||
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( | |||
const std::vector<std::string> &flags, |