From: Jacob Lifshay Date: Thu, 6 Apr 2023 03:09:18 +0000 (-0700) Subject: switch to using mdwn_inline instead of special-cases in Makefile X-Git-Tag: opf_rfc_ls012_v1~112 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fba04aa8ae27751053f558ad0a1a48784e578d0d;p=libreriscv.git switch to using mdwn_inline instead of special-cases in Makefile also automatically tracks [[!include]] dependencies --- diff --git a/openpower/mdwn_inline.py b/openpower/mdwn_inline.py index 53d30ac08..296bad33e 100755 --- a/openpower/mdwn_inline.py +++ b/openpower/mdwn_inline.py @@ -1,9 +1,18 @@ #!/usr/bin/env python3 - import sys +import os.path + +opened_files = [] +def open_tracked(name, mode='r'): + opened_files.append(name) + return open(name, mode) -with open(sys.argv[2], "w") as o: - with open(sys.argv[1], "r") as f: +output_file = sys.argv[2] +file_path = os.path.abspath(__file__) +openpower_path = os.path.split(file_path)[0] +wiki_path = os.path.split(openpower_path)[0] +with open(output_file, "w") as o: + with open_tracked(sys.argv[1], "r") as f: for line in f.readlines(): if sys.argv[1].endswith("comparison_table.tex") and \ line.startswith("\begin{itemize}"): @@ -13,25 +22,33 @@ with open(sys.argv[2], "w") as o: if not line.startswith("[[!inline"): o.write(line) continue - print (line.strip()) + print(line.strip()) # assume first thing is pagename line = line.split('"') fname = line[1] - print ("\t", fname) + print("\t", fname) if fname.endswith(".py"): if fname.startswith("gf_reference"): - with open("../../nmigen-gf/"+fname) as inc: + with open_tracked( + wiki_path + "/../nmigen-gf/" + fname) as inc: o.write(inc.read()) else: - with open("../%s" % fname) as inc: + with open_tracked(wiki_path + "/" + fname) as inc: o.write(inc.read()) else: if fname.endswith(".mdwn"): - with open("../%s" % fname) as inc: + with open_tracked(wiki_path + "/" + fname) as inc: o.write(inc.read()) elif fname == 'openpower/isatables/fields.text': - with open("../../openpower-isa/%s" % fname) as inc: + with open_tracked( + wiki_path + "/../openpower-isa/" + fname) as inc: o.write(inc.read()) else: - with open("../%s.mdwn" % fname) as inc: + with open_tracked( + wiki_path + "/" + fname + ".mdwn") as inc: o.write(inc.read()) + +deps_file = output_file + '.d' +with open(deps_file, "w") as o: + deps = " ".join(opened_files) + o.write(f"{output_file} {deps_file}: {deps}\n") diff --git a/openpower/sv/rfc/Makefile b/openpower/sv/rfc/Makefile index 16e39328d..56480d2c7 100644 --- a/openpower/sv/rfc/Makefile +++ b/openpower/sv/rfc/Makefile @@ -1,15 +1,19 @@ .PHONY: all clean upload -all: $(patsubst %.mdwn,%.pdf,$(wildcard ls[0-9][0-9][0-9].mdwn)) +.SECONDARY: -ls010.pdf: ls010.mdwn ../svp64.mdwn \ - ../normal.mdwn \ - ../ldst.mdwn \ - ../branches.mdwn \ - ../po9_encoding.mdwn \ - ../cr_ops.mdwn +main_sources = $(wildcard ls[0-9][0-9][0-9].mdwn) +pdfs = $(patsubst %.mdwn,%.pdf,$(main_sources)) +deps = $(patsubst %,tex_out/%.d,$(main_sources)) -%.pdf: %.mdwn ../../pandoc_img.py +all: $(pdfs) + +# generate dependency files, also generates intermediate .mdwn files too +tex_out/%.mdwn.d: %.mdwn ../../mdwn_inline.py + mkdir -p $(dir $@) + ../../mdwn_inline.py $< tex_out/$*.mdwn + +%.pdf: tex_out/%.mdwn ../../pandoc_img.py pandoc \ --filter ../../pandoc_img.py \ -V margin-top=0.9in \ @@ -19,7 +23,7 @@ ls010.pdf: ls010.mdwn ../svp64.mdwn \ -V fontsize=9pt \ -V papersize=legal \ -V linkcolor=blue \ - -f markdown $(filter-out ../../pandoc_img.py,$^) \ + -f markdown $< \ -s --self-contained \ --mathjax \ -o $@ @@ -29,4 +33,6 @@ upload: ssh libre-soc.org 'cp opf_isa_wg/*.pdf /var/www/ftp.libre-riscv.org/opf_ext_rfc/' clean: - rm -fr *.pdf + rm -fr *.pdf tex_out + +-include $(deps)