2 * Copyright (C) 2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 let eps = Wrappi_globals.get_entry_points ()
25 let nr_eps = List.length eps
27 let dump_and_exit () =
28 printf "entry points (%d):\n" nr_eps;
31 printf " %s\n" (Wrappi_types.string_of_entry_point ep)
36 (* Parse command line arguments. *)
38 let display_version () =
39 printf "%s %s\n" Config.package_name Config.package_version;
43 let argspec = Arg.align [
44 "--dump", Arg.Unit dump_and_exit, " Dump API data and exit";
45 "--version", Arg.Unit display_version, " Display version number and exit";
47 let anon_fun str = raise (Arg.Bad "generator: unknown parameter") in
50 wrappi generator - generate a lot of code
54 To run the generator normally (note it MUST be run from the top
55 level SOURCE directory):
59 Options are for debugging only:
61 ./generator/generator [--options]
64 Arg.parse argspec anon_fun usage_msg
66 let perror msg = function
67 | Unix_error (err, _, _) ->
68 eprintf "%s: %s\n" msg (error_message err)
70 eprintf "%s: %s\n" msg (Printexc.to_string exn)
73 printf "generator, %d entry points\n" nr_eps;
75 (* Acquire a lock so parallel builds won't run the generator
76 * simultaneously. It's assumed that ./configure.ac only exists in
77 * the top level source directory. Note the lock is released
78 * implicitly when the program exits.
81 try openfile "configure.ac" [O_RDWR] 0
83 | Unix_error (ENOENT, _, _) ->
85 You are probably running this from the wrong directory.
86 Run it from the top source directory using the command
87 make -C generator stamp-generator
91 perror "open: configure.ac" exn;
94 (try lockf lock_fd F_LOCK 1
96 perror "lock: configure.ac" exn;
99 (* Create a structure that we'll pass around to each generator function. *)
101 Wrappi_types.api_entry_points = eps
105 Wrappi_c.generate api;
107 printf "generated %d lines of code in %d files\n"
108 (get_lines_generated ()) (List.length (get_files_generated ()));
110 (* Create the stamp file last and unconditionally. This is used
111 * by the Makefile to know when we must rerun the generator.
113 let chan = open_out "generator/stamp-generator" in