X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvirtualfilesystem.cpp;h=cccc16945f6c74db42750a0c80e4eaac32000bf7;hb=19a821ee581f0fe60860627472cc59065247bf13;hp=0dc8de604ffd4253e4ae51e4920ef4c95dd09d0a;hpb=37ffa892c453a91f06d34068e239e1ba316d7700;p=builder.git diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index 0dc8de6..cccc169 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -1,9 +1,11 @@ +#include #include #include #include #include #include "builder.h" #include "csourcefile.h" +#include "executable.h" #include "misc.h" #include "sharedlibrary.h" #include "staticlibrary.h" @@ -129,6 +131,41 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath return 0; } +FileTarget *VirtualFileSystem::find_binary(const string &name) +{ + SearchPath path; + if(const char *env_path = getenv("PATH")) + { + vector parts = split(env_path, ':'); + for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) + path.push_back(*i); + } + else + { + path.push_back("/bin"); + path.push_back("/usr/bin"); + } + + for(SearchPath::const_iterator i=path.begin(); i!=path.end(); ++i) + { + FS::Path filename = *i/name; + if(FileTarget *tgt = get_target(filename)) + { + builder.get_logger().log("vfs", format("Binary %s found in %s as existing %s", name, *i, tgt->get_type())); + return tgt; + } + else if(file_exists(filename)) + { + builder.get_logger().log("vfs", format("Binary %s found in %s", name, *i)); + return new Executable(builder, filename); + } + + builder.get_logger().log("vfs", format("Binary %s not found in %s", name, *i)); + } + + return 0; +} + bool VirtualFileSystem::file_exists(const FS::Path &filename) { if(nonexistent.count(filename))