diff --git a/mob.ini b/mob.ini index 0e2145e..5e468e5 100644 --- a/mob.ini +++ b/mob.ini @@ -62,6 +62,7 @@ cmake = cmake.exe perl = perl.exe devenv = devenv.exe msbuild = msbuild.exe +nmake = nmake.exe nuget = nuget.exe vswhere = vswhere.exe nasm = nasm.exe diff --git a/src/tools/nmake.cpp b/src/tools/nmake.cpp new file mode 100644 index 0000000..0285b3e --- /dev/null +++ b/src/tools/nmake.cpp @@ -0,0 +1,82 @@ +#include "pch.h" +#include "tools.h" +#include "../core/conf.h" +#include "../core/process.h" + +namespace mob +{ + + nmake::nmake() + : basic_process_runner("nmake"), arch_(arch::def) + { + } + + fs::path nmake::binary() + { + return conf().tool().get("nmake"); + } + + nmake& nmake::path(const fs::path& p) + { + cwd_ = p; + return *this; + } + + nmake& nmake::target(const std::string& s) + { + target_ = s; + return *this; + } + + nmake& nmake::def(const std::string& s) + { + def_.push_back(s); + return *this; + } + + nmake& nmake::architecture(arch a) + { + arch_ = a; + return *this; + } + + int nmake::result() const + { + return exit_code(); + } + + void nmake::do_run() + { + process p; + + p + .binary(binary()) + .cwd(cwd_) + .stderr_filter([](process::filter& f) + { + // initial log line, can't get rid of it, /L or /NOLOGO don't seem + // to work + if (f.line.find("Microsoft (R) Macro Assembler (x64)") != std::string::npos) + f.lv = context::level::trace; + if (f.line.find("Copyright (C) Microsoft Corporation.") != std::string::npos) + f.lv = context::level::trace; + }) + .arg("/C", process::log_quiet) // silent + .arg("/S", process::log_quiet) // silent + .arg("/L", process::log_quiet) // silent, nmake likes to spew crap + .arg("/D", process::log_dump) // verbose stuff + .arg("/P", process::log_dump) // verbose stuff + .arg("/W", process::log_dump) // verbose stuff + .arg("/K"); // don't stop on errors + + for (auto&& def : def_) + p.arg(def); + + p + .arg(target_) + .env(env::vs(arch_)); + + execute_and_join(p); + } + +} // namespace diff --git a/src/tools/tools.h b/src/tools/tools.h index d5c7590..a710f26 100644 --- a/src/tools/tools.h +++ b/src/tools/tools.h @@ -458,6 +458,56 @@ private: void do_patch(const fs::path& patch_file); }; +// tool that runs `nmake` +// +class nmake : public basic_process_runner +{ +public: + // path to the job binary + // + static fs::path binary(); + + nmake(); + + // path in which to invoke nmake + // + nmake& path(const fs::path& p); + + // makefile target + // + nmake& target(const std::string& s); + + // adds a macro definition as "NAME=value" + // + nmake& def(const std::string& s); + + // sets the architecture used to run nmake, used to get the appropriate + // VS environment variables, defaults to arch::def + // + nmake& architecture(arch a); + + // nmake's exit code + // + int result() const; + +protected: + // runs nmake + // + void do_run() override; + +private: + // set in path() + fs::path cwd_; + + // set in def(), just plain arguments + std::vector def_; + + // set in target(), another plain argument + std::string target_; + + // set in architecture() + arch arch_; +}; // tool that runs `jom`, an alternative to `nmake` that supports parallel // builds, bundled with mob in third-party/bin diff --git a/vs/mob.vcxproj b/vs/mob.vcxproj index 3cf7610..cafed2a 100644 --- a/vs/mob.vcxproj +++ b/vs/mob.vcxproj @@ -116,6 +116,7 @@ + diff --git a/vs/mob.vcxproj.filters b/vs/mob.vcxproj.filters index 3c419ca..de212c4 100644 --- a/vs/mob.vcxproj.filters +++ b/vs/mob.vcxproj.filters @@ -204,6 +204,9 @@ src\tasks + + src\tools + diff --git a/vs/nmake.cpp b/vs/nmake.cpp new file mode 100644 index 0000000..e69de29