+ 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