Skip to content

Instantly share code, notes, and snippets.

@erincandescent
Last active December 23, 2015 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erincandescent/6626179 to your computer and use it in GitHub Desktop.
Save erincandescent/6626179 to your computer and use it in GitHub Desktop.
(let (languages (make-eqv-hashtable))
(define add-language (lambda (name func)
(hashtable-set! languages name func)
))
(define object (lambda (src)
(let ((error (lambda () (fatal! "Unknown language src"))))
((hashtable-ref languages name error) src)
)
))
)
(add-language ("c") (lambda (input)
(let ((output (replace-ext input "o")))
(actions (output) (input) (
((CC) -o (output) (input) (CFLAGS))
))
(output)
)
))
(add-language ("cpp" "cxx" "cc" "C") (lambda (input)
(let ((output (replace-ext input "o")))
(actions (output) (input) (
((CXX) -o (output) (input) (CFLAGS))
))
(output)
)
))
(define link (lambda (output objs)
(actions (output) objs (
((LD) -o (output) (objs) (LDFLAGS) (LDLIBS))
))
))
(define objects (lambda (srcs))
(if (null? srcs)
'()
(cons (object (car srcs)) (objects (cdr srcs)))
)
))
(define executable (lambda (output sources)
(link output (objects sources))
))
# In the Makefile
(executable "hello" '("hello.c"))
(executable "hello++" '("hello++.cc"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment