122 lines
4.1 KiB
Plaintext
Executable file
122 lines
4.1 KiB
Plaintext
Executable file
#!/usr/bin/env -S jq -r -f
|
|
# Takes iditacards output json and produces the dynamic ninja build
|
|
# Example usage: cue export -- *.cue *.yaml | ./configure.jq > output/build.ninja
|
|
|
|
def ifblank(x): if . | length > 0 then . else x end;
|
|
def cuesources: $ARGS.positional | join(" ");
|
|
def header: "# Generated from configure.jq, do not edit this file!
|
|
|
|
root = .
|
|
|
|
rule configure
|
|
description = recreate build.ninja using configure.jq
|
|
command = cue export -- *.cue *.yaml | ./configure.jq --args -- *.cue *.yaml > $out
|
|
generator = 1
|
|
|
|
build build.ninja: configure | configure.jq \(cuesources)
|
|
|
|
base = .
|
|
include rules.ninja
|
|
|
|
build output/.everything.json: cuegen \(cuesources)
|
|
filter = .
|
|
";
|
|
|
|
def dirof: split("/")[0:-1] | join("/") | if . | length > 0 then . + "/" else "" end;
|
|
def filof: . as $saved | split("/")[-1] | ifblank($saved);
|
|
def rawof: filof as $saved | split(".")[0:-1] | join(".") | ifblank($saved);
|
|
|
|
def generate_pdf_builds($dir; $raw; $tex): "
|
|
build output/\($dir)\($raw).pdf: tex2pdf \($tex) || output/\($dir).\($raw).pdf.dd
|
|
dyndep = output/\($dir).\($raw).pdf.dd
|
|
|
|
build output/\($dir).\($raw).pdf.dd: scantex \($tex)
|
|
target = output/\($dir)\($raw).pdf
|
|
";
|
|
|
|
def generate_png_from_pdf_builds($dir; $raw; $pdf):
|
|
(.size | split("x")[0]) as $w |
|
|
(.size | split("x")[1]) as $h |
|
|
(if .print then "raw." else "" end) as $ext | "
|
|
build output/\($dir)\($raw).\($ext)png: pdf2png \($pdf)
|
|
w = \($w)
|
|
h = \($h)
|
|
";
|
|
|
|
def generate_png_copy_builds($dir; $raw; $png):
|
|
(if .print then "raw." else "" end) as $ext | "
|
|
build output/\($dir)\($raw).\($ext)png: copy \($png)
|
|
";
|
|
|
|
def generate_print_png_builds($dir; $raw; $rawpng):
|
|
if .print then "
|
|
build output/\($dir)\($raw).png: convert \($rawpng)
|
|
args = \(.print)
|
|
" else empty end;
|
|
|
|
def generate_template_builds:
|
|
(.name | dirof) as $dir |
|
|
(.name | rawof) as $raw | ("
|
|
build output/\($dir).\($raw).update | output/\($dir).\($raw).json: extract output/.everything.json
|
|
filter = --arg asset '\(.name)' '.assets[$$asset].data'
|
|
target = output/\($dir).\($raw).json
|
|
|
|
build output/\($dir)/tex/\($raw).tex: template2tex output/\($dir).\($raw).json | templates/\(.template)
|
|
template = templates/\(.template)
|
|
",
|
|
generate_pdf_builds($dir; $raw; "output/\($dir)/tex/\($raw).tex"),
|
|
generate_png_from_pdf_builds($dir; $raw; "output/\($dir)\($raw).pdf"),
|
|
generate_print_png_builds($dir; $raw; "output/\($dir)\($raw).raw.png")
|
|
);
|
|
|
|
def generate_image_builds:
|
|
(.name | dirof) as $dir |
|
|
(.name | rawof) as $raw | (
|
|
generate_png_copy_builds($dir; $raw; .source),
|
|
generate_print_png_builds($dir; $raw; "output/\($dir)\($raw).raw.png")
|
|
);
|
|
|
|
def generate_tex_builds:
|
|
(.size | split("x")[0]) as $w |
|
|
(.size | split("x")[1]) as $h |
|
|
(.name | dirof) as $dir |
|
|
(.name | rawof) as $raw | (
|
|
generate_pdf_builds($dir; $raw; .source),
|
|
generate_png_from_pdf_builds($dir; $raw; "output/\($dir)\($raw).pdf"),
|
|
generate_print_png_builds($dir; $raw; "output/\($dir)\($raw).raw.png")
|
|
);
|
|
|
|
def generate_texdoc_builds:
|
|
(.name | dirof) as $dir |
|
|
(.name | rawof) as $raw | "
|
|
build output/\($dir)\($raw).pdf: tex2pdf2x \(.source) || output/\($dir).\($raw).pdf.dd
|
|
dyndep = output/\($dir).\($raw).pdf.dd
|
|
|
|
build output/\($dir).\($raw).pdf.dd: scantex \(.source)
|
|
target = output/\($dir)\($raw).pdf
|
|
";
|
|
|
|
def generate_cat_builds:
|
|
(.contents | map("output/" + . + ".pdf") | join(" ")) as $pdfcontents |
|
|
(.contents | map("output/" + . + ".png") | join(" ")) as $pngcontents |
|
|
(.contents | map("output/" + . + ".raw.png") | join(" ")) as $rawcontents |
|
|
(.name | dirof) as $dir |
|
|
(.name | rawof) as $raw | "
|
|
build output/\($dir)\($raw).pdf: pdfunite \($pdfcontents)
|
|
build output/\($dir)\($raw).png: pngunite \($pngcontents)
|
|
build output/\($dir)\($raw).raw.png: pngunite \($rawcontents)
|
|
";
|
|
|
|
def generate_builds:
|
|
(select(.kind == "template") | generate_template_builds),
|
|
(select(.kind == "image") | generate_image_builds),
|
|
(select(.kind == "tex") | generate_tex_builds),
|
|
(select(.kind == "texdoc") | generate_texdoc_builds),
|
|
(select(.kind == "cat") | generate_cat_builds);
|
|
|
|
def expandout: to_entries[] | .value + { name: .key };
|
|
def everything: (.assets, .pseudoassets) | expandout;
|
|
|
|
header,
|
|
(everything | generate_builds)
|