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.
26 let api = Wrappi_accumulator.get_api ()
27 let nr_tds = StringMap.cardinal api.api_typedefs
28 let nr_ens = StringMap.cardinal api.api_enums
29 let nr_sds = StringMap.cardinal api.api_structs
30 let nr_uns = StringMap.cardinal api.api_unions
31 let nr_eps = StringMap.cardinal api.api_entry_points
33 (* Extend the API with some entry points which are purely
34 * generated from other things, eg. from enums.
36 let api = Wrappi_enums.extend_api api
38 let dump_and_exit () =
39 printf "typedefs (%d):\n" nr_tds;
40 iter_typedefs api (fun td -> printf " %s\n" (string_of_typedef td));
42 printf "enums (%d):\n" nr_ens;
43 iter_enums api (fun en -> printf " %s\n" (string_of_enum en));
45 printf "structs (%d):\n" nr_sds;
46 iter_structs api (fun sd -> printf " %s\n" (string_of_struct sd));
48 printf "unions (%d):\n" nr_uns;
49 iter_unions api (fun un -> printf " %s\n" (string_of_union un));
51 printf "entry points (%d):\n" nr_eps;
52 iter_entry_points api (fun ep -> printf " %s\n" (string_of_entry_point ep));
56 (* Parse command line arguments. *)
58 let display_version () =
59 printf "%s %s\n" Config.package_name Config.package_version;
63 let argspec = Arg.align [
64 "--dump", Arg.Unit dump_and_exit, " Dump API data and exit";
65 "--version", Arg.Unit display_version, " Display version number and exit";
67 let anon_fun str = raise (Arg.Bad "generator: unknown parameter") in
70 wrappi generator - generate a lot of code
74 To run the generator normally (note it MUST be run from the top
75 level SOURCE directory):
79 Options are for debugging only:
81 ./generator/generator [--options]
84 Arg.parse argspec anon_fun usage_msg
86 let perror msg = function
87 | Unix_error (err, _, _) ->
88 eprintf "%s: %s\n" msg (error_message err)
90 eprintf "%s: %s\n" msg (Printexc.to_string exn)
93 printf "generator, %d typedefs, %d enums, %d structs, %d unions, %d entry points\n"
94 nr_tds nr_ens nr_sds nr_uns nr_eps;
96 (* Acquire a lock so parallel builds won't run the generator
97 * simultaneously. It's assumed that ./configure.ac only exists in
98 * the top level source directory. Note the lock is released
99 * implicitly when the program exits.
102 try openfile "configure.ac" [O_RDWR] 0
104 | Unix_error (ENOENT, _, _) ->
106 You are probably running this from the wrong directory.
107 Run it from the top source directory using the command
108 make -C generator stamp-generator
112 perror "open: configure.ac" exn;
115 (try lockf lock_fd F_LOCK 1
117 perror "lock: configure.ac" exn;
121 Wrappi_c_impl.generate api;
122 Wrappi_c.generate api;
124 printf "generated %d lines of code in %d files\n"
125 (get_lines_generated ()) (List.length (get_files_generated ()));
127 (* Create the stamp file last and unconditionally. This is used
128 * by the Makefile to know when we must rerun the generator.
130 let chan = open_out "generator/stamp-generator" in