aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-01-11 20:59:29 +0100
committerdec05eba <dec05eba@protonmail.com>2018-01-11 20:59:33 +0100
commitb7b7b3d359765e3ffb011dc34ff928e614766666 (patch)
tree26c2f87ccd6f2d2b499c2320b3809af334d8995a
parentaee178901d8bd03f9e0aeb50e3a5ed7570d9f910 (diff)
Generate dependency file (recompile source files when header files are modified)
-rw-r--r--backend/ninja/Ninja.cpp33
1 files changed, 12 insertions, 21 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index 6d871fd..530dffe 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -119,26 +119,7 @@ namespace backend
}
return result;
}
-
- string getCompileWithoutLinkingFlag(Compiler compiler)
- {
- string result;
- switch (compiler)
- {
- case Compiler::GCC:
- {
- result = "-c";
- break;
- }
- case Compiler::MSVC:
- {
- result = "/c";
- break;
- }
- }
- return result;
- }
-
+
string getObjectFileNameFlag(Compiler compiler, const string &objectFileName)
{
string result;
@@ -496,12 +477,15 @@ namespace backend
case Compiler::GCC:
{
result += "rule cpp_COMPILER\n";
+ result += " depfile = $out.d\n";
result += " command = ccache c++ $ARGS -c $in -o $out\n\n";
result += "rule cpp_BUILD_EXEC\n";
+ result += " depfile = $out.d\n";
result += " command = ccache c++ $ARGS -o $out $in $LINK_ARGS $aliasing\n\n";
result += "rule c_COMPILER\n";
+ result += " depfile = $out.d\n";
result += " command = ccache cc $ARGS -c $in -o $out\n\n";
break;
}
@@ -529,6 +513,7 @@ namespace backend
case Compiler::GCC:
{
result += "rule cpp_COMPILER\n";
+ result += " depfile = $out.d\n";
result += " command = ccache c++ $ARGS -c -fPIC $in -o $out\n\n";
result += "rule cpp_BUILD_STATIC\n";
@@ -538,6 +523,7 @@ namespace backend
result += " $in\n\n";
result += "rule c_COMPILER\n";
+ result += " depfile = $out.d\n";
result += " command = ccache cc $ARGS -c -fPIC $in -o $out\n\n";
break;
}
@@ -565,13 +551,16 @@ namespace backend
case Compiler::GCC:
{
result += "rule cpp_COMPILER\n";
+ result += " depfile = $out.d\n";
result += " command = ccache c++ $ARGS -c -fPIC $in -o $out\n\n";
// --whole-archive
result += "rule cpp_BUILD_DYNAMIC\n";
+ result += " depfile = $out.d\n";
result += " command = ccache c++ $in -shared -o $out $LINK_ARGS $aliasing\n\n";
result += "rule c_COMPILER\n";
+ result += " depfile = $out.d\n";
result += " command = ccache cc $ARGS -c -fPIC $in -o $out\n\n";
break;
}
@@ -690,7 +679,9 @@ namespace backend
case Compiler::GCC:
{
// -Werror
- result += " '-I" + config.getPackageName() + "@exe' " + cflags + " '-I..' -Wall -Wextra -Werror=return-type -fdiagnostics-show-option '-fdiagnostics-color=always' '-pipe' '-D_FILE_OFFSET_BITS=64' '-Winvalid-pch' -fstack-protector " + optimizationFlags;
+ // TODO: Find equivalent -MMD -MP for other compilers than gcc. MMD is used to create "dependency files" -> if headers are modified then source files will be recompiled
+ // when compiling next time...
+ result += " -MMD -MP '-I" + config.getPackageName() + "@exe' " + cflags + " '-I..' -Wall -Wextra -Werror=return-type -fdiagnostics-show-option '-fdiagnostics-color=always' '-pipe' '-D_FILE_OFFSET_BITS=64' '-Winvalid-pch' -fstack-protector " + optimizationFlags;
if(sourceFileLanguage == SourceFileLanguage::CPP)
{
result += " -fexceptions -Wnon-virtual-dtor";