10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-04 21:23:56 +01:00
QuantumPackage/scripts/compilation/read_compilation_cfg.py

48 lines
1.2 KiB
Python
Raw Normal View History

2020-03-17 16:39:43 +01:00
#!/usr/bin/env python3
2019-01-25 11:39:31 +01:00
# -*- coding: utf-8 -*-
import os, sys
2020-03-17 16:39:43 +01:00
import configparser
2019-01-25 11:39:31 +01:00
def get_l_option_section(config):
"""List of options chosen by the user"""
l = [o for o in ['OPENMP'] if config.getboolean("OPTION", o)]
l.append(config.get("OPTION", "MODE").strip())
return l
def get_compilation_option(pwd_cfg, flag_name):
"""
Return the flag compilation of a compile.cfg located in pwd_cfg
"""
if not os.path.isfile(pwd_cfg):
2020-03-17 16:39:43 +01:00
print("Configuration file %s not found"%(pwd_cfg))
2019-01-25 11:39:31 +01:00
sys.exit(1)
2020-03-17 16:39:43 +01:00
config = configparser.ConfigParser(inline_comment_prefixes=(';','#'))
2019-01-25 11:39:31 +01:00
config.read(pwd_cfg)
if flag_name == "FC" and config.getboolean("OPTION","CACHE"):
l = ["cache_compile.py"]
else:
l = []
l_option_section = get_l_option_section(config)
for section in ["COMMON"] + l_option_section:
try:
l.extend(config.get(section, flag_name).split())
2020-03-17 16:39:43 +01:00
except configparser.NoOptionError:
2019-01-25 11:39:31 +01:00
pass
return " ".join(l)
if __name__ == '__main__':
qpackage_root = os.environ['QP_ROOT']
pwd_cfg = os.path.join(qpackage_root, "config/ifort_gpi2.cfg")
2020-03-17 16:39:43 +01:00
print(get_compilation_option(pwd_cfg, "FC"))
print(get_compilation_option(pwd_cfg, "FCFLAGS"))