barrier/win32util/autodep.cpp

150 lines
3.2 KiB
C++
Raw Normal View History

Applied patch by maruel: - Fixed taking the address of begin() on an empty std::vector. - Fixed nsis makefile to use %ProgramFiles% environment variable. - Fixed nsis makefile to pass the output directory and file to makensis. - Fixed synergy.nsi to get the files from the output directory. That enables a debug build of the installer. - Fixes to compile under VS2005. I did not apply VS2005 project files, instead adding nmake files. nmake is pretty weak but the makefiles can be modified without having visual studio. Also modified the .rc files to not use winres.h. This plus nmake means synergy can now be built using the freely downloadable Microsoft Windows SDK for Vista, available from microsoft's web site. This change removes all of the old VC++6 project files in favor of the nmake files. It also removes the XCode project in favor of ./configure and make. All of the nmake files are named nmake.mak. Only the top level makefile is directly useful (the rest are included by it) so all builds are from the top level directory. nmake knows the following targets: all: build synergy.exe, synergyc.exe and synergys.exe clean: remove all intermediate files, keep programs clobber: clean and remove programs installer: build programs and an installer debug: build a debug version of 'all' release: build a release version of 'all' debug-installer: build an installer of the debug build release-installer: build an installer of the release build The default build version is release so 'all' and 'installer' will build a release version. The installer itself never has debug symbols, just the stuff it installs. The default target is 'all'. To build use: nmake /nologo /f nmake.mak <target> VC++ and VisualStudio users may need to manually run vcvars.bat in a command.exe or cmd.exe window before invoking nmake. The Window 98/Me command.exe may not handle potentially long command lines; I haven't tried to verify if that works.
2007-09-06 05:01:44 +00:00
#include <fstream>
#include <iostream>
#include <locale>
#include <set>
#include <string>
using namespace std;
static
string
baseName(const string& filename)
{
return filename.substr(0, filename.rfind('.'));
}
static
int
writeMakefile(const string& dstdir, const set<string>& depFilenames)
{
string makeFilename = dstdir + "\\deps.mak";
ofstream makeFile(makeFilename.c_str());
if (!makeFile) {
cerr << "Can't open '" << makeFilename << "' for writing" << endl;
return 1;
}
for (set<string>::const_iterator i = depFilenames.begin();
i != depFilenames.end(); ++i) {
makeFile << "!if EXIST(\"" << *i << "\")" << endl;
makeFile << "!include \"" << *i << "\"" << endl;
makeFile << "!endif" << endl;
}
return 0;
}
static
void
writeDependencies(
const string& filename,
const string& srcdir,
const string& dstdir,
const set<string>& paths)
{
string basename = baseName(filename);
string depFilename = dstdir + "\\" + basename + ".d";
ofstream depFile(depFilename.c_str());
if (!depFile) {
cerr << "Can't open '" << depFilename << "' for writing" << endl;
return;
}
// Write dependencies rule for filename
depFile << "\"" << dstdir << "\\" << basename << ".obj\": \"" <<
srcdir << "\\" << filename << "\" \\" << endl;
for (set<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
depFile << "\t\"" << *i << "\" \\" << endl;
}
depFile << "\t$(NULL)" << endl;
}
static
int
writeDepfiles(const string& srcdir, const string& dstdir)
{
const string includeLine = "Note: including file:";
// Parse stdin
string line;
string filename;
set<string> paths;
locale loc = locale::classic();
const ctype<char>& ct = use_facet<ctype<char> >(loc);
while (getline(cin, line)) {
bool echo = true;
// Check for include line
if (line.compare(0, includeLine.length(), includeLine) == 0) {
// Strip includeLine and leading spaces
line.erase(0, line.find_first_not_of(" ", includeLine.length()));
if (line.length() == 0) {
continue;
}
// Uppercase all drive letters
if (line.length() > 2 && line[1] == ':') {
line[0] = ct.toupper(line[0]);
}
// Record path
paths.insert(line);
echo = false;
}
// Maybe a source filename
else if (line.rfind(".cpp") == line.length() - 4) {
// Write dependencies for previous source file
if (filename.length() != 0) {
writeDependencies(filename, srcdir, dstdir, paths);
paths.clear();
}
filename = line;
}
// Otherwise other output
else {
// do nothing
}
if (echo) {
cout << line << endl;
}
}
// Write dependencies for last source file
if (filename.length() != 0) {
writeDependencies(filename, srcdir, dstdir, paths);
paths.clear();
}
return 0;
}
int
main(int argc, char** argv)
{
if (argc < 3) {
cerr << "usage: " << argv[0] <<
" <src-directory> <dst-directory> [<depfiles>]" << endl;
return 1;
}
string srcdir = argv[1];
string dstdir = argv[2];
// If depfiles were supplied then create a makefile in outdir to load
// all of them.
int result;
if (argc > 3) {
set<string> depFilenames(argv + 3, argv + argc);
result = writeMakefile(dstdir, depFilenames);
}
// Otherwise parse stdin and create a depfile for each listed file
else {
result = writeDepfiles(srcdir, dstdir);
}
return result;
}