2 #-------------------------------------------------------------------------------
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software: you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation, either version 3 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
32 # postProcFreeFOAMDeps
35 # Patches up the dependency files generated when compiling with -MD.
37 #------------------------------------------------------------------------------
39 """Usage: generateOpenFOAMDeps
41 Patches up the dependency files generated when compiling with -MD.
46 sys
.path
.insert(0, '@FOAM_PYTHON_DIR@')
47 from FreeFOAM
.compat
import *
53 re
.compile(r
'^/usr/'),
54 re
.compile(r
'ImplI?\.[CH]'),
57 def checkBlacklistPatterns(f
):
58 for p
in blacklistPatterns
:
59 if p
.search(f
) is not None:
64 (re
.compile(r
'_(\.[CH]|/)'), r
'\1'),
65 (re
.compile(r
'_subst(\.[CH]|/)'), r
'\1'),
66 (re
.compile(r
'(src/OSspecific)/OSspecific/(sig\w+\.[CH])'), r
'\1/POSIX/signals/\2'),
67 (re
.compile(r
'(src/OSspecific)/OSspecific/((\w+)\.[CH])'), r
'\1/POSIX/\3/\2'),
70 SOURCE_DIR
= "@CMAKE_SOURCE_DIR@"
71 BINARY_DIR
= "@CMAKE_BINARY_DIR@"
72 incdir
= op
.join(BINARY_DIR
, 'include')
74 for parent
, dirs
, files
in os
.walk(BINARY_DIR
):
75 for f
in filter(lambda f
: op
.splitext(f
)[1]=='.d', files
):
76 f
= op
.join(parent
, f
)
77 # skip blacklisted files
78 if checkBlacklistPatterns(f
):
82 for l
in open(f
, 'rt'):
83 lines
+= l
.strip().replace(' \\', '').split()
87 # resolve wrapper entries, remove blacklisted files, perform
88 # substitutions and strip prefix
89 for i
, l
in enumerate(reversed(lines
)):
91 # resolve wrapped entries
94 if l
.startswith(incdir
):
97 # remove blacklisted files
98 if checkBlacklistPatterns(l
):
102 if l
.startswith(SOURCE_DIR
):
103 l
= op
.relpath(l
, SOURCE_DIR
)
104 # perform substitutions
105 for p
, r
in substPatterns
:
109 # remove duplicates and sort
111 lines
= sorted(set(lines
[1:]))
113 open(op
.splitext(f
)[0]+'.ffd', 'wt').write(('\n'.join(lines
))+'\n')
115 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file