From f9fc3966a7a1dba91bab09c7e35e84671a99275d Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 3 Jan 2020 21:45:34 +0000 Subject: [PATCH] stdlib: Implement wildcard function. --- Goalfile.in | 6 +++--- stdlib/prelude.gl | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Goalfile.in b/Goalfile.in index aec3e5f..4a80a3f 100644 --- a/Goalfile.in +++ b/Goalfile.in @@ -73,15 +73,15 @@ goal maintainer-clean = : clean { %OCAMLLEX %< } -# XXX Depends on *.ml *.mli, but we don't have a function for this yet. # XXX Goalfile itself depends on this and we should probably have a # way to reevaluate it. # XXX Atomic output. -goal depend () = "src/.depend" : { +goal depend () = +"src/.depend" : wildcard ("src/*.ml"), wildcard ("src/*.mli") { rm -f %@ %@-t # Like many existing tools, ocamldep produces make-compatible # output which doesn't work directly in goals. - %OCAMLDEP -all -one-line src/*.ml src/*.mli | + %OCAMLDEP -all -one-line %< | sed 's|[./[:alnum:]]\+|"&"|g' | sed 's|" "|", "|g' | sed 's|.*|& ;|' > %@-t diff --git a/stdlib/prelude.gl b/stdlib/prelude.gl index 5b8818a..15b1c0b 100644 --- a/stdlib/prelude.gl +++ b/stdlib/prelude.gl @@ -17,7 +17,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # This file is included first and automatically in all Goalfiles -# (unless you use --no-prelude). It contains standard goals and +# (unless you use --no-prelude). It contains standard functions and # tactics. # The only tactic that ‘make’ has. @@ -36,3 +36,14 @@ tactic *file (filename) = { tactic *exists (filename) = { test -f %filename || exit 99 } + +# Expand a wildcard into a list of filenames. +function wildcard (wc) = { + shopt -s nullglob + # Note that the substitution is quoted by goals, so to expand + # it we must assign it to a variable and then use it unquoted. + wc=%wc + for f in $wc; do + echo "$f" + done +} -- 1.8.3.1