makefile-targets and some other meta info functions added

This commit is contained in:
2026-08-18 02:15:33 +02:00
parent a21f4a4a39
commit 635d2d40d1
13 changed files with 538 additions and 251 deletions
+28 -16
View File
@@ -9,19 +9,19 @@
(define calls '())
(define context #f)
(makefile first
(default-target status)
(phony status all context)
(makefile 'first
(default-target 'status)
(phony 'status 'all 'context)
(target status
(target 'status
(set! calls (append calls '(first-status))))
(target all
(deps status)
(target 'all
(deps 'status)
(set! calls (append calls '(first-all))))
(target context
(deps input.txt other.txt)
(target 'context
(deps 'input.txt 'other.txt)
(set! context (list $target $deps $<))))
(check-equal? (current-makefile-prefix) 'first)
@@ -30,6 +30,14 @@
(check-true (procedure? makefile-target-first-all))
(check-true (procedure? makefile-target-first-context))
;; The public inspection API preserves definition order and original values.
(check-equal? (makefile-prefixes) '(first))
(check-equal? (makefile-targets) '(status all context))
(check-true (makefile-target-exists? 'status))
(check-false (makefile-target-exists? 'missing))
(check-eq? (makefile-target-procedure 'status)
makefile-target-first-status)
;; make resolves the target procedure through the active prefix.
(make 'all)
(check-equal? calls '(first-status first-all))
@@ -42,10 +50,10 @@
(makefile-target-first-context)
(check-equal? context '("context" ("input.txt" "other.txt") "input.txt"))
(makefile second
(default-target status)
(phony status)
(target status
(makefile 'second
(default-target 'status)
(phony 'status)
(target 'status
(set! calls (append calls '(second-status)))))
;; The last makefile definition becomes active.
@@ -60,7 +68,11 @@
calls
'(first-status first-all first-status second-status first-status))
;; The registry stores the generated procedure itself.
(check-eq?
(hash-ref makefile-targets '("first" . "status"))
makefile-target-first-status)
;; Both prefixes remain inspectable after switching the active makefile.
(check-equal? (makefile-prefixes) '(first second))
(check-equal? (makefile-targets 'first) '(status all context))
(check-equal? (makefile-targets 'second) '(status))
(check-true (makefile-target-exists? 'first 'status))
(check-false (makefile-target-exists? 'first 'missing))
(check-eq? (makefile-target-procedure 'first 'status)
makefile-target-first-status)