mirror of
https://git.savannah.gnu.org/git/make.git
synced 2024-11-24 20:20:35 +00:00
adb50bd4c9
The new GNU Maintainer's Manual allows the use of year ranges in certain situations; take advantage of this simplification.
57 lines
1.8 KiB
Scheme
57 lines
1.8 KiB
Scheme
;; Contents of the (gnu make) Guile module
|
|
;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
|
|
;; This file is part of GNU Make.
|
|
;;
|
|
;; GNU Make is free software; you can redistribute it and/or modify it under
|
|
;; the terms of the GNU General Public License as published by the Free
|
|
;; Software Foundation; either version 3 of the License, or (at your option)
|
|
;; any later version.
|
|
;;
|
|
;; GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
;; details.
|
|
;;
|
|
;; You should have received a copy of the GNU General Public License along
|
|
;; with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
(define (to-string-maybe x)
|
|
(cond
|
|
;; In GNU make, "false" is the empty string
|
|
((or (not x)
|
|
(unspecified? x)
|
|
(variable? x)
|
|
(null? x)
|
|
(and (string? x) (string-null? x)))
|
|
#f)
|
|
;; We want something not false... not sure about this
|
|
((eq? x #t) "#t")
|
|
;; Basics
|
|
((or (symbol? x) (number? x))
|
|
(object->string x))
|
|
((char? x)
|
|
(string x))
|
|
;; Printable string (no special characters)
|
|
((and (string? x) (string-every char-set:printing x))
|
|
x)
|
|
;; No idea: fail
|
|
(else (error "Unknown object:" x))))
|
|
|
|
(define (obj-to-str x)
|
|
(let ((acc '()))
|
|
(define (walk x)
|
|
(cond ((pair? x) (walk (car x)) (walk (cdr x)))
|
|
((to-string-maybe x) => (lambda (s) (set! acc (cons s acc))))))
|
|
(walk x)
|
|
(string-join (reverse! acc))))
|
|
|
|
;; eval (GNU make eval) the input string S
|
|
(define (gmk-eval s)
|
|
(gmk-expand (format #f "$(eval ~a)" (obj-to-str s))))
|
|
|
|
;; Return the value of the GNU make variable V
|
|
(define (gmk-var v)
|
|
(gmk-expand (format #f "$(~a)" (obj-to-str v))))
|
|
|
|
;; Export the public interfaces
|
|
(export gmk-expand gmk-eval gmk-var)
|