2005-01-13 06:30:05 -05:00
|
|
|
(define *fname->rule*-table '())
|
2005-01-17 11:56:59 -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 11:56:59 -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 11:56:59 -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 11:56:59 -05:00
|
|
|
(begin
|
|
|
|
(set! *fname->rule*-table
|
|
|
|
(alist-cons fname rule *fname->rule*-table))
|
|
|
|
(set! rule-set (rule-set-add rule rule-set))))))
|
|
|
|
|
|
|
|
(define-syntax make
|
|
|
|
(syntax-rules ()
|
|
|
|
((make ?fname ?state)
|
|
|
|
(rule-make (*fname->rule*-get ?fname)
|
|
|
|
?state
|
|
|
|
rule-set))))
|
|
|
|
|
|
|
|
(define-syntax makefile
|
|
|
|
(syntax-rules ()
|
|
|
|
((makefile ?rule0 ...)
|
|
|
|
(begin
|
|
|
|
(set! rule-set (make-empty-rule-set))
|
|
|
|
?rule0 ...))))
|
2005-01-13 06:30:05 -05:00
|
|
|
|
|
|
|
(define-syntax make-is-out-of-date?
|
|
|
|
(syntax-rules ()
|
2005-01-17 11:56:59 -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 11:56:59 -05:00
|
|
|
(> (file-last-mod ?prereq0)
|
2005-01-13 06:30:05 -05:00
|
|
|
(file-last-mod ?target))
|
|
|
|
...)
|
|
|
|
(last ?args))))))
|
|
|
|
|
2005-01-17 11:56:59 -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 11:56:59 -05:00
|
|
|
((makefile-rule ?target (?prereq0 ...) ?thunk)
|
|
|
|
(makefile-rule-tmpvars () ?target (?prereq0 ...) ?thunk))))
|
|
|
|
|
|
|
|
(define-syntax makefile-rule-tmpvars
|
|
|
|
(syntax-rules ()
|
|
|
|
((makefile-rule-tmpvars (tmp1 ...) ?target () ?thunk)
|
|
|
|
;;
|
|
|
|
;; ?target could be an expr: eval only once
|
|
|
|
;;
|
|
|
|
(let ((target ?target))
|
|
|
|
(*fname->rule*-add! target
|
|
|
|
(make-rule (list (*fname->rule*-get tmp1)
|
2005-01-13 06:30:05 -05:00
|
|
|
...)
|
2005-01-17 11:56:59 -05:00
|
|
|
(make-is-out-of-date? target tmp1 ...)
|
|
|
|
(lambda ?args (?thunk))))))
|
|
|
|
;;
|
|
|
|
;; recursively construct temporary, hygienic variables
|
|
|
|
;;
|
|
|
|
((makefile-rule-tmpvars (tmp1 ...) ?target (?prereq0 ?prereq1 ...) ?thunk)
|
|
|
|
(let ((tmp2 ?prereq0))
|
|
|
|
(makefile-rule-tmpvars (tmp1 ... tmp2) ?target (?prereq1 ...) ?thunk)))))
|
2005-01-13 06:30:05 -05:00
|
|
|
|
2005-01-17 11:56:59 -05:00
|
|
|
(define-syntax makefile-rule-md5
|
|
|
|
(syntax-rules ()
|
|
|
|
((makefile-rule-md5 ?fingerprint ?target (?prereq0 ...) ?thunk)
|
|
|
|
(makefile-rule-md5-tmpvars () ?fingerprint ?target (?prereq0 ...) ?thunk))))
|
2005-01-13 06:30:05 -05:00
|
|
|
|
2005-01-17 11:56:59 -05:00
|
|
|
(define-syntax makefile-rule-md5-tmpvars
|
2005-01-13 06:30:05 -05:00
|
|
|
(syntax-rules ()
|
2005-01-17 11:56:59 -05:00
|
|
|
((makefile-rule-md5-tmpvars (tmp1 ...) ?fingerprint ?target () ?thunk)
|
|
|
|
;;
|
|
|
|
;; ?target could be an expr: eval only once
|
|
|
|
;;
|
|
|
|
(let ((target ?target))
|
|
|
|
(*fname->rule*-add! target
|
|
|
|
(make-rule (list (*fname->rule*-get tmp1)
|
|
|
|
...)
|
|
|
|
(make-has-md5-digest=? ?fingerprint
|
|
|
|
target
|
|
|
|
tmp1 ...)
|
|
|
|
(lambda ?args (?thunk))))))
|
|
|
|
;;
|
|
|
|
;; recursively construct temporary, hygienic variables
|
|
|
|
;;
|
|
|
|
((makefile-rule-md5-tmpvars (tmp1 ...)
|
|
|
|
?fingerprint
|
|
|
|
?target
|
|
|
|
(?prereq0 ?prereq1 ...)
|
|
|
|
?thunk)
|
|
|
|
(let ((tmp2 ?prereq0))
|
|
|
|
(makefile-rule-md5-tmpvars (tmp1 ... tmp2)
|
|
|
|
?fingerprint
|
|
|
|
?target
|
|
|
|
(?prereq1 ...)
|
|
|
|
?thunk)))))
|