write a make rule for the modules a unit reads
An import pastes another file's forms into the output, so a Makefile had to make every object depend on every .sex. --depfile names the modules read, including those read only for an import's interface, with an empty rule for each, as cc -MD -MP does. Fixes #40.
This commit is contained in:
30
sexc.scm
30
sexc.scm
@@ -64,6 +64,11 @@
|
||||
(required #f)
|
||||
(value #t)
|
||||
(single-char #\o))
|
||||
(depfile
|
||||
,(fmt #f "Write a make rule for the output to FILE: it depends on" nl
|
||||
(pad padding) "the source and on every module read for it. Needs -o")
|
||||
(required #f)
|
||||
(value #t))
|
||||
(line-directives
|
||||
,(fmt #f "How much #line information to emit: statement (default)," nl
|
||||
(pad padding) "toplevel, or none. `statement' is what makes a debugger" nl
|
||||
@@ -150,6 +155,28 @@
|
||||
(map pp sex-forms)
|
||||
(emit-c sex-forms)))))
|
||||
|
||||
;;; app.o: app.sex /m/greet.sex, and an empty rule per module, so that
|
||||
;;; make takes a module deleted since as out of date rather than as a
|
||||
;;; file it has no rule to make
|
||||
(define (dependency-rule target source modules)
|
||||
(let ((spell (lambda (path) (string-translate* path '((" " . "\\ "))))))
|
||||
(apply string-append
|
||||
(spell target) ":"
|
||||
(append (map (lambda (path) (string-append " " (spell path)))
|
||||
(if source (cons source modules) modules))
|
||||
(list "\n")
|
||||
(map (lambda (path) (string-append "\n" (spell path) ":\n"))
|
||||
modules)))))
|
||||
|
||||
(define (write-dependencies depfile output input)
|
||||
(when (or (eq? output 'default) (equal? output "-"))
|
||||
(error "--depfile needs -o, to name what depends on the modules"))
|
||||
(with-output-to-file depfile
|
||||
(lambda ()
|
||||
(display (dependency-rule output
|
||||
(and (not (eq? input 'stdin)) input)
|
||||
(module-dependencies))))))
|
||||
|
||||
(define (compile-to-file sex-forms output args cc-args)
|
||||
"Hand the generated C to the C compiler. Returns the compiler's exit
|
||||
status, which is ours to pass on."
|
||||
@@ -255,6 +282,9 @@ status, which is ours to pass on."
|
||||
(sex-line-directives 'none))
|
||||
|
||||
(let ((sex-forms (semantic-process-forms (read-raw-forms input) input)))
|
||||
(let ((depfile (get-arg args 'depfile #f)))
|
||||
(when depfile
|
||||
(write-dependencies depfile output input)))
|
||||
(if (or (get-arg args 'macro-expand #f)
|
||||
(get-arg args 'emit-c #f))
|
||||
;; Emit processed and macro-expanded sex code, or emit C code
|
||||
|
||||
Reference in New Issue
Block a user