File: fastdep.cc.orig

package info (click to toggle)
fastdep 0.16-14
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 604 kB
  • ctags: 328
  • sloc: cpp: 2,161; ansic: 814; sh: 208; makefile: 121
file content (153 lines) | stat: -rw-r--r-- 3,550 bytes parent folder | download | duplicates (5)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#if defined(WIN32)
#include <direct.h>
#else
#include <unistd.h>
#endif
#include "getopt.h"

#include <iostream>
#include <fstream>

#include "FileCache.h"
#include "FileStructure.h"
#include "CheckVersion.h"

#define CWDBUFFERLENGTH 1024

void PrintVersion()
{
	std::cout	<< "fastdep v" << FASTDEP_VERSION_MAJOR << "." << FASTDEP_VERSION_MINOR << std::endl
					<< "copyright Bart Vanhauwaert, 2001, 2002" << std::endl
					<< "licensed under the GNU Public License" << std::endl;
}


/*
 * Generate dependencies for all files.
 */
int main(int argc, char **argv)
{
	char cwd_buffer[CWDBUFFERLENGTH+1];
	cwd_buffer[0] = 0;
#if  defined(WIN32)
	_getcwd(cwd_buffer, CWDBUFFERLENGTH);
#else
	getcwd(cwd_buffer, CWDBUFFERLENGTH);
#endif
	FileCache Cache(cwd_buffer);
	Cache.addIncludeDir(cwd_buffer,".");
	std::string RemakeDepTarget;
	std::vector<std::string> ExtraRemakeDeps;
	std::string OutputFilename;
	bool doDebug = false;

	while (1)
	{
		int option_index = 0;
		static struct option long_options[] =
		{
			{"remakedeptarget", 1, 0, 0 },
			{"extraremakedep", 1, 0, 0 },
			{"version", 0, 0, 0 },
			{"stdinclude", 2, 0, 0 },
			{"compile", 1, 0, 0 },
			{"extraincludes", 1, 0, 0},
			{"debug",0,0,0 },
			{"atleastversion",1,0,0 },
			{0, 0, 0, 0}
		};
		int c = getopt_long(argc,argv,"vI:dqo:O:D:",long_options, &option_index);
		if (c==-1)
			break;
		switch (c)
		{
			case 0:
				switch (option_index)
				{
					case 0:
						RemakeDepTarget = std::string(optarg);
						break;
					case 1:
						ExtraRemakeDeps.push_back(std::string(optarg));
						break;
					case 2:
						PrintVersion();
						return 0;
				        case 3:
					  if (optarg)
					    {
					      Cache.addIncludeDir(cwd_buffer, optarg);
					    }
					  else
					    {
					      Cache.addIncludeDir(cwd_buffer, "/usr/include");
					    }
					  break;
                   case 4:
					 Cache.SetCompileCommand( std::string(optarg) );
					 break;
                   case 5:
                     Cache.addIncludeDirFromFile(cwd_buffer, optarg);
                     break;
					case 6:
						doDebug = true;
						break;
					case 7:
						return atLeastVersion(optarg);
						break;
				}
				break;
            case 'I':
                Cache.addIncludeDir(cwd_buffer, optarg);
                break;
            case 'O':
                Cache.SetObjectsDir(optarg);
                break;
            case 'v':
                PrintVersion();
                return 0;
            case 'd':
                Cache.SetObjectsShouldNotContainDirectories();
                break;
            case 'q':
                Cache.SetQuietModeOn();
					break;
				case 'o':
					OutputFilename = optarg;
					break;
				case 'D':
					Cache.addPreDefine(optarg);
					break;
		}
	}
#if ! defined (WIN32)
	Cache.addExcludeDir("","/usr/include");
#endif
	if (optind == argc)
	{
		std::cout << "Usage : fastdep filename.c" << std::endl;
		return 0;
	}
	if (doDebug)
		Cache.inDebugMode();
	std::ostream* theStream = &std::cout;
	if (OutputFilename != "")
	{
		theStream = new std::ofstream(OutputFilename.c_str());
		if (RemakeDepTarget == "")
			RemakeDepTarget = OutputFilename;
	}
	for (int i=optind; i<argc; ++i)
		Cache.generate(*theStream, cwd_buffer,argv[i]);
	if (RemakeDepTarget != "")
	{
		*theStream << RemakeDepTarget << ":" << Cache.getAllDependenciesLine();
		for (unsigned int i=0; i<ExtraRemakeDeps.size(); ++i)
			*theStream << " \\\n\t" << ExtraRemakeDeps[i];
		*theStream << std::endl;
	}
	if (OutputFilename != "")
		delete theStream;

	return 0;
}