2 * Copyright (C) 2019 Richard W.M. Jones
3 * Copyright (C) 2019 Red Hat Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 (* See also "let id" in [lexer.mll]. *)
26 Str.regexp "\\([a-zA-Z_][a-zA-Z0-9_]*\\)[ \t]*=[ \t]*\\(.*\\)"
30 goals: Build software.
32 goals [-f Goalfile] ['var=value' ...] ['target' ...]
34 For detailed help see goals(1).
39 (* Command line arguments. *)
40 let filename = ref "Goalfile" in
43 "-f", Arg.Set_string filename,
44 "filename Set name of Goalfile";
45 "--file", Arg.Set_string filename,
46 "filename Set name of Goalfile";
48 let argspec = Arg.align argspec in
50 let anon_fun s = args := s :: !args in
51 Arg.parse argspec anon_fun usage;
53 (*let args = List.rev !args in*)
54 let filename = !filename in
56 (* Parse the input file. *)
57 let env = Parse.parse_goalfile filename in
59 (* Parse the command line anon args. Each parameter has the
60 * form "name=<expr>" to assign a value to a variable, or
61 * "<expr>" to indicate a target to build.
63 let targets = ref [] in
67 if Str.string_match var_regexp arg 0 then (
69 let name = Str.matched_group 1 arg in
70 let expr = Parse.parse_cli_expr (Str.matched_group 2 arg) in
71 env := Ast.StringMap.add name expr !env
75 let expr = Parse.parse_cli_expr arg in
76 targets := expr :: !targets
79 let targets = List.rev !targets and env = !env in
81 (* If no target was set on the command line, use "all ()". *)
83 if targets <> [] then targets
84 else [Ast.ECall ("all", [])] in
86 (*Ast.print_env stdout env;*)
88 (* Evaluate the target expressions in turn. *)
89 Eval.evaluate env targets