Last active
December 23, 2015 11:09
-
-
Save erincandescent/6626179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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