diff options
Diffstat (limited to 'src/task_so.cc')
| -rw-r--r-- | src/task_so.cc | 111 | 
1 files changed, 45 insertions, 66 deletions
| diff --git a/src/task_so.cc b/src/task_so.cc index 5623bcf..8c6dbd4 100644 --- a/src/task_so.cc +++ b/src/task_so.cc @@ -7,35 +7,24 @@  #include <fstream>  #include "libctor.h" -#include "settings.h"  #include "execute.h" - -namespace -{ -std::string readFile(const std::string &fileName) -{ -	std::ifstream ifs(fileName.c_str(), std::ios::in | std::ios::binary | std::ios::ate); - -	std::ifstream::pos_type fileSize = ifs.tellg(); -	ifs.seekg(0, std::ios::beg); - -	std::vector<char> bytes(fileSize); -	ifs.read(bytes.data(), fileSize); - -	return std::string(bytes.data(), fileSize); -} -} // namespace :: +#include "util.h" +#include "tools.h"  TaskSO::TaskSO(const BuildConfiguration& config,                 const Settings& settings,                 const std::string& target, -               const std::vector<std::string>& objects) -	: Task(config) +               const std::vector<std::string>& objects, +               const std::string& sourceDir) +	: Task(config, settings, sourceDir)  	, config(config)  	, settings(settings) +	, sourceDir(sourceDir)  { -	targetFile = settings.builddir; -	targetFile /= target; +	std::filesystem::path base = sourceDir; +	std::filesystem::create_directories(std::filesystem::path(settings.builddir) / base); + +	_targetFile = base / target;  	for(const auto& object : objects)  	{  		std::filesystem::path objectFile = object; @@ -45,19 +34,18 @@ TaskSO::TaskSO(const BuildConfiguration& config,  	for(const auto& dep : config.depends)  	{ -		std::filesystem::path depFile = settings.builddir; -		depFile /= dep; -		depFiles.push_back(depFile); +		depFiles.push_back(dep);  	} -	flagsFile = settings.builddir / targetFile.stem(); +	flagsFile = std::filesystem::path(settings.builddir) / cleanUp(sourceDir) / targetFile().stem();  	flagsFile += ".flags";  	target_type = TargetType::DynamicLibrary;  	source_language = Language::C;  	for(const auto& source : config.sources)  	{ -		std::filesystem::path sourceFile(source); +		std::filesystem::path sourceFile(source.file); +		// TODO: Use task languages instead  		if(sourceFile.extension().string() != ".c")  		{  			source_language = Language::Cpp; @@ -67,7 +55,7 @@ TaskSO::TaskSO(const BuildConfiguration& config,  bool TaskSO::dirtyInner()  { -	if(!std::filesystem::exists(targetFile)) +	if(!std::filesystem::exists(targetFile()))  	{  		return true;  	} @@ -77,15 +65,6 @@ bool TaskSO::dirtyInner()  		return true;  	} -	for(const auto& objectFile : objectFiles) -	{ -		if(std::filesystem::last_write_time(targetFile) <= -		   std::filesystem::last_write_time(objectFile)) -		{ -			return true; -		} -	} -  	{  		auto lastFlags = readFile(flagsFile.string());  		if(flagsString() != lastFlags) @@ -100,38 +79,21 @@ bool TaskSO::dirtyInner()  int TaskSO::runInner()  { -	std::string objectlist; -	for(const auto& objectFile : objectFiles) -	{ -		if(!objectlist.empty()) -		{ -			objectlist += " "; -		} -		objectlist += objectFile.string(); -	} +	auto tool_chain = getToolChain(config.system);  	std::vector<std::string> args; -	args.push_back("-fPIC"); -	args.push_back("-shared"); - -	args.push_back("-o"); -	args.push_back(targetFile.string()); +	append(args, getOption(tool_chain, opt::position_independent_code)); +	append(args, getOption(tool_chain, opt::build_shared)); -	for(const auto& objectFile : objectFiles) -	{ -		args.push_back(objectFile.string()); -	} +	append(args, getOption(tool_chain, opt::output, targetFile().string())); -	for(const auto& depFile : depFiles) +	for(const auto& task : getDependsTasks())  	{ -		args.push_back(depFile.string()); +		args.push_back(task->targetFile().string());  	} -	for(const auto& flag : config.ldflags) -	{ -		args.push_back(flag); -	} +	append(args, config.flags.ldflags);  	{ // Write flags to file.  		std::ofstream flagsStream(flagsFile); @@ -140,7 +102,7 @@ int TaskSO::runInner()  	if(settings.verbose == 0)  	{ -		std::cout << "LD => " << targetFile.string() << "\n"; +		std::cout << "LD => " << targetFile().string() << "\n";  	}  	auto tool = compiler(); @@ -149,10 +111,10 @@ int TaskSO::runInner()  int TaskSO::clean()  { -	if(std::filesystem::exists(targetFile)) +	if(std::filesystem::exists(targetFile()))  	{ -		std::cout << "Removing " << targetFile.string() << "\n"; -		std::filesystem::remove(targetFile); +		std::cout << "Removing " << targetFile().string() << "\n"; +		std::filesystem::remove(targetFile());  	}  	if(std::filesystem::exists(flagsFile)) @@ -182,13 +144,23 @@ std::vector<std::string> TaskSO::depends() const  std::string TaskSO::target() const  { -	return targetFile.string(); +	return _targetFile.string(); +} + +std::filesystem::path TaskSO::targetFile() const +{ +	return std::filesystem::path(settings.builddir) / sourceDir / _targetFile; +} + +bool TaskSO::derived() const +{ +	return false;  }  std::string TaskSO::flagsString() const  {  	std::string flagsStr = compiler(); -	for(const auto& flag : config.ldflags) +	for(const auto& flag : config.flags.ldflags)  	{  		flagsStr += " " + flag;  	} @@ -203,5 +175,12 @@ std::string TaskSO::flagsString() const  		flagsStr += dep;  	} +	auto deps = depends(); +	for(const auto& dep : deps) +	{ +		flagsStr += " "; +		flagsStr += dep; +	} +  	return flagsStr;  } | 
