Add GNU Guile as an optional embedded scripting language for make.
[make.git] / tests / scripts / functions / guile
blob82c02bcc976cc7f7402e199bb57128dc573e7f1e
1 #                                                                    -*-perl-*-
3 $description = 'Test the $(guile ...) function.';
5 $details = 'This only works on systems that support it.';
7 # If this instance of make doesn't support GNU Guile, skip it
8 exists $FEATURES{guile} or return -1;
10 # Verify simple data type conversions
11 # Currently we don't support vectors:
12 #    echo '$(guile (vector 1 2 3))'; \
13 run_make_test(q!
14 x:;@echo '$(guile #f)'; \
15     echo '$(guile #t)'; \
16     echo '$(guile #\c)'; \
17     echo '$(guile 1234)'; \
18     echo '$(guile 'foo)'; \
19     echo '$(guile "bar")'; \
20     echo '$(guile (cons 'a 'b))'; \
21     echo '$(guile '(a b (c . d) 1 (2) 3))'
23               '', "\n#t\nc\n1234\nfoo\nbar\na b\na b c d 1 2 3");
25 # Verify the gmk-expand function
26 run_make_test(q!
27 VAR = $(guile (gmk-expand "$(shell echo hi)"))
28 x:;@echo '$(VAR)'
30               '', "hi");
32 # Verify the gmk-eval function
33 run_make_test(q!
34 $(guile (gmk-eval "VAR = hi $(shell echo there)"))
35 x:;@echo '$(VAR)'
37               '', "hi there");
39 # Verify the gmk-eval function with a list
40 run_make_test(q!
41 $(guile (gmk-eval '(VAR = 1 (2) () 3)))
42 x:;@echo '$(VAR)'
44               '', "1 2 3");
46 # Verify the gmk-var function
47 run_make_test(q!
48 VALUE = hi $(shell echo there)
49 VAR = $(guile (gmk-var "VALUE"))
50 x:;@echo '$(VAR)'
52               '', "hi there");
54 # Verify the gmk-var function with a symbol
55 run_make_test(q!
56 VALUE = hi $(shell echo there)
57 VAR = $(guile (gmk-var 'VALUE))
58 x:;@echo '$(VAR)'
60               '', "hi there");
62 # Write a Guile program using define and run it
63 run_make_test(q!
64 # Define the "fib" function in Guile
65 define fib
66 ;; A procedure for counting the n:th Fibonacci number
67 ;; See SICP, p. 37
68 (define (fib n)
69   (cond ((= n 0) 0)  
70         ((= n 1) 1)
71         (else (+ (fib (- n 1))
72                  (fib (- n 2))))))
73 endef
74 $(guile $(fib))
76 # Now run it
77 x:;@echo $(guile (fib $(FIB)))
79               'FIB=10', "55");