ubuntu: Add extra suppressions for libnl.1 leaks.
[libguestfs.git] / generator / generator_main.ml
1 (* libguestfs
2  * Copyright (C) 2009-2011 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_erlang
42 open Generator_bindtests
43 open Generator_errnostring
44
45 let perror msg = function
46   | Unix_error (err, _, _) ->
47       eprintf "%s: %s\n" msg (error_message err)
48   | exn ->
49       eprintf "%s: %s\n" msg (Printexc.to_string exn)
50
51 (* Main program. *)
52 let () =
53   let lock_fd =
54     try openfile "BUGS" [O_RDWR] 0
55     with
56     | Unix_error (ENOENT, _, _) ->
57         eprintf "\
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
61 ";
62         exit 1
63     | exn ->
64         perror "open: BUGS" exn;
65         exit 1 in
66
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
70    * program exits.
71    *)
72   (try lockf lock_fd F_LOCK 1
73    with exn ->
74      perror "lock: BUGS" exn;
75      exit 1);
76
77   (* Read the API versions file. *)
78   load_api_versions "src/api-support/added";
79
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;
120
121   List.iter (
122     fun (typ, jtyp) ->
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);
126   ) java_structs;
127
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;
138
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);
144
145   (* Always generate this file last, and unconditionally.  It's used
146    * by the Makefile to know when we must re-run the generator.
147    *)
148   let chan = open_out "generator/stamp-generator" in
149   fprintf chan "1\n";
150   close_out chan