-/* Specific flags and argument handling of the front-end of the
+ /* Specific flags and argument handling of the front-end of the
GNU compiler for the Java(TM) language.
Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
/* This bit is set if they did `-lpthread' (or added some other thread
library). */
#define THREADLIB (1<<5)
+/* True if this arg is a parameter to the previous option-taking arg. */
+#define PARAM_ARG (1<<6)
+/* True if this arg is a .java input file name. */
+#define JAVA_FILE_ARG (1<<7)
+/* True if this arg is a .class input file name. */
+#define CLASS_FILE_ARG (1<<8)
#ifndef MATH_LIBRARY
#define MATH_LIBRARY "-lm"
char *main_class_name = NULL;
int lang_specific_extra_outfiles = 0;
+/* Once we have the proper support in jc1 (and gcc.c) working,
+ set COMBINE_INPUTS to one. This enables combining multiple *.java
+ and *.class input files to be passed to a single jc1 invocation. */
+#define COMBINE_INPUTS 0
+
char jvgenmain_spec[] =
"jvgenmain %i %{!pipe:%u.i} |\n\
cc1 %{!pipe:%U.i} %1 \
link in libjava. */
int library = 1;
+#if COMBINE_INPUTS
+ /* This will be 1 if multiple input files (.class and/or .java)
+ should be passed to a single jc1 invocation. */
+ int combine_inputs = 0;
+
+ /* Index of last .java or .class argument. */
+ int last_input_index;
+
+ /* A buffer containing the concatenation of the inputs files
+ (e.g. "foo.java&bar.class&baz.class"). if combine_inputs. */
+ char* combined_inputs_buffer;
+
+ /* Next available location in combined_inputs_buffer. */
+ int combined_inputs_pos;
+
+ /* Number of .java and .class source file arguments seen. */
+ int java_files_count = 0;
+ int class_files_count = 0;
+
+ /* Cumulative length of the .java and .class source file names. */
+ int java_files_length = 0;
+ int class_files_length = 0;
+#endif
+
/* The number of arguments being added to what's in argv, other than
libraries. We use this to track the number of times we've inserted
-xc++/-xnone. */
/* Saw `-ljava' on command line. */
int saw_libjava = 0;
+ /* Saw -C or -o option, respectively. */
+ int saw_C = 0;
+ int saw_o = 0;
+
/* An array used to flag each argument that needs a bit set for
LANGSPEC, MATHLIB, WITHLIBC, or GCLIB. */
int *args;
if (quote)
{
quote = NULL;
+ args[i] |= PARAM_ARG;
continue;
}
need_math = 0;
}
else if (strncmp (argv[i], "-fmain=", 7) == 0)
- main_class_name = argv[i] + 7;
+ {
+ main_class_name = argv[i] + 7;
+ added--;
+ }
else if (strcmp (argv[i], "-ljava") == 0)
saw_libjava = 1;
else if (strcmp (argv[i], "-lc") == 0)
}
else if (strncmp (argv[i], "-x", 2) == 0)
saw_speclang = 1;
+ else if (strcmp (argv[i], "-C") == 0)
+ {
+ saw_C = 1;
+#if COMBINE_INPUTS
+ combine_inputs = 1;
+#endif
+ if (library != 0)
+ added -= 2;
+ library = 0;
+ will_link = 0;
+ }
else if (((argv[i][2] == '\0'
&& (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
|| strcmp (argv[i], "-Tdata") == 0))
- quote = argv[i];
+ {
+ if (strcmp (argv[i], "-o") == 0)
+ saw_o = 1;
+ quote = argv[i];
+ }
+ else if (strcmp(argv[i], "-classpath") == 0
+ || strcmp(argv[i], "-CLASSPATH") == 0)
+ {
+ quote = argv[i];
+ added -= 1;
+ }
else if (library != 0
&& ((argv[i][2] == '\0'
&& (char *) strchr ("cSEM", argv[i][1]) != NULL)
continue;
}
- /* If the filename ends in .c or .i, put options around it.
- But not if a specified -x option is currently active. */
+#if COMBINE_INPUTS
len = strlen (argv[i]);
- if (len > 2
- && (argv[i][len - 1] == 'c' || argv[i][len - 1] == 'i')
- && argv[i][len - 2] == '.')
+ if (len > 5 && strcmp (argv[i] + len - 5, ".java") == 0)
+ {
+ args[i] |= JAVA_FILE_ARG;
+ java_files_count++;
+ java_files_length += len;
+ last_input_index = i;
+ }
+ if (len > 6 && strcmp (argv[i] + len - 6, ".class") == 0)
{
- args[i] |= LANGSPEC;
- added += 2;
+ args[i] |= CLASS_FILE_ARG;
+ class_files_count++;
+ class_files_length += len;
+ last_input_index = i;
}
+#endif
}
}
if (quote)
(*fn) ("argument to `%s' missing\n", quote);
+ num_args = argc + added;
+ if (will_link)
+ num_args += need_math + need_thread;
+ if (saw_C)
+ {
+ num_args += 3;
+#if COMBINE_INPUTS
+ class_files_length = 0;
+ num_args -= class_files_count;
+ num_args += 2; /* For -o NONE. */
+#endif
+ if (saw_o)
+ (*fn) ("cannot specify both -C and -o");
+ }
+#if COMBINE_INPUTS
+ if (saw_o && java_files_count + (saw_C ? 0 : class_files_count) > 1)
+ combine_inputs = 1;
+
+ if (combine_inputs)
+ {
+ int len = java_files_length + java_files_count - 1;
+ num_args -= java_files_count;
+ num_args++; /* Add one for the combined arg. */
+ if (class_files_length > 0)
+ {
+ len += class_files_length + class_files_count - 1;
+ num_args -= class_files_count;
+ }
+ combined_inputs_buffer = (char*) xmalloc (len);
+ combined_inputs_pos = 0;
+ }
/* If we know we don't have to do anything, bail now. */
- if (! added && ! library && main_class_name == NULL)
+#endif
+#if 0
+ if (! added && ! library && main_class_name == NULL && ! saw_C)
{
free (args);
return;
}
+#endif
- num_args = argc + added + need_math + need_thread;
if (main_class_name)
{
lang_specific_extra_outfiles++;
}
- arglist = (char **) xmalloc (num_args * sizeof (char *));
+ arglist = (char **) xmalloc ((num_args + 1) * sizeof (char *));
- /* NOTE: We start at 1 now, not 0. */
for (i = 0, j = 0; i < argc; i++, j++)
{
arglist[j] = argv[i];
+ if ((args[i] & PARAM_ARG) || i == 0)
+ continue;
+
+ if (strcmp (argv[i], "-classpath") == 0
+ || strcmp (argv[i], "-CLASSPATH") == 0)
+ {
+ char* patharg
+ = (char*) xmalloc (strlen (argv[i]) + strlen (argv[i+1]) + 3);
+ sprintf (patharg, "-f%s=%s", argv[i]+1, argv[i+1]);
+ arglist[j] = patharg;
+ i++;
+ continue;
+ }
+
if (strncmp (argv[i], "-fmain=", 7) == 0)
{
if (! will_link)
--j;
saw_threadlib = argv[i];
}
+
+ if ((args[i] & CLASS_FILE_ARG) && saw_C)
+ {
+ --j;
+ continue;
+ }
+
+#if COMBINE_INPUTS
+ if (combine_inputs && (args[i] & (CLASS_FILE_ARG|JAVA_FILE_ARG)) != 0)
+ {
+ if (combined_inputs_pos > 0)
+ combined_inputs_buffer[combined_inputs_pos++] = '&';
+ strcpy (&combined_inputs_buffer[combined_inputs_pos], argv[i]);
+ combined_inputs_pos += strlen (argv[i]);
+ --j;
+ continue;
+ }
+#endif
}
+#if COMBINE_INPUTS
+ if (combine_inputs)
+ {
+ combined_inputs_buffer[combined_inputs_pos] = '\0';
+#if 0
+ if (! saw_C)
+#endif
+ arglist[j++] = combined_inputs_buffer;
+ }
+#endif
+
/* Add `-ljava' if we haven't already done so. */
if (library && ! saw_libjava)
{
if (saw_libc)
arglist[j++] = saw_libc;
+ if (saw_C)
+ {
+ arglist[j++] = "-fsyntax-only";
+ arglist[j++] = "-femit-class-files";
+ arglist[j++] = "-S";
+#if COMBINE_INPUTS
+ arglist[j++] = "-o";
+ arglist[j++] = "NONE";
+#endif
+ }
+
arglist[j] = NULL;
*in_argc = j;