#!/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}"):
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")
.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 \
-V fontsize=9pt \
-V papersize=legal \
-V linkcolor=blue \
- -f markdown $(filter-out ../../pandoc_img.py,$^) \
+ -f markdown $< \
-s --self-contained \
--mathjax \
-o $@
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)