From e0e7c73adcb7becdca0dc0e9092f9bd18d0d92f0 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 30 Sep 2019 20:09:54 +0200 Subject: [PATCH] Compiling --- Makefile | 66 +++++++ README.md | 23 +-- build.ninja | 88 ---------- configure.sh | 16 +- install/Makefile | 67 +++++++ install/build.ninja | 75 -------- install/scripts/install_ninja.sh | 27 --- make.config.gfortran | 3 +- make.config.ifort | 3 +- ocaml/ninja_ocaml.py | 288 ------------------------------- scripts/clean.sh | 5 +- scripts/compile_irpf90.sh | 46 ++--- scripts/compile_ocaml_dep.sh | 31 ---- scripts/compile_src.sh | 23 ++- 14 files changed, 194 insertions(+), 567 deletions(-) create mode 100644 Makefile delete mode 100644 build.ninja create mode 100644 install/Makefile delete mode 100644 install/build.ninja delete mode 100755 install/scripts/install_ninja.sh delete mode 100755 ocaml/ninja_ocaml.py delete mode 100755 scripts/compile_ocaml_dep.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4444cc8 --- /dev/null +++ b/Makefile @@ -0,0 +1,66 @@ +include make.config + + +default_target: all + +.phony: clean always + +clean: + ./scripts/clean.sh + +# put all files of PROPERTIES here +# -------------------------------- + +ezfio_config/properties.config ocaml/Property.ml: scripts/create_properties_python.py src/PROPERTIES/properties.irp.f src/PROPERTIES/properties_energy.irp.f src/PROPERTIES/properties_general.irp.f src/irpf90.make + bash -c "source qmcchemrc ; exec python2 ./scripts/create_properties_ezfio.py" + +# EZFIO +# ----- + +build lib/libezfio.a lib/libezfio_irp.a EZFIO/lib/libezfio.a EZFIO/lib/libezfio_irp.a EZFIO/Ocaml/ezfio.ml EZFIO/Python/ezfio.py: ezfio_config/qmc.config ezfio_config/properties.config make.config scripts/create_properties_ezfio.py src/tags src/irpf90_entities src/irpf90.make src/irpf90.make + ./scripts/compile_ezfio.sh + + +# Fortran executables +# ------------------- + + +always: /dev/null + +src/tags src/irpf90_entities src/irpf90.make: make.config always + ./scripts/compile_irpf90.sh + +src/MAIN/qmc src/MAIN/qmc_create_walkers src/MAIN/qmcchem_info: lib/libezfio.a lib/libezfio_irp.a src/tags src/irpf90_entities src/irpf90.make src/irpf90.make + ./scripts/compile_src.sh + +# OCaml +# ----- + +ocaml/qmcchem: EZFIO/Ocaml/ezfio.ml ocaml/Property.ml + ./scripts/compile_ocaml.sh + +# Archive +# ------- + +qmcchem.tar.gz: all + git archive --format tar.gz HEAD --prefix "QmcChem/" -7 -o qmcchem.tar.gz + + +# Binaries +# -------- + +bin/qmc: src/MAIN/qmc + cp src/MAIN/qmc bin/ + +bin/qmcchem_info: src/MAIN/qmcchem_info + cp src/MAIN/qmcchem_info bin/ + +bin/qmc_create_walkers: src/MAIN/qmc_create_walkers + cp src/MAIN/qmc_create_walkers bin/ + +bin/qmcchem: + cp ocaml/qmcchem bin/ + +all: bin/qmc bin/qmcchem_info bin/qmc_create_walkers bin/qmcchem + + diff --git a/README.md b/README.md index ba76183..717af25 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,12 @@ Warnings: Requirements ------------ -* [Ninja build tool](http://github.com/martine/ninja) * [OCaml compiler with Opam and Core library](http://github.com/ocaml) * [ZeroMQ high performance communication library](http://www.zeromq.org) * [F77_ZMQ ZeroMQ Fortran interface](http://github.com/scemama/f77_zmq/) * [IRPF90 Fortran code generator](http://irpf90.ups-tlse.fr) * [EZFIO Easy Fortran I/O library generator](http://github.com/scemama/EZFIO) -* GNU C++ Compiler (g++) for ZeroMQ and Ninja +* GNU C++ Compiler (g++) for ZeroMQ * Python >= 2.6 for install scripts * Bash for install scripts * Fortran compiler, Intel Fortran recommended @@ -58,9 +57,8 @@ Installation The ``make.config`` file contains compiler specific parameters. You should change them to match your hardware. -The ``configure.sh`` script will first download the -[Ninja](http://github.com/martine/ninja) build tool, and will then run Ninja -using the ``install/build.ninja`` file. The configuration script will work in +The ``configure.sh`` script will first download the dependencies by running +``make`` in the ``install/`` directory. The configuration script will work in the ``install`` directory. It will first download into the ``install/Downloads`` directory everything that needs to be installed. The building of the dependencies takes place in the ``install/_build`` @@ -80,17 +78,20 @@ environment variables are located in the ``qmcchemrc`` file: $ source qmcchemrc ``` +The ``QMCCHEM_NIC`` environment variable should be set to the proper network interface, +usually ``ib0`` on HPC machines. + To compile the program, run ```bash -$ ninja +$ make ``` Example of a QMC=Chem calculation --------------------------------- -1.Calculation with the [quantum package](http://github.com/LCPQ/quantum_package) +1.Calculation with the [quantum package](http://github.com/QuantumPackage/qp2) Create the `xyz` file containing the nuclear coordinates of the system @@ -108,18 +109,18 @@ EOF Choose a suitable basis set and create the [EZFIO database](https://github.com/LCPQ/ezfio) ```bash -$ qp_create_ezfio_from_xyz -b cc-pvdz h2o.xyz -o h2o +$ qp_create_ezfio -b cc-pvdz h2o.xyz -o h2o ``` Run the SCF calculation ```bash -$ qp_run SCF h2o +$ qp_run scf h2o ``` Run the CIPSI calculation ```bash -$ qp_run full_ci h2o +$ qp_run fci h2o ``` Transform the input for use in QMC=Chem @@ -135,7 +136,7 @@ $ qp_run save_for_qmcchem h2o Before using QMC=Chem, you need to load the environment variables: ```bash -$ source qmcchem.rc +$ source qmcchemrc ``` In QMC=Chem, everything goes through the use of the ``qmcchem`` command. diff --git a/build.ninja b/build.ninja deleted file mode 100644 index 4b789ea..0000000 --- a/build.ninja +++ /dev/null @@ -1,88 +0,0 @@ -rule compile_ezfio - command = ./scripts/compile_ezfio.sh - description = Compiling the EZFIO library - pool = console - -rule build_properties_config - command = bash -c "source qmcchemrc ; exec python2 ./scripts/create_properties_ezfio.py" - pool = console - -rule compile_irpf90 - command = ./scripts/compile_irpf90.sh - description = Compiling IRPF90 - pool = console - -rule compile_src - command = ./scripts/compile_src.sh - description = Compiling src - pool = console - -rule create_archive - command = git archive --format tar.gz HEAD --prefix "QmcChem/" -7 -o qmcchem.tar.gz - description = Creating archive - pool = console - -rule compile_ocaml_dep - command = scripts/compile_ocaml_dep.sh - description = Finding dependencies in OCaml files - pool = console - -rule compile_ocaml - command = cd ocaml ; make $target - description = Compiling OCaml tools - pool = console - -rule copy_to_bin - command = bash -c "cp $in $out ; touch $out" - description = Copying $in into bin/ - pool = console - -rule clean - command = ./scripts/clean.sh - pool = console - -# put all files of PROPERTIES here -# -------------------------------- - -build ezfio_config/properties.config ocaml/Property.ml: build_properties_config | scripts/create_properties_python.py src/PROPERTIES/properties.irp.f src/PROPERTIES/properties_energy.irp.f src/PROPERTIES/properties_general.irp.f || src/IRPF90_temp/build.ninja - -# EZFIO -# ----- - -build lib/libezfio.a lib/libezfio_irp.a EZFIO/lib/libezfio.a EZFIO/lib/libezfio_irp.a EZFIO/Ocaml/ezfio.ml EZFIO/Python/ezfio.py: compile_ezfio | ezfio_config/qmc.config ezfio_config/properties.config make.config scripts/create_properties_ezfio.py || src/tags src/irpf90_entities src/irpf90.make src/IRPF90_temp/build.ninja - -# Fortran executables -# ------------------- - -build always: phony - -build src/tags src/irpf90_entities src/irpf90.make src/IRPF90_temp/build.ninja: compile_irpf90 | make.config always - -build src/MAIN/qmc src/MAIN/qmc_create_walkers src/MAIN/qmcchem_info: compile_src | lib/libezfio.a lib/libezfio_irp.a src/tags || src/irpf90_entities src/irpf90.make src/IRPF90_temp/build.ninja - -# Archive -# ------- - -build qmcchem.tar.gz: create_archive - -# Ocaml -# ----- - -build ocaml/qmcchem : compile_ocaml | EZFIO/Ocaml/ezfio.ml ocaml/Property.ml - - -# Copy binaries in bin -# -------------------- - -build bin/qmc: copy_to_bin src/MAIN/qmc -build bin/qmcchem_info: copy_to_bin src/MAIN/qmcchem_info -build bin/qmc_create_walkers: copy_to_bin src/MAIN/qmc_create_walkers -build bin/qmcchem: copy_to_bin ocaml/qmcchem - -default bin/qmc bin/qmcchem_info bin/qmc_create_walkers bin/qmcchem - -# Clean -# ----- - -build clean: clean - diff --git a/configure.sh b/configure.sh index 7b618cf..5096d7a 100755 --- a/configure.sh +++ b/configure.sh @@ -6,20 +6,6 @@ QMCCHEM_PATH=$PWD mkdir -p "${QMCCHEM_PATH}"/bin cd "${QMCCHEM_PATH}"/install mkdir -p Downloads _build -# TODO : Check if network is up (ping) -if [[ ! -x "${QMCCHEM_PATH}"/bin/ninja ]] -then - echo "Installing Ninja" - ./scripts/install_ninja.sh &> _build/ninja.log - if [[ ! -x "${QMCCHEM_PATH}"/bin/ninja ]] - then - echo "Installation of Ninja failed" - exit 1 - fi - touch _build/ninja.ok -fi -touch "${QMCCHEM_PATH}"/{src,ocaml}/.ls_md5 -"${QMCCHEM_PATH}"/bin/ninja "$@" cd "${QMCCHEM_PATH}" @@ -39,7 +25,7 @@ echo "Configuration OK." echo "Now, source the qmcchemrc file and build the program:" echo "" echo "source qmcchemrc" -echo "ninja" +echo "make" echo "" echo "=====================================================================" diff --git a/install/Makefile b/install/Makefile new file mode 100644 index 0000000..5486960 --- /dev/null +++ b/install/Makefile @@ -0,0 +1,67 @@ +default_target: all + +Downloads/irpf90.tar.gz: + wget --no-check-certificate \ + "https://gitlab.com/scemama/irpf90/-/archive/v1.7.2/irpf90-v1.7.2.tar.gz" \ + -O $@.tmp -o /dev/null && mv $@.tmp $@ + +Downloads/ezfio.tar.gz: + wget --no-check-certificate \ + "https://gitlab.com/scemama/EZFIO/-/archive/master/EZFIO-master.tar.gz" \ + -O $@.tmp -o /dev/null && mv $@.tmp $@ + +Downloads/zmq.tar.gz: + wget --no-check-certificate \ + "http://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz" \ + -O $@.tmp -o /dev/null && mv $@.tmp $@ + +Downloads/f77_zmq.tar.gz: + wget --no-check-certificate \ + "https://github.com/scemama/f77_zmq/archive/v4.2.5.tar.gz" \ + -O $@.tmp -o /dev/null && mv $@.tmp $@ + +Downloads/opam_installer.sh: + wget --no-check-certificate \ + "https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh" \ + -O $@.tmp -o /dev/null && mv $@.tmp $@ + +_build/irpf90.ok ../bin/irpman ../bin/irpf90: Downloads/irpf90.tar.gz + export target=irpf90 ; \ + ./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\ + touch _build/$${target}.ok || cat _build/$${target}.log + + +_build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h: Downloads/zmq.tar.gz + export target=zmq ; \ + ./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\ + touch _build/$${target}.ok || cat _build/$${target}.log + +_build/ezfio.ok: Downloads/ezfio.tar.gz + export target=ezfio ; \ + ./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\ + touch _build/$${target}.ok || cat _build/$${target}.log + +_build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so: Downloads/f77_zmq.tar.gz _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h + export target=f77_zmq ; \ + ./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\ + touch _build/$${target}.ok || cat _build/$${target}.log + +_build/qmcchemrc.ok ../qmcchemrc: _build/irpf90.ok ../bin/irpman ../bin/irpf90 _build/ezfio.ok + export target=qmcchemrc; \ + ./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\ + touch _build/$${target}.ok || cat _build/$${target}.log + +_build/ocaml.ok ../bin/opam: Downloads/opam_installer.sh _build/qmcchemrc.ok ../qmcchemrc + export target=ocaml; \ + ./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\ + touch _build/$${target}.ok || cat _build/$${target}.log + +_build/ocaml_zmq.ok: ../bin/opam ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/ocaml.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h + export target=ocaml_zmq; \ + ./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\ + touch _build/$${target}.ok || cat _build/$${target}.log + + + +all: _build/ocaml_zmq.ok _build/ocaml.ok ../bin/opam _build/qmcchemrc.ok ../qmcchemrc _build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so _build/ezfio.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/irpf90.ok ../bin/irpman ../bin/irpf90 + diff --git a/install/build.ninja b/install/build.ninja deleted file mode 100644 index 4ba1432..0000000 --- a/install/build.ninja +++ /dev/null @@ -1,75 +0,0 @@ -# This script should be run in the install dircetory - -# URLs -###### - -URL_OPAM ="https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh" -URL_IRPF90="https://gitlab.com/scemama/irpf90/-/archive/v1.7.2/irpf90-v1.7.2.tar.gz" -URL_EZFIO ="https://gitlab.com/scemama/EZFIO/-/archive/master/EZFIO-master.tar.gz" - -URL_ZMQ ="http://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz" -URL_F77ZMQ="https://github.com/scemama/f77_zmq/archive/v4.2.5.tar.gz" - -# Rules -####### - -rule download - command = [ -e ${out} ] || (wget --no-check-certificate ${url} -O ${out}.tmp -o /dev/null && mv ${out}.tmp ${out}) - description = Downloading ${descr} - -rule install - command = ./scripts/install_${target}.sh > _build/${target}.log 2>&1 && touch _build/${target}.ok || cat _build/${target}.log - description = Installing ${descr} | tail -f install/_build/${target}.log - - -# Builds -######## - -build Downloads/irpf90.tar.gz: download - url = ${URL_IRPF90} - descr = IRPF90 code generator - -build Downloads/ezfio.tar.gz: download - url = ${URL_EZFIO} - descr = EZFIO I/O library generator - -build Downloads/zmq.tar.gz: download - url = ${URL_ZMQ} - descr = ZeroMQ communication library - -build Downloads/f77_zmq.tar.gz: download - url = ${URL_F77ZMQ} - descr = Fortran ZeroMQ interface - -build Downloads/opam_installer.sh: download - url = ${URL_OPAM} - descr = OCaml OPAM installer - -build _build/irpf90.ok ../bin/irpman ../bin/irpf90: install | Downloads/irpf90.tar.gz - target = irpf90 - descr = IRPF90 - -build _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h: install | Downloads/zmq.tar.gz - target = zmq - descr = ZeroMQ - -build _build/ezfio.ok: install | Downloads/ezfio.tar.gz _build/irpf90.ok ../bin/irpman ../bin/irpf90 - target = ezfio - descr = EZFIO - -build _build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so: install | Downloads/f77_zmq.tar.gz _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h - target = f77_zmq - descr = Fortran ZeroMQ interface - -build _build/qmcchemrc.ok ../qmcchemrc: install | _build/irpf90.ok ../bin/irpman ../bin/irpf90 _build/ezfio.ok - target = qmcchemrc - description = QMC=Chem environment variables - -build _build/ocaml.ok ../bin/opam: install | Downloads/opam_installer.sh _build/qmcchemrc.ok ../qmcchemrc - target = ocaml - descr = OCaml compiler - -build _build/ocaml_zmq.ok: install | ../bin/opam ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/ocaml.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h - target = ocaml_zmq - descr = OCaml ZeroMQ interface - diff --git a/install/scripts/install_ninja.sh b/install/scripts/install_ninja.sh deleted file mode 100755 index ef6e1ed..0000000 --- a/install/scripts/install_ninja.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -x - -set -u -set -e - -TARGET=ninja -URL="https://github.com/martine/ninja/archive/v1.5.3.tar.gz" - -function _install() -{ - cd .. ; QMCCHEM_PATH="$PWD" ; cd - - set -e - set -u - cd "${BUILD}" - ./configure.py --bootstrap - cd - - mv "${BUILD}/ninja" "${QMCCHEM_PATH}"/bin/ - return 0 -} - -if [[ ! -f "Downloads/${TARGET}.tar.gz" ]] -then - wget --no-check-certificate ${URL} -O "Downloads/${TARGET}.tar.gz.tmp" - mv "Downloads/${TARGET}.tar.gz"{.tmp,} -fi -source scripts/build.sh - diff --git a/make.config.gfortran b/make.config.gfortran index 0f44979..c1bca00 100644 --- a/make.config.gfortran +++ b/make.config.gfortran @@ -6,7 +6,6 @@ CPU_TYPE="-mavx" ## FORTRAN compiler FC="gfortran -ffree-line-length-none" -NINJA="ninja" FCFLAGS="-O2 -g ${CPU_TYPE}" LIB="-lblas -llapack" @@ -14,5 +13,5 @@ LIB="-lblas -llapack" IRPF90="${QMCCHEM_PATH}/bin/irpf90" IRPF90_FLAGS="--align=16" -export FC NINJA FCFLAGS LIB IRPF90 IRPF90_FLAGS +export FC FCFLAGS LIB IRPF90 IRPF90_FLAGS diff --git a/make.config.ifort b/make.config.ifort index 504ffba..ce5434f 100644 --- a/make.config.ifort +++ b/make.config.ifort @@ -10,7 +10,6 @@ ALIGN="32" ## FORTRAN compiler FC="ifort" -NINJA="ninja" FCFLAGS="-O2 -g -ip -ftz -finline ${CPU_TYPE}" #-traceback LIB="-mkl=sequential" @@ -18,5 +17,5 @@ LIB="-mkl=sequential" IRPF90="${QMCCHEM_PATH}/bin/irpf90" IRPF90_FLAGS="--align=${ALIGN} ${IRPF90_FLAGS}" -export FC NINJA FCFLAGS LIB IRPF90 IRPF90_FLAGS +export FC FCFLAGS LIB IRPF90 IRPF90_FLAGS diff --git a/ocaml/ninja_ocaml.py b/ocaml/ninja_ocaml.py deleted file mode 100755 index fde91e3..0000000 --- a/ocaml/ninja_ocaml.py +++ /dev/null @@ -1,288 +0,0 @@ -#!/usr/bin/env python2 -# -# Copyright 2015 Anthony Scemama -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This file can be downloaded here: -# https://raw.githubusercontent.com/scemama/ninja_ocaml/master/ninja_ocaml.py -# - -"""Build OCaml projects using ninja.""" - -__author__ = """Anthony Scemama """ - -import os -import sys -import subprocess - -def _help_ (): - print """ - 1) Download and install ninja : - https://github.com/martine/ninja/releases/latest - 2) Copy the script into your OCaml project. - 3) Run the script. It will build a default build.ninja file - 4) Edit the build.ninja file - 5) Compile the main target using `ninja` - 6) Compile all the targets using `ninja all` - """ - -def create_generated_ninja(): - """Creates the generated.ninja file""" - - # Header - PACKAGES="" - THREAD="" - SYNTAX="" - OCAMLC_FLAGS="" - GENERATED_NINJA="generated.ninja" - with open('build.ninja','r') as f: - for line in f: - if line.startswith("PACKAGES"): - PACKAGES=line.split('=',1)[1].strip() - elif line.startswith("THREAD"): - THREAD=line.split('=',1)[1].strip() - elif line.startswith("SYNTAX"): - SYNTAX=line.split('=',1)[1].strip() - elif line.startswith("OCAMLC_FLAGS"): - OCAMLC_FLAGS=line.split('=',1)[1].strip() - elif line.startswith("LINK_FLAGS"): - LINK_FLAGS=line.split('=',1)[1].strip() - elif line.startswith("GENERATED_NINJA"): - GENERATED_NINJA=line.split('=',1)[1].strip() - - if PACKAGES != "": - LINK_FLAGS = "-linkpkg "+PACKAGES - - header = [ -""" -######################################################## -# This file was auto-generated. # -# This file will be overwritten. Don't edit this file! # -# Changes should be done in the build.ninja file. # -######################################################## - -""", - - "PACKAGES=%s"%(PACKAGES), - "THREAD=%s"%(THREAD), - "SYNTAX=%s"%(SYNTAX), - "OCAMLC_FLAGS=%s"%(OCAMLC_FLAGS), - "LINK_FLAGS=%s"%(LINK_FLAGS), - "GENERATED_NINJA=%s"%(GENERATED_NINJA), - ] - - header += """ -rule ocamlc - command = ocamlfind ocamlc -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in - description = Compiling $out (bytecode) - -rule ocamlopt - command = ocamlfind ocamlopt -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $o $in - description = Compiling $out (native) - -rule ocamlc_link - command = ocamlfind ocamlc $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in - description = Compiling $out (bytecode) - -rule ocamlopt_link - command = ocamlfind ocamlopt $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in - description = Compiling $out (native) - -""".splitlines() - - # Get the list of .ml files - all_files = os.listdir(os.getcwd()) - files = [ os.path.splitext(i)[0] for i in all_files if i.endswith('.ml') ] - while "myocamlbuild" in files: - files.remove("myocamlbuild") - ml_files = ' '.join( [ '%s.ml'%i for i in files ] ) - - # Dependencies - result = subprocess.Popen( - ("ocamlfind ocamldep {0} {1} {2}".format(PACKAGES,SYNTAX,ml_files)).split() - ,stdout=subprocess.PIPE).communicate()[0] - result = result.replace('\\\n',' ') - dependencies = {} - for line in result.splitlines(): - key, value = line.split(':') - dependencies[key.strip()] = value.strip() - - result = header - template = """ -build {0}.cmi: ocamlc {0}.mli | $GENERATED_NINJA -build {0}.cmo: ocamlc {0}.ml | $GENERATED_NINJA {1} -build {0}.cmx {0}.o: ocamlopt {0}.ml | $GENERATED_NINJA {2} - o = {0}.o -""" - - template_root_byte = """ -build {2}.byte: ocamlc_link {1} {0} -""" - - template_root_native = """ -build {2}: ocamlopt_link {1} {0} -""" - - # Find roots - dep = {} - for f in dependencies: - dep[f] = [ i.strip() for i in dependencies[f].split() ] - - roots = {} - for f in dependencies: - Found = False - for g,l in dep.iteritems(): - if f in l: - Found = True - if not Found: - roots[f] = [] - - def get_deps(l): - result = [] - for i in l: - if i in dep: - result += get_deps(dep[i]) - result += l - newresult = [] - for r in result: - if r not in newresult: - newresult.append(r) - return newresult - - for r in roots: - roots[r] = [ i for i in get_deps(dep[r]) if not i.endswith(".cmi") ] - - # Write the $GENERATED_NINJA file - result += [ template.format(basename, - dependencies["%s.cmo"%basename], - dependencies["%s.cmx"%basename] - ) for basename in files ] - result += [ template_root_byte.format(basename, - ' '.join(roots[basename]), - os.path.splitext(basename)[0] - ) for basename in roots if basename.endswith('.cmo')] - result += [ template_root_native.format(basename, - ' '.join(roots[basename]), - os.path.splitext(basename)[0] - ) for basename in roots if basename.endswith('.cmx')] - - output = '\n'.join(result) - try: - with open(GENERATED_NINJA,'r') as f: - inp = f.read() - except IOError: - inp = "" - - if inp != output: - with open(GENERATED_NINJA,'w') as f: - f.write(output) - -def create_build_ninja (): - with open('build.ninja','w') as f: - f.write(""" -MAIN= -# Main program to build - -PACKAGES= -# Required opam packages, for example: -# PACKAGES=-package core - -THREAD= -# If you need threding support, use: -# THREAD=-thread - -SYNTAX= -# If you need pre-processing, use: -# SYNTAX=-syntax camlp4o - -OCAMLC_FLAGS= -# Flags to give to ocamlc, for example: -# OCAMLC_FLAGS=-g -warn-error A - -LINK_FLAGS= -# Flags to give to the linker, for example: -# LINK_FLAGS=-cclib '-Wl,-rpath=../lib,--enable-new-dtags' - -GENERATED_NINJA=generated.ninja -# Name of the auto-generated ninja file - -rule create_generated - command = python2 ./ninja_ocaml.py - description = Finding dependencies between modules - -rule run_ninja - command = ninja -f $in $target - description = Compiling OCaml executables - pool = console - -rule run_clean - command = ninja -f $GENERATED_NINJA -t clean ; rm $GENERATED_NINJA - pool = console - description = Cleaning directory - -rule ocamlc - command = ocamlfind ocamlc -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in - description = Compiling $in (bytecode) - -rule ocamlopt - command = ocamlfind ocamlopt -c $OCAMLC_FLAGS $THREAD $PACKAGES $SYNTAX -o $out $in - description = Compiling $in (native) - -rule ocamlc_link - command = ocamlfind ocamlc $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in - description = Compiling $out (bytecode) - -rule ocamlopt_link - command = ocamlfind ocamlopt $OCAMLC_FLAGS $THREAD $LINK_FLAGS $PACKAGES $SYNTAX -o $out $in - description = Compiling $out (native) - - -build clean: run_clean -build always $GENERATED_NINJA: create_generated - -build $MAIN: run_ninja $GENERATED_NINJA - target = $MAIN - -build all: run_ninja $GENERATED_NINJA - target = - -default $MAIN - -""") - - -def main(): - - for h in "help -h -help --help ?".split(): - if h in sys.argv: - _help_ () - return - - if "build.ninja" in os.listdir(os.getcwd()): - create_generated_ninja () - else: - create_build_ninja () - print """ -========================================================== -A default build.ninja file was created. -Now, edit build.ninja and compile your project using: - - ninja - -========================================================== -""" - -if __name__ == '__main__': - main() - diff --git a/scripts/clean.sh b/scripts/clean.sh index 026e001..a9725c4 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -4,11 +4,10 @@ make -C ocaml clean if [[ -d src/IRPF90_temp ]] then - ninja -C src/IRPF90_temp -t clean + make -C src/IRPF90_temp -t clean fi -ninja -t clean -rm -f ocaml/qmcchem ocaml/.ls_md5 ocaml/generated.ninja +rm -f ocaml/qmcchem ocaml/.ls_md5 rm -f EZFIO/Ocaml/ezfio.ml cd src rm -rf tags irpf90_entities irpf90.make IRPF90_temp IRPF90_man .ls_md5 diff --git a/scripts/compile_irpf90.sh b/scripts/compile_irpf90.sh index 1f06469..2bee7bb 100755 --- a/scripts/compile_irpf90.sh +++ b/scripts/compile_irpf90.sh @@ -19,31 +19,31 @@ then REF=$(cat ${LSMD5_FILE}) fi -if [[ ${MD5} != ${REF} ]] +if [[ ${MD5} == ${REF} ]] then - echo ${MD5} > ${LSMD5_FILE} - echo Running IRPF90 - - source ${QMCCHEM_PATH}/make.config - - LIB="${LIB} ${QMCCHEM_PATH}/lib/libezfio_irp.a ${QMCCHEM_PATH}/lib/libf77zmq.a ${QMCCHEM_PATH}/lib/libzmq.a -lstdc++ -lrt -lz" - SRC="${SRC} ZMQ/f77_zmq_module.f90" - OBJ="${OBJ} IRPF90_temp/ZMQ/f77_zmq_module.o" - INCLUDES="${INCLUDES} -I AO -I SAMPLING -I TOOLS -I JASTROW -I MAIN -I PROPERTIES -I ZMQ" - IRPF90_FLAGS="${IRPF90_FLAGS} --ninja" - - # Check IRPF90 version - if [[ $( ${IRPF90} -v | python2 -c "import sys ; print float(sys.stdin.read().rsplit('.',1)[0]) >= 1.6") == False ]] - then - echo "IRPF90 version >= 1.6 required" - exit -1 - fi - - export IRPF90 IRPF90_FLAGS INCLUDES LIB SRC OBJ - - exec ${IRPF90} ${IRPF90_FLAGS} ${INCLUDES} || exit -1 + exit 0 fi - +echo ${MD5} > ${LSMD5_FILE} +echo Running IRPF90 + +source ${QMCCHEM_PATH}/make.config + +LIB="${LIB} ${QMCCHEM_PATH}/lib/libezfio_irp.a ${QMCCHEM_PATH}/lib/libf77zmq.a ${QMCCHEM_PATH}/lib/libzmq.a -lstdc++ -lrt -lz" +SRC="${SRC} ZMQ/f77_zmq_module.f90" +OBJ="${OBJ} IRPF90_temp/ZMQ/f77_zmq_module.o" +INCLUDES="${INCLUDES} -I AO -I SAMPLING -I TOOLS -I JASTROW -I MAIN -I PROPERTIES -I ZMQ" +IRPF90_FLAGS="${IRPF90_FLAGS}" + +# Check IRPF90 version +if [[ $( ${IRPF90} -v | python2 -c "import sys ; print float(sys.stdin.read().rsplit('.',1)[0]) >= 1.6") == False ]] +then + echo "IRPF90 version >= 1.6 required" + exit -1 +fi + +export IRPF90 IRPF90_FLAGS INCLUDES LIB SRC OBJ + +exec ${IRPF90} ${IRPF90_FLAGS} ${INCLUDES} || exit -1 diff --git a/scripts/compile_ocaml_dep.sh b/scripts/compile_ocaml_dep.sh deleted file mode 100755 index 84fe181..0000000 --- a/scripts/compile_ocaml_dep.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -if [[ -z ${QMCCHEM_PATH} ]] -then - echo "Error: qmcchemrc not loaded" - exit -1 -fi - -cd ${QMCCHEM_PATH}/ocaml || exit -1 - -cp ${QMCCHEM_PATH}/EZFIO/Ocaml/ezfio.ml . || exit -1 - -LSMD5_FILE=${QMCCHEM_PATH}/ocaml/.ls_md5 -FILES="*.ml *.mli" -MD5=$(ls -ltr --full-time ${FILES} 2>/dev/null | md5sum | cut -d ' ' -f 1) - -REF=0 - -if [[ -f ${LSMD5_FILE} ]] -then - REF=$(cat ${LSMD5_FILE}) -fi - -if [[ ${MD5} != ${REF} ]] -then - echo ${MD5} > ${LSMD5_FILE} - echo Finding dependencies in OCaml files - python2 ./ninja_ocaml.py || exit -1 -fi - - diff --git a/scripts/compile_src.sh b/scripts/compile_src.sh index 756750d..9e22e19 100755 --- a/scripts/compile_src.sh +++ b/scripts/compile_src.sh @@ -6,6 +6,25 @@ then exit -1 fi -cd ${QMCCHEM_PATH}/src/IRPF90_temp || exit -1 -exec ninja ${@} +cd ${QMCCHEM_PATH}/src || exit -1 + + +source ${QMCCHEM_PATH}/make.config + +LIB="${LIB} ${QMCCHEM_PATH}/lib/libezfio_irp.a ${QMCCHEM_PATH}/lib/libf77zmq.a ${QMCCHEM_PATH}/lib/libzmq.a -lstdc++ -lrt -lz" +SRC="${SRC} ZMQ/f77_zmq_module.f90" +OBJ="${OBJ} IRPF90_temp/ZMQ/f77_zmq_module.o" +INCLUDES="${INCLUDES} -I AO -I SAMPLING -I TOOLS -I JASTROW -I MAIN -I PROPERTIES -I ZMQ" +IRPF90_FLAGS="${IRPF90_FLAGS} ${INCLUDES}" + +# Check IRPF90 version +if [[ $( ${IRPF90} -v | python2 -c "import sys ; print float(sys.stdin.read().rsplit('.',1)[0]) >= 1.6") == False ]] +then + echo "IRPF90 version >= 1.6 required" + exit -1 +fi + +export IRPF90 IRPF90_FLAGS INCLUDES LIB SRC OBJ + +exec make ${@}