Created
June 17, 2026 09:09
-
-
Save will-bainbridge/c4d777bc3ea38872cd6615ce5ab5f5f8 to your computer and use it in GitHub Desktop.
YMCD Configuration for OpenFOAM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print_function | |
| import os | |
| import subprocess | |
| import sys | |
| def getBuildPath(path): | |
| if os.path.isdir(os.path.join(path, 'Make')): | |
| return path | |
| else: | |
| return getBuildPath(os.path.dirname(os.path.abspath(path))) | |
| def runMake(arguments): | |
| proc = subprocess.Popen( | |
| ['make'] + arguments, | |
| stdin=subprocess.PIPE, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.STDOUT, | |
| universal_newlines=True | |
| ) | |
| proc.wait() | |
| if proc.returncode == 0: | |
| return [ o for o in proc.stdout.read().split() if o[0] == '-' ] | |
| else: | |
| return [] | |
| def getOptions(): | |
| rulesPath = os.path.join(os.environ['WM_DIR'], 'rules') | |
| generalRulesPath = os.path.join(rulesPath, 'General') | |
| options = [] | |
| arguments = [ | |
| 'GENERAL_RULES=' + generalRulesPath, | |
| '--file=' + os.path.join(generalRulesPath, 'general'), | |
| '--eval=print-variable:\n\t@echo $(GFLAGS)', | |
| 'print-variable' | |
| ] | |
| options.extend(runMake(arguments)) | |
| compilerRulesPath = os.path.join(rulesPath, os.environ['WM_ARCH'] + os.environ['WM_COMPILER']) | |
| arguments = [ | |
| 'DEFAULT_RULES=' + compilerRulesPath, | |
| '--file=' + os.path.join(compilerRulesPath, 'c++'), | |
| '--eval=print-variable:\n\t@echo $(CC) $(c++FLAGS)', | |
| 'print-variable' | |
| ] | |
| options.extend(runMake(arguments)) | |
| return options | |
| def getIncludes(buildPath): | |
| srcPath = os.path.join(os.environ['WM_PROJECT_DIR'], 'src') | |
| includes = [ '-I' + s for s in [ | |
| os.path.join(srcPath, os.environ['WM_PROJECT'] , 'lnInclude'), | |
| os.path.join(srcPath, 'OSspecific', os.environ['WM_OSTYPE'], 'lnInclude'), | |
| 'lnInclude', | |
| '.' | |
| ] ] | |
| arguments = [ | |
| 'LIB_SRC=' + srcPath, | |
| '--file=' + os.path.join(buildPath, 'Make', 'options'), | |
| '--eval=print-variable:\n\t@echo $(EXE_INC)', | |
| 'print-variable' | |
| ] | |
| includes.extend([ argument for argument in runMake(arguments) if argument != '-I' ]) | |
| return includes | |
| def Settings(**kwargs): | |
| try: | |
| os.environ['WM_PROJECT_DIR'] | |
| except KeyError: | |
| exit(0) | |
| filePath = kwargs['filename'] | |
| buildPath = getBuildPath(os.path.dirname(filePath)) | |
| flags = ['-x', 'c++'] | |
| flags.extend(getOptions()) | |
| flags.extend(getIncludes(buildPath)) | |
| return {'flags' : flags, 'include_paths_relative_to_dir' : buildPath} | |
| if __name__ == '__main__': | |
| for flag in Settings(filename=sys.argv[1])['flags']: | |
| print(flag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment