scsh-make/makros.scm

92 lines
2.9 KiB
Scheme
Raw Normal View History

2005-01-13 06:30:05 -05:00
(define *fname->rule*-table '())
2005-01-17 02:56:42 -05:00
(define rule-set (make-empty-rule-set))
2005-01-13 06:30:05 -05:00
;;; (*fname->rule*-get fname) ---> rule
(define (*fname->rule*-get fname)
(let ((rule-found? (assoc fname *fname->rule*-table)))
2005-01-17 02:56:42 -05:00
(if rule-found? (cdr rule-found?))))
2005-01-13 06:30:05 -05:00
;;; (*fname->rule*-add! fname) ---> {}
(define (*fname->rule*-add! fname rule)
2005-01-17 02:56:42 -05:00
(let ((rule-found? (assoc fname *fname->rule*-table)))
2005-01-13 06:30:05 -05:00
(if rule-found?
(error "There already exists a rule with this fname!")
2005-01-17 02:56:42 -05:00
(begin
(set! *fname->rule*-table
(alist-cons fname rule *fname->rule*-table))
(set! rule-set (rule-set-add rule rule-set))))))
2005-01-13 06:30:05 -05:00
(define-syntax make-is-out-of-date?
(syntax-rules ()
2005-01-17 02:56:42 -05:00
((make-is-out-of-date? ?target)
2005-01-13 06:30:05 -05:00
(lambda ?args
(cons (file-not-exists? ?target) ?args)))
((make-is-out-of-date? ?target ?prereq0 ...)
(lambda ?args
(cons (or (file-not-exists? ?target)
2005-01-17 02:56:42 -05:00
(> (file-last-mod ?prereq0)
2005-01-13 06:30:05 -05:00
(file-last-mod ?target))
...)
(last ?args))))))
2005-01-17 02:56:42 -05:00
(define-syntax make-has-md5-digest=?
(syntax-rules ()
((make-has-md5-digest=? ?fingerprint ?target)
(lambda ?args
(cons (or (file-not-exists? ?target)
(=? (md5-digest-for-port (open-input-file ?target))
?fingerprint))
?args)))
((make-has-md5-digest=? ?fingerprint ?target ?prereq0 ...)
(lambda ?args
(cons (or (file-not-exists? ?target)
(=? (md5-digest->number (md5-digest-for-port
(open-input-file ?target)))
(md5-digest->number ?fingerprint)))
(last ?args))))))
2005-01-13 06:30:05 -05:00
(define-syntax makefile-rule
(syntax-rules ()
2005-01-17 02:56:42 -05:00
((makefile-rule '() ?prereqs ?action-thunk)
(error "Target specification in makefile-rule matches '()!"))
((makefile-rule (?target0 ...) ?prereqs ?action-thunk)
(begin
(makefile-rule ?target0 ?prereqs ?action-thunk)
...))
2005-01-13 06:30:05 -05:00
((makefile-rule ?target '() ?action-thunk)
(*fname->rule*-add! ?target
(make-rule '()
(make-is-out-of-date? ?target)
(lambda ?args (?action-thunk)))))
((makefile-rule ?target (?prereq0 ...) ?action-thunk)
(begin
(*fname->rule*-add! ?target
(make-rule (list (*fname->rule*-get ?prereq0)
...)
(make-is-out-of-date? ?target ?prereq0 ...)
(lambda ?args (?action-thunk))))))
2005-01-17 02:56:42 -05:00
((makefile-rule ?target ?prereq0 ?action-thunk)
(*fname->rule*-add! ?target
(make-rule (list (*fname->rule*-get ?prereq0))
(make-is-out-of-date? ?target ?prereq0)
(lambda ?args (?action-thunk)))))))
(define-syntax with-is-out-of-date?-check-func
(syntax-rules ()
((with-is-out-of-date?-producer ?make-is-out-of-date? ?makefile-rule
2005-01-13 06:30:05 -05:00
(define-syntax makefile
(syntax-rules ()
; ((makefile ()) '())
2005-01-17 02:56:42 -05:00
((makefile ?rule0 ...)
(begin
(set! rule-set (make-empty-rule-set))
?rule0 ...))))
2005-01-13 06:30:05 -05:00
(define-syntax make
(syntax-rules ()
((make ?fname)
(rule-make (*fname->rule*-get ?fname)
2005-01-17 02:56:42 -05:00
"This is not an empty initial state."
rule-set))))