1 /* src/cacaoh/cacaoh.c - main for header generation (cacaoh)
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: cacaoh.c 7246 2007-01-29 18:49:05Z twisti $
38 #include "cacaoh/headers.h"
40 #include "mm/gc-common.h"
41 #include "mm/memory.h"
43 #include "toolbox/hashtable.h"
44 #include "toolbox/logging.h"
46 #include "vm/exceptions.h"
47 #include "vm/global.h"
48 #include "vm/stringlocal.h"
51 #include "vmcore/classcache.h"
52 #include "vmcore/loader.h"
53 #include "vmcore/options.h"
54 #include "vmcore/statistics.h"
55 #include "vmcore/suck.h"
58 /* define heap sizes **********************************************************/
60 #define HEAP_MAXSIZE 2 * 1024 * 1024 /* default 2MB */
61 #define HEAP_STARTSIZE 100 * 1024 /* default 100kB */
64 /* define cacaoh options ******************************************************/
79 { "help", false, OPT_HELP },
80 { "version", false, OPT_VERSION },
81 { "verbose", false, OPT_VERBOSE },
82 { "d", true, OPT_DIRECTORY },
83 { "classpath", true, OPT_CLASSPATH },
84 { "bootclasspath", true, OPT_BOOTCLASSPATH },
89 /* usage ***********************************************************************
91 Obviously prints usage information of cacaoh.
93 *******************************************************************************/
97 printf("Usage: cacaoh [options] <classes>\n"
100 " -help Print this message\n"
101 " -classpath <path> \n"
102 " -bootclasspath <path> \n"
103 " -d <dir> Output directory\n"
104 " -version Print version information\n"
105 " -verbose Enable verbose output\n");
107 /* exit with error code */
113 /* version *********************************************************************
115 Prints cacaoh version information.
117 *******************************************************************************/
119 static void version(void)
121 printf("cacaoh version "VERSION"\n");
122 printf("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,\n");
123 printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n");
124 printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n");
125 printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n");
127 printf("This program is free software; you can redistribute it and/or\n");
128 printf("modify it under the terms of the GNU General Public License as\n");
129 printf("published by the Free Software Foundation; either version 2, or (at\n");
130 printf("your option) any later version.\n\n");
132 printf("This program is distributed in the hope that it will be useful, but\n");
133 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
134 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
135 printf("General Public License for more details.\n");
141 /* forward declarations *******************************************************/
143 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv);
146 /* main ************************************************************************
150 *******************************************************************************/
152 int main(int argc, char **argv)
154 JavaVMInitArgs *vm_args;
160 /********** internal (only used by main) *****************************/
172 /* set the bootclasspath */
174 cp = getenv("BOOTCLASSPATH");
177 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
178 strcpy(bootclasspath, cp);
182 #if defined(WITH_CLASSPATH_GNU)
183 strlen(CACAO_VM_ZIP) +
186 strlen(CLASSPATH_CLASSES) +
189 bootclasspath = MNEW(char, cplen);
190 #if defined(WITH_CLASSPATH_GNU)
191 strcat(bootclasspath, CACAO_VM_ZIP);
192 strcat(bootclasspath, ":");
194 strcat(bootclasspath, CLASSPATH_CLASSES);
198 /* set the classpath */
200 cp = getenv("CLASSPATH");
203 classpath = MNEW(char, strlen(cp) + strlen("0"));
204 strcat(classpath, cp);
207 classpath = MNEW(char, strlen(".") + strlen("0"));
208 strcpy(classpath, ".");
212 /* initialize options with default values */
215 opt_directory = NULL;
217 heapmaxsize = HEAP_MAXSIZE;
218 heapstartsize = HEAP_STARTSIZE;
221 /* parse the options ******************************************************/
223 vm_args = cacaoh_options_prepare(argc, argv);
225 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
235 /* forget old classpath and set the argument as new classpath */
236 MFREE(classpath, char, strlen(classpath));
238 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
239 strcpy(classpath, opt_arg);
242 case OPT_BOOTCLASSPATH:
243 /* Forget default bootclasspath and set the argument as
244 new boot classpath. */
245 MFREE(bootclasspath, char, strlen(bootclasspath));
247 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
248 strcpy(bootclasspath, opt_arg);
252 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
253 strcpy(opt_directory, opt_arg);
271 /**************************** Program start **************************/
275 log_println("Java - header-generator started");
278 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
279 (must be done _after_ threads_preinit) */
282 vm_abort("utf8_init failed\n");
284 /* initialize the classcache hashtable stuff: lock, hashtable
285 (must be done _after_ threads_preinit) */
287 if (!classcache_init())
288 vm_abort("classcache_init failed\n");
290 /* initialize the loader with bootclasspath (must be done _after_
294 vm_abort("suck_init failed\n");
296 suck_add(bootclasspath);
298 /* Also add the normal classpath, so the bootstrap class loader
299 can find the files. */
303 /* initialize the loader subsystems (must be done _after_
307 vm_abort("loader_init failed\n");
310 /* load Java classes ******************************************************/
312 for (i = opt_index; i < vm_args->nOptions; i++) {
313 cp = vm_args->options[i].optionString;
315 /* convert classname */
317 for (j = strlen(cp) - 1; j >= 0; j--) {
328 /* exceptions are catched with new_exception call */
330 if (!(c = load_class_bootstrap(utf_new_char(cp))))
331 vm_abort("java.lang.NoClassDefFoundError: %s\n", cp);
334 vm_abort("java.lang.LinkageError: %s\n", cp);
336 headerfile_generate(c, opt_directory);
339 /************************ Release all resources **********************/
344 log_println("Java - header-generator stopped");
345 #if defined(ENABLE_STATISTICS)
346 statistics_print_memory_usage();
354 /* cacaoh_options_prepare ******************************************************
356 Prepare the JavaVMInitArgs.
358 *******************************************************************************/
360 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv)
362 JavaVMInitArgs *vm_args;
365 vm_args = NEW(JavaVMInitArgs);
367 vm_args->nOptions = argc - 1;
368 vm_args->options = MNEW(JavaVMOption, argc);
370 for (i = 1; i < argc; i++)
371 vm_args->options[i - 1].optionString = argv[i];
378 * These are local overrides for various environment variables in Emacs.
379 * Please do not remove this and leave it at the end of the file, where
380 * Emacs will automagically detect them.
381 * ---------------------------------------------------------------------
384 * indent-tabs-mode: t