1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 ------------------------------------------------------------------------------
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
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/>.
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.
37 wmkdepend [ -Idir ... -Idir ] [ -iheader .. -iheader ] filename
39 \*---------------------------------------------------------------------------*/
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
)
54 fwprintf(stderr
, L
"\nError: %s\n\n", message
);
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
[])
72 printUsage("input file not supplied");
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)
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]);
107 L
"Making dependency list for source file %s\n",
111 std::string::size_type basePos
= sourceFile
.rfind('/');
112 if (basePos
== std::string::npos
)
121 std::string::size_type dotPos
= sourceFile
.rfind('.');
124 dotPos
== std::string::npos
125 || dotPos
== sourceFile
.size()-1
132 L
"cannot find extension in source file name %s\n",
138 std::string depFile
= sourceFile
.substr(0, dotPos
);
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.*");
154 << sourceFile
.substr(basePos
, dotPos
- basePos
) << ".class: "
161 << sourceFile
.substr(basePos
, dotPos
- basePos
) << ".o: "
166 wmake::Parser::sourceFile
= sourceFile
;
167 wmake::Parser::depFile
= depFile
;
169 wmake::Parser::includeFile(sourceFile
);
176 /*****************************************************************************/