Change behavior. (require racket-makefile) and use (make <target>) instead of racket Makefile.rkt <target>

This commit is contained in:
2026-08-08 22:38:13 +02:00
parent f32503f3e7
commit 57707e5fc0
11 changed files with 276 additions and 32 deletions
+23 -2
View File
@@ -12,6 +12,7 @@
deps
phony
default-target
make
run
rm-f
rm-rf
@@ -20,20 +21,32 @@
$deps
$<)
;; For target declarations we want a bound identifier to remain an ordinary
;; Racket expression. This makes generated targets such as (target obj ...)
;; possible inside a for loop. An unbound identifier is a literal target name.
(define-for-syntax (literal-name-or-expression stx)
(if (and (identifier? stx)
(not (identifier-binding stx)))
(datum->syntax stx `(quote ,(syntax-e stx)) stx stx)
stx))
;; For interactive make invocations a bare identifier is always a literal
;; target name. Thus (make compile) means the target named "compile" even if
;; Racket happens to provide a binding named compile.
(define-for-syntax (literal-make-name stx)
(if (identifier? stx)
(datum->syntax stx `(quote ,(syntax-e stx)) stx stx)
stx))
(define-syntax (makefile-module-begin stx)
(syntax-case stx ()
[(_ form ...)
#'(racket-module-begin
(reset-makefile!)
form ...
(module+ main
(run-selected-target!)))]))
;; Re-export make so that `racket -t Makefile.rkt -e "(make all)"`
;; imports the make form into the command-line evaluation namespace.
(provide make quote #%top-interaction #%app #%datum #%top))]))
(define-syntax (deps stx)
(raise-syntax-error 'deps "only valid as the dependency clause of target" stx))
@@ -70,6 +83,14 @@
(with-syntax ([target-name (literal-name-or-expression #'name)])
#'(set-default-target! target-name))]))
(define-syntax (make stx)
(syntax-case stx ()
[(_ name ...)
(with-syntax ([(target-name ...)
(map literal-make-name
(syntax->list #'(name ...)))])
#'(make-targets! target-name ...))]))
(define-syntax $target
(syntax-id-rules ()
[$target