makefile-targets and some other meta info functions added
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#lang racket
|
||||
|
||||
(require rackunit
|
||||
racket/file
|
||||
racket-makefile
|
||||
(only-in "../private/engine.rkt" reset-makefiles!))
|
||||
|
||||
(reset-makefiles!)
|
||||
|
||||
(define tmp (make-temporary-file "racket-makefile-generated~a" 'directory))
|
||||
(define called '())
|
||||
|
||||
(dynamic-wind
|
||||
void
|
||||
(λ ()
|
||||
(parameterize ([current-directory tmp])
|
||||
(makefile 'stuff
|
||||
(define sources '("foo.c" "bar.c" "baz.c"))
|
||||
|
||||
(for ([src sources])
|
||||
(call-with-output-file src
|
||||
#:exists 'truncate/replace
|
||||
(λ (out)
|
||||
(displayln src out))))
|
||||
|
||||
(define objects
|
||||
(for/list ([src sources])
|
||||
(define obj (path-replace-extension src #".o"))
|
||||
(target obj
|
||||
(deps src)
|
||||
(set! called (append called (list (list $< $target))))
|
||||
(copy-file $< $target #t))
|
||||
obj))
|
||||
|
||||
(default-target 'all)
|
||||
(phony 'all 'clean)
|
||||
|
||||
(target 'all
|
||||
(deps objects))
|
||||
|
||||
(target 'clean
|
||||
(apply rm-f objects)))
|
||||
|
||||
;; Definitions inside makefile remain ordinary module definitions.
|
||||
(check-equal? sources '("foo.c" "bar.c" "baz.c"))
|
||||
(check-equal? (map path->string objects) '("foo.o" "bar.o" "baz.o"))
|
||||
|
||||
(check-equal? (current-makefile-prefix) 'stuff)
|
||||
(check-true (procedure? makefile-target-stuff-all))
|
||||
(check-true (procedure? makefile-target-stuff-clean))
|
||||
|
||||
(check-equal?
|
||||
(makefile-targets 'stuff)
|
||||
(append objects '(all clean)))
|
||||
|
||||
(for ([obj objects])
|
||||
(check-true
|
||||
(procedure?
|
||||
(makefile-target-procedure 'stuff obj))))
|
||||
|
||||
(make 'all)
|
||||
|
||||
(check-equal?
|
||||
called
|
||||
'(("foo.c" "foo.o")
|
||||
("bar.c" "bar.o")
|
||||
("baz.c" "baz.o")))
|
||||
|
||||
(for ([obj objects])
|
||||
(check-true (file-exists? obj)))
|
||||
|
||||
(make 'clean)
|
||||
|
||||
(for ([obj objects])
|
||||
(check-false (file-exists? obj)))))
|
||||
(λ ()
|
||||
(delete-directory/files tmp #:must-exist? #f)))
|
||||
Reference in New Issue
Block a user