commit 002347687dd4be1f5c865a21b8f78ccd30022cbd
parent 14c07143c6fd1c0d94f8f594a74d4ee8e3282e75
Author: lou woell <lou@repetitions.de>
Date:   Sun,  6 Sep 2026 15:24:31 +0200

improve build system

Diffstat:
Mlisp/ethics.lisp | 60+++++++++++++++++++++++++++++++++++++++++++-----------------
Alisp/lou.spinoza.ethica.asd | 10++++++++++
Mmakefile | 37+++++++++++++++++++++++++++++++------
3 files changed, 84 insertions(+), 23 deletions(-)

diff --git a/lisp/ethics.lisp b/lisp/ethics.lisp @@ -1,11 +1,3 @@ -(asdf:defsystem :lou.spinoza.ethics - :depends-on (#:plump - #:clip - #:markdown.cl - #:com.inuoe.jzon)) - -(ql:quickload :lou.spinoza.ethics) - (defpackage :ethics (:use :cl) (:export #:write-ethics) @@ -19,8 +11,9 @@ (defparameter config '(:build-dir #p"../build/" - :meta-data #p"../data/meta.json" - :data-dir #p"../data")) + :template-dir #p"../html/" + :data-dir #p"../data/" + :versions ("en_elwes" "la_spinoza"))) (defun read-version (key dir tbl) (loop :with meta := nil @@ -35,9 +28,14 @@ :finally (return meta))) (defun import-versions (config tbl) - (loop :for path :in (uiop:subdirectories (getf config :data-dir)) + (loop :for path :in (loop :with data-dir := (getf config :data-dir) + :for v :in (getf config :versions) + :collect (make-pathname :directory + (append (pathname-directory data-dir) + (list v)))) :as fname := (car (last (pathname-directory path))) :as data := (read-version fname path tbl) + :do (format t "~A~&" path) :collect (list :key fname :path path @@ -72,11 +70,11 @@ :finally (return (gethash "ethica" tbl)))) (defun import-ethics (config) - (let ((tbl (jzon:parse (getf config :meta-data)))) + (let ((tbl (jzon:parse (merge-pathnames #p"meta.json" (getf config :data-dir))))) (build-tree tbl) (import-versions config tbl))) -;; --- +;; --- generate html (defun process-to-file (template outpath &rest bindings) (with-open-file (out outpath @@ -92,7 +90,7 @@ (defun make-node (node vkey types &optional (level 1)) (clip:process - #p"../html/node.chtml" + (merge-pathnames #p"node.chtml" (getf config :template-dir)) :node node :level level :vkey vkey @@ -101,16 +99,44 @@ (defun write-ethics () (destructuring-bind (ethica &rest versions) (import-ethics config) - (process-to-file #p"../html/index.chtml" - #p"../build/index.html" + (process-to-file (merge-pathnames #p"index.chtml" (getf config :template-dir)) + (merge-pathnames #p"index.html" (getf config :build-dir)) :versions versions) (dolist (version versions) (let ((key (getf version :key))) (process-to-file - #p"../html/ethics.chtml" + (merge-pathnames #p "ethics.chtml" (getf config :template-dir)) (merge-pathnames (getf version :file) (getf config :build-dir)) :tree (gethash "ethica" ethica) :name (getf version :name) :vkey key + :types (getf version :types)))))) + +;; --- plumbing + +(defmacro parse-args (&rest args) + `(loop :with version := nil + :for arg :on (uiop:command-line-arguments) :by #'cddr + :as flag := (car arg) + :as value := (cadr arg) + :if (string= flag "--") + :do (setf versions (cdr arg)) + (loop-finish) + :else + :nconc (parse-arg flag value ,@args) :into pairs + :finally (return (append pairs (list :versions versions))))) + +(defun parse-arg (flag value &rest args) + (let ((key (and (uiop:string-prefix-p "--" flag) + (intern (string-upcase (subseq flag 2)) + :keyword)))) + (if (member key args) + (list key value) + (error "Unrecognized command line argument: ~a ~a" flag value)))) + +(defun main () + (let ((config (parse-args :build-dir :template-dir :data-dir))) + (print config) + (write-ethics))) diff --git a/lisp/lou.spinoza.ethica.asd b/lisp/lou.spinoza.ethica.asd @@ -0,0 +1,10 @@ +(asdf:defsystem :lou.spinoza.ethica + :defsystem-depends-on (:deploy) + :build-operation "deploy-console-op" + :build-pathname "ethicagen" + :entry-point "ethics::main" + :depends-on (#:plump + #:clip + #:markdown.cl + #:com.inuoe.jzon) + :components ((:file "ethics"))) diff --git a/makefile b/makefile @@ -1,13 +1,38 @@ +LISP=sbcl + BUILD_DIR=./build +DATA_DIR=./data +TEMPLATE_DIR=./html -SRC_DIRS=./data ./lisp ./html ./assets -FILES=makefile readme.md +SRC_DIRS=$(DATA_DIR) $(TEMPLATE_DIR) ./lisp ./assets +FILES=makefile readme.md ARCHIVE=$(BUILD_DIR)/ethica.zip -.PHONY: deploy -deploy: $(ARCHIVE) - rsync -rL $(BUILD_DIR)/ repetitions:~/ethica +GEN=lisp/bin/ethicagen + +VERSIONS=la_spinoza en_elwes de_stern de_auerbach fr_saisset fr_appuhn +HTML = $(foreach v, $(VERSIONS), $(BUILD_DIR)/$(v).html) + +.PHONY: all +all: $(HTML) + +$(HTML) &: $(DATA_DIR)/* $(DATA_DIR)/meta.json $(TEMPLATE_DIR) $(GEN) + $(GEN) --data-dir $(DATA_DIR)/\ + --build-dir $(BUILD_DIR)/\ + --template-dir $(TEMPLATE_DIR)/\ + -- $(VERSIONS) $(ARCHIVE): $(SRC_DIRS) $(FILES) - zip -r $@ $^ + git archive main -o $@ + +$(GEN): lisp/lou.spinoza.ethica.asd lisp/ethics.lisp + $(LISP) --load 'lisp/lou.spinoza.ethica.asd'\ + --eval '(ql:quickload :lou.spinoza.ethica)'\ + --eval '(asdf:make :lou.spinoza.ethica)'\ + --eval '(quit)' + +deploy: $(ARCHIVE) all + rsync -rL $(BUILD_DIR)/ repetitions:~/ethica + +.PHONY: deploy clean