Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / wmake / src / wmkdepend.cpp
blobdb3c088a3858c2deb76a671986018387c3e86288
1 /*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
6 \\/ M anipulation |
7 ------------------------------------------------------------------------------
8 License
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 Application
25 wmkdepend
27 Description
28 A fast dependency list generator that emulates the behaviour and
29 output of cpp -M. However, the output contains no duplications and
30 is ~40% faster than cpp.
32 The algorithm uses flex to scan for includes and searches the files
33 found. Each file is entered into a hash table so that files are scanned
34 only once. This is why this program is faster than cpp.
36 Usage
37 wmkdepend [ -Idir ... -Idir ] [ -iheader .. -iheader ] filename
39 \*---------------------------------------------------------------------------*/
41 #include <cstdio>
42 #include <cstdlib>
43 #include <cstring>
45 #include "wmkdependParser.h"
47 // Note: since we use the Coco/R default error messages, we must use
48 // wide streams for stderr.
50 void printUsage(const char* message = NULL)
52 if (message)
54 fwprintf(stderr, L"\nError: %s\n\n", message);
57 fwprintf
59 stderr,
60 L"Usage: wmkdepend %s filename\nOptions:\n%s\n",
61 "[ -Idir ... -Idir ] [ -iheader .. -iheader ]",
62 " -Idir specify include directory\n"
63 " -iheader specify header name to ignore\n"
68 int main(int argc, char* argv[])
70 if (argc == 1)
72 printUsage("input file not supplied");
73 ::exit(1);
76 for (int i=1; i < argc; i++)
78 if (strncmp(argv[i], "-I", 2) == 0)
80 if (strlen(argv[i]) > 2)
82 std::string dirName(argv[i] + 2);
84 // add trailing slash if required
85 if (dirName.rfind('/') != dirName.size()-1)
87 dirName += '/';
90 wmake::Parser::includeDirs.push_back(dirName);
93 else if (strncmp(argv[i], "-i", 2) == 0)
95 if (strlen(argv[i]) > 2)
97 wmake::Parser::visitedFiles.insert(argv[i] + 2);
102 std::string sourceFile(argv[argc-1]);
104 fwprintf
106 stderr,
107 L"Making dependency list for source file %s\n",
108 sourceFile.c_str()
111 std::string::size_type basePos = sourceFile.rfind('/');
112 if (basePos == std::string::npos)
114 basePos = 0;
116 else
118 basePos++;
121 std::string::size_type dotPos = sourceFile.rfind('.');
124 dotPos == std::string::npos
125 || dotPos == sourceFile.size()-1
126 || dotPos <= basePos
129 fwprintf
131 stderr,
132 L"cannot find extension in source file name %s\n",
133 sourceFile.c_str()
135 ::exit(1);
138 std::string depFile = sourceFile.substr(0, dotPos);
139 depFile += ".dep";
141 const std::string sourceExt = sourceFile.substr(dotPos);
142 if (sourceExt == ".java")
144 // import directories to ignore
145 wmake::Parser::ignoreDir("java.*");
146 wmake::Parser::ignoreDir("org.*");
147 wmake::Parser::ignoreDir("com.*");
148 wmake::Parser::ignoreDir("sunw.*");
149 wmake::Parser::ignoreDir("sun.*");
150 wmake::Parser::ignoreDir("launcher.*");
152 std::cout
153 << "$(CLASSES_DIR)/"
154 << sourceFile.substr(basePos, dotPos - basePos) << ".class: "
155 << depFile << "\n";
157 else
159 std::cout
160 << "$(OBJECTS_DIR)/"
161 << sourceFile.substr(basePos, dotPos - basePos) << ".o: "
162 << depFile << "\n";
166 wmake::Parser::sourceFile = sourceFile;
167 wmake::Parser::depFile = depFile;
169 wmake::Parser::includeFile(sourceFile);
171 return 0;
176 /*****************************************************************************/