1 /**************************************************************************
3 forb-idl-main.c (Driver program for the IDL parser & backend)
5 Copyright (C) 1999 Elliot Lee
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 $Id: forb-idl-main.c 2060 2008-05-19 21:11:07Z tml $
23 ***************************************************************************/
31 #include <libIDL/IDL.h>
32 #include <glib/goption.h>
33 #include <glib/gi18n.h>
34 #include "forb_config.h"
36 #include "forb-idl2.h"
42 /* FIXME: this program doesn't seem to support i18n? */
43 #ifndef GETTEXT_PACKAGE
44 #define GETTEXT_PACKAGE NULL
47 /* Settings made from the command line (prefaced with cl_) */
48 static gboolean cl_disable_stubs = FALSE,
49 cl_disable_skels = FALSE,
50 cl_disable_common = FALSE,
51 cl_disable_headers = FALSE,
52 cl_enable_skeleton_impl = FALSE;
53 static int cl_idlwarnlevel = 2;
54 static int cl_debuglevel = 0;
55 static int cl_is_pidl = 0;
56 static int cl_disable_idata = 0;
57 static int cl_enable_imodule = 0;
58 static int cl_add_imodule = 0;
59 static gboolean cl_disable_defs_skels = FALSE;
60 static gboolean cl_showcpperrors = FALSE;
61 static char *cl_output_lang = "c";
62 static char *cl_header_guard_prefix = "";
63 static char *cl_backend_dir = NULL;
64 static gboolean cl_onlytop = TRUE;
65 static char *cl_deps_file = NULL;
66 static char *cl_output_directory = "";
67 static char **idl_files = NULL;
69 #define BASE_CPP_ARGS "-D__FORB_IDL__ "
70 static GString *cl_cpp_args;
72 /* Callbacks for goption */
75 cl_libIDL_version_callback (const char *option_name,
80 g_print("libIDL %s (CORBA %s)\n",
81 IDL_get_libver_string(),
82 IDL_get_IDLver_string());
87 cl_cpp_define_callback (const char *option_name,
92 g_string_append_printf (cl_cpp_args, "-D%s ", value);
97 cl_cpp_include_callback (const char *option_name,
102 g_string_append_printf (cl_cpp_args, "-I%s ", value);
107 cl_version_callback (const char *option_name,
112 g_print ("forb-idl-2 %s - serial %d\n",
113 VERSION, FORB_CONFIG_SERIAL);
117 /* static gboolean */
118 /* cl_c_output_formatter_callback (const char *option_name, */
119 /* const char *value, */
121 /* GError **error) */
123 /* g_warning ("Do not use the 'c-output-formatter' option. It is ignored and will soon go away."); */
127 static const GOptionEntry cl_libIDL_goptions[] = {
128 { "libIDL-version", 0, 0, G_OPTION_ARG_CALLBACK, cl_libIDL_version_callback, N_("Show version of libIDL used"), NULL },
132 static const GOptionEntry cl_cpp_goptions[] = {
133 { "define", 'D', G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, cl_cpp_define_callback, N_("Define value in preprocessor"), N_("DEFINE") },
134 { "include", 'I', G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, cl_cpp_include_callback, N_("Add search path for include files"), N_("DIR") },
138 static const GOptionEntry goptions[] = {
139 { "version", 'v', 0, G_OPTION_ARG_CALLBACK, cl_version_callback, N_("Output compiler version and serial"), NULL },
140 { "lang", 'l', 0, G_OPTION_ARG_STRING, &cl_output_lang, N_("Output language (default is C)"), N_("LANG") },
141 { "debug", 'd', 0, G_OPTION_ARG_INT, &cl_debuglevel, N_("Debug level (0 to 4)"), N_("LEVEL") },
142 { "idlwarnlevel", 0, 0, G_OPTION_ARG_INT, &cl_idlwarnlevel, N_("IDL warning level (0 to 4, default is 2)"), N_("LEVEL") },
143 { "showcpperrors", 0, 0, G_OPTION_ARG_NONE, &cl_showcpperrors, N_("Show CPP errors"), NULL },
144 { "nostubs", 0, 0, G_OPTION_ARG_NONE, &cl_disable_stubs, N_("Don't output stubs"), NULL },
145 { "noskels", 0, 0, G_OPTION_ARG_NONE, &cl_disable_skels, N_("Don't output skels"), NULL },
146 { "nocommon", 0, 0, G_OPTION_ARG_NONE, &cl_disable_common, N_("Don't output common"), NULL },
147 { "noheaders", 0, 0, G_OPTION_ARG_NONE, &cl_disable_headers, N_("Don't output headers"), NULL },
148 /* { "noidata", 0, 0, G_OPTION_ARG_NONE, &cl_disable_idata, N_("Don't generate Interface type data"), NULL }, */
149 /* { "imodule", 'i', 0, G_OPTION_ARG_NONE, &cl_enable_imodule, N_("Output only an imodule file"), NULL }, */
150 /* { "add-imodule", 0, 0, G_OPTION_ARG_NONE, &cl_add_imodule, N_("Output an imodule file"), NULL }, */
151 /* { "skeleton-impl", 0, 0, G_OPTION_ARG_NONE, &cl_enable_skeleton_impl, N_("Output skeleton implementation"), NULL }, */
152 { "backenddir", 0, 0, G_OPTION_ARG_FILENAME, &cl_backend_dir, N_("Override IDL backend library directory"), N_("DIR") },
153 /* { "c-output-formatter", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, &cl_c_output_formatter_callback, "DEPRECATED and IGNORED", "PROGRAM" }, */
154 { "onlytop", 0, 0, G_OPTION_ARG_NONE, &cl_onlytop, N_("Inhibit includes"), NULL },
155 { "pidl", 0, 0, G_OPTION_ARG_NONE, &cl_is_pidl, N_("Treat as Pseudo IDL"), NULL },
156 { "nodefskels", 0, 0, G_OPTION_ARG_NONE, &cl_disable_defs_skels, N_("Don't output defs for skels in header"), NULL },
157 { "deps", 0, 0, G_OPTION_ARG_FILENAME, &cl_deps_file, N_("Generate dependency info suitable for inclusion in Makefile"), N_("FILENAME") },
158 { "headerguardprefix", 0, 0, G_OPTION_ARG_STRING, &cl_header_guard_prefix, N_("Prefix for #ifdef header guards. Sometimes useful to avoid conflicts."), N_("PREFIX") },
159 { "output-dir", 0, 0, G_OPTION_ARG_FILENAME, &cl_output_directory, N_("Where to put generated files. This directory must exist."), N_("DIR") },
160 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &idl_files, NULL, N_("<IDL files>") },
164 /********** main routines **********/
165 int main(int argc, char *argv[])
167 GOptionContext *context;
169 GError *error = NULL;
177 /* Argument parsing, etc. */
178 cl_cpp_args = g_string_new("-D__FORB_IDL__ ");
180 /* GOption cannot parse single-letter options without space
181 * between option and argument (-I../dir) or single-dash options.
182 * So fix those up before parsing, to retain command line compatibility
183 * with previous popt based versions of forb-idl-2
185 args = g_ptr_array_sized_new (2 * argc);
186 g_ptr_array_add (args, g_strdup (argv[0]));
188 for (i = 1; i < argc; ++i) {
189 if (argv[i][0] == '-' &&
190 (argv[i][1] == 'D' || argv[i][1] == 'I') &&
191 argv[i][2] != '\0') {
192 g_ptr_array_add (args, g_strndup (argv[i], 2));
193 g_ptr_array_add (args, g_strdup (argv[i] + 2));
194 } else if (strcmp (argv[i], "-define") == 0 ||
195 strcmp (argv[i], "-include") == 0) {
196 g_ptr_array_add (args, g_strdup_printf ("-%s", argv[i]));
198 g_ptr_array_add (args, g_strdup (argv[i]));
202 /* Parsing will modify the array; memdup it beforehand
203 * so we can free it correctly
206 argv = freeme = g_memdup (args->pdata, argc * sizeof (gpointer));
207 g_ptr_array_add (args, NULL); /* so we can use g_strfreev */
209 /* Now parse the options */
210 context = g_option_context_new ("");
211 g_option_context_add_main_entries (context, goptions, GETTEXT_PACKAGE);
213 group = g_option_group_new ("libIDL", N_("libIDL options"), N_("Show libIDL options"), NULL, NULL);
214 g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
215 g_option_group_add_entries (group, cl_libIDL_goptions);
216 g_option_context_add_group (context, group);
218 group = g_option_group_new ("cpp", N_("Preprocessor options"), N_("Show preprocessor options"), NULL, NULL);
219 g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
220 g_option_group_add_entries (group, cl_cpp_goptions);
221 g_option_context_add_group (context, group);
223 result = g_option_context_parse (context, &argc, &argv, &error);
225 g_option_context_free (context);
226 g_strfreev ((char **) g_ptr_array_free (args, FALSE));
230 g_print ("forb-idl-2: %s\n", error->message);
231 g_error_free (error);
236 g_print ("No input files given!\n");
240 /* Prep our run info for the backend */
241 rinfo.cpp_args = cl_cpp_args->str;
242 rinfo.debug_level = cl_debuglevel;
243 rinfo.idl_warn_level = cl_idlwarnlevel;
244 rinfo.show_cpp_errors = cl_showcpperrors;
245 rinfo.is_pidl = cl_is_pidl;
246 rinfo.do_skel_defs = !cl_disable_defs_skels;
247 rinfo.enabled_passes =
248 (cl_disable_stubs?0:OUTPUT_STUBS)
249 |(cl_disable_skels?0:OUTPUT_SKELS)
250 |(cl_disable_common?0:OUTPUT_COMMON)
251 |(cl_disable_headers?0:OUTPUT_HEADERS)
252 /* |(cl_enable_skeleton_impl?OUTPUT_SKELIMPL:0) */
253 /* |(cl_add_imodule?OUTPUT_IMODULE:0) */
254 |(cl_deps_file != NULL?OUTPUT_DEPS:0)
257 rinfo.deps_file = cl_deps_file;
259 /* if (cl_enable_imodule) /\* clobber *\/ */
260 /* rinfo.enabled_passes = */
261 /* OUTPUT_COMMON | OUTPUT_HEADERS | OUTPUT_IMODULE; */
263 rinfo.output_language = cl_output_lang;
264 rinfo.header_guard_prefix = cl_header_guard_prefix;
265 rinfo.output_directory = cl_output_directory;
266 rinfo.backend_directory = cl_backend_dir;
267 rinfo.onlytop = cl_onlytop;
268 rinfo.idata = !cl_disable_idata;
271 printf ("forb-idl-2 " VERSION " compiling\n");
272 printf (" %s mode, %s preprocessor errors, passes: %s%s%s%s%s%s\n\n",
273 rinfo.is_pidl ? "pidl" : "",
274 rinfo.show_cpp_errors ? "show" : "hide",
275 rinfo.enabled_passes&OUTPUT_STUBS ? "stubs " : "",
276 rinfo.enabled_passes&OUTPUT_SKELS ? "skels " : "",
277 rinfo.enabled_passes&OUTPUT_COMMON ? "common " : "",
278 rinfo.enabled_passes&OUTPUT_HEADERS ? "headers " : "",
279 rinfo.enabled_passes&OUTPUT_SKELIMPL ? "skel_impl " : "",
280 rinfo.enabled_passes&OUTPUT_IMODULE ? "imodule" : "");
284 for (i = 0; idl_files[i]; ++i) {
285 if (cl_debuglevel) g_print ("Processing file %s\n", idl_files[i]);
286 rinfo.input_filename = idl_files[i];
287 if (!forb_idl_to_backend(idl_files[i], &rinfo)) {
288 g_warning("%s compilation failed", idl_files[i]);