10
0
mirror of https://gitlab.com/scemama/EZFIO.git synced 2024-11-19 04:22:25 +01:00
EZFIO/configure.py

121 lines
3.3 KiB
Python
Raw Normal View History

2015-06-01 16:45:10 +02:00
#!/usr/bin/env python
import os
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',
"FC" : 'gfortran -g -ffree-line-length-none -fPIC',
"FCFLAGS" : '-O2',
"RANLIB" : 'ranlib',
"AR" : 'ar',
"NINJA" : 'ninja',
"CONFIG_FILES" :
' '.join([ x for x in os.listdir('config') if x != '.empty'])
}
def create_make_config():
with open("make.config",'w') as out:
for var,default in d_default.iteritems():
try:
cur = os.environ[var]
except KeyError:
cur = default
out.write('{0}={1}\n'.format(var,cur))
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 01:48:43 +02:00
key, value = line.strip().split('=')
except:
print "Error in make.config:"
print line
sys.exit(1)
result[key] = value
return result
def create_build_ninja():
if "make.config" not in os.listdir(os.getcwd()):
create_make_config()
d = read_make_config()
d["irpf90_files"] = [ "src/{0}".format(x) for x in
"""
IRPF90_temp/build.ninja irpf90.make irpf90_entities
tags
""".split() ] + \
"""
Python/ezfio.py Ocaml/ezfio.ml Bash/ezfio.sh
""".split()
d["irpf90_sources"] = [ "src/{0}".format(x) for x in
"""
libezfio_error.irp.f create_ocaml.py groups_templates.py
libezfio_file.irp.f create_python.py libezfio_groups-gen.py
libezfio_groups.irp.f ezfio-head.py libezfio_util-gen.py
libezfio_util.irp.f ezfio-tail.py read_config.py run.irp.f
f_types.py test.py create_bash.py groups.py
""".split() ] + [ "make.config" ]
d["irpf90_files"] = ' '.join(d["irpf90_files"])
d["irpf90_sources"] = ' '.join(d["irpf90_sources"])
template = """
rule build_archive
command = git archive --format=tar HEAD > EZFIO.{VERSION}.tar && mkdir -p EZFIO && cd EZFIO && tar -xvf ../EZFIO.{VERSION}.tar && cd .. && rm EZFIO.{VERSION}.tar && tar -zcvf EZFIO.{VERSION}.tar.gz EZFIO && rm -rf EZFIO
description = Building archive
rule build_make_config
command = python configure.py
description = Creating make.config
rule compile_irpf90
command = cd src ; {IRPF90} --ninja
description = Compiling IRPF90
rule build_irpf90_a
command = {NINJA} -C src/IRPF90_temp
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 ; {RANLIB} lib/libezfio_irp.a
description = Building libezfio_irp.a
build make.config: build_make_config | configure.py
build {irpf90_files}: compile_irpf90 | {irpf90_sources}
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
"""
with open('generated.ninja','w') as f:
f.write(template.format(**d))
if __name__ == '__main__':
create_build_ninja()