It now picks the default value from the number of cores.
#----------------------------------------------------------------------
# Build the goals tool itself.
+let CC = "@CC@"
+let OCAMLLIB = "@OCAMLLIB@"
let MENHIR = "@MENHIR@"
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 objects = [
# These must be in dependency order.
"src/config.cmx",
+ "src/utils-c.o",
"src/utils.cmx",
"src/cmdline.cmx",
"src/jobs.cmx",
goal tool = : ocaml_link ("src/goals", objects) ;
+# C code.
+"src/utils-c.o" : "src/utils-c.c" {
+ %CC %CFLAGS -c %< -o %@
+}
+
# Parser.
"src/parser.mli", "src/parser.ml" : "src/parser.mly" {
%MENHIR --explain %<
echo 'val lexer_read : (Lexing.lexbuf -> token) option ref' >> src/parser.mli
echo 'val eval_substitute : (Ast.env -> Ast.loc -> Ast.substs -> string) option ref' >> src/parser.mli
$(OCAMLLEX) src/lexer.mll
- $(OCAMLFIND) opt $(OCAMLFLAGS) $(OCAMLPACKAGES) -I src \
+ $(OCAMLFIND) opt $(OCAMLFLAGS) $(OCAMLPACKAGES) -I . -I src \
+ src/utils-c.c \
$$($(OCAMLDEP) -sort src/*.mli src/*.ml) \
-linkpkg -o $@
Implement more make functions, see:
https://www.gnu.org/software/make/manual/html_node/Functions.html#Functions
+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
AC_C_PROTOTYPES
test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
+dnl C headers and functions.
+AC_CHECK_HEADERS([sys/sysinfo.h])
+AC_CHECK_FUNCS([get_nprocs])
+
dnl Check for basic OCaml environment and findlib.
AC_PROG_OCAML
if test "x$OCAMLC" = "xno"; then
let input_file = ref "Goalfile"
let includes = ref [stdlibdir]
let add_include dir = includes := dir :: !includes
-let nr_jobs = ref 4 (* XXX use nproc *)
+let nr_jobs = ref (nprocs ())
let use_prelude = ref true
let parse () =
failwithf "%s: cannot find the standard library directory, expected %s. If the standard library directory is in a non-standard location then set GOALS_DATADIR. If you can trying to run goals from the build directory then use ‘./run goals ...’"
Sys.executable_name stdlibdir;
+ let jobshelp =
+ sprintf "jobs Set number of parallel jobs (default: %d)" !nr_jobs in
let argspec = [
"-C", Arg.Set_string directory,
"directory Change to directory before running";
"--include", Arg.String add_include,
"dir Add include directory";
"-j", Arg.Set_int nr_jobs,
- "jobs Set number of parallel jobs";
+ jobshelp;
"--jobs", Arg.Set_int nr_jobs,
- "jobs Set number of parallel jobs";
+ jobshelp;
"--no-prelude",Arg.Clear use_prelude,
" Do not automatically use prelude.gl from stdlib";
"-v", Arg.Unit print_version,
--- /dev/null
+/* Goalfile utilities
+ * 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.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <caml/memory.h>
+#include <caml/mlvalues.h>
+
+#ifdef HAVE_SYS_SYSINFO_H
+#include <sys/sysinfo.h>
+#endif
+
+value
+nprocs (value unitv)
+{
+ CAMLparam1 (unitv);
+ int n;
+
+#ifdef HAVE_GET_NPROCS
+ n = get_nprocs ();
+#else
+ n = 1;
+#endif
+
+ CAMLreturn (Val_int (n));
+}
open Printf
+external nprocs : unit -> int = "nprocs"
+
let failwithf fs = ksprintf failwith fs
let (//) = Filename.concat
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
+val nprocs : unit -> int
+(** Return the number of processors on the system. *)
+
val failwithf : ('a, unit, string, 'b) format4 -> 'a
(** Like [failwith] but supports printf-like arguments. *)