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