1 | ;; Contents of the (gnu make) Guile module
|
---|
2 | ;; Copyright (C) 2011-2016 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.
|
---|
14 | ;;
|
---|
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/>.
|
---|
17 |
|
---|
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 | (variable? x)
|
---|
24 | (null? x)
|
---|
25 | (and (string? x) (string-null? x)))
|
---|
26 | #f)
|
---|
27 | ;; We want something not false... not sure about this
|
---|
28 | ((eq? x #t) "#t")
|
---|
29 | ;; Basics
|
---|
30 | ((or (symbol? x) (number? x))
|
---|
31 | (object->string x))
|
---|
32 | ((char? x)
|
---|
33 | (string x))
|
---|
34 | ;; Printable string (no special characters)
|
---|
35 | ((and (string? x) (string-every char-set:printing x))
|
---|
36 | x)
|
---|
37 | ;; No idea: fail
|
---|
38 | (else (error "Unknown object:" x))))
|
---|
39 |
|
---|
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))))
|
---|
47 |
|
---|
48 | ;; Return the value of the GNU make variable V
|
---|
49 | (define (gmk-var v)
|
---|
50 | (gmk-expand (format #f "$(~a)" (obj-to-str v))))
|
---|
51 |
|
---|
52 | ;; Export the public interfaces
|
---|
53 | (export gmk-expand gmk-eval gmk-var)
|
---|