From cc4382997ab8c27128589d99a58d89b579f9550e Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 28 Oct 2021 17:52:03 +0200 Subject: [PATCH] Improved autoconf scripts --- Makefile.am | 68 +++++++++++++++++++---------------------- configure.ac | 2 +- tools/build_doc.sh | 37 ++++++++++++++-------- tools/build_makefile.py | 14 ++++----- tools/build_qmckl_f.sh | 30 ++++++++++-------- tools/build_qmckl_h.sh | 27 ++++++++-------- tools/tangle.sh | 9 ++++-- 7 files changed, 104 insertions(+), 83 deletions(-) diff --git a/Makefile.am b/Makefile.am index 802c8ea..406fee7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,6 +30,7 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ACLOCAL_AMFLAGS = -I m4 VERSION_MAJOR = @VERSION_MAJOR@ @@ -43,7 +44,7 @@ EXTRA_DIST = pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = pkgconfig/qmckl.pc -qmckl_h = $(srcdir)/include/qmckl.h +qmckl_h = include/qmckl.h include_HEADERS = $(qmckl_h) qmckl_f = share/qmckl/fortran/qmckl_f.f90 @@ -53,10 +54,9 @@ src_qmckl_f = src/qmckl_f.f90 src_qmckl_fo = src/qmckl_f.o header_tests = tests/chbrclf.h tests/n2.h +fortrandir = $(datadir)/fortran +fortran_DATA = $(qmckl_f) -fortrandir = $(datadir)/qmckl/fortran/ - -dist_fortran_DATA = $(qmckl_f) AM_CPPFLAGS = -I$(srcdir)/src -I$(srcdir)/include AM_CPPFLAGS += -DQMCKL_TEST_DIR="\"$(abs_srcdir)/share/qmckl/test_data/\"" @@ -65,11 +65,9 @@ AM_CPPFLAGS += -DQMCKL_TEST_DIR="\"$(abs_srcdir)/share/qmckl/test_data/\"" lib_LTLIBRARIES = src/libqmckl.la src_libqmckl_la_SOURCES = $(qmckl_h) $(src_qmckl_f) $(C_FILES) $(F_FILES) $(H_PRIVATE_FUNC_FILES) $(H_PRIVATE_TYPE_FILES) $(header_tests) -export qmckl_f qmckl_h srcdir +CLEANFILES+=$(test_qmckl_f) $(test_qmckl_fo) $(src_qmckl_f) $(src_qmckl_fo) $(test_qmckl_o) $(src_qmckl_o) -CLEANFILES+=$(test_qmckl_f) $(src_qmckl_f) $(test_qmckl_o) $(src_qmckl_o) - -htmlize_el=$(srcdir)/share/doc/qmckl/html/htmlize.el +htmlize_el=share/doc/qmckl/html/htmlize.el include generated.mk @@ -81,19 +79,11 @@ ln_s_verbose_0 = @echo " LN_S $<"; htmldir = $(docdir)/html dist_html_DATA = $(HTML_FILES) \ share/doc/qmckl/html/index.html \ - $(srcdir)/share/doc/qmckl/html/qmckl.css + share/doc/qmckl/html/qmckl.css textdir = $(docdir)/text dist_text_DATA = $(TEXT_FILES) -$(test_qmckl_fo): $(test_qmckl_f) -$(test_qmckl_f): $(srcdir)/$(qmckl_f) - cp $(srcdir)/$(qmckl_f) $(test_qmckl_f) - -$(src_qmckl_fo): $(src_qmckl_f) -$(src_qmckl_f): $(srcdir)/$(qmckl_f) - cp $(srcdir)/$(qmckl_f) $(src_qmckl_f) - share/doc/qmckl/html/index.html: share/doc/qmckl/html/README.html $(ln_s_verbose)cd share/doc/qmckl/html/ && \ rm -rf index.html && \ @@ -113,24 +103,24 @@ if VFC_CI AM_LDFLAGS=-lvfc_probes -lvfc_probes_f endif -dist_src_DATA = $(ORG_FILES) $(TANGLED_FILES) $(EXPORTED_FILES) +dist_src_DATA = $(ORG_FILES) $(TANGLED_FILES) $(EXPORTED_FILES) $(qmckl_f) $(test_qmckl_f) -BUILT_SOURCES = $(C_FILES) $(F_FILES) $(FH_FUNC_FILES) $(FH_TYPE_FILES) $(H_FUNC_FILES) $(H_TYPE_FILES) $(H_PRIVATE_FUNC_FILES) $(H_PRIVATE_TYPE_FILES) $(qmckl_f) $(qmckl_h) $(header_tests) +BUILT_SOURCES = $(C_FILES) $(F_FILES) $(FH_FUNC_FILES) $(FH_TYPE_FILES) $(H_FUNC_FILES) $(H_TYPE_FILES) $(H_PRIVATE_FUNC_FILES) $(H_PRIVATE_TYPE_FILES) $(qmckl_f) $(src_qmckl_f) $(test_qmckl_f) $(qmckl_h) $(header_tests) -CLEANFILES += $(BUILT_SOURCES) $(C_TEST_FILES) $(F_TEST_FILES) $(TANGLED_FILES) $(C_TEST_FILES) $(F_TEST_FILES) $(qmckl_f) $(qmckl_h) $(HTML_FILES) $(TEXT_FILES) share/doc/qmckl/html/index.html $(EXPORTED_FILES) $(header_tests) +CLEANFILES += $(BUILT_SOURCES) $(C_TEST_FILES) $(F_TEST_FILES) $(TANGLED_FILES) $(C_TEST_FILES) $(F_TEST_FILES) $(qmckl_f) $(src_qmckl_f) $(test_qmckl_f) $(qmckl_h) $(HTML_FILES) $(TEXT_FILES) share/doc/qmckl/html/index.html $(EXPORTED_FILES) $(header_tests) EXTRA_DIST += \ - $(srcdir)/tools/build_doc.sh \ - $(srcdir)/tools/build_makefile.py \ - $(srcdir)/tools/build_qmckl_f.sh \ - $(srcdir)/tools/build_qmckl_h.sh \ - $(srcdir)/tools/config_doc.el \ - $(srcdir)/tools/config_tangle.el \ - $(srcdir)/tools/init.el \ - $(srcdir)/tools/install_htmlize.sh \ - $(srcdir)/tools/lib.org \ - $(srcdir)/tools/tangle.sh \ - $(srcdir)/tools/theme.setup + tools/build_doc.sh \ + tools/build_makefile.py \ + tools/build_qmckl_f.sh \ + tools/build_qmckl_h.sh \ + tools/config_doc.el \ + tools/config_tangle.el \ + tools/init.el \ + tools/install_htmlize.sh \ + tools/lib.org \ + tools/tangle.sh \ + tools/theme.setup ## Silent @@ -154,11 +144,17 @@ cat_h_verbose_0 = @echo " HEADER $@"; SUFFIXES = .f90 .h .org .c _f.f90 _func.h _type.h _private_func.h _private_type.h -$(qmckl_h): $(H_FUNC_FILES) $(H_TYPE_FILES) - $(cat_h_verbose)$(srcdir)/tools/build_qmckl_h.sh +$(test_qmckl_f): $(src_qmckl_f) + cp $(src_qmckl_f) $(test_qmckl_f) -$(qmckl_f): $(FH_FUNC_FILES) $(FH_TYPE_FILES) - $(cat_h_verbose)$(srcdir)/tools/build_qmckl_f.sh +$(qmckl_f): $(src_qmckl_f) + cp $(src_qmckl_f) $(qmckl_f) + +$(qmckl_h): $(H_FUNC_FILES) $(H_TYPE_FILES) + $(cat_h_verbose)top_builddir=$(top_builddir) srcdir=$(srcdir) qmckl_h=$(qmckl_h) $(srcdir)/tools/build_qmckl_h.sh + +$(src_qmckl_f): $(FH_FUNC_FILES) $(FH_TYPE_FILES) + $(cat_h_verbose)top_builddir=$(top_builddir) srcdir=$(srcdir) src_qmckl_f=$(src_qmckl_f) $(srcdir)/tools/build_qmckl_f.sh $(htmlize_el): $(srcdir)/tools/install_htmlize.sh $(htmlize_el) @@ -168,7 +164,7 @@ tests/chbrclf.h: $(qmckl_h) tests/n2.h: $(qmckl_h) generated.mk: $(ORG_FILES) - $(PYTHON) $(srcdir)/tools/build_makefile.py + top_builddir=$(top_builddir) srcdir=$(srcdir) qmckl_h=$(qmckl_h) src_qmckl_f=$(src_qmckl_f) $(PYTHON) $(srcdir)/tools/build_makefile.py cppcheck: cppcheck.out diff --git a/configure.ac b/configure.ac index ab57775..5fef528 100644 --- a/configure.ac +++ b/configure.ac @@ -42,7 +42,7 @@ AC_CONFIG_AUX_DIR(tools) AM_INIT_AUTOMAKE([subdir-objects color-tests parallel-tests silent-rules 1.11]) AM_MAINTAINER_MODE() LT_INIT -AC_CONFIG_SRCDIR([Makefile.in]) +AC_CONFIG_SRCDIR([configure.ac]) AC_CONFIG_HEADERS([include/config.h]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/tools/build_doc.sh b/tools/build_doc.sh index c49a365..f218c15 100755 --- a/tools/build_doc.sh +++ b/tools/build_doc.sh @@ -1,11 +1,20 @@ #!/bin/bash # Extracts documentation from an org-mode file. -set -e +# Check required environment variables +# ------------------------------------ -srcdir=$PWD +if [[ -z ${srcdir} ]] ; then + echo "Error: srcdir environment variable is not defined" + exit 1 +fi -readonly DOCS=${srcdir}/share/doc/qmckl/ +if [[ -z ${top_builddir} ]] ; then + echo "Error: srcdir environment variable is not defined" + exit 1 +fi + +readonly DOCS=${top_builddir}/share/doc/qmckl/ readonly ORG=${srcdir}/org/ readonly HTMLIZE=${DOCS}/html/htmlize.el readonly CONFIG_DOC=${srcdir}/tools/config_doc.el @@ -19,14 +28,18 @@ function extract_doc() html=${DOCS}/html/$(basename ${org%.org}.html) text=${DOCS}/text/$(basename ${org%.org}.txt) - ./tools/missing emacs --batch \ - --load ${HTMLIZE} \ - --load ${CONFIG_DOC} \ - ${org} \ - --load ${CONFIG_TANGLE} \ - -f org-html-export-to-html \ + ${srcdir}/tools/missing emacs --batch \ + --load="${HTMLIZE}" \ + --load="${CONFIG_DOC}" \ + ${org} \ + --load="../${CONFIG_TANGLE}" \ + -f org-html-export-to-html \ -f org-ascii-export-to-ascii + rc=$? + if [ $rc -ne 0 ] ; then + return $rc + fi mv ${local_html} ${html} mv ${local_text} ${text} } @@ -36,16 +49,16 @@ do exported=${i%.org}.exported exported=$(dirname $exported)/.$(basename $exported) NOW=$(date +"%m%d%H%M.%S") - extract_doc ${i} &> $exported + extract_doc ${i} &> $exported rc=$? # Make log file older than the exported files touch -t ${NOW} $exported # Fail if tangling failed - if [[ $rc -ne 0 ]] ; then + if [ $rc -ne 0 ] ; then cat $exported - exit rc + exit $rc fi done diff --git a/tools/build_makefile.py b/tools/build_makefile.py index 01c811a..42880f2 100755 --- a/tools/build_makefile.py +++ b/tools/build_makefile.py @@ -56,13 +56,13 @@ def main(): fh_func=i+"_fh_func.f90" fh_type=i+"_fh_type.f90" - ORG_FILES += ["$(srcdir)/"+org] + ORG_FILES += [org] TANGLED_FILES += [tangled] EXPORTED_FILES += [exported] - DEPS_ORG["$(srcdir)/"+org] = tangled - DEPS_DOC["$(srcdir)/"+org] = exported - TEXT["$(srcdir)/"+org] = text - HTML["$(srcdir)/"+org] = html + DEPS_ORG[org] = tangled + DEPS_DOC[org] = exported + TEXT[org] = text + HTML[org] = html grep = open(org, "r").read() @@ -206,7 +206,7 @@ def main(): "if QMCKL_DEVEL" ] for f in DEPS_ORG.keys(): output += [ DEPS_ORG[f] + ": "+f, - "\t$(tangle_verbose)$(srcdir)/tools/tangle.sh "+f, + "\t$(tangle_verbose)top_builddir=$(top_builddir) srcdir=$(srcdir) $(srcdir)/tools/tangle.sh "+f, "" ] output += [ "endif", "" ] @@ -257,7 +257,7 @@ def main(): for f in sorted(DEPS_DOC.keys()): output += [ DEPS_DOC[f] + ": " + f + " $(htmlize_el)", - "\t$(export_verbose)$(srcdir)/tools/build_doc.sh "+f, + "\t$(export_verbose)top_builddir=$(top_builddir) srcdir=$(srcdir) $(srcdir)/tools/build_doc.sh "+f, "" ] output += ["endif"] diff --git a/tools/build_qmckl_f.sh b/tools/build_qmckl_f.sh index 514a7c0..6ce896a 100755 --- a/tools/build_qmckl_f.sh +++ b/tools/build_qmckl_f.sh @@ -1,22 +1,27 @@ -#!/bin/bash -# Script to build the final qmckl_f.f90 file +#!/bin/sh +# Script to build the final src/qmckl_f.f90 file set -e -# All the produced header files are concatenated in the =qmckl_f.f90= +# All the produced header files are concatenated in the =src/qmckl_f.f90= # file, located in the share/qmckl/fortran directory. # Check required environment variables # ------------------------------------ -if [[ -z ${srcdir} ]] ; then +if [ -z ${srcdir} ] ; then echo "Error: srcdir environment variable is not defined" exit 1 fi -if [[ -z ${qmckl_f} ]] ; then - echo "Error: qmckl_f environment variable is not defined" +if [ -z ${top_builddir} ] ; then + echo "Error: top_builddir environment variable is not defined" + exit 1 +fi + +if [ -z ${src_qmckl_f} ] ; then + echo "Error: src_qmckl_f environment variable is not defined" exit 1 fi @@ -25,11 +30,10 @@ fi # Generate Fortran interface file # ------------------------------- -HEADERS_TYPE="${srcdir}/src/qmckl_*_fh_type.f90" -HEADERS="${srcdir}/src/qmckl_*_fh_func.f90" +HEADERS_TYPE="src/qmckl_*_fh_type.f90" +HEADERS="src/qmckl_*_fh_func.f90" -OUTPUT="${qmckl_f}" -cat << EOF > ${OUTPUT} +cat << EOF > ${src_qmckl_f} ! ! ------------------------------------------ ! QMCkl - Quantum Monte Carlo kernel library @@ -78,14 +82,14 @@ EOF for i in ${HEADERS_TYPE} do - cat $i >> ${OUTPUT} + cat $i >> ${src_qmckl_f} done for i in ${HEADERS} do - cat $i >> ${OUTPUT} + cat $i >> ${src_qmckl_f} done -cat << EOF >> ${OUTPUT} +cat << EOF >> ${src_qmckl_f} end module qmckl EOF diff --git a/tools/build_qmckl_h.sh b/tools/build_qmckl_h.sh index 3ddeada..d74d30e 100755 --- a/tools/build_qmckl_h.sh +++ b/tools/build_qmckl_h.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Script to build the final qmckl.h file # All the produced header files are concatenated in the =qmckl.h= @@ -11,12 +11,17 @@ set -e # Check required environment variables # ------------------------------------ -if [[ -z ${srcdir} ]] ; then +if [ -z ${srcdir} ] ; then echo "Error: srcdir environment variable is not defined" exit 1 fi -if [[ -z ${qmckl_h} ]] ; then +if [ -z ${top_builddir} ] ; then + echo "Error: top_builddir environment variable is not defined" + exit 1 +fi + +if [ -z ${qmckl_h} ] ; then echo "Error: qmckl_h environment variable is not defined" exit 1 fi @@ -28,17 +33,15 @@ fi HEADERS="" for i in $(cat ${srcdir}/org/table_of_contents) do - HEADERS+="${i%.org}_type.h " + HEADERS="${HEADERS} ${i%.org}_type.h " done for i in $(cat ${srcdir}/org/table_of_contents) do - HEADERS+="${i%.org}_func.h " + HEADERS="${HEADERS} ${i%.org}_func.h " done -OUTPUT=${qmckl_h} - -cat << EOF > ${OUTPUT} +cat << EOF > ${qmckl_h} /* * ------------------------------------------ * QMCkl - Quantum Monte Carlo kernel library @@ -97,13 +100,13 @@ EOF for i in ${HEADERS} do header=${srcdir}/src/$i - if [[ -f $header ]] ; then - echo "/* $header */" >> ${OUTPUT} - cat $header >> ${OUTPUT} + if [ -f $header ] ; then + echo "/* $header */" >> ${qmckl_h} + cat $header >> ${qmckl_h} fi done -cat << EOF >> ${OUTPUT} +cat << EOF >> ${qmckl_h} #ifdef __cplusplus } #endif diff --git a/tools/tangle.sh b/tools/tangle.sh index ebd1929..56e2667 100755 --- a/tools/tangle.sh +++ b/tools/tangle.sh @@ -9,10 +9,15 @@ # The =missing= script is used to check if emacs is present on the system. if [[ -z ${srcdir} ]] ; then - print "Error: srcdir environment variable is not defined" + echo "Error: srcdir environment variable is not defined" exit 1 fi +if [[ -z ${top_builddir} ]] ; then + echo "Error: srcdir environment variable is not defined" + exit 1 +fi + function tangle() { local org_file=$1 @@ -24,7 +29,7 @@ function tangle() elif [[ ${org_file} -ot ${f_file} ]] ; then return fi - ./tools/missing \ + ${srcdir}/tools/missing \ emacs --batch ${org_file} \ --load=${PWD}/tools/config_tangle.el \ -f org-babel-tangle