diff --git a/Makefile.am b/Makefile.am index 0940b9a..fbe62e0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,9 +83,6 @@ dist_html_DATA = $(HTML_FILES) \ textdir = $(docdir)/text dist_text_DATA = $(TEXT_FILES) -generated.mk: $(ORG_FILES) - $(srcdir)/tools/build_makefile.sh - $(test_qmckl_fo): $(test_qmckl_f) $(test_qmckl_f): $(srcdir)/$(qmckl_f) cp $(srcdir)/$(qmckl_f) $(test_qmckl_f) @@ -107,6 +104,9 @@ doc: html text if QMCKL_DEVEL +generated.mk: $(ORG_FILES) + python $(srcdir)/tools/build_makefile.py + dist_src_DATA = $(ORG_FILES) $(TANGLED_FILES) $(EXPORTED_FILES) 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) diff --git a/autogen.sh b/autogen.sh index 035e706..97ce9ec 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,6 +1,6 @@ #!/bin/bash -./tools/build_makefile.sh +python ./tools/build_makefile.py autoreconf -i echo "To configure in maintainer mode, use: $ QMCKL_DEVEL=1 ./configure --enable-silent-rules --enable-maintainer-mode diff --git a/configure.ac b/configure.ac index b51e038..97fd524 100644 --- a/configure.ac +++ b/configure.ac @@ -177,7 +177,15 @@ AM_CONDITIONAL([QMCKL_DEVEL],[test "x$QMCKL_DEVEL" != x]) if test "x${QMCKL_DEVEL}" != "x"; then AC_PROG_AWK - ${srcdir}/tools/build_makefile.sh + AC_CHECK_PROGS([PYTHON],[python python3 python2],[no]) + if test x${PYTHON} == xno ; then + AC_MSG_ERROR([ + -------------------------------------------- + Error: Python is required to build makefiles + -------------------------------------------- + ]) + fi + python ${srcdir}/tools/build_makefile.py AC_CHECK_PROGS([EMACS],[emacs26 emacs],[no]) if test x${EMACS} == xno ; then diff --git a/tools/build_makefile.py b/tools/build_makefile.py new file mode 100755 index 0000000..ff09b1d --- /dev/null +++ b/tools/build_makefile.py @@ -0,0 +1,268 @@ +#!/usr/bin/env python2 +# +# Creates all the dependencies from the org-mode files + +from __future__ import print_function +from glob import glob + +def main(): + C_FILES = [] + C_O_FILES = [] + F_FILES = [] + F_O_FILES = [] + FH_FUNC_FILES = [] + FH_TYPE_FILES = [] + H_FUNC_FILES = [] + H_TYPE_FILES = [] + H_PRIVATE_FUNC_FILES = [] + H_PRIVATE_TYPE_FILES = [] + C_TEST_FILES = [] + F_TEST_FILES = [] + TANGLED_FILES = [] + ORG_FILES = [] + TANGLED_FILES = [] + EXPORTED_FILES = [] + + DEPS = {} + DEPS_ORG = {} + DEPS_TEST = {} + TESTS = {} + HTML = {} + TEXT = {} + DEPS_DOC = {} + + for org in glob("org/*.org"): + i = org.split('/')[-1].rsplit(".",1)[0] + tangled = "org/"+i+".tangled" + exported = "org/"+i+".exported" + c_test_x = "tests/test_"+i + c_test_o = "tests/test_"+i+".$(OBJEXT)" + f_test_o = "tests/test_"+i+"_f.$(OBJEXT)" + c_test = "tests/test_"+i+".c" + f_test = "tests/test_"+i+"_f.f90" + html = "share/doc/qmckl/html/"+i+".html" + text = "share/doc/qmckl/text/"+i+".txt" + + i="src/"+i + + c=i+".c" + o=i+".$(OBJEXT)" + h_func=i+"_func.h" + h_type=i+"_type.h" + h_private_func=i+"_private_func.h" + h_private_type=i+"_private_type.h" + f90=i+"_f.f90" + fo=i+"_f.$(OBJEXT)" + fh_func=i+"_fh_func.f90" + fh_type=i+"_fh_type.f90" + + ORG_FILES += ["$(srcdir)/"+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 + + grep = open(org, "r").read() + + if "(eval c)" in grep: + C_FILES += [c] + C_O_FILES += [o] + + if c in DEPS: + DEPS[c] += [tangled] + else: + DEPS[c] = [tangled] + + if o in DEPS: + DEPS[o] += [c, "$(qmckl_h)"] + else: + DEPS[o] = [c, "$(qmckl_h)"] + + if "(eval h_func)" in grep: + H_FUNC_FILES += [h_func] + + if h_func in DEPS: + DEPS[h_func] += [tangled] + else: + DEPS[h_func] = [tangled] + + if "(eval h_type)" in grep: + H_TYPE_FILES += [h_type] + + if h_type in DEPS: + DEPS[h_type] += [tangled] + else: + DEPS[h_type] = [tangled] + + if "(eval h_private_type)" in grep: + H_PRIVATE_TYPE_FILES += [h_private_type] + + if h_private_type in DEPS: + DEPS[h_private_type] += [tangled] + else: + DEPS[h_private_type] = [tangled] + + if o in DEPS: + DEPS[o] += [h_private_type] + else: + DEPS[o] = [h_private_type] + + if "(eval h_private_func)" in grep: + H_PRIVATE_FUNC_FILES += [h_private_func] + + if o in DEPS: + DEPS[o] += [h_private_func] + else: + DEPS[o] = [h_private_func] + + if h_private_func in DEPS: + DEPS[h_private_func] += [tangled] + else: + DEPS[h_private_func] = [tangled] + + if "(eval f)" in grep: + F_FILES += [f90] + + if f90 in DEPS: + DEPS[f90] += [tangled, "$(src_qmckl_fo)"] + else: + DEPS[f90] = [tangled, "$(src_qmckl_fo)"] + + if fo in DEPS: + DEPS[fo] += [f90, "$(src_qmckl_fo)"] + else: + DEPS[fo] = [f90, "$(src_qmckl_fo)"] + + if "(eval fh_func)" in grep: + FH_FUNC_FILES += [fh_func] + + if fh_func in DEPS: + DEPS[fh_func] += [tangled] + else: + DEPS[fh_func] = [tangled] + + if "(eval fh_type)" in grep: + FH_TYPE_FILES += [fh_type] + + if fh_type in DEPS: + DEPS[fh_type] += [tangled] + else: + DEPS[fh_type] = [tangled] + + + if "(eval c_test)" in grep: + C_TEST_FILES += [c_test] + + if c_test in DEPS_TEST: + DEPS_TEST[c_test] = [tangled] + else: + DEPS_TEST[c_test] = [tangled] + + if c_test_x in TESTS: + TESTS[c_test_x] += [c_test, "$(qmckl_h)"] + else: + TESTS[c_test_x] = [c_test, "$(qmckl_h)"] + + if "(eval f_test)" in grep: + F_TEST_FILES += [f_test] + + if f_test in DEPS: + DEPS_TEST[f_test] += [tangled, "$(test_qmckl_fo)"] + else: + DEPS_TEST[f_test] = [tangled, "$(test_qmckl_fo)"] + + if c_test_x in TESTS: + TESTS[c_test_x] += [f_test, "$(test_qmckl_fo)"] + else: + TESTS[c_test_x] = [f_test, "$(test_qmckl_fo)"] + + output = ["", + "## Source files", + "", + "ORG_FILES="+" ".join(ORG_FILES), + "TANGLED_FILES="+" ".join(TANGLED_FILES), + "EXPORTED_FILES="+" ".join(EXPORTED_FILES), + "C_FILES="+" ".join(C_FILES), + "F_FILES="+" ".join(F_FILES), + "C_O_FILES="+" ".join(C_O_FILES), + "FH_FUNC_FILES="+" ".join(FH_FUNC_FILES), + "FH_TYPE_FILES="+" ".join(FH_TYPE_FILES), + "H_FUNC_FILES="+" ".join(H_FUNC_FILES), + "H_TYPE_FILES="+" ".join(H_TYPE_FILES), + "H_PRIVATE_FUNC_FILES="+" ".join(H_PRIVATE_FUNC_FILES), + "H_PRIVATE_TYPE_FILES="+" ".join(H_PRIVATE_TYPE_FILES), + "C_TEST_FILES="+" ".join(C_TEST_FILES), + "F_TEST_FILES="+" ".join(F_TEST_FILES), + "TESTS="+" ".join(TESTS.keys()).replace("$(srcdir)/",""), + "HTML_FILES="+" ".join(HTML.values()), + "TEXT_FILES="+" ".join(TEXT.values()), + "" ] + + output+= ["", + "## Org-mode inherited dependencies", + "", + "if QMCKL_DEVEL" ] + for f in DEPS_ORG.keys(): + output += [ DEPS_ORG[f] + ": "+f, + "\t$(tangle_verbose)$(srcdir)/tools/tangle.sh "+f, + "" ] + output += [ "endif", + "" ] + + output+= ["", + "## Source dependencies", + "", + "if QMCKL_DEVEL" ] + for f in sorted(DEPS.keys()): + if DEPS[f][-1].endswith(".tangled"): + output += [ f + ": " + " ".join(DEPS[f]) ] + output += [ "endif", + "$(src_qmckl_fo): $(src_qmckl_f)" ] + for f in sorted(DEPS.keys()): + if not DEPS[f][-1].endswith(".tangled"): + output += [ f + ": " + " ".join(DEPS[f]) ] + + output+= ["", + "## Test files", + "", + "$(test_qmckl_fo): $(test_qmckl_f)"] + for f in sorted(TESTS.keys()): + output += [ f + "$(EXEEXT): " + " ".join(TESTS[f]) ] + output += ["", + "check_PROGRAMS = $(TESTS)" ] + for f in sorted(TESTS.keys()): + prefix = "tests_" + f.rsplit("/",1)[-1] + output += [ prefix + "_SOURCES = " + " ".join(TESTS[f]).replace("$(srcdir)",""), + prefix + "_LDADD = src/libqmckl.la", + prefix + "_LDFLAGS = -no-install", + "" ] + + output+= ["", + "## Documentation", + "", + "if QMCKL_DEVEL" ] + + for f in sorted(ORG_FILES): + output += [ HTML[f] + ": " + DEPS_DOC[f], + TEXT[f] + ": " + DEPS_DOC[f], + "" ] + + for f in sorted(DEPS_DOC.keys()): + output += [ DEPS_DOC[f] + ": " + f + " $(htmlize_el)", + "\t$(export_verbose)$(srcdir)/tools/build_doc.sh "+f, + "" ] + output += ["endif"] + + f = open("generated.mk","w") + f.write("\n".join(output)) + + + +if __name__ == "__main__": + main() + + + + diff --git a/tools/build_makefile.sh b/tools/build_makefile.sh deleted file mode 100755 index 7939f3c..0000000 --- a/tools/build_makefile.sh +++ /dev/null @@ -1,224 +0,0 @@ -#!/bin/bash -# -# Creates all the dependencies from the org-mode files - -if [[ -z ${srcdir} ]] ; then - srcdir=. -fi - - -WD=$PWD - -function make_src() -{ - - cd ${srcdir} - - declare -A DEPS DEPS_ORG DEPS_TEST TESTS HTML TEXT DEPS_DOC - - C_FILES= - F_FILES= - FH_FUNC_FILES= - FH_TYPE_FILES= - H_FUNC_FILES= - H_TYPE_FILES= - H_PRIVATE_FUNC_FILES= - H_PRIVATE_TYPE_FILES= - C_TEST_FILES= - F_TEST_FILES= - TANGLED_FILES= - - for org in org/*.org ; do - i=$(basename ${org%.org}) - tangled="org/${i}.tangled" - exported="org/${i}.exported" - c_test_x="tests/test_${i}" - c_test_o="tests/test_${i}.\$(OBJEXT)" - f_test_o="tests/test_${i}_f.\$(OBJEXT)" - c_test="tests/test_${i}.c" - f_test="tests/test_${i}_f.f90" - html="share/doc/qmckl/html/${i}.html" - text="share/doc/qmckl/text/${i}.txt" - - i="src/${i}" - - c="${i}.c" - o="${i}.\$(OBJEXT)" - h_func="${i}_func.h" - h_type="${i}_type.h" - h_private_func="${i}_private_func.h" - h_private_type="${i}_private_type.h" - f90="${i}_f.f90" - fo="${i}_f.\$(OBJEXT)" - fh_func="${i}_fh_func.f90" - fh_type="${i}_fh_type.f90" - - ORG_FILES+="\$(srcdir)/$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 - - grep -q "(eval c)" $org - if [[ $? -eq 0 ]] ; then - DEPS[$c]+=" $tangled" - DEPS[$o]+=" $c \$(qmckl_h)" - C_FILES+=" $c" - C_O_FILES+=" $o" - fi - - grep -q "(eval h_func)" $org - if [[ $? -eq 0 ]] ; then - DEPS[$h_func]+=" $tangled" - H_FUNC_FILES+=" $h_func" - fi - - grep -q "(eval h_type)" $org - if [[ $? -eq 0 ]] ; then - DEPS[$h_type]+=" $tangled" - H_TYPE_FILES+=" $h_type" - fi - - grep -q "(eval h_private_type)" $org - if [[ $? -eq 0 ]] ; then - DEPS[$o]+=" $h_private_type" - DEPS[$h_private_type]+=" $tangled" - H_PRIVATE_TYPE_FILES+=" $h_private_type" - fi - - grep -q "(eval h_private_func)" $org - if [[ $? -eq 0 ]] ; then - DEPS[$o]+=" $h_private_func" - DEPS[$h_private_func]+=" $tangled" - H_PRIVATE_FUNC_FILES+=" $h_private_func" - fi - - grep -q "(eval f)" $org - if [[ $? -eq 0 ]] ; then - DEPS[$f90]+=" $tangled \$(src_qmckl_fo)" - DEPS[$fo]+="$f90 \$(src_qmckl_fo)" - F_FILES+=" $f90" - fi - - grep -q "(eval fh_func)" $org - if [[ $? -eq 0 ]] ; then - DEPS[$fh_func]+=" $tangled" - FH_FUNC_FILES+=" $fh_func" - fi - - grep -q "(eval fh_type)" $org - if [[ $? -eq 0 ]] ; then - DEPS[$fh_type]+=" $tangled" - FH_TYPE_FILES+=" $fh_type" - fi - - grep -q "(eval c_test)" $org - if [[ $? -eq 0 ]] ; then - DEPS_TEST["${c_test}"]=" ${tangled}" - C_TEST_FILES+=" ${c_test}" - TESTS["${c_test_x}"]+="${c_test} \$(qmckl_h)" - fi - - grep -q "(eval f_test)" $org - if [[ $? -eq 0 ]] ; then - DEPS_TEST["${f_test}"]+=" ${tangled} \$(test_qmckl_fo)" - F_TEST_FILES+=" ${f_test}" - TESTS["${c_test_x}"]+=" ${f_test} \$(test_qmckl_fo)" - fi - done - - - echo - echo "## Source files" - echo - echo "ORG_FILES=${ORG_FILES}" - echo "TANGLED_FILES=${TANGLED_FILES}" - echo "EXPORTED_FILES=${EXPORTED_FILES}" - echo "C_FILES=${C_FILES}" - echo "F_FILES=${F_FILES}" - echo "C_O_FILES=${C_O_FILES}" - echo "FH_FUNC_FILES=${FH_FUNC_FILES}" - echo "FH_TYPE_FILES=${FH_TYPE_FILES}" - echo "H_FUNC_FILES=${H_FUNC_FILES}" - echo "H_TYPE_FILES=${H_TYPE_FILES}" - echo "H_PRIVATE_FUNC_FILES=${H_PRIVATE_FUNC_FILES}" - echo "H_PRIVATE_TYPE_FILES=${H_PRIVATE_TYPE_FILES}" - echo "C_TEST_FILES=${C_TEST_FILES}" - echo "F_TEST_FILES=${F_TEST_FILES}" - echo "TESTS=${!TESTS[@]}" | sed "s|\$(srcdir)/||g" - echo "HTML_FILES"=${HTML[@]} - echo "TEXT_FILES"=${TEXT[@]} - echo - - echo - - echo "## Org-mode inherited dependencies" - echo - echo "if QMCKL_DEVEL" - for f in ${!DEPS_ORG[@]} ; do - echo ${DEPS_ORG[$f]}: $f - echo " \$(tangle_verbose)\$(srcdir)/tools/tangle.sh $f" - echo "" - done - echo "endif" - echo - - echo - echo "## Source dependencies" - echo - echo "if QMCKL_DEVEL" - for f in ${!DEPS[@]} ; do - x="${DEPS[$f]}" - if [[ "${x%.tangled}x" != ${x}x ]] ; then - echo "${f}: ${DEPS[$f]}" - fi - done | sort - echo "endif" - echo "${src_qmckl_fo}: ${src_qmckl_f}" - for f in ${!DEPS[@]} ; do - x="${DEPS[$f]}" - if [[ "${x%.tangled}x" == ${x}x ]] ; then - echo "${f}: ${DEPS[$f]}" - fi - done | sort - - echo - echo "## Test files" - echo - echo "\$(test_qmckl_fo): \$(test_qmckl_f)" - echo "if QMCKL_DEVEL" - for f in ${!DEPS_TEST[@]} ; do - echo "${f}: ${DEPS_TEST[$f]}" - done | sort - echo "endif" - echo - echo "check_PROGRAMS = \$(TESTS)" - for f in ${!TESTS[@]} ; do - echo "tests_$(basename $f)_SOURCES = ${TESTS[$f]}" #| sed "s|\$(srcdir)/||" - echo "tests_$(basename $f)_LDADD = src/libqmckl.la" - echo "tests_$(basename $f)_LDFLAGS = -no-install" - done | sort - - echo - echo "## Documentation" - echo - echo "if QMCKL_DEVEL" - for f in ${ORG_FILES} ; do - echo "${HTML[$f]}: ${DEPS_DOC[$f]}" - echo "${TEXT[$f]}: ${DEPS_DOC[$f]}" - echo "" - done - for f in ${!DEPS_DOC[@]} ; do - echo "${DEPS_DOC[$f]}: $f \$(htmlize_el)" - echo " \$(export_verbose)\$(srcdir)/tools/build_doc.sh $f" - echo "" - done - echo "endif" -} - - -OUTPUT=${WD}/generated.mk -make_src > ${OUTPUT} -