Merge pull request #1954 from Icedude907/build-scaninc-speed
[Build System Rewrite] Massive build speed improvement via scaninc changes
This commit is contained in:
commit
51131e2582
2 changed files with 54 additions and 7 deletions
12
Makefile
12
Makefile
|
@ -162,8 +162,6 @@ MAKEFLAGS += --no-print-directory
|
|||
.SECONDARY:
|
||||
# Delete files that weren't built properly
|
||||
.DELETE_ON_ERROR:
|
||||
# Secondary expansion is required for dependency variables in object rules.
|
||||
.SECONDEXPANSION:
|
||||
|
||||
RULES_NO_SCAN += libagbsyscall clean clean-assets tidy tidymodern tidynonmodern generated clean-generated
|
||||
.PHONY: all rom modern compare
|
||||
|
@ -330,7 +328,10 @@ endef
|
|||
# Calls SCANINC to find dependencies
|
||||
define C_SCANINC
|
||||
ifneq ($(NODEP),1)
|
||||
$1.o: $2 $$(shell $(SCANINC) $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include -I gflib $2)
|
||||
$1.o: $1.d
|
||||
$1.d: $2
|
||||
$(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include -I gflib $2
|
||||
include $1.d
|
||||
endif
|
||||
endef
|
||||
|
||||
|
@ -359,7 +360,10 @@ endef
|
|||
|
||||
define ASM_SCANINC
|
||||
ifneq ($(NODEP),1)
|
||||
$1.o: $2 $$(shell $(SCANINC) $(INCLUDE_SCANINC_ARGS) -I "" $2)
|
||||
$1.o: $1.d
|
||||
$1.d: $2
|
||||
$(SCANINC) -M $1.d $(INCLUDE_SCANINC_ARGS) -I "" $2
|
||||
include $1.d
|
||||
endif
|
||||
endef
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include <queue>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
#include <fstream>
|
||||
#include "scaninc.h"
|
||||
#include "source_file.h"
|
||||
|
||||
|
@ -38,15 +41,19 @@ bool CanOpenFile(std::string path)
|
|||
return true;
|
||||
}
|
||||
|
||||
const char *const USAGE = "Usage: scaninc [-I INCLUDE_PATH] FILE_PATH\n";
|
||||
const char *const USAGE = "Usage: scaninc [-I INCLUDE_PATH] [-M DEPENDENCY_OUT_PATH] FILE_PATH\n";
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::queue<std::string> filesToProcess;
|
||||
std::set<std::string> dependencies;
|
||||
std::set<std::string> dependencies_includes;
|
||||
|
||||
std::vector<std::string> includeDirs;
|
||||
|
||||
bool makeformat = false;
|
||||
std::string make_outfile;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
|
@ -68,6 +75,13 @@ int main(int argc, char **argv)
|
|||
}
|
||||
includeDirs.push_back(includeDir);
|
||||
}
|
||||
else if(arg.substr(0, 2) == "-M")
|
||||
{
|
||||
makeformat = true;
|
||||
argc--;
|
||||
argv++;
|
||||
make_outfile = std::string(argv[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
FATAL_ERROR(USAGE);
|
||||
|
@ -112,6 +126,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
path = include;
|
||||
}
|
||||
dependencies_includes.insert(path);
|
||||
bool inserted = dependencies.insert(path).second;
|
||||
if (inserted && exists)
|
||||
{
|
||||
|
@ -121,8 +136,36 @@ int main(int argc, char **argv)
|
|||
includeDirs.pop_back();
|
||||
}
|
||||
|
||||
if(!makeformat)
|
||||
{
|
||||
for (const std::string &path : dependencies)
|
||||
{
|
||||
std::printf("%s\n", path.c_str());
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write out make rules to a file
|
||||
std::ofstream output(make_outfile);
|
||||
|
||||
// Print a make rule for the object file
|
||||
size_t ext_pos = make_outfile.find_last_of(".");
|
||||
auto object_file = make_outfile.substr(0, ext_pos + 1) + "o";
|
||||
output << object_file.c_str() << ": ";
|
||||
for (const std::string &path : dependencies)
|
||||
{
|
||||
output << path << " ";
|
||||
}
|
||||
|
||||
// Dependency list rule.
|
||||
// Although these rules are identical, they need to be separate, else make will trigger the rule again after the file is created for the first time.
|
||||
output << "\n" << make_outfile.c_str() << ": ";
|
||||
for (const std::string &path : dependencies_includes)
|
||||
{
|
||||
output << path << " ";
|
||||
}
|
||||
output.flush();
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue