| 1 | /**************************************************************************
|
|---|
| 2 |
|
|---|
| 3 | orbit-idl-main.c (Driver program for the IDL parser & backend)
|
|---|
| 4 |
|
|---|
| 5 | Copyright (C) 1999 Elliot Lee
|
|---|
| 6 |
|
|---|
| 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.
|
|---|
| 11 |
|
|---|
| 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.
|
|---|
| 16 |
|
|---|
| 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.
|
|---|
| 20 |
|
|---|
| 21 | $Id: orbit-idl-main.c,v 1.32 2005/03/10 12:05:21 tml Exp $
|
|---|
| 22 |
|
|---|
| 23 | ***************************************************************************/
|
|---|
| 24 |
|
|---|
| 25 | #include "config.h"
|
|---|
| 26 | #include <unistd.h>
|
|---|
| 27 | #include <stdio.h>
|
|---|
| 28 | #include <stdlib.h>
|
|---|
| 29 | #include <errno.h>
|
|---|
| 30 | #include <glib.h>
|
|---|
| 31 | #include <libIDL/IDL.h>
|
|---|
| 32 | #include <popt.h>
|
|---|
| 33 |
|
|---|
| 34 | #include "orbit-idl2.h"
|
|---|
| 35 |
|
|---|
| 36 | /* Settings made from the command line (prefaced with cl_) */
|
|---|
| 37 | #ifdef USE_LIBIDL_CODE
|
|---|
| 38 | static gboolean cl_disable_stubs = FALSE,
|
|---|
| 39 | cl_disable_skels = FALSE,
|
|---|
| 40 | cl_disable_common = FALSE,
|
|---|
| 41 | cl_disable_headers = FALSE,
|
|---|
| 42 | cl_enable_skeleton_impl = FALSE;
|
|---|
| 43 |
|
|---|
| 44 | static int cl_idlwarnlevel = 2;
|
|---|
| 45 | static int cl_debuglevel = 0;
|
|---|
| 46 | static int cl_is_pidl = 0;
|
|---|
| 47 | static int cl_output_version = 0;
|
|---|
| 48 | static int cl_disable_idata = 0;
|
|---|
| 49 | static int cl_enable_imodule = 0;
|
|---|
| 50 | static int cl_add_imodule = 0;
|
|---|
| 51 | static gboolean cl_disable_defs_skels = FALSE;
|
|---|
| 52 | static gboolean cl_showcpperrors = FALSE;
|
|---|
| 53 | static char *cl_output_lang = "c";
|
|---|
| 54 | static char *cl_header_guard_prefix = "";
|
|---|
| 55 | static char *cl_backend_dir = NULL;
|
|---|
| 56 | static gboolean cl_onlytop = FALSE;
|
|---|
| 57 | static char *cl_deps_file = NULL;
|
|---|
| 58 | static char *cl_output_directory = "";
|
|---|
| 59 | #else
|
|---|
| 60 | static gboolean cl_disable_stubs = TRUE,
|
|---|
| 61 | cl_disable_skels = TRUE,
|
|---|
| 62 | cl_disable_common = TRUE,
|
|---|
| 63 | cl_disable_headers = TRUE,
|
|---|
| 64 | cl_enable_skeleton_impl = FALSE;
|
|---|
| 65 | /* Voyager: Which file to create */
|
|---|
| 66 | static gboolean
|
|---|
| 67 | cl_create_headers = FALSE,
|
|---|
| 68 | cl_create_ctemplate = FALSE,
|
|---|
| 69 | cl_create_ih = FALSE;
|
|---|
| 70 |
|
|---|
| 71 | static int cl_idlwarnlevel = 2;
|
|---|
| 72 | static int cl_debuglevel = 0;
|
|---|
| 73 | static int cl_is_pidl = 0;
|
|---|
| 74 | static int cl_output_version = 0;
|
|---|
| 75 | static int cl_disable_idata = 0;
|
|---|
| 76 | static int cl_enable_imodule = 0;
|
|---|
| 77 | static int cl_add_imodule = 0;
|
|---|
| 78 | static gboolean cl_disable_defs_skels = FALSE;
|
|---|
| 79 | static gboolean cl_showcpperrors = FALSE;
|
|---|
| 80 | static char *cl_output_lang = "c";
|
|---|
| 81 | static char *cl_header_guard_prefix = "";
|
|---|
| 82 | static char *cl_backend_dir = NULL;
|
|---|
| 83 | static gboolean cl_onlytop = TRUE;
|
|---|
| 84 | static char *cl_deps_file = NULL;
|
|---|
| 85 | static char *cl_output_directory = "";
|
|---|
| 86 | #endif
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | #define BASE_CPP_ARGS "-D__ORBIT_IDL__ "
|
|---|
| 90 | static GString *cl_cpp_args;
|
|---|
| 91 |
|
|---|
| 92 | static char *c_output_formatter = NULL;
|
|---|
| 93 |
|
|---|
| 94 | /* Callbacks for popt */
|
|---|
| 95 | static void
|
|---|
| 96 | cl_libIDL_version_callback(poptContext con, enum poptCallbackReason reason,
|
|---|
| 97 | const struct poptOption *opt, char *arg,
|
|---|
| 98 | void *data)
|
|---|
| 99 | {
|
|---|
| 100 | g_print("libIDL %s (CORBA %s)",
|
|---|
| 101 | IDL_get_libver_string(),
|
|---|
| 102 | IDL_get_IDLver_string());
|
|---|
| 103 |
|
|---|
| 104 | exit(0);
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | static void
|
|---|
| 108 | cl_cpp_callback(poptContext con, enum poptCallbackReason reason,
|
|---|
| 109 | const struct poptOption *opt, char *arg,
|
|---|
| 110 | void *data)
|
|---|
| 111 | {
|
|---|
| 112 | g_assert(opt!=NULL);
|
|---|
| 113 |
|
|---|
| 114 | if(opt->shortName=='D')
|
|---|
| 115 | g_string_append(cl_cpp_args, "-D");
|
|---|
| 116 | else if(opt->shortName=='I')
|
|---|
| 117 | g_string_append(cl_cpp_args, "-I");
|
|---|
| 118 |
|
|---|
| 119 | g_string_append(cl_cpp_args, arg);
|
|---|
| 120 | g_string_append_c(cl_cpp_args, ' ');
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | static const
|
|---|
| 124 | struct poptOption cl_libIDL_callback_options[] = {
|
|---|
| 125 | {NULL, '\0', POPT_ARG_CALLBACK, (void *)cl_libIDL_version_callback,
|
|---|
| 126 | 0, NULL, NULL},
|
|---|
| 127 | {"libIDL-version", '\0', POPT_ARG_NONE, NULL, 0,
|
|---|
| 128 | "Show version of libIDL used.", NULL},
|
|---|
| 129 | {NULL, '\0', 0, NULL, 0, NULL, NULL}
|
|---|
| 130 | };
|
|---|
| 131 |
|
|---|
| 132 | static const
|
|---|
| 133 | struct poptOption cl_cpp_callback_options[] = {
|
|---|
| 134 | {NULL, '\0', POPT_ARG_CALLBACK, (void *)cl_cpp_callback, 0, NULL, NULL},
|
|---|
| 135 | {"define", 'D', POPT_ARGFLAG_ONEDASH | POPT_ARG_STRING, NULL, 0,
|
|---|
| 136 | "Define value in preprocessor", NULL},
|
|---|
| 137 | {"include", 'I', POPT_ARGFLAG_ONEDASH | POPT_ARG_STRING, NULL, 0,
|
|---|
| 138 | "Add search path for include files", NULL},
|
|---|
| 139 | {NULL, '\0', 0, NULL, 0, NULL, NULL}
|
|---|
| 140 | };
|
|---|
| 141 |
|
|---|
| 142 | #ifdef USE_LIBIDL_CODE
|
|---|
| 143 | static
|
|---|
| 144 | struct poptOption options[] = {
|
|---|
| 145 | {NULL, '\0', POPT_ARG_INCLUDE_TABLE, &cl_cpp_callback_options, 0, NULL, NULL},
|
|---|
| 146 | {NULL, '\0', POPT_ARG_INCLUDE_TABLE, &cl_libIDL_callback_options, 0, NULL, NULL},
|
|---|
| 147 | {"version", 'v', POPT_ARG_NONE, &cl_output_version, 0, "Output compiler version and serial", NULL},
|
|---|
| 148 | {"lang", 'l', POPT_ARG_STRING, &cl_output_lang, 0, "Output language (default is C)", NULL},
|
|---|
| 149 | {"debug", 'd', POPT_ARG_INT, &cl_debuglevel, 0, "Debug level 0 to 4", NULL},
|
|---|
| 150 | {"idlwarnlevel", '\0', POPT_ARG_INT, &cl_idlwarnlevel, 0, "IDL warning level 0 to 4, default is 2", NULL},
|
|---|
| 151 | {"showcpperrors", '\0', POPT_ARG_NONE, &cl_showcpperrors, 0, "Show CPP errors", NULL},
|
|---|
| 152 | {"nostubs", '\0', POPT_ARG_NONE, &cl_disable_stubs, 0, "Don't output stubs", NULL},
|
|---|
| 153 | {"noskels", '\0', POPT_ARG_NONE, &cl_disable_skels, 0, "Don't output skels", NULL},
|
|---|
| 154 | {"nocommon", '\0', POPT_ARG_NONE, &cl_disable_common, 0, "Don't output common", NULL},
|
|---|
| 155 | {"noheaders", '\0', POPT_ARG_NONE, &cl_disable_headers, 0, "Don't output headers", NULL},
|
|---|
| 156 | {"noidata", '\0', POPT_ARG_NONE, &cl_disable_idata, 0, "Don't generate Interface type data", NULL},
|
|---|
| 157 | {"imodule", 'i', POPT_ARG_NONE, &cl_enable_imodule, 0, "Output only an imodule file", NULL},
|
|---|
| 158 | {"add-imodule", '\0', POPT_ARG_NONE, &cl_add_imodule, 0, "Output an imodule file", NULL},
|
|---|
| 159 | {"skeleton-impl", '\0', POPT_ARG_NONE, &cl_enable_skeleton_impl, 0, "Output skeleton implementation", NULL},
|
|---|
| 160 | {"backenddir", '\0', POPT_ARG_STRING, &cl_backend_dir, 0, "Override IDL backend library directory", "DIR"},
|
|---|
| 161 | {"c-output-formatter", '\0', POPT_ARG_STRING, &c_output_formatter, 0, "DEPRECATED and IGNORED", "PROGRAM"},
|
|---|
| 162 | {"onlytop", '\0', POPT_ARG_NONE, &cl_onlytop, 0, "Inhibit includes", NULL},
|
|---|
| 163 | {"pidl", '\0', POPT_ARG_NONE, &cl_is_pidl, 0, "Treat as Pseudo IDL", NULL},
|
|---|
| 164 | {"nodefskels", '\0', POPT_ARG_NONE, &cl_disable_defs_skels, 0, "Don't output defs for skels in header", NULL},
|
|---|
| 165 | {"deps", '\0', POPT_ARG_STRING, &cl_deps_file, 0, "Generate dependency info suitable for inclusion in Makefile", "FILENAME"},
|
|---|
| 166 | {"headerguardprefix", '\0', POPT_ARG_STRING, &cl_header_guard_prefix, 0, "Prefix for #ifdef header guards. Sometimes useful to avoid conflicts.", NULL},
|
|---|
| 167 | {"output-dir", '\0', POPT_ARG_STRING, &cl_output_directory, 0, "Where to put generated files. This directory must exist.", NULL},
|
|---|
| 168 | POPT_AUTOHELP
|
|---|
| 169 | {NULL, '\0', 0, NULL, 0, NULL, NULL}
|
|---|
| 170 | };
|
|---|
| 171 | #else
|
|---|
| 172 | static
|
|---|
| 173 | struct poptOption options[] = {
|
|---|
| 174 | {NULL, '\0', POPT_ARG_INCLUDE_TABLE, &cl_cpp_callback_options, 0, NULL, NULL},
|
|---|
| 175 | {NULL, '\0', POPT_ARG_INCLUDE_TABLE, &cl_libIDL_callback_options, 0, NULL, NULL},
|
|---|
| 176 | {"version", 'v', POPT_ARG_NONE, &cl_output_version, 0, "Output compiler version and serial", NULL},
|
|---|
| 177 | {"lang", 'l', POPT_ARG_STRING, &cl_output_lang, 0, "Output language (default is C)", NULL},
|
|---|
| 178 | {"debug", 'd', POPT_ARG_INT, &cl_debuglevel, 0, "Debug level 0 to 4", NULL},
|
|---|
| 179 | {"idlwarnlevel", '\0', POPT_ARG_INT, &cl_idlwarnlevel, 0, "IDL warning level 0 to 4, default is 2", NULL},
|
|---|
| 180 | {"showcpperrors", '\0', POPT_ARG_NONE, &cl_showcpperrors, 0, "Show CPP errors", NULL},
|
|---|
| 181 | #if 0
|
|---|
| 182 | {"nostubs", '\0', POPT_ARG_NONE, &cl_disable_stubs, 0, "Don't output stubs", NULL},
|
|---|
| 183 | {"noskels", '\0', POPT_ARG_NONE, &cl_disable_skels, 0, "Don't output skels", NULL},
|
|---|
| 184 | {"nocommon", '\0', POPT_ARG_NONE, &cl_disable_common, 0, "Don't output common", NULL},
|
|---|
| 185 | #endif
|
|---|
| 186 | {"ihfile", '\0', POPT_ARG_NONE, &cl_create_ih, 0, "Output implementation file", NULL},
|
|---|
| 187 | {"header", '\0', POPT_ARG_NONE, &cl_create_headers, 0, "Output headers", NULL},
|
|---|
| 188 | {"c-template", '\0', POPT_ARG_NONE, &cl_create_ctemplate, 0, "Output a C template file with method bodies", NULL},
|
|---|
| 189 | {"add-imodule", '\0', POPT_ARG_NONE, &cl_add_imodule, 0, "Output an imodule file", NULL},
|
|---|
| 190 | {"skeleton-impl", '\0', POPT_ARG_NONE, &cl_enable_skeleton_impl, 0, "Output skeleton implementation", NULL},
|
|---|
| 191 | {"backenddir", '\0', POPT_ARG_STRING, &cl_backend_dir, 0, "Override IDL backend library directory", "DIR"},
|
|---|
| 192 | #if 0
|
|---|
| 193 | {"onlytop", '\0', POPT_ARG_NONE, &cl_onlytop, 0, "Inhibit includes", NULL},
|
|---|
| 194 | #endif
|
|---|
| 195 | {"pidl", '\0', POPT_ARG_NONE, &cl_is_pidl, 0, "Treat as Pseudo IDL", NULL},
|
|---|
| 196 | {"nodefskels", '\0', POPT_ARG_NONE, &cl_disable_defs_skels, 0, "Don't output defs for skels in header", NULL},
|
|---|
| 197 | {"deps", '\0', POPT_ARG_STRING, &cl_deps_file, 0, "Generate dependency info suitable for inclusion in Makefile", "FILENAME"},
|
|---|
| 198 | {"headerguardprefix", '\0', POPT_ARG_STRING, &cl_header_guard_prefix, 0, "Prefix for #ifdef header guards. Sometimes useful to avoid conflicts.", NULL},
|
|---|
| 199 | {"output-dir", '\0', POPT_ARG_STRING, &cl_output_directory, 0, "Where to put generated files. This directory must exist.", NULL},
|
|---|
| 200 | POPT_AUTOHELP
|
|---|
| 201 | {NULL, '\0', 0, NULL, 0, NULL, NULL}
|
|---|
| 202 | };
|
|---|
| 203 | #endif
|
|---|
| 204 |
|
|---|
| 205 | /********** main routines **********/
|
|---|
| 206 | int main(int argc, const char *argv[])
|
|---|
| 207 | {
|
|---|
| 208 | poptContext pcon;
|
|---|
| 209 | int rc, retval = 0;
|
|---|
| 210 | const char *arg;
|
|---|
| 211 | OIDL_Run_Info rinfo;
|
|---|
| 212 |
|
|---|
| 213 | /* Argument parsing, etc. */
|
|---|
| 214 | cl_cpp_args = g_string_new("-D__ORBIT_IDL__ ");
|
|---|
| 215 |
|
|---|
| 216 | pcon = poptGetContext ("orbit-idl-2", argc, argv, options, 0);
|
|---|
| 217 | poptSetOtherOptionHelp (pcon, "<IDL files>");
|
|---|
| 218 |
|
|---|
| 219 | if(argc < 2) {
|
|---|
| 220 | poptPrintUsage(pcon, stdout, 0);
|
|---|
| 221 | return 0;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | if((rc=poptGetNextOpt(pcon)) < -1) {
|
|---|
| 225 | g_print ("orbit-idl-2: bad argument %s: %s\n",
|
|---|
| 226 | poptBadOption(pcon, POPT_BADOPTION_NOALIAS),
|
|---|
| 227 | poptStrerror(rc));
|
|---|
| 228 | exit(0);
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | if (cl_output_version) {
|
|---|
| 232 | printf ("orbit-idl-2 %s - serial %d\n\n",
|
|---|
| 233 | VERSION, ORBIT_CONFIG_SERIAL);
|
|---|
| 234 | exit (0);
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | if (c_output_formatter != NULL)
|
|---|
| 238 | g_warning ("Please do not use the 'c-output-formatter' option. It is ignored and will soon go away.");
|
|---|
| 239 |
|
|---|
| 240 | /* --header given */
|
|---|
| 241 | if(cl_create_headers)
|
|---|
| 242 | cl_disable_headers=FALSE;
|
|---|
| 243 | /* --ihfile given */
|
|---|
| 244 | if(cl_create_ih)
|
|---|
| 245 | cl_enable_skeleton_impl=TRUE;
|
|---|
| 246 | /* --c-template given */
|
|---|
| 247 | if(cl_create_ctemplate)
|
|---|
| 248 | cl_disable_stubs=FALSE;
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 | /* Prep our run info for the backend */
|
|---|
| 252 | rinfo.cpp_args = cl_cpp_args->str;
|
|---|
| 253 | rinfo.debug_level = cl_debuglevel;
|
|---|
| 254 | rinfo.idl_warn_level = cl_idlwarnlevel;
|
|---|
| 255 | rinfo.show_cpp_errors = cl_showcpperrors;
|
|---|
| 256 | rinfo.is_pidl = cl_is_pidl;
|
|---|
| 257 | rinfo.do_skel_defs = !cl_disable_defs_skels;
|
|---|
| 258 | rinfo.enabled_passes =
|
|---|
| 259 | (cl_disable_stubs?0:OUTPUT_STUBS)
|
|---|
| 260 | |(cl_disable_skels?0:OUTPUT_SKELS)
|
|---|
| 261 | |(cl_disable_common?0:OUTPUT_COMMON)
|
|---|
| 262 | |(cl_disable_headers?0:OUTPUT_HEADERS)
|
|---|
| 263 | |(cl_enable_skeleton_impl?OUTPUT_SKELIMPL:0)
|
|---|
| 264 | |(cl_add_imodule?OUTPUT_IMODULE:0)
|
|---|
| 265 | |(cl_deps_file != NULL?OUTPUT_DEPS:0);
|
|---|
| 266 |
|
|---|
| 267 | rinfo.deps_file = cl_deps_file;
|
|---|
| 268 |
|
|---|
| 269 | if (cl_enable_imodule) /* clobber */
|
|---|
| 270 | rinfo.enabled_passes =
|
|---|
| 271 | OUTPUT_COMMON | OUTPUT_HEADERS | OUTPUT_IMODULE;
|
|---|
| 272 |
|
|---|
| 273 | rinfo.output_language = cl_output_lang;
|
|---|
| 274 | rinfo.header_guard_prefix = cl_header_guard_prefix;
|
|---|
| 275 | rinfo.output_directory = cl_output_directory;
|
|---|
| 276 | rinfo.backend_directory = cl_backend_dir;
|
|---|
| 277 | rinfo.onlytop = cl_onlytop;
|
|---|
| 278 | rinfo.idata = !cl_disable_idata;
|
|---|
| 279 |
|
|---|
| 280 | printf ("orbit-idl-2 " VERSION " compiling\n");
|
|---|
| 281 | printf (" %s mode, %s preprocessor errors, passes: %s%s%s%s%s%s\n\n",
|
|---|
| 282 | rinfo.is_pidl ? "pidl" : "",
|
|---|
| 283 | rinfo.show_cpp_errors ? "show" : "hide",
|
|---|
| 284 | cl_disable_stubs ? "" : "stubs ",
|
|---|
| 285 | cl_disable_skels ? "" : "skels ",
|
|---|
| 286 | cl_disable_common ? "" : "common ",
|
|---|
| 287 | cl_disable_headers ? "" : "headers ",
|
|---|
| 288 | cl_enable_skeleton_impl ? "skel_impl " : "",
|
|---|
| 289 | cl_enable_imodule ? "imodule" : "");
|
|---|
| 290 |
|
|---|
| 291 | /* Do it */
|
|---|
| 292 | while((arg=poptGetArg(pcon))!=NULL) {
|
|---|
| 293 | rinfo.input_filename = g_strdup (arg); /* g_path_get_basename(arg); - what !? */
|
|---|
| 294 | if (!orbit_idl_to_backend(arg, &rinfo)) {
|
|---|
| 295 | g_warning("%s compilation failed", arg);
|
|---|
| 296 | retval = 1;
|
|---|
| 297 | }
|
|---|
| 298 | g_free(rinfo.input_filename);
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | return retval;
|
|---|
| 302 | }
|
|---|