Skip to content

Instantly share code, notes, and snippets.

@srenatus
Last active April 10, 2024 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srenatus/bbea51ca88ca93da7fa4414c4f749c1a to your computer and use it in GitHub Desktop.
Save srenatus/bbea51ca88ca93da7fa4414c4f749c1a to your computer and use it in GitHub Desktop.
babashkba make helper, to be called as `make`
#!/usr/bin/env bb
(require '[babashka.fs :as :fs]
'[babashka.process :refer [shell]])
(def make "/usr/bin/make")
(defn find-root
([] (find-root (fs/cwd)))
([wd] (cond
(fs/exists? (fs/path wd "Makefile")) {:dir wd}
(fs/same-file? (fs/home) wd) :not-found
(fs/exists? (fs/path wd ".git")) :not-found
:else (recur (fs/parent wd)))))
(defn run-make [wd & args]
(if (= :not-found wd)
(throw (ex-info "Makefile not found" {:babashka/exit 1}))
(-> (apply shell (assoc wd :continue true) make args)
:exit
System/exit)))
(when (= *file* (System/getProperty "babashka.file"))
(apply run-make (find-root) *command-line-args*))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment