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.
23 open Wrappi_boilerplate
28 let generate_implementation ep =
29 generate_header CStyle LGPLv2plus;
39 #include \"internal.h\"
43 (* Depending on whether this is a local or remote function, include
44 * different definitions here.
46 (*if ep.ep_local then ... *)
48 (* Make a unique, reproducible filename for each entry point. *)
49 let filename_of_ep ep =
50 let filename = Loc.file_name ep.ep_loc in
51 let filename = Filename.basename filename in
53 try Filename.chop_extension filename
54 with Invalid_argument _ -> filename in
55 let filename = sprintf "%s-%s.c" filename ep.ep_name in
58 let generate_lib_implementation_files_mk api =
59 generate_header HashStyle GPLv2plus;
61 let eps = StringMap.bindings api.api_entry_points in
62 let cmp (a, _) (b, _) = compare a b in
63 let eps = List.sort cmp eps in
64 let eps = List.map snd eps in
66 let rec loop = function
68 | [ep] -> pr "\t%s\n" (filename_of_ep ep)
69 | ep :: eps -> pr "\t%s \\\n" (filename_of_ep ep); loop eps
72 pr "local_implementation_files := \\\n";
74 loop (List.filter (fun ep -> ep.ep_local) eps);
77 pr "remote_implementation_files := \\\n";
79 loop (List.filter (fun ep -> not ep.ep_local) eps)
82 let gitignores = ref [] in
84 iter_entry_points api (
86 let filename = filename_of_ep ep in
88 gitignores := ("/" ^ filename) :: !gitignores;
90 output_to ("lib/" ^ filename) generate_implementation ep
93 let gitignores = List.rev !gitignores in
94 output_to "lib/.gitignore"
95 (fun () -> List.iter (pr "%s\n") gitignores) ();
97 output_to "lib/implementation_files.mk"
98 generate_lib_implementation_files_mk api