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"
37 #include "mm/memory.h"
39 #include "toolbox/hashtable.h"
40 #include "toolbox/logging.h"
42 #include "vm/global.h"
43 #include "vm/string.hpp"
46 #include "vmcore/classcache.h"
47 #include "vmcore/loader.h"
48 #include "vmcore/options.h"
49 #include "vmcore/statistics.h"
50 #include "vmcore/suck.h"
53 /* define cacaoh options ******************************************************/
68 { "help", false, OPT_HELP },
69 { "version", false, OPT_VERSION },
70 { "verbose", false, OPT_VERBOSE },
71 { "d", true, OPT_DIRECTORY },
72 { "classpath", true, OPT_CLASSPATH },
73 { "bootclasspath", true, OPT_BOOTCLASSPATH },
78 /* usage ***********************************************************************
80 Obviously prints usage information of cacaoh.
82 *******************************************************************************/
86 printf("Usage: cacaoh [options] <classes>\n"
89 " -help Print this message\n"
90 " -classpath <path> \n"
91 " -bootclasspath <path> \n"
92 " -d <dir> Output directory\n"
93 " -version Print version information\n"
94 " -verbose Enable verbose output\n");
96 /* exit with error code */
102 /* version *********************************************************************
104 Prints cacaoh version information.
106 *******************************************************************************/
108 static void version(void)
110 printf("cacaoh version "VERSION"\n");
111 printf("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,\n");
112 printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n");
113 printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n");
114 printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n");
116 printf("This program is free software; you can redistribute it and/or\n");
117 printf("modify it under the terms of the GNU General Public License as\n");
118 printf("published by the Free Software Foundation; either version 2, or (at\n");
119 printf("your option) any later version.\n\n");
121 printf("This program is distributed in the hope that it will be useful, but\n");
122 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
123 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
124 printf("General Public License for more details.\n");
130 /* forward declarations *******************************************************/
132 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv);
135 /* main ************************************************************************
139 *******************************************************************************/
141 int main(int argc, char **argv)
143 JavaVMInitArgs *vm_args;
149 /********** internal (only used by main) *****************************/
159 /* set the bootclasspath */
161 cp = getenv("BOOTCLASSPATH");
164 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
165 strcpy(bootclasspath, cp);
169 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
170 strlen(CACAO_VM_ZIP) +
173 strlen(JAVA_RUNTIME_LIBRARY_CLASSES) +
176 bootclasspath = MNEW(char, cplen);
177 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
178 strcat(bootclasspath, CACAO_VM_ZIP);
179 strcat(bootclasspath, ":");
181 strcat(bootclasspath, JAVA_RUNTIME_LIBRARY_CLASSES);
185 /* set the classpath */
187 cp = getenv("CLASSPATH");
190 classpath = MNEW(char, strlen(cp) + strlen("0"));
191 strcat(classpath, cp);
194 classpath = MNEW(char, strlen(".") + strlen("0"));
195 strcpy(classpath, ".");
199 /* initialize options with default values */
202 opt_directory = NULL;
205 /* parse the options ******************************************************/
207 vm_args = cacaoh_options_prepare(argc, argv);
209 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
219 /* forget old classpath and set the argument as new classpath */
220 MFREE(classpath, char, strlen(classpath));
222 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
223 strcpy(classpath, opt_arg);
226 case OPT_BOOTCLASSPATH:
227 /* Forget default bootclasspath and set the argument as
228 new boot classpath. */
229 MFREE(bootclasspath, char, strlen(bootclasspath));
231 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
232 strcpy(bootclasspath, opt_arg);
236 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
237 strcpy(opt_directory, opt_arg);
254 /**************************** Program start **************************/
258 log_println("Java - header-generator started");
263 /* initialize the classcache hashtable stuff: lock, hashtable
264 (must be done _after_ threads_preinit) */
266 if (!classcache_init())
267 vm_abort("classcache_init failed\n");
269 /* initialize the loader with bootclasspath (must be done _after_
273 vm_abort("suck_init failed\n");
275 suck_add(bootclasspath);
277 /* Also add the normal classpath, so the bootstrap class loader
278 can find the files. */
282 /* AFTER: classcache_init */
288 /* load Java classes ******************************************************/
290 for (i = opt_index; i < vm_args->nOptions; i++) {
291 cp = vm_args->options[i].optionString;
293 /* convert classname */
295 for (j = strlen(cp) - 1; j >= 0; j--) {
306 /* exceptions are catched with new_exception call */
308 if (!(c = load_class_bootstrap(utf_new_char(cp))))
309 vm_abort("java.lang.NoClassDefFoundError: %s\n", cp);
312 vm_abort("java.lang.LinkageError: %s\n", cp);
314 headerfile_generate(c, opt_directory);
317 /************************ Release all resources **********************/
322 log_println("Java - header-generator stopped");
323 #if defined(ENABLE_STATISTICS)
324 statistics_print_memory_usage();
332 /* cacaoh_options_prepare ******************************************************
334 Prepare the JavaVMInitArgs.
336 *******************************************************************************/
338 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv)
340 JavaVMInitArgs *vm_args;
343 vm_args = NEW(JavaVMInitArgs);
345 vm_args->nOptions = argc - 1;
346 vm_args->options = MNEW(JavaVMOption, argc);
348 for (i = 1; i < argc; i++)
349 vm_args->options[i - 1].optionString = argv[i];
356 * These are local overrides for various environment variables in Emacs.
357 * Please do not remove this and leave it at the end of the file, where
358 * Emacs will automagically detect them.
359 * ---------------------------------------------------------------------
362 * indent-tabs-mode: t