diff --git a/Makefile b/Makefile index 6c5b4a1..5ac6182 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ include version include make.config -.PHONY: default clean veryclean archive configure +.PHONY: default clean veryclean archive default: make.config cd src && $(MAKE) @@ -34,7 +34,6 @@ clean: - bash -c "[[ -f lib/libezfio.a ]] && rm $$PWD/lib/*" - bash -c "[[ -f Python/ezfio.py ]] && rm $$PWD/Python/*" - bash -c "[[ -f Ocaml/ezfio.ml ]] && rm $$PWD/Ocaml/*" - - bash -c "[[ -f Bash/ezfio.sh ]] && rm $$PWD/Bash/*" - $(MAKE) -C $$PWD/src veryclean archive: distclean diff --git a/build.ninja b/build.ninja index 719f5ba..bafb5d1 100644 --- a/build.ninja +++ b/build.ninja @@ -1,16 +1,16 @@ include version rule build_generated_ninja - command = python $in ninja + command = python configure.py description = Creating generated.ninja - generator = 1 rule run_ninja - command = bash -c 'source .make.config.sh ; exec bash -c "$$NINJA -f $in"' + command = bash -c 'source .make.config.sh ; $$NINJA -f $in' description = Building Fortran library + pool = console 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 + 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 clean_all @@ -18,9 +18,10 @@ rule clean_all description = Cleaning directory -build make.config .make.config.sh generated.ninja: build_generated_ninja configure.py +build make.config .make.config.sh generated.ninja impossible_target: build_generated_ninja build all: run_ninja generated.ninja + default all build EZFIO.${VERSION}.tar.gz: build_archive diff --git a/configure.py b/configure.py index 8069e58..86e8773 100755 --- a/configure.py +++ b/configure.py @@ -2,6 +2,20 @@ import os,sys +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) + + with open("version",'r') as f: version = f.read().strip().rsplit('=')[1] @@ -13,22 +27,37 @@ d_default = { "RANLIB" : 'ranlib', "AR" : 'ar', "NINJA" : 'ninja', - "CONFIG_FILES" : - ' '.join([ os.path.join("config",x) for x in os.listdir('config') if x != '.empty']) } +CONFIG_FILES=' '.join([ os.path.join("config",x) for x in os.listdir('config') if x != '.empty']) + def create_make_config(): + try: + d = read_make_config() + except: + d = {} + fmt = { "make.config" :'{0}={1}\n' , - ".make.config.sh": '{0}="{1}"\n' } + ".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 + for filename in fmt: - with open(filename,'w') as out: - for var,default in d_default.iteritems(): - try: - cur = os.environ[var] - except KeyError: - cur = default - out.write(fmt[filename].format(var,cur)) + out = "" + for var,default in d_default.iteritems(): + cur = d[var] + out += fmt[filename].format(var,cur) + write_if_different(filename,out) + + return d + def read_make_config(): @@ -47,9 +76,7 @@ def read_make_config(): def create_build_ninja(): - create_make_config() - - d = read_make_config() + d=create_make_config() d["irpf90_files"] = [ "src/{0}".format(x) for x in """ @@ -71,20 +98,13 @@ def create_build_ninja(): 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 + command = bash -c 'source .make.config.sh ; cd src ; {IRPF90} --ninja' description = Compiling IRPF90 rule build_irpf90_a - command = {NINJA} -C src/IRPF90_temp + command = {NINJA} -C src/IRPF90_temp && touch $out description = Compiling Fortran files rule build_libezfio_a @@ -103,9 +123,6 @@ rule build_ocaml command = cd src ; python create_ocaml.py description = Building Ocaml module - -build make.config: build_make_config | configure.py - build {irpf90_files}: compile_irpf90 | {irpf90_sources} {CONFIG_FILES} build src/IRPF90_temp/irpf90.a: build_irpf90_a | {irpf90_files} @@ -119,9 +136,8 @@ build Python/ezfio.py: build_python | lib/libezfio.a build Ocaml/ezfio.ml: build_ocaml | lib/libezfio.a """ - - with open('generated.ninja','w') as f: - f.write(template.format(**d)) + d["CONFIG_FILES"] = CONFIG_FILES + write_if_different('generated.ninja',template.format(**d)) if __name__ == '__main__': diff --git a/version b/version index 0743293..f406e04 100644 --- a/version +++ b/version @@ -1 +1 @@ -VERSION=1.3.0 +VERSION=1.3.1