* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
+open Unix
open Printf
+open Wrappi_pr
+
let eps = Wrappi_globals.get_entry_points ()
+let nr_eps = List.length eps
let dump_and_exit () =
- printf "entry points:\n";
+ printf "entry points (%d):\n" nr_eps;
List.iter (fun ep ->
printf " %s\n" (Wrappi_types.string_of_entry_point ep)
in
let argspec = Arg.align [
- "--dump", Arg.Unit dump_and_exit, " Dump API data and exit.";
- "--version", Arg.Unit display_version, " Display version number and exit.";
+ "--dump", Arg.Unit dump_and_exit, " Dump API data and exit";
+ "--version", Arg.Unit display_version, " Display version number and exit";
] in
let anon_fun str = raise (Arg.Bad "generator: unknown parameter") in
- let usage_msg = "wrappi generator: generates lots of code
+ let usage_msg = "
+NAME
+ wrappi generator - generate a lot of code
+
+SYNOPSIS
To run the generator normally (note it MUST be run from the top
level SOURCE directory):
OPTIONS" in
Arg.parse argspec anon_fun usage_msg
+let perror msg = function
+ | Unix_error (err, _, _) ->
+ eprintf "%s: %s\n" msg (error_message err)
+ | exn ->
+ eprintf "%s: %s\n" msg (Printexc.to_string exn)
+
let () =
- printf "generator, %d entry points\n" (List.length eps)
+ printf "generator, %d entry points\n" nr_eps;
+
+ (* Acquire a lock so parallel builds won't run the generator
+ * simultaneously. It's assumed that ./configure.ac only exists in
+ * the top level source directory. Note the lock is released
+ * implicitly when the program exits.
+ *)
+ let lock_fd =
+ try openfile "configure.ac" [O_RDWR] 0
+ with
+ | Unix_error (ENOENT, _, _) ->
+ eprintf "\
+You are probably running this from the wrong directory.
+Run it from the top source directory using the command
+ make -C generator stamp-generator
+";
+ exit 1
+ | exn ->
+ perror "open: configure.ac" exn;
+ exit 1 in
+
+ (try lockf lock_fd F_LOCK 1
+ with exn ->
+ perror "lock: configure.ac" exn;
+ exit 1);
+
+ (* Create a structure that we'll pass around to each generator function. *)
+ let api = {
+ Wrappi_types.api_entry_points = eps
+ } in
+
+ (* Generate code. *)
+ Wrappi_c.generate api;
+
+ printf "generated %d lines of code in %d files\n"
+ (get_lines_generated ()) (List.length (get_files_generated ()));
+
+ (* Create the stamp file last and unconditionally. This is used
+ * by the Makefile to know when we must rerun the generator.
+ *)
+ let chan = open_out "generator/stamp-generator" in
+ fprintf chan "1\n";
+ close_out chan