summaryrefslogtreecommitdiffstats
path: root/MakeDependencyFile.cc
blob: ba7d3fe4fdeee7687dfcc7a9aad7a078222a5754 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "MakeDependencyFile.h"
#include "FileSystemUtilities.h"

#include <iostream>

MakeDependencyFile::MakeDependencyFile(const std::string& aTarget,
	const std::vector<std::string>& Deps)
: DepFileExists(true), CorrectDeps(true), Target(aTarget), Dependencies(Deps)
{
}

MakeDependencyFile::MakeDependencyFile(const std::string& File)
: Str(File)
{
	DepFileExists = fileExists(File);
	Target = Str.makeFileName();
	Str.literal(":");
	std::string D;
	do
	{
		Dependencies.push_back(D);
		D = Str.makeFileName();
		if (D.empty() && Str.literal("\\"))
			D = Str.makeFileName();
	} while (!D.empty());
	Dependencies.erase(Dependencies.begin());
	Str.whiteSpace();
	CorrectDeps = Str.eos();
}

bool MakeDependencyFile::upToDate() const
{
	// Target does not exist lets remake
	if (!fileExists(Target))
		return false;
	// Incorrect dep file, lets remake
	if (!CorrectDeps)
	{
		std::cout << "  dep file incorrectly formatted, forcing remake" << std::endl;
		return false;
	}
	// Dependencies do not exist, lets remake to be sure
	if (!DepFileExists)
	{
		std::cout << "  does not exist, forcing remake " << std::endl;
		return false;
	}
	for (unsigned int i=0; i<Dependencies.size(); ++i)
		if (fileExists(Dependencies[i]) &&
			fileIsNewer(Dependencies[i],Target))
			return false;
	return true;
}