about summary refs log tree commit diff stats
path: root/build/latex/letter
diff options
context:
space:
mode:
Diffstat (limited to 'build/latex/letter')
-rwxr-xr-xbuild/latex/letter/build.sh27
-rw-r--r--build/latex/letter/flake.nix5
-rw-r--r--build/latex/letter/init2
3 files changed, 28 insertions, 6 deletions
diff --git a/build/latex/letter/build.sh b/build/latex/letter/build.sh
index c67ad52..1ff2b6e 100755
--- a/build/latex/letter/build.sh
+++ b/build/latex/letter/build.sh
@@ -1,6 +1,8 @@
 #!/usr/bin/env sh
 
-file="./%INIT_APPLICATION_NAME.tex"
+root="$(git rev-parse --show-toplevel)"
+
+file="$root/%INIT_APPLICATION_NAME.tex"
 dst=build
 
 clear=false
@@ -21,10 +23,31 @@ for arg in "$@"; do
 done
 
 # find all directories which are not the destination dir or inside it
-find . -type d -not -name "$dst" -not -path "./$dst/*" -printf '%P\n' | while IFS= read -r dir; do
+find "$root" -type d -not -name "$dst" -not -path "./$dst/*" -printf '%P\n' | while IFS= read -r dir; do
     mkdir --parents "$dst/$dir"
 done
 
 test "$clear" = true && rm "$dst/${file%tex}out"
 
+fd . "$root/figures" --type file --extension tex | while read -r figure; do
+    figure_name_full="$(basename "$figure")"
+    figure_name="${figure_name_full%.tex}"
+
+    figure_hash="$(sha256sum "$figure")"
+    figure_cache_hash="$(
+        [ -e "$dst/figures/$figure_name/$figure_name.sha256sum_hash" ] &&
+            cat "$dst/figures/$figure_name/$figure_name.sha256sum_hash"
+    )"
+
+    echo "Compiling figure: '$figure_name'.."
+    mkdir --parents "$dst/figures/$figure_name"
+
+    if [ "$figure_hash" = "$figure_cache_hash" ]; then
+        echo "   -> Didn't change, not re-compiling."
+    else
+        echo "$figure_hash" >"$dst/figures/$figure_name/$figure_name.sha256sum_hash"
+        pdflatex -output-directory="$dst" -file-line-error -jobname="figures/$figure_name/$figure_name" "$figure"
+    fi
+done
+
 latexmk -outdir="$dst" -file-line-error -pdflatex -recorder "$file"
diff --git a/build/latex/letter/flake.nix b/build/latex/letter/flake.nix
index 6a21c68..bfdf673 100644
--- a/build/latex/letter/flake.nix
+++ b/build/latex/letter/flake.nix
@@ -46,15 +46,12 @@
     };
     crane = {
       url = "github:ipetkov/crane";
-      inputs = {
-        nixpkgs.follows = "nixpkgs";
-      };
+      inputs = {};
     };
     rust-overlay = {
       url = "github:oxalica/rust-overlay";
       inputs = {
         nixpkgs.follows = "nixpkgs";
-        flake-utils.follows = "flake-utils";
       };
     };
   };
diff --git a/build/latex/letter/init b/build/latex/letter/init
index 9ee0462..e8f72c8 100644
--- a/build/latex/letter/init
+++ b/build/latex/letter/init
@@ -182,6 +182,8 @@ reuse="$(nix build nixpkgs#reuse.out --no-link --print-out-paths)/bin/reuse"
 
 git add .
 
+cp "$replacement_file" ".git/init_variables_$(date --iso-8601=date)"
+
 git diff --name-only --cached |
     xargs -I {} "$reuse" annotate \
         --copyright "$AUTHOR_NAME <$AUTHOR_EMAIL>" \