Library: makefile-edn

..

Original Idea - provide mappers from EDN to Makefiles - and back again.

Message from 2022-10-07: I no longer think this is a good idea.

I now believe:

  1. Build dependencies are just data and code
  2. Generally, it’s nice to have a auto-caching build everything-command
  3. This can be solved with EDN, babashka.fs/glob and babashka.fs/modified-since

Why?

  1. It’s possible to get equivalent performance with just babashka - perhaps even better if we don’t have to start / restart processes
  2. There’s just one language
  3. The “do we check in the Makefile?” question does not exist
  4. Other things can use the same EDN data that models build dependencies.

How?

Read this: https://blog.michielborkent.nl/speeding-up-builds-fs-modified-since.html

Makefile EDN spec

:comment Makefile comment with # string
:target Makefile target string
:dependencies Dependencies for makefile target sequence of strings
:commands Sequence of commands to produce target sequence of strings

Example makefile as EDN

(def makefile
  [{:comment "Generate target for root index"}
   ;; # Generate target for root index

   {:target "index.html"
    :dependencies ["index.clj" "aphorisms/index.html" "aphorisms/play.edn"]
    :commands ["./index.clj"]}
   ;; index.html: index.clj aphorisms/index.html aphorisms/play.edn
   ;;     ./index.clj

   {:target "aphorisms/index.html"
    :dependencies ["aphorisms/index.org"]
    :commands ["pandoc -s --shift-heading-level-by=1 --toc --from=org+smart -H live.html -i aphorisms/index.org -o aphorisms/index.html"]}
   ;; aphorisms/index.html: aphorisms/index.org
   ;;   pandoc -s --shift-heading-level-by=1 --toc --from=org+smart -H live.html -i aphorisms/index.org -o aphorisms/index.html
   ])

Library API

makefile-edn/<-makefile-str - read from makefile string makefile-edn/->makefile-str - write to makefile string

Usage

Either as Clojure library or as babashka script. Could perhaps just provide the library — then babashka pulls in the library as needed.