let OCAMLDEP = "@OCAMLDEP@"
let OCAMLFIND = "@OCAMLFIND@"
let OCAMLLEX = "@OCAMLLEX@"
-# XXX
-let CFLAGS = [ "-g", "-O2", "-I%OCAMLLIB", "-I." ]
-#let CFLAGS = "@CFLAGS@ -I%OCAMLLIB -I."
-let OCAMLFLAGS = [ "-g", "-safe-string", "-warn-error", "CDEFLMPSUVYZX+52-3" ]
-let OCAMLPACKAGES = [ "-package", "str,unix,threads", "-I", "src", "-thread" ]
-#let OCAMLFLAGS = "@OCAMLFLAGS@"
-#let OCAMLPACKAGES = "@OCAMLPACKAGES@"
+let CFLAGS = join (split ("@CFLAGS@"), ["-I%OCAMLLIB", "-I."])
+let OCAMLFLAGS = split ("@OCAMLFLAGS@")
+let OCAMLPACKAGES = join (split ("@OCAMLPACKAGES@"), ["-I", "src"])
let objects = [
# These must be in dependency order.
{ .... }
Unclear if this would be helpful or not.
-Split "flags" strings. eg. Currently there is no way to pass
-$CFLAGS from autoconf into a goalfile.
-
Make re-execs itself if the Makefile (or any include) changes, and
goals should do something similar. See:
https://www.gnu.org/software/make/manual/html_node/Remaking-Makefiles.html
This takes a list of strings and sorts it, removing duplicates.
+=head3 split (string)
+
+For example:
+
+ split ("-g -O2") β ["-g", "-O2"]
+
+Split a string using shell rules into a list of strings. This is
+commonly used for splitting C<CFLAGS> provided by autoconf into a list
+for use by goals:
+
+ let CFLAGS = split ("@CFLAGS@")
+ goal compile (name) =
+ "%name.o" : "%name.c" { %CC %CFLAGS -c %< -o %@ }
+
=head3 subst (from, to, text)
For example:
for f in %xs; do echo "$f"; done | sort -u
}
+# Split a string into a list.
+# https://superuser.com/a/1066541
+pure function split (s) returning strings = {
+ s=%s
+ eval 'for f in '$s'; do echo "$f"; done'
+}
+
# Substitute.
pure function subst (from, to, text) returning string = @{
# We need to replace any / characters in βtoβ with escaped ones.
--- /dev/null
+-g
+-O2
+-I.
+-Dvar=hello world
+-Dvar2="good bye!"
--- /dev/null
+# Goals test.
+# Copyright (C) 2020 Richard W.M. Jones
+# Copyright (C) 2020 Red Hat Inc.
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Test the split function.
+
+let xs = split (" -g -O2 -I. -Dvar=\"hello world\"
+ -Dvar2=\"\\\"good bye!\\\"\" ")
+
+goal all = { for f in %xs; do echo "$f"; done }
--- /dev/null
+#!/usr/bin/env bash
+# Goals test.
+# Copyright (C) 2020 Richard W.M. Jones
+# Copyright (C) 2020 Red Hat Inc.
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -e
+
+goals -f 10-function-split.gl > 10-function-split.out
+diff -u 10-function-split.out 10-function-split.expected
+rm 10-function-split.out