[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using guile as an extension language for GNU make

From: Thien-Thi Nguyen
Subject: Re: Using guile as an extension language for GNU make
Date: Tue, 20 Sep 2011 18:17:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

() Paul Smith <address@hidden>
() Mon, 19 Sep 2011 11:14:34 -0400

   In make, everything is just words: broken up on whitespace.  So for
   example, maybe someone writes a Guile function that computes a complex
   set of prerequisites for a target:

           target: $(guile (...some Guile program...))

Even before thinking about the return value (which, scanning ahead,
you seem to have hit upon a workable plan), i have some questions
about the "some Guile program":

- Is that just a procedure call or can it be definition(s) + expression(s)?
  e.g., single proc call:
    $(guile (compute-complex-prerequisites "$@"))
  e.g., complex:
    $(guile (use-modules (srfi srfi-13))
            (define (ext filename)
              (string-append filename ".ext"))
            (define (ext-all ls)
              (map ext ls))
            (define normalize  ;;; nb: alias
            (define (compute-complex-prerequisites s)
              (ext-all (normalize s)))
            ;; comment: do it!
            (trace 'compute-complex-prerequisites "$@")
            (compute-complex-prerequisites "$@"))

- (if the former) How would ‘compute-complex-prerequisites’ be defined?

- Would stuff like ‘normalize’ and ‘trace’ be provided (builtin)?

- What happens if the stuff inside the double quotes includes
  $(call...) or $(eval...)?  What about those constructs elsewhere?

   Then I'd like to convert a list like '(dep1 dep2 dep3) into a string "dep1
   dep2 dep3" (not "(dep1 dep2 dep3)" as display would do).

   But of course each element of the list could be something more complex,
   as well.  So it gets tricky.

In Scheme, w/ SRFI 13, you could express this as:

(define (as-string x)
  (cond ((not x) "")
        ((unspecified? x) "")
        ((eq? #t x) "t")
        ((string? x) x)
        ((null? x) "")
        (else (object->string x))))
(define (space-sep x)
  (let ((acc '()))
    (define (walk x)
      (cond ((pair? x)
             (walk (car x))
             (walk (cdr x)))
            ((null? x))
             (set! acc (cons x acc)))))
    (walk x)
    (string-join (map as-string (reverse! acc)))))
This is not so tricky, i think.

   Yes but implementing it in C, with the memory management etc., would be
   a lot of (not fun/interesting) work.

   Hm.  I guess I could write a little Guile program to do it for me :-).

Yes, that's the idea!

   Well, since Guile is not required and I want GNU make to continue to
   work as-is on systems where Guile is not available, I won't be rewriting
   core features in Guile.   Yet?!?!  :-).

IMHO ‘patsubst’ is not a core feature (sez the spewful ignoramus).  Rather,
i think rewriting ‘patsubst’ would be a good exercise to help you formulate
and answer questions about small technical details that will eventually serve
as a foundation for rewriting core features.  Why not give it a try?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]