EZFIO/configure.py

147 lines
3.7 KiB
Python
Raw Normal View History

2018-04-30 19:49:11 +02:00
#!/usr/bin/env python2
2015-06-01 16:45:10 +02:00
2015-06-02 15:54:06 +02:00
import os,sys
2015-06-01 16:45:10 +02:00
2015-06-25 14:59:35 +02:00
def write_if_different(filename,s):
try:
with open(filename, "r") as f:
ref = f.read()
except:
ref = ""
if ref == s:
return
else:
with open(filename, "w") as f:
f.write(s)
2015-06-02 01:48:43 +02:00
with open("version",'r') as f:
version = f.read().strip().rsplit('=')[1]
d_default = {
"VERSION" : version,
"IRPF90" : 'irpf90',
2018-06-04 19:43:32 +02:00
"FC" : 'gfortran -g -ffree-line-length-none -fPIC -fopenmp',
2015-06-02 01:48:43 +02:00
"FCFLAGS" : '-O2',
"RANLIB" : 'ranlib',
"AR" : 'ar',
2018-04-30 20:00:00 +02:00
"BUILD_SYSTEM" : 'make',
"NINJA" : 'ninja',
2015-06-02 01:48:43 +02:00
}
2015-06-25 14:59:35 +02:00
CONFIG_FILES=' '.join([ os.path.join("config",x) for x in os.listdir('config') if x != '.empty'])
2015-06-02 01:48:43 +02:00
def create_make_config():
2015-06-25 14:59:35 +02:00
try:
d = read_make_config()
except:
d = {}
2015-06-04 00:39:20 +02:00
fmt = { "make.config" :'{0}={1}\n' ,
2015-06-25 14:59:35 +02:00
".make.config.sh": 'export {0}="{1}"\n' }
for var,default in d_default.iteritems():
if var not in d:
try:
cur = os.environ[var]
except KeyError:
cur = default
d[var]=cur
2015-06-04 00:39:20 +02:00
for filename in fmt:
2015-06-25 14:59:35 +02:00
out = ""
for var,default in d_default.iteritems():
cur = d[var]
out += fmt[filename].format(var,cur)
write_if_different(filename,out)
return d
2015-06-02 01:48:43 +02:00
def read_make_config():
result = {}
with open("make.config",'r') as f:
for line in f.readlines():
2015-06-01 16:45:10 +02:00
try:
2015-06-02 21:46:40 +02:00
key, value = line.strip().split('=',1)
2015-06-02 01:48:43 +02:00
except:
print "Error in make.config:"
print line
sys.exit(1)
result[key] = value
return result
def create_build_ninja():
2015-06-25 14:59:35 +02:00
d=create_make_config()
2015-06-02 01:48:43 +02:00
d["irpf90_files"] = [ "src/{0}".format(x) for x in
"""
2015-06-10 12:20:44 +02:00
IRPF90_temp/build.ninja irpf90.make irpf90_entities
2015-06-02 12:12:11 +02:00
tags libezfio_groups-gen.py libezfio_util-gen.py
2015-06-02 15:54:06 +02:00
""".split() ]
2015-06-02 01:48:43 +02:00
d["irpf90_sources"] = [ "src/{0}".format(x) for x in
"""
libezfio_error.irp.f create_ocaml.py groups_templates.py
2015-06-02 12:12:11 +02:00
libezfio_file.irp.f create_python.py
libezfio_groups.irp.f ezfio-head.py
libezfio_util.irp.f ezfio-tail.py read_config.py
2015-06-02 15:54:06 +02:00
f_types.py test.py groups.py
2015-06-02 01:48:43 +02:00
""".split() ] + [ "make.config" ]
d["irpf90_files"] = ' '.join(d["irpf90_files"])
d["irpf90_sources"] = ' '.join(d["irpf90_sources"])
template = """
rule compile_irpf90
2015-06-25 14:59:35 +02:00
command = bash -c 'source .make.config.sh ; cd src ; {IRPF90} --ninja'
2015-06-02 01:48:43 +02:00
description = Compiling IRPF90
rule build_irpf90_a
2015-06-25 14:59:35 +02:00
command = {NINJA} -C src/IRPF90_temp && touch $out
2015-06-02 01:48:43 +02:00
description = Compiling Fortran files
rule build_libezfio_a
command = cp src/IRPF90_temp/irpf90.a lib/libezfio.a ; {RANLIB} lib/libezfio.a
description = Building libezfio.a
rule build_libezfio_irp_a
command = cp lib/libezfio.a lib/libezfio_irp.a ; {AR} dv lib/libezfio_irp.a irp_stack.irp.o > /dev/null ; {RANLIB} lib/libezfio_irp.a
2015-06-02 01:48:43 +02:00
description = Building libezfio_irp.a
2015-06-02 15:54:06 +02:00
rule build_python
2018-04-30 19:53:30 +02:00
command = cd src ; python2 create_python.py
2015-06-02 15:54:06 +02:00
description = Building Python module
rule build_ocaml
2018-04-30 19:53:30 +02:00
command = cd src ; python2 create_ocaml.py
2015-06-02 15:54:06 +02:00
description = Building Ocaml module
2015-06-02 01:48:43 +02:00
2015-06-03 14:34:41 +02:00
build {irpf90_files}: compile_irpf90 | {irpf90_sources} {CONFIG_FILES}
2015-06-02 01:48:43 +02:00
build src/IRPF90_temp/irpf90.a: build_irpf90_a | {irpf90_files}
build lib/libezfio.a: build_libezfio_a | src/IRPF90_temp/irpf90.a
build lib/libezfio_irp.a: build_libezfio_irp_a | lib/libezfio.a
2015-06-02 15:54:06 +02:00
build Python/ezfio.py: build_python | lib/libezfio.a
build Ocaml/ezfio.ml: build_ocaml | lib/libezfio.a
2015-06-02 01:48:43 +02:00
"""
2015-06-25 14:59:35 +02:00
d["CONFIG_FILES"] = CONFIG_FILES
write_if_different('generated.ninja',template.format(**d))
2015-06-02 01:48:43 +02:00
if __name__ == '__main__':
create_build_ninja()