From 13593b8870bcb7a00884cf2a9b150068f9e6a40d Mon Sep 17 00:00:00 2001 From: Sylvain Tricot Date: Tue, 24 Nov 2020 09:57:35 +0100 Subject: [PATCH] Revert back to GNU Make for building. Makefiles are easier to maintain, I eventually prefer using GNU Make instead of scons. SConstruct files will be removed when makefiles will be ready in a future commit. --- Makefile | 83 ++++++++++++++++ src/Makefile | 36 +++++++ src/Makefile.old | 60 ++++++++++++ src/msspec/phagen/fortran/Makefile | 6 ++ src/msspec/spec/fortran/Makefile | 25 +++++ src/msspec/spec/fortran/comp_curve.mk | 5 + src/msspec/spec/fortran/eig_mi.mk | 12 +++ src/msspec/spec/fortran/eig_pw.mk | 12 +++ .../spec/fortran/phd_mi_noso_nosp_nosym.mk | 11 +++ .../spec/fortran/phd_se_noso_nosp_nosym.mk | 11 +++ src/options.mk | 97 +++++++++++++++++++ 11 files changed, 358 insertions(+) create mode 100644 Makefile create mode 100644 src/Makefile create mode 100644 src/Makefile.old create mode 100644 src/msspec/phagen/fortran/Makefile create mode 100644 src/msspec/spec/fortran/Makefile create mode 100644 src/msspec/spec/fortran/comp_curve.mk create mode 100644 src/msspec/spec/fortran/eig_mi.mk create mode 100644 src/msspec/spec/fortran/eig_pw.mk create mode 100644 src/msspec/spec/fortran/phd_mi_noso_nosp_nosym.mk create mode 100644 src/msspec/spec/fortran/phd_se_noso_nosp_nosym.mk create mode 100644 src/options.mk diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fdfc501 --- /dev/null +++ b/Makefile @@ -0,0 +1,83 @@ +MAKESELF:=makeself +VERSION:=$(shell git describe|sed 's/-\([[:digit:]]\+\)-.*/\.post\1/') +SETUPFILE:=MsSpec-$(VERSION).setup + + +VERBOSE:=0 +ifeq ($(VERBOSE),0) + SUPPRESS_OUPUT:=1>/dev/null 2>/dev/null + MAKEFLAGS += --no-print-directory +else + SUPPRESS_OUPUT:= +endif + + +.PHONY: clean version selfex venv doc + + +selfex: results + @echo "Creating the self-extractible setup program... " +# copy the src folder and purge it + @cp -r src src_ + @+$(MAKE) -C ./src_ purge +# update the version + @echo "$(VERSION)" > ./src_/VERSION +# distribute the README.md file + @cp README.md ./src_/ +# create the package folder + @mkdir -p package +# create the *.lsm file + @echo "Begin4" > msspec.lsm + @echo "Title: Python MsSpec" >> msspec.lsm + @echo "Version: $(VERSION)" >> msspec.lsm + @echo "Entered-date: `date +%Y-%m-%d`" >> msspec.lsm + @echo "Description: A multiple scattering package for spectroscopies using electrons to probe materials" >> msspec.lsm + @echo "Keywords: " >> msspec.lsm + @echo "Author: sylvain.tricot@univ-rennes1.fr (Sylvain Tricot), didier.sebilleau@univ-rennes1.fr (Didier Sébilleau)" >> msspec.lsm + @echo "Maintained-by: sylvain.tricot@univ-rennes1.fr (Sylvain Tricot)" >> msspec.lsm + @echo "Primary-site: https://msspec.cnrs.fr" >> msspec.lsm + @echo "Alternate-site:" >> msspec.lsm + @echo "Original-site:" >> msspec.lsm + @echo "Platforms:" >> msspec.lsm + @echo "Copying-policy: Gnu Library General Public License (GLPL) 2.0" >> msspec.lsm + @echo "End" >> msspec.lsm +# create the self-extractible archive + @$(MAKESELF) --license "./license.txt" --lsm ./msspec.lsm ./src_ package/$(SETUPFILE) "Python MsSpec" ./install.sh $(SUPPRESS_OUPUT) +# remove *.lsm file and src_ + @rm ./msspec.lsm + @rm -rf ./src_ + + +version: + @python ./CI/update_version.py + + +clean: + @echo "Cleaning all..." + @find ./src -type f -name '*.pyc' -exec rm -f {} + + @find ./src -type d -name '__pycache__' -exec rm -rf {} + + @rm -rf src/dist + @rm -rf src/*.egg* + @+$(MAKE) -C src/ clean $(SUPPRESS_OUPUT) + @+$(MAKE) -C doc/ clean $(SUPPRESS_OUPUT) + @rm -rf package + +purge: clean + @echo "Removing also shared objects..." + @find ./src -type f -name '*.so' -exec rm -f {} + + +results: + @+$(MAKE) -C src results + + +venv: + @virtualenv --python=python3 --system-site-packages ci_venv $(SUPPRESS_OUPUT) + @. "./ci_venv/bin/activate" && pip install --upgrade pip && pip install --upgrade -r requirements.txt $(SUPPRESS_OUPUT) + +doc: + @echo "Building pdf and html documentation..." + @mkdir -p package/ + @+$(MAKE) -C doc/ latexpdf $(SUPPRESS_OUPUT) + @rm -rf package/*.pdf + @cp "doc/build/latex/MsSpec-python.pdf" "./package/MsSpec-${VERSION}.pdf" + @+$(MAKE) -C doc/ html $(SUPPRESS_OUPUT) diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..598e623 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,36 @@ +include options.mk + +.PHONY: pybinding results clean + +pybinding: + @echo "Building Python binding for phagen and spec..." + @+$(MAKE) -C msspec/phagen/fortran all + @+$(MAKE) -C msspec/spec/fortran all + +results: msspec/results.txt + +msspec/results.txt: pybinding + @echo "Generating results for unittests" + @coverage run --source=./ --omit=msspec/es/*,msspec/msspecgui/* msspec/create_tests_results.py +# create the html coverage report + @coverage html -d ../doc/source/htmlcov + @rm .coverage + +tests: pybinding + @echo "Runing unittests" + @python -m msspec.tests 1>/dev/null + +clean: + @echo "Cleaning all..." + @find ./ -type f -name '*.pyc' -exec rm -f {} + + @find ./ -type d -name '__pycache__' -exec rm -rf {} + + @+$(MAKE) -C msspec/spec/fortran clean + @+$(MAKE) -C msspec/phagen/fortran clean +# remove previous sdist + @rm -rf dist + @rm -rf *.egg* + + +help: + @echo "help message" + diff --git a/src/Makefile.old b/src/Makefile.old new file mode 100644 index 0000000..a7cc556 --- /dev/null +++ b/src/Makefile.old @@ -0,0 +1,60 @@ +VERSION:=$(shell python -c "import msspec; print(msspec.__version__)") + +VERBOSE:=0 +ifeq ($(VERBOSE),0) + SUPPRESS_OUPUT:=1>/dev/null 2>/dev/null + MAKEFLAGS += --no-print-directory --silent +else + SUPPRESS_OUPUT:= +endif + + +install: sdist + @echo "Installing the newly created Python package..." + @pip install dist/msspec-*.tar.gz $(SUPPRESS_OUPUT) + +sdist: install_deps + @echo "Creating Python source distribution..." +# Create the source distrib + @python setup.py sdist $(SUPPRESS_OUPUT) + +install_deps: pybinding + @echo "Installing Python dependencies..." +# Install dependencies with pip + @pip install --upgrade -r requirements.txt $(SUPPRESS_OUPUT) + +pybinding: + @echo "Building Python binding for phagen and spec..." + @+$(MAKE) -C msspec/spec/fortran pybinding $(SUPPRESS_OUPUT) + @+$(MAKE) -C msspec/phagen/fortran pybinding $(SUPPRESS_OUPUT) + +results: msspec/results.txt + +msspec/results.txt: pybinding + @echo "Generating results for unittests" + @coverage run --source=./ --omit=msspec/es/*,msspec/msspecgui/* msspec/create_tests_results.py 1>/dev/null +# create the html coverage report + @coverage html -d ../doc/source/htmlcov + @rm .coverage + +tests: pybinding + @echo "Runing unittests" + @python -m msspec.tests 1>/dev/null + +clean: + @echo "Cleaning all..." + @find ./ -type f -name '*.pyc' -exec rm -f {} + + @find ./ -type d -name '__pycache__' -exec rm -rf {} + + @+$(MAKE) -C msspec/spec/fortran clean $(SUPPRESS_OUPUT) + @+$(MAKE) -C msspec/phagen/fortran clean $(SUPPRESS_OUPUT) +# remove previous sdist + @rm -rf dist + @rm -rf *.egg* + +purge: clean + @echo "Removing also shared objects..." + @find ./ -type f -name '*.so' -exec rm -f {} + + +help: + @echo "help message" + diff --git a/src/msspec/phagen/fortran/Makefile b/src/msspec/phagen/fortran/Makefile new file mode 100644 index 0000000..a00c241 --- /dev/null +++ b/src/msspec/phagen/fortran/Makefile @@ -0,0 +1,6 @@ + +SRCS = phagen_scf_2.1_dp.f +MAIN_F = main.f +SO = libphagen.so + +include ../../../options.mk diff --git a/src/msspec/spec/fortran/Makefile b/src/msspec/spec/fortran/Makefile new file mode 100644 index 0000000..f7def44 --- /dev/null +++ b/src/msspec/spec/fortran/Makefile @@ -0,0 +1,25 @@ +.PHONY: all phd_se phd_mi eig_mi eig_pw comp_curve clean + +all: phd_se phd_mi eig_mi eig_pw comp_curve + +phd_se: + @+$(MAKE) -f phd_se_noso_nosp_nosym.mk all + +phd_mi: + @+$(MAKE) -f phd_mi_noso_nosp_nosym.mk all + +eig_mi: + @+$(MAKE) -f eig_mi.mk all + +eig_pw: + @+$(MAKE) -f eig_pw.mk all + +comp_curve: + @+$(MAKE) -f comp_curve.mk all + +clean: + @+$(MAKE) -f phd_se_noso_nosp_nosym.mk $@ + @+$(MAKE) -f phd_mi_noso_nosp_nosym.mk $@ + @+$(MAKE) -f eig_mi.mk $@ + @+$(MAKE) -f eig_pw.mk $@ + @+$(MAKE) -f comp_curve.mk $@ diff --git a/src/msspec/spec/fortran/comp_curve.mk b/src/msspec/spec/fortran/comp_curve.mk new file mode 100644 index 0000000..616e9ba --- /dev/null +++ b/src/msspec/spec/fortran/comp_curve.mk @@ -0,0 +1,5 @@ +SRCS = treatment/comp_curves.f +MAIN_F = treatment/main.f +SO = comp_curves.so + +include ../../../options.mk diff --git a/src/msspec/spec/fortran/eig_mi.mk b/src/msspec/spec/fortran/eig_mi.mk new file mode 100644 index 0000000..c9be31d --- /dev/null +++ b/src/msspec/spec/fortran/eig_mi.mk @@ -0,0 +1,12 @@ +memalloc_src := memalloc/dim_mod.f memalloc/modules.f memalloc/allocation.f +cluster_gen_src := $(wildcard cluster_gen/*.f) +common_sub_src := $(wildcard common_sub/*.f) +renormalization_src := $(wildcard renormalization/*.f) +eig_common_src := $(wildcard eig/common/*.f) +eig_mi_src := $(wildcard eig/mi/*.f) + +SRCS = $(memalloc_src) $(cluster_gen_src) $(common_sub_src) $(renormalization_src) $(eig_mi_src) +MAIN_F = eig/mi/main.f +SO = _eig_pw.so + +include ../../../options.mk diff --git a/src/msspec/spec/fortran/eig_pw.mk b/src/msspec/spec/fortran/eig_pw.mk new file mode 100644 index 0000000..dd7f2a3 --- /dev/null +++ b/src/msspec/spec/fortran/eig_pw.mk @@ -0,0 +1,12 @@ +memalloc_src := memalloc/dim_mod.f memalloc/modules.f memalloc/allocation.f +cluster_gen_src := $(wildcard cluster_gen/*.f) +common_sub_src := $(wildcard common_sub/*.f) +renormalization_src := $(wildcard renormalization/*.f) +eig_common_src := $(wildcard eig/common/*.f) +eig_pw_src := $(wildcard eig/pw/*.f) + +SRCS = $(memalloc_src) $(cluster_gen_src) $(common_sub_src) $(renormalization_src) $(eig_pw_src) +MAIN_F = eig/pw/main.f +SO = _eig_pw.so + +include ../../../options.mk diff --git a/src/msspec/spec/fortran/phd_mi_noso_nosp_nosym.mk b/src/msspec/spec/fortran/phd_mi_noso_nosp_nosym.mk new file mode 100644 index 0000000..2179c68 --- /dev/null +++ b/src/msspec/spec/fortran/phd_mi_noso_nosp_nosym.mk @@ -0,0 +1,11 @@ +memalloc_src := memalloc/dim_mod.f memalloc/modules.f memalloc/allocation.f +cluster_gen_src := $(wildcard cluster_gen/*.f) +common_sub_src := $(wildcard common_sub/*.f) +renormalization_src := $(wildcard renormalization/*.f) +phd_mi_noso_nosp_nosym_src := $(wildcard phd_mi_noso_nosp_nosym/*.f) + +SRCS = $(memalloc_src) $(cluster_gen_src) $(common_sub_src) $(renormalization_src) $(phd_mi_noso_nosp_nosym_src) +MAIN_F = phd_mi_noso_nosp_nosym/main.f +SO = _phd_mi_noso_nosp_nosym.so + +include ../../../options.mk diff --git a/src/msspec/spec/fortran/phd_se_noso_nosp_nosym.mk b/src/msspec/spec/fortran/phd_se_noso_nosp_nosym.mk new file mode 100644 index 0000000..9769213 --- /dev/null +++ b/src/msspec/spec/fortran/phd_se_noso_nosp_nosym.mk @@ -0,0 +1,11 @@ +memalloc_src := memalloc/dim_mod.f memalloc/modules.f memalloc/allocation.f +cluster_gen_src := $(wildcard cluster_gen/*.f) +common_sub_src := $(wildcard common_sub/*.f) +renormalization_src := $(wildcard renormalization/*.f) +phd_se_noso_nosp_nosym_src := $(wildcard phd_se_noso_nosp_nosym/*.f) + +SRCS = $(memalloc_src) $(cluster_gen_src) $(common_sub_src) $(renormalization_src) $(phd_se_noso_nosp_nosym_src) +MAIN_F = phd_se_noso_nosp_nosym/main.f +SO = _phd_se_noso_nosp_nosym.so + +include ../../../options.mk diff --git a/src/options.mk b/src/options.mk new file mode 100644 index 0000000..d3e7187 --- /dev/null +++ b/src/options.mk @@ -0,0 +1,97 @@ +FC = gfortran +F2PY = f2py3 + +DEBUG = 0 +VERBOSE = 0 +BUILDDIR = ./build + + +################################################################################ +# GFORTRAN CONFIGURATION # +################################################################################ +GFORTRAN_FFLAGS = -O2 -ffast-math +GFORTRAN_FFLAGS_DBG = -g -Wall -Wextra -Warray-temporaries -Wconversion +GFORTRAN_FFLAGS_DBG += -fbacktrace -ffree-line-length-0 -fcheck=all +GFORTRAN_FFLAGS_DBG += -ffpe-trap=zero,overflow,underflow -finit-real=nan +################################################################################ + +################################################################################ +# IFORT CONFIGURATION # +################################################################################ +IFORT_FFLAGS = +IFORT_FFLAGS_DBG = +################################################################################ + +################################################################################ +# F2PY CONFIGURATION # +################################################################################ +F2PYFLAGS = --opt=-O2 +F2PYFLAGS_DBG = --debug-capi --debug +################################################################################ + + + +################################################################################ +# /!\ DO NOT EDIT BELOW THAT LINE (unlesss you know what you're doing...) # +# CORE CONFIGURATION # +################################################################################ +VERSION:=$(shell python -c "import msspec; print(msspec.__version__)") + +ifeq ($(VERBOSE),0) + OUPUT_REDIRECTION := 1>/dev/null 2>/dev/null + MAKEFLAGS = -s --no-print-directory +else + OUPUT_REDIRECTION:= + MAKEFLAGS += --debug=b +endif + +PREFIX= +SUFFIX= + +ifeq ($(FC),gfortran) + PREFIX = GFORTRAN +endif + +ifeq ($(FC),IFORT) + PREFIX = IFORT +endif + +ifeq ($(DEBUG),1) + SUFFIX = _DBG +endif + +FFLAGS = $($(PREFIX)_FFLAGS$(SUFFIX)) + +OBJS = $(addprefix $(BUILDDIR)/, $(patsubst %.f,%.o, $(filter-out $(MAIN_F), $(SRCS)))) + +.PHONY: clean obj all compilation_info + +compilation_info: + @echo "Compiler used: $(FC)" + @echo "fortran flags: $(FFLAGS)" + @echo "f2py flags: $(FFLAGS)" + + +all: $(SO) + + +obj: $(OBJS) + + +clean: + @echo "Cleaning..." + rm -rf $(BUILDDIR) + rm -rf $(SO) + + +$(BUILDDIR)/%.o: %.f + @echo "Compiling $@..." + mkdir -p $(basename $@) + $(FC) $(FFLAGS) -J $(BUILDDIR) -I $(BUILDDIR) -fPIC -o $@ -c $^ $(OUPUT_REDIRECTION) + + +$(SO): $(OBJS) $(MAIN_F) + @echo "building Python binding $@..." + mkdir -p $(BUILDDIR) + $(F2PY) $(F2PYFLAGS) -I$(BUILDDIR) -m $(basename $@) -c $(OBJS) $(MAIN_F) $(OUPUT_REDIRECTION) + mv $(basename $@).*.so $@