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 let dump_and_exit () =
34 printf "typedefs (%d):\n" nr_tds;
35 iter_typedefs api (fun td -> printf " %s\n" (string_of_typedef td));
37 printf "enums (%d):\n" nr_ens;
38 iter_enums api (fun en -> printf " %s\n" (string_of_enum en));
40 printf "structs (%d):\n" nr_sds;
41 iter_structs api (fun sd -> printf " %s\n" (string_of_struct sd));
43 printf "unions (%d):\n" nr_uns;
44 iter_unions api (fun un -> printf " %s\n" (string_of_union un));
46 printf "entry points (%d):\n" nr_eps;
47 iter_entry_points api (fun ep -> printf " %s\n" (string_of_entry_point ep));
51 (* Parse command line arguments. *)
53 let display_version () =
54 printf "%s %s\n" Config.package_name Config.package_version;
58 let argspec = Arg.align [
59 "--dump", Arg.Unit dump_and_exit, " Dump API data and exit";
60 "--version", Arg.Unit display_version, " Display version number and exit";
62 let anon_fun str = raise (Arg.Bad "generator: unknown parameter") in
65 wrappi generator - generate a lot of code
69 To run the generator normally (note it MUST be run from the top
70 level SOURCE directory):
74 Options are for debugging only:
76 ./generator/generator [--options]
79 Arg.parse argspec anon_fun usage_msg
81 let perror msg = function
82 | Unix_error (err, _, _) ->
83 eprintf "%s: %s\n" msg (error_message err)
85 eprintf "%s: %s\n" msg (Printexc.to_string exn)
88 printf "generator, %d typedefs, %d enums, %d structs, %d unions, %d entry points\n"
89 nr_tds nr_ens nr_sds nr_uns nr_eps;
91 (* Acquire a lock so parallel builds won't run the generator
92 * simultaneously. It's assumed that ./configure.ac only exists in
93 * the top level source directory. Note the lock is released
94 * implicitly when the program exits.
97 try openfile "configure.ac" [O_RDWR] 0
99 | Unix_error (ENOENT, _, _) ->
101 You are probably running this from the wrong directory.
102 Run it from the top source directory using the command
103 make -C generator stamp-generator
107 perror "open: configure.ac" exn;
110 (try lockf lock_fd F_LOCK 1
112 perror "lock: configure.ac" exn;
116 Wrappi_c.generate api;
118 printf "generated %d lines of code in %d files\n"
119 (get_lines_generated ()) (List.length (get_files_generated ()));
121 (* Create the stamp file last and unconditionally. This is used
122 * by the Makefile to know when we must rerun the generator.
124 let chan = open_out "generator/stamp-generator" in