2 * Copyright (C) 2009-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
19 (* Please read generator/README first. *)
25 open Generator_structs
26 open Generator_api_versions
31 open Generator_capitests
38 open Generator_haskell
42 open Generator_bindtests
43 open Generator_errnostring
45 let perror msg = function
46 | Unix_error (err, _, _) ->
47 eprintf "%s: %s\n" msg (error_message err)
49 eprintf "%s: %s\n" msg (Printexc.to_string exn)
54 try openfile "BUGS" [O_RDWR] 0
56 | Unix_error (ENOENT, _, _) ->
58 You are probably running this from the wrong directory.
59 Run it from the top source directory using the command
60 make -C generator stamp-generator
64 perror "open: BUGS" exn;
67 (* Acquire a lock so parallel builds won't try to run the generator
68 * twice at the same time. Subsequent builds will wait for the first
69 * one to finish. Note the lock is released implicitly when the
72 (try lockf lock_fd F_LOCK 1
74 perror "lock: BUGS" exn;
77 (* Read the API versions file. *)
78 load_api_versions "src/api-support/added";
80 output_to "src/guestfs_protocol.x" generate_xdr;
81 output_to "src/guestfs.h" generate_guestfs_h;
82 output_to "src/guestfs-internal-actions.h" generate_internal_actions_h;
83 output_to "src/actions.c" generate_client_actions;
84 output_to "src/bindtests.c" generate_bindtests;
85 output_to "src/guestfs-structs.pod" generate_structs_pod;
86 output_to "src/guestfs-actions.pod" generate_actions_pod;
87 output_to "src/guestfs-availability.pod" generate_availability_pod;
88 output_to "src/errnostring_gperf.gperf" generate_errnostring_gperf;
89 output_to "src/errnostring.c" generate_errnostring_c;
90 output_to "src/errnostring.h" generate_errnostring_h;
91 output_to "src/MAX_PROC_NR" generate_max_proc_nr;
92 output_to "src/libguestfs.syms" generate_linker_script;
93 output_to "daemon/actions.h" generate_daemon_actions_h;
94 output_to "daemon/stubs.c" generate_daemon_actions;
95 output_to "daemon/names.c" generate_daemon_names;
96 output_to "daemon/optgroups.c" generate_daemon_optgroups_c;
97 output_to "daemon/optgroups.h" generate_daemon_optgroups_h;
98 output_to "capitests/tests.c" generate_tests;
99 output_to "fish/cmds_gperf.gperf" generate_fish_cmds_gperf;
100 output_to "fish/cmds.c" generate_fish_cmds;
101 output_to "fish/completion.c" generate_fish_completion;
102 output_to "fish/fish-cmds.h" generate_fish_cmds_h;
103 output_to "fish/guestfish-commands.pod" generate_fish_commands_pod;
104 output_to "fish/guestfish-actions.pod" generate_fish_actions_pod;
105 output_to "fish/prepopts.c" generate_fish_prep_options_c;
106 output_to "fish/prepopts.h" generate_fish_prep_options_h;
107 output_to "ocaml/guestfs.mli" generate_ocaml_mli;
108 output_to "ocaml/guestfs.ml" generate_ocaml_ml;
109 output_to "ocaml/guestfs_c_actions.c" generate_ocaml_c;
110 output_to "ocaml/bindtests.ml" generate_ocaml_bindtests;
111 output_to "perl/Guestfs.xs" generate_perl_xs;
112 output_to "perl/lib/Sys/Guestfs.pm" generate_perl_pm;
113 output_to "perl/bindtests.pl" generate_perl_bindtests;
114 output_to "python/guestfs-py.c" generate_python_c;
115 output_to "python/guestfs.py" generate_python_py;
116 output_to "python/bindtests.py" generate_python_bindtests;
117 output_to "ruby/ext/guestfs/_guestfs.c" generate_ruby_c;
118 output_to "ruby/bindtests.rb" generate_ruby_bindtests;
119 output_to "java/com/redhat/et/libguestfs/GuestFS.java" generate_java_java;
123 let cols = cols_of_struct typ in
124 let filename = sprintf "java/com/redhat/et/libguestfs/%s.java" jtyp in
125 output_to filename (generate_java_struct jtyp cols);
128 output_to "java/Makefile.inc" generate_java_makefile_inc;
129 output_to "java/com_redhat_et_libguestfs_GuestFS.c" generate_java_c;
130 output_to "java/Bindtests.java" generate_java_bindtests;
131 output_to "haskell/Guestfs.hs" generate_haskell_hs;
132 output_to "haskell/Bindtests.hs" generate_haskell_bindtests;
133 output_to "csharp/Libguestfs.cs" generate_csharp;
134 output_to "php/extension/php_guestfs_php.h" generate_php_h;
135 output_to "php/extension/guestfs_php.c" generate_php_c;
136 output_to "erlang/guestfs.erl" generate_erlang_erl;
137 output_to "erlang/erl-guestfs.c" generate_erlang_c;
139 (* Generate the list of files generated -- last. *)
140 printf "generated %d lines of code\n" (get_lines_generated ());
141 let files = List.sort compare (get_files_generated ()) in
142 output_to "generator/files-generated.txt"
143 (fun () -> List.iter (pr "%s\n") files);
145 (* Always generate this file last, and unconditionally. It's used
146 * by the Makefile to know when we must re-run the generator.
148 let chan = open_out "generator/stamp-generator" in