configure: Fix info about virt-resize when OCaml bindings are disabled.
[libguestfs.git] / generator / generator_main.ml
1 (* libguestfs
2  * Copyright (C) 2009-2010 Red Hat Inc.
3  *
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.
8  *
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.
13  *
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
17  *)
18
19 (* Please read generator/README first. *)
20
21 open Unix
22 open Printf
23
24 open Generator_pr
25 open Generator_structs
26 open Generator_api_versions
27
28 open Generator_c
29 open Generator_xdr
30 open Generator_daemon
31 open Generator_capitests
32 open Generator_fish
33 open Generator_ocaml
34 open Generator_perl
35 open Generator_python
36 open Generator_ruby
37 open Generator_java
38 open Generator_haskell
39 open Generator_csharp
40 open Generator_php
41 open Generator_bindtests
42 open Generator_errnostring
43
44 let perror msg = function
45   | Unix_error (err, _, _) ->
46       eprintf "%s: %s\n" msg (error_message err)
47   | exn ->
48       eprintf "%s: %s\n" msg (Printexc.to_string exn)
49
50 (* Main program. *)
51 let () =
52   let lock_fd =
53     try openfile "BUGS" [O_RDWR] 0
54     with
55     | Unix_error (ENOENT, _, _) ->
56         eprintf "\
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
60 ";
61         exit 1
62     | exn ->
63         perror "open: BUGS" exn;
64         exit 1 in
65
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
69    * program exits.
70    *)
71   (try lockf lock_fd F_LOCK 1
72    with exn ->
73      perror "lock: BUGS" exn;
74      exit 1);
75
76   (* Read the API versions file. *)
77   load_api_versions "src/api-support/added";
78
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;
118
119   List.iter (
120     fun (typ, jtyp) ->
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);
124   ) java_structs;
125
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;
134
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);
140
141   (* Always generate this file last, and unconditionally.  It's used
142    * by the Makefile to know when we must re-run the generator.
143    *)
144   let chan = open_out "generator/stamp-generator" in
145   fprintf chan "1\n";
146   close_out chan