Update copyright notices.
[make.git] / gmk-default.scm
blobb9161c4e2dfb0b8b8c211a9278ee57fa269c4487
1 ;; Contents of the (gnu make) Guile module
2 ;; Copyright (C) 2011, 2012 Free Software Foundation, Inc.
3 ;; This file is part of GNU Make.
4 ;;
5 ;; GNU Make is free software; you can redistribute it and/or modify it under
6 ;; the terms of the GNU General Public License as published by the Free
7 ;; Software Foundation; either version 3 of the License, or (at your option)
8 ;; any later version.
9 ;;
10 ;; GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 ;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13 ;; details.
15 ;; You should have received a copy of the GNU General Public License along
16 ;; with this program.  If not, see <http://www.gnu.org/licenses/>.
18 (define (to-string-maybe x)
19   (cond
20    ;; In GNU make, "false" is the empty string
21    ((or (not x)
22         (unspecified? x)
23         (null? x)
24         (and (string? x) (string-null? x)))
25     #f)
26    ;; We want something not false... not sure about this
27    ((eq? x #t) "#t")
28    ;; Basics
29    ((or (symbol? x) (number? x))
30     (object->string x))
31    ((char? x)
32     (string x))
33    ;; Printable string (no special characters)
34    ((and (string? x)
35          (eq? (string-length (string-delete x char-set:printing)) 0))
36     x)
37    ;; No idea: fail
38    (else (error "Unknown object:" x))))
40 (define (obj-to-str x)
41   (let ((acc '()))
42     (define (walk x)
43       (cond ((pair? x) (walk (car x)) (walk (cdr x)))
44             ((to-string-maybe x) => (lambda (s) (set! acc (cons s acc))))))
45     (walk x)
46     (string-join (reverse! acc))))
48 ;; eval (GNU make eval) the input string S
49 (define (gmk-eval s)
50   (gmk-expand (format #f "$(eval ~a)" (obj-to-str s))))
52 ;; Return the value of the GNU make variable V
53 (define (gmk-var v)
54   (gmk-expand (format #f "$(~a)" (obj-to-str v))))
56 ;; Export the public interfaces
57 (export gmk-expand gmk-eval gmk-var)