1 /* src/cacaoh/cacaoh.c - main for header generation (cacaoh)
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 #include "cacaoh/headers.h"
36 #include "mm/gc-common.h"
37 #include "mm/memory.h"
39 #include "toolbox/hashtable.h"
40 #include "toolbox/logging.h"
42 #include "vm/exceptions.h"
43 #include "vm/global.h"
44 #include "vm/stringlocal.h"
47 #include "vmcore/classcache.h"
48 #include "vmcore/loader.h"
49 #include "vmcore/options.h"
50 #include "vmcore/statistics.h"
51 #include "vmcore/suck.h"
54 /* define cacaoh options ******************************************************/
69 { "help", false, OPT_HELP },
70 { "version", false, OPT_VERSION },
71 { "verbose", false, OPT_VERBOSE },
72 { "d", true, OPT_DIRECTORY },
73 { "classpath", true, OPT_CLASSPATH },
74 { "bootclasspath", true, OPT_BOOTCLASSPATH },
79 /* usage ***********************************************************************
81 Obviously prints usage information of cacaoh.
83 *******************************************************************************/
87 printf("Usage: cacaoh [options] <classes>\n"
90 " -help Print this message\n"
91 " -classpath <path> \n"
92 " -bootclasspath <path> \n"
93 " -d <dir> Output directory\n"
94 " -version Print version information\n"
95 " -verbose Enable verbose output\n");
97 /* exit with error code */
103 /* version *********************************************************************
105 Prints cacaoh version information.
107 *******************************************************************************/
109 static void version(void)
111 printf("cacaoh version "VERSION"\n");
112 printf("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,\n");
113 printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n");
114 printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n");
115 printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n");
117 printf("This program is free software; you can redistribute it and/or\n");
118 printf("modify it under the terms of the GNU General Public License as\n");
119 printf("published by the Free Software Foundation; either version 2, or (at\n");
120 printf("your option) any later version.\n\n");
122 printf("This program is distributed in the hope that it will be useful, but\n");
123 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
124 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
125 printf("General Public License for more details.\n");
131 /* forward declarations *******************************************************/
133 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv);
136 /* main ************************************************************************
140 *******************************************************************************/
142 int main(int argc, char **argv)
144 JavaVMInitArgs *vm_args;
150 /********** internal (only used by main) *****************************/
160 /* set the bootclasspath */
162 cp = getenv("BOOTCLASSPATH");
165 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
166 strcpy(bootclasspath, cp);
170 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
171 strlen(CACAO_VM_ZIP) +
174 strlen(JAVA_RUNTIME_LIBRARY_CLASSES) +
177 bootclasspath = MNEW(char, cplen);
178 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
179 strcat(bootclasspath, CACAO_VM_ZIP);
180 strcat(bootclasspath, ":");
182 strcat(bootclasspath, JAVA_RUNTIME_LIBRARY_CLASSES);
186 /* set the classpath */
188 cp = getenv("CLASSPATH");
191 classpath = MNEW(char, strlen(cp) + strlen("0"));
192 strcat(classpath, cp);
195 classpath = MNEW(char, strlen(".") + strlen("0"));
196 strcpy(classpath, ".");
200 /* initialize options with default values */
203 opt_directory = NULL;
206 /* parse the options ******************************************************/
208 vm_args = cacaoh_options_prepare(argc, argv);
210 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
220 /* forget old classpath and set the argument as new classpath */
221 MFREE(classpath, char, strlen(classpath));
223 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
224 strcpy(classpath, opt_arg);
227 case OPT_BOOTCLASSPATH:
228 /* Forget default bootclasspath and set the argument as
229 new boot classpath. */
230 MFREE(bootclasspath, char, strlen(bootclasspath));
232 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
233 strcpy(bootclasspath, opt_arg);
237 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
238 strcpy(opt_directory, opt_arg);
255 /**************************** Program start **************************/
259 log_println("Java - header-generator started");
264 /* initialize the classcache hashtable stuff: lock, hashtable
265 (must be done _after_ threads_preinit) */
267 if (!classcache_init())
268 vm_abort("classcache_init failed\n");
270 /* initialize the loader with bootclasspath (must be done _after_
274 vm_abort("suck_init failed\n");
276 suck_add(bootclasspath);
278 /* Also add the normal classpath, so the bootstrap class loader
279 can find the files. */
283 /* AFTER: classcache_init */
289 /* load Java classes ******************************************************/
291 for (i = opt_index; i < vm_args->nOptions; i++) {
292 cp = vm_args->options[i].optionString;
294 /* convert classname */
296 for (j = strlen(cp) - 1; j >= 0; j--) {
307 /* exceptions are catched with new_exception call */
309 if (!(c = load_class_bootstrap(utf_new_char(cp))))
310 vm_abort("java.lang.NoClassDefFoundError: %s\n", cp);
313 vm_abort("java.lang.LinkageError: %s\n", cp);
315 headerfile_generate(c, opt_directory);
318 /************************ Release all resources **********************/
323 log_println("Java - header-generator stopped");
324 #if defined(ENABLE_STATISTICS)
325 statistics_print_memory_usage();
333 /* cacaoh_options_prepare ******************************************************
335 Prepare the JavaVMInitArgs.
337 *******************************************************************************/
339 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv)
341 JavaVMInitArgs *vm_args;
344 vm_args = NEW(JavaVMInitArgs);
346 vm_args->nOptions = argc - 1;
347 vm_args->options = MNEW(JavaVMOption, argc);
349 for (i = 1; i < argc; i++)
350 vm_args->options[i - 1].optionString = argv[i];
357 * These are local overrides for various environment variables in Emacs.
358 * Please do not remove this and leave it at the end of the file, where
359 * Emacs will automagically detect them.
360 * ---------------------------------------------------------------------
363 * indent-tabs-mode: t