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