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 # generateOpenFOAMDeps
35 # Patches OpenFOAM to generate dependency files, runs Allwmake and then
36 # postprocesses the generated dependency files.
38 #------------------------------------------------------------------------------
40 """Usage: generateOpenFOAMDeps <WM_PROJECT_DIR>
42 Patches OpenFOAM to generate dependency files, runs Allwmake and then
43 postprocesses the generated dependency files.
45 Requires that WM_PROJECT_DIR be a git-checkout and that git-python is
50 <WM_PROJECT_DIR> Top-level OpenFOAM source directory
55 sys
.path
.insert(0, '@FOAM_PYTHON_DIR@')
56 from FreeFOAM
.compat
import *
65 re
.compile(r
'^/usr/'),
71 echo('Error: the path to the OpenFOAM installation is required',
75 WM_PROJECT_DIR
=op
.abspath(args
[0])
78 os
.environ
['FOAM_INST_DIR'] = op
.dirname(WM_PROJECT_DIR
)
79 os
.environ
['WM_COMPILER'] = 'FreeFOAM'
80 os
.environ
['WM_COMPILE_OPTION'] = 'Dep'
81 os
.environ
['WM_MPLIB'] = 'SYSTEMOPENMPI'
84 if not op
.exists(op
.join(WM_PROJECT_DIR
, 'bin/foamInstallationTest')):
85 echo('Error: %s/bin/foamInstallationTest is missing', file=sys
.stderr
)
88 if not op
.exists(op
.join(WM_PROJECT_DIR
, '.git/HEAD')):
89 echo('Error: %s/.git/HEAD is missing', file=sys
.stderr
)
92 repo
= git
.Repo(WM_PROJECT_DIR
)
95 echo('Error: OpenFOAM checkout %s is dirty'%WM_PROJECT_DIR
, file=sys
.stderr
)
98 if repo
.head
.is_detached
:
99 echo('Error: OpenFOACM checkout %s is detached'%WM_PROJECT_DIR
, file=sys
.stderr
)
102 # create new, temporary branch and check it out
103 orig_branch
= repo
.active_branch
105 tmp_branch
= repo
.create_head('TMP_FREEFOAM_GENERATE_OPENFOAM_DEPS')
107 echo('Error: Creating temporary branch %s failed with:\n%s'%
108 ('TMP_FREEFOAM_GENERATE_OPENFOAM_DEPS', str(e
)), file=sys
.stderr
)
112 tmp_branch
.checkout()
113 except git
.GitCommandError
as e
:
114 echo('Error: Checking out the temporary branch %s failed with:\n%s'%
115 ('TMP_FREEFOAM_GENERATE_OPENFOAM_DEPS', str(e
)), file=sys
.stderr
)
119 wmakePatch
= tempfile
.TemporaryFile()
120 wmakePatch
.write(r
"""
121 From 3e7ebcead5c87781e84752ce42647c24b18ce2da Mon Sep 17 00:00:00 2001
122 From: Michael Wild <themiwi@users.sourceforge.net>
123 Date: Mon, 25 Jul 2011 08:38:08 +0200
124 Subject: [PATCH] Patch wmake to only generate dependency files
126 Signed-off-by: Michael Wild <themiwi@users.sourceforge.net>
128 diff --git a/Allwmake b/Allwmake
129 index 55554dc..6047743 100755
134 cd ${0%/*} || exit 1 # run from this directory
138 if [ "$PWD" != "$WM_PROJECT_DIR" ]
140 echo "Error: Current directory is not \$WM_PROJECT_DIR"
142 # build ThirdParty sources
143 if [ -d "$WM_THIRD_PARTY_DIR" ]
145 - ( cd $WM_THIRD_PARTY_DIR && ./Allwmake )
146 + : #( cd $WM_THIRD_PARTY_DIR && ./Allwmake )
149 # build OpenFOAM libraries and applications
150 diff --git a/wmake/Makefile b/wmake/Makefile
151 index 2f2be98..878a7be 100644
154 @@ -41,7 +41,7 @@ SHELL = /bin/sh
155 #------------------------------------------------------------------------------
162 #------------------------------------------------------------------------------
163 @@ -106,7 +106,7 @@ SEXE = a.out
164 #------------------------------------------------------------------------------
166 GENERAL_RULES = $(WM_DIR)/rules/General
167 -RULES = $(WM_DIR)/rules/$(WM_ARCH)$(WM_COMPILER)
168 +RULES = $(WM_DIR)/rules/FreeFOAM
169 BIN = $(WM_DIR)/bin/$(WM_ARCH)$(WM_COMPILER)
171 include $(GENERAL_RULES)/general
172 @@ -148,16 +148,14 @@ LIB_HEADER_DIRS = \
175 @$(WM_SCRIPTS)/mkObjectDir $(EXE)
176 - $(LINKEXE) $(OBJECTS) -L$(LIB_WM_OPTIONS_DIR) \
177 - $(EXE_LIBS) $(PROJECT_LIBS) $(SYS_LIBS) $(LINK_LIBS) $(GLIBS) -o $(EXE)
181 @echo \'$(SEXE)\' is up to date.
184 @$(WM_SCRIPTS)/mkObjectDir $(SEXE)
185 - $(LINKEXE) $(OBJECTS) $(EXE_LIBS) \
186 - $(SYS_LIBS) $(LINK_LIBS) $(GLIBS) -o $(SEXE)
190 #------------------------------------------------------------------------------
191 @@ -171,7 +169,7 @@ $(LIB).$(SO): $(OBJECTS)
192 @$(WM_SCRIPTS)/mkObjectDir $(LIB)
194 @cd $(OBJECTS_DIR) ; \
195 - $(LINKLIBSO) $(LOCAL_OBJECTS) -L$(LIB_WM_OPTIONS_DIR) $(LIB_LIBS) $(GLIB_LIBS) -o $(LIB).$(SO)
199 @echo \'$(LIB).a\' is up to date.
200 @@ -188,7 +186,7 @@ libo: $(LIB).o
202 @$(WM_SCRIPTS)/mkObjectDir $(LIB)
204 - $(LD) -r -o $(LIB).o $(OBJECTS)
208 @echo \'$(LIB).jar\' is up to date.
209 diff --git a/wmake/MakefileFiles b/wmake/MakefileFiles
210 index 6dc6e9d..d4f2d7d 100644
211 --- a/wmake/MakefileFiles
212 +++ b/wmake/MakefileFiles
214 #------------------------------------------------------------------------------
216 GENERAL_RULES = $(WM_DIR)/rules/General
217 -RULES = $(WM_DIR)/rules/$(WM_ARCH)$(WM_COMPILER)
218 +RULES = $(WM_DIR)/rules/FreeFOAM
219 OBJECTS_DIR = $(WM_OPTIONS)
222 diff --git a/wmake/MakefileOptions b/wmake/MakefileOptions
223 index db304ba..ee4a871 100644
224 --- a/wmake/MakefileOptions
225 +++ b/wmake/MakefileOptions
227 #------------------------------------------------------------------------------
229 GENERAL_RULES = $(WM_DIR)/rules/General
230 -RULES = $(WM_DIR)/rules/$(WM_ARCH)$(WM_COMPILER)
231 +RULES = $(WM_DIR)/rules/FreeFOAM
233 include $(GENERAL_RULES)/general
234 include $(RULES)/general
235 diff --git a/wmake/rules/FreeFOAM/X b/wmake/rules/FreeFOAM/X
237 index 0000000..6133345
239 +++ b/wmake/rules/FreeFOAM/X
242 +XINC = $(XFLAGS) -I/usr/include/X11
244 diff --git a/wmake/rules/FreeFOAM/c b/wmake/rules/FreeFOAM/c
246 index 0000000..49c780b
248 +++ b/wmake/rules/FreeFOAM/c
254 +cFLAGS = $(GFLAGS) $(cDEP) $(LIB_HEADER_DIRS)
256 +ctoo = $(WM_SCHEDULER) $(cc) $(cFLAGS) $$SOURCE -M -MF $(subst .o,.d,$@)
258 +LINK_LIBS = $(cDBUG)
262 diff --git a/wmake/rules/FreeFOAM/c++ b/wmake/rules/FreeFOAM/c++
264 index 0000000..b68cefa
266 +++ b/wmake/rules/FreeFOAM/c++
268 +.SUFFIXES: .C .cxx .cc .cpp
272 +ptFLAGS = -DNoRepository
274 +c++FLAGS = $(GFLAGS) $(ptFLAGS) $(LIB_HEADER_DIRS) -fPIC
276 +Ctoo = $(WM_SCHEDULER) $(CC) $(c++FLAGS) $$SOURCE -M -MF $(subst .o,.d,$@)
281 +LINK_LIBS = $(c++DBUG)
285 diff --git a/wmake/rules/FreeFOAM/general b/wmake/rules/FreeFOAM/general
287 index 0000000..27779cd
289 +++ b/wmake/rules/FreeFOAM/general
291 +CPP = cpp -traditional-cpp $(GFLAGS)
294 +PROJECT_LIBS = -l$(WM_PROJECT) -ldl
296 +include $(GENERAL_RULES)/standard
300 +include $(RULES)/c++
301 diff --git a/wmake/rules/FreeFOAM/mplib b/wmake/rules/FreeFOAM/mplib
303 index 0000000..8a84b40
305 +++ b/wmake/rules/FreeFOAM/mplib
310 diff --git a/wmake/rules/FreeFOAM/mplibSYSTEMOPENMPI b/wmake/rules/FreeFOAM/mplibSYSTEMOPENMPI
312 index 0000000..98fa814
314 +++ b/wmake/rules/FreeFOAM/mplibSYSTEMOPENMPI
316 +PFLAGS = -DOMPI_SKIP_MPICXX
317 diff --git a/wmake/rules/General/bison b/wmake/rules/General/bison
318 index fe2e00a..e4ed987 100644
319 --- a/wmake/rules/General/bison
320 +++ b/wmake/rules/General/bison
321 @@ -4,8 +4,8 @@ ytoo = bison -v -d -y $$SOURCE ; mv y.tab.c $*.c ; mv y.tab.h $*.h ; $(cc) $(cFL
323 Ytoo = bison -v -d -y $$SOURCE ; mv y.tab.c $*.C ; mv y.tab.h $*.H ; $(CC) $(c++FLAGS) -c $*.C -o $@
332 diff --git a/wmake/rules/General/btyacc b/wmake/rules/General/btyacc
333 index f868b05..4fa52e8 100644
334 --- a/wmake/rules/General/btyacc
335 +++ b/wmake/rules/General/btyacc
338 ytoo = btyacc -v -d $(SKELETON) $$SOURCE ; mv y_tab.c $*.C ; mv y_tab.h $*.H ; $(CC) $(c++FLAGS) -c $*.C -o $@
343 diff --git a/wmake/rules/General/btyacc++ b/wmake/rules/General/btyacc++
344 index c65365c..b9f66b7 100644
345 --- a/wmake/rules/General/btyacc++
346 +++ b/wmake/rules/General/btyacc++
349 Ytoo = btyacc++ -v -d $(SKELETON) $$SOURCE ; mv y_tab.c $*.C ; mv y_tab.h $*.H ; $(CC) $(c++FLAGS) -c $*.C -o $@
354 diff --git a/wmake/rules/General/byacc b/wmake/rules/General/byacc
355 index 919da82..8292151 100644
356 --- a/wmake/rules/General/byacc
357 +++ b/wmake/rules/General/byacc
360 ytoo = byacc -v $(YYPREFIX) -d $$SOURCE ; mv y.tab.c $*.C ; mv y.tab.h $*.H ; $(CC) $(c++FLAGS) -c $*.C -o $@
365 diff --git a/wmake/rules/General/flex b/wmake/rules/General/flex
366 index 06defbb..11aeae7 100644
367 --- a/wmake/rules/General/flex
368 +++ b/wmake/rules/General/flex
371 ltoo = flex $$SOURCE ; mv lex.yy.c $*.c ; $(cc) $(cFLAGS) -c $*.c -o $@
376 diff --git a/wmake/rules/General/flex++ b/wmake/rules/General/flex++
377 index 304b131..4a29dd9 100644
378 --- a/wmake/rules/General/flex++
379 +++ b/wmake/rules/General/flex++
383 -Ltoo = flex -+ -f $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) -c $*.C -o $@
384 +Ltoo = flex -+ -f $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) $*.C -M -MF $(subst .o,.d,$@)
389 diff --git a/wmake/rules/General/flex++.test b/wmake/rules/General/flex++.test
390 index 8503e57..bb0f976 100644
391 --- a/wmake/rules/General/flex++.test
392 +++ b/wmake/rules/General/flex++.test
396 -Ltoo = flex++ $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) -c $*.C -o $@
397 +Ltoo = flex++ $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) $*.C -M -MF $(subst .o,.d,$@)
402 diff --git a/wmake/rules/General/moc b/wmake/rules/General/moc
403 index e85cb47..67ffced 100644
404 --- a/wmake/rules/General/moc
405 +++ b/wmake/rules/General/moc
408 qttoo = $(QTDIR)/bin/moc -f $$SOURCE -o $*.C ; $(CC) $(c++FLAGS) -c $*.C -o $@
413 diff --git a/wmake/rules/General/sourceToDep b/wmake/rules/General/sourceToDep
414 index 14e95d6..31ea59d 100644
415 --- a/wmake/rules/General/sourceToDep
416 +++ b/wmake/rules/General/sourceToDep
418 -.SUFFIXES: .c .cc .cxx .cpp .C .F .f .dep
419 +.SUFFIXES: .c .cc .cxx .cpp .C .F .f .FreeFOAMdep
421 MKDEP = $(BIN)/wmkdep -I$(*D) $(LIB_HEADER_DIRS)
450 diff --git a/wmake/rules/General/version b/wmake/rules/General/version
451 index 11f83c7..22951dd 100644
452 --- a/wmake/rules/General/version
453 +++ b/wmake/rules/General/version
454 @@ -7,7 +7,7 @@ Cvertoo = \
455 sed -e 's/VERSION_STRING/$(shell wmakePrintBuild -major)/' \
456 -e 's/BUILD_STRING/$(shell wmakePrintBuild -update)/' \
458 - $(CC) $(c++FLAGS) -c $*.C -o $@
459 + $(CC) $(c++FLAGS) $*.C -M -MF $(subst .o,.d,$@)
464 diff --git a/wmake/rules/General/yacc b/wmake/rules/General/yacc
465 index f9d393e..b99597e 100644
466 --- a/wmake/rules/General/yacc
467 +++ b/wmake/rules/General/yacc
468 @@ -4,8 +4,8 @@ ytoo = yacc -v -d $$SOURCE ; mv y.tab.c $*.c ; mv y.tab.h $(@D)/parser.h ; $(CC)
470 Ytoo = yacc -v -d $$SOURCE ; mv y.tab.c $*.C ; mv y.tab.h $(@D)/parser.H ; $(CC) $(c++FLAGS) -c $*.C -o $@
479 diff --git a/wmake/scripts/addCompile b/wmake/scripts/addCompile
480 index 04f0919..bb394f9 100755
481 --- a/wmake/scripts/addCompile
482 +++ b/wmake/scripts/addCompile
484 #------------------------------------------------------------------------------
487 -objectName=${sourceName%.*}.o
488 +objectName=${sourceName%.*}.d
489 className=${sourceName%.*}.class
492 +depName=${1%.*}.FreeFOAMdep
496 @@ -52,13 +52,13 @@ else
500 -sed -e s%".*.o.*:"%'$(OBJECTS_DIR)/'"$objectName\:"% \
501 +sed -e s%".*.d.*:"%'$(OBJECTS_DIR)/'"$objectName\:"% \
502 -e s%$WM_PROJECT_DIR%'$(WM_PROJECT_DIR)'% \
505 echo '$(OBJECTS_DIR)/'$objectName': $(EXE_DEP)' >> $depName
506 echo '$(OBJECTS_DIR)/'$objectName':' >> $depName
507 -echo ' @SOURCE_DIR='$sourceDir >> $depName
508 -echo ' SOURCE='$1' ; $('$sub'too)' >> $depName
509 +echo ' @SOURCE_DIR=$(PWD)/'$sourceDir >> $depName
510 +echo ' SOURCE=$(PWD)/'$1' ; $('$sub'too)' >> $depName
512 #------------------------------------------------------------------------------
513 diff --git a/wmake/src/Makefile b/wmake/src/Makefile
514 index 81603b6..741a06e 100644
515 --- a/wmake/src/Makefile
516 +++ b/wmake/src/Makefile
517 @@ -48,7 +48,7 @@ SHELL = /bin/sh
518 #------------------------------------------------------------------------------
520 GENERAL_RULES = $(WM_DIR)/rules/General
521 -RULES = $(WM_DIR)/rules/$(WM_ARCH)$(WM_COMPILER)
522 +RULES = $(WM_DIR)/rules/FreeFOAM
523 BIN = $(WM_DIR)/bin/$(WM_ARCH)$(WM_COMPILER)
525 include $(RULES)/general
526 diff --git a/wmake/src/wmkdep.l b/wmake/src/wmkdep.l
527 index d22c695..78b2fab 100644
528 --- a/wmake/src/wmkdep.l
529 +++ b/wmake/src/wmkdep.l
530 @@ -166,10 +166,10 @@ int main(int argc, char* argv[])
531 /* initialise depFile to zero and use strncat rather than strncpy
532 because there is a bug in the SGI strncat that if 0 preceeds the .
533 it inserts a space */
534 - depFile = (char*)malloc(strlen(sourceFile) + 3);
535 + depFile = (char*)malloc(strlen(sourceFile) + 11);
537 strncat(depFile, sourceFile, (dotPtr - sourceFile)/sizeof(char));
538 - strcat(depFile, ".dep");
539 + strcat(depFile, ".FreeFOAMdep");
541 if (strcmp(sourceExt, "java") == 0)
543 @@ -185,7 +185,7 @@ int main(int argc, char* argv[])
544 objectFile = (char*)malloc(strlen(sourceFile) + 16);
545 strcpy(objectFile, "$(OBJECTS_DIR)/");
546 strncat(objectFile, slashPtr, (dotPtr - slashPtr)/sizeof(char));
547 - strcat(objectFile, ".o");
548 + strcat(objectFile, ".d");
550 printf("%s: %s\n", objectFile, depFile);
552 diff --git a/wmake/wmakeDerivedFiles b/wmake/wmakeDerivedFiles
553 index 8d522e9..1fe8294 100755
554 --- a/wmake/wmakeDerivedFiles
555 +++ b/wmake/wmakeDerivedFiles
556 @@ -79,7 +79,7 @@ rm tmpSourceFile
559 -e 's%^%$(OBJECTS_DIR)/%' \
560 - -e 's%\.[a-zA-Z]*$%\.o%' \
561 + -e 's%\.[a-zA-Z]*$%\.d%' \
562 files.$$ > tmpObjectFiles
564 echo "OBJECTS = " > tmpObjectFiles2
565 @@ -95,7 +95,7 @@ rm tmpObjectFiles tmpObjectFiles2
566 # make localObjectFiles
567 # ~~~~~~~~~~~~~~~~~~~~~
569 - -e 's%\.[a-zA-Z]*$%\.o%' \
570 + -e 's%\.[a-zA-Z]*$%\.d%' \
571 files.$$ > tmpLocalObjectFiles
573 echo "LOCAL_OBJECTS = " > tmpLocalObjectFiles2
574 @@ -110,7 +110,7 @@ rm tmpLocalObjectFiles tmpLocalObjectFiles2
576 # make dependencyFiles
577 # ~~~~~~~~~~~~~~~~~~~~
578 -sed 's/\.[a-zA-Z]*$/\.dep/' \
579 +sed 's/\.[a-zA-Z]*$/\.FreeFOAMdep/' \
580 files.$$ > tmpDependencyFiles
582 echo "DEPENDENCIES = " > tmpDependencyFiles2
583 @@ -125,7 +125,7 @@ rm tmpDependencyFiles tmpDependencyFiles2
587 -sed -e 's/\.[a-zA-Z]*$/.dep/' \
588 +sed -e 's/\.[a-zA-Z]*$/.FreeFOAMdep/' \
590 files.$$ > includeDeps
600 repo
.git
.am(istream
=wmakePatch
)
601 except git
.GitCommandError
as e
:
602 echo('Error: Failed to patch wmake:\n%s'%str
(e
), file=sys
.stderr
)
608 os
.chdir(WM_PROJECT_DIR
)
609 subprocess
.check_call('./Allwmake')
610 except subprocess
.CalledProcessError
as e
:
611 echo('Error: Running Allwmake failed with status %d:\n%s'%
612 (e
.returncode
, str(e
)), file=sys
.stderr
)
617 orig_branch
.checkout()
618 repo
.delete_head(tmp_branch
, force
=True)
619 except Exception as e
:
620 echo('Error: Failed restoring branch %s and deleting %s:\n%s'%
621 (orig_branch
.name
, tmp_branch
.name
, str(e
)), file=sys
.stderr
)
628 for parent
, dirs
, files
in os
.walk(WM_PROJECT_DIR
):
629 if re
.search(r
'FreeFOAMDPDep(SYSTEMOPENMPI)?$', parent
):
630 srcdir
= op
.dirname(op
.dirname(parent
))
631 for f
in filter(lambda f
: op
.splitext(f
)[1]=='.d', files
):
632 f
= op
.join(parent
, f
)
635 for l
in open(f
, 'rt'):
636 lines
+= l
.strip().replace(' \\', '').split()
639 # resolve lnInclude entries, remove blacklisted files and strip prefix
641 for i
, l
in enumerate(reversed(lines
)):
643 # if not absolute, make it so
645 l
= op
.normpath(op
.join(srcdir
, l
))
646 if l
.find('lnInclude/') > -1:
648 if op
.exists(l
) and op
.islink(l
):
651 ll
= op
.normpath(op
.join(op
.dirname(l
), ll
))
654 echo('WARNING: "%s" does not exist or is not a symlink'%l
,
656 # remove blacklisted files
658 for p
in blacklistPatterns
:
659 if p
.search(l
) is not None:
665 # strip WM_PROJECT_DIR
666 if l
.startswith(WM_PROJECT_DIR
):
667 l
= op
.relpath(l
, WM_PROJECT_DIR
)
670 # remove duplicates and sort
671 lines
= sorted(set(lines
))
672 open(op
.splitext(f
)[0]+'.ofd', 'wt').write(('\n'.join(lines
))+'\n')
674 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file