This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] gjnih


Hi,

This patch adds another front-end to gcjh, called gjnih.  It is intended
to be a command-line compatible replacement for Sun's javah tool.  It
generates JNI headers by default.  "make check" in libjava shows no new
regressions.  OK for mainline?

Tom

2005-04-28  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* gjavah.c (gjavah_main): New function.
	(toolname): New variable.
	(error): Replace hard-coded gcjh with toolname.
	(process_file): Likewise.
	(usage): Likewise.
	(help): Likewise.
	(version): Likewise.
	(main): Mark as weak.
	* gjavah-jni.c: New file.
	* gjavah.h: Likewise.
	* gcj.texi (Invoking gjnih): New node.
	(Top): Add gjnih node.
	* Make-lang.in (java): Add gjnih.
	(JAVA_TARGET_INDEPENDENT_BIN_TOOLS): Likewise.
	(GJNIH_OBJS): New variable.
	(gjnih$(exeext)): New target.
	(JAVA_MANFILES): Add gjnih.1.
	(java.uninstall): Add gjnih.1.
	(java.mostlyclean): Add gjnih.
	(java.maintainer-clean): Add gjnih.1.
	(.INTERMEDIATE): Add gjnih.pod.
	(gjnih.pod): New target.
	* config-lang.in (stagestuff): Add gjnih.

Index: Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Make-lang.in,v
retrieving revision 1.157
diff -u -u -r1.157 Make-lang.in
--- Make-lang.in	24 Apr 2005 22:16:49 -0000	1.157
+++ Make-lang.in	28 Apr 2005 23:33:50 -0000
@@ -49,11 +49,12 @@
 
 # Define the names for selecting java in LANGUAGES.
 java: jc1$(exeext) $(GCJ)$(exeext) jvgenmain$(exeext) \
-      gcjh$(exeext) jv-scan$(exeext) jcf-dump$(exeext)
+      gcjh$(exeext) jv-scan$(exeext) jcf-dump$(exeext) \
+      gjnih$(exeext)
 
 # Define the name of target independent tools to be installed in $(bindir)
 # Names are subject to changes
-JAVA_TARGET_INDEPENDENT_BIN_TOOLS = gcjh jv-scan jcf-dump
+JAVA_TARGET_INDEPENDENT_BIN_TOOLS = gcjh gjnih jv-scan jcf-dump
 
 # Tell GNU make to ignore these if they exist.
 .PHONY: java
@@ -112,6 +113,10 @@
   java/win32-host.o java/zextract.o version.o errors.o ggc-none.o \
   intl.o
 
+GJNIH_OBJS = java/gjavah.o java/gjavah-jni.o java/jcf-io.o java/jcf-depend.o \
+  java/jcf-path.o java/win32-host.o java/zextract.o version.o errors.o \
+  ggc-none.o intl.o
+
 JVSCAN_OBJS = java/parse-scan.o java/jv-scan.o version.o intl.o
 
 JCFDUMP_OBJS = java/jcf-dump.o java/jcf-io.o java/jcf-depend.o java/jcf-path.o \
@@ -138,6 +143,10 @@
 	rm -f $@
 	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GCJH_OBJS) $(CPPLIBS) $(ZLIB) $(LIBS)
 
+gjnih$(exeext): $(GJNIH_OBJS) $(LIBDEPS)
+	rm -f $@
+	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GJNIH_OBJS) $(CPPLIBS) $(ZLIB) $(LIBS)
+
 jv-scan$(exeext): $(JVSCAN_OBJS) $(LIBDEPS)
 	rm -f $@
 	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(JVSCAN_OBJS) $(LIBICONV) $(LIBS)
@@ -175,7 +184,7 @@
 html:: $(htmldir)/java/index.html
 JAVA_MANFILES = doc/gcj.1 doc/gcjh.1 doc/jv-scan.1 doc/jcf-dump.1 doc/gij.1 \
                 doc/jv-convert.1 doc/grmic.1 doc/grmiregistry.1 \
-		doc/gcj-dbtool.1
+		doc/gcj-dbtool.1 doc/gjnih.1
 
 java.man: $(JAVA_MANFILES)
 
@@ -231,6 +240,7 @@
 	-rm -rf $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext)
 	-rm -rf $(DESTDIR)$(man1dir)/$(JAVA_INSTALL_NAME)$(man1ext)
 	-rm -rf $(DESTDIR)$(man1dir)/gcjh$(man1ext)
+	-rm -rf $(DESTDIR)$(man1dir)/gjnih$(man1ext)
 	-rm -rf $(DESTDIR)$(man1dir)/jv-scan$(man1ext)
 	-rm -rf $(DESTDIR)$(man1dir)/jcf-dump$(man1ext)
 	-rm -rf $(DESTDIR)$(man1dir)/gij$(man1ext)
@@ -248,13 +258,14 @@
 	-rm -f java/parse.c java/parse-scan.c
 	-rm -f java/*$(objext) $(DEMANGLER_PROG)
 	-rm -f java/*$(coverageexts)
-	-rm -f jc1$(exeext) $(GCJ)$(exeext) jvgenmain$(exeext) gcjh$(exeext) jv-scan$(exeext) jcf-dump$(exeext) s-java
+	-rm -f jc1$(exeext) $(GCJ)$(exeext) jvgenmain$(exeext) gcjh$(exeext) \
+          gjnih$(exeext) jv-scan$(exeext) jcf-dump$(exeext) s-java
 java.clean:
 java.distclean:
 	-rm -f java/config.status java/Makefile
 	-rm -f java/parse.output java/y.tab.c
 java.maintainer-clean:
-	-rm -f $(docobjdir)/gcj.1 $(docobjdir)/gcjh.1
+	-rm -f $(docobjdir)/gcj.1 $(docobjdir)/gcjh.1 $(docobjdir)/gjnih.1
 	-rm -f $(docobjdir)/jv-scan.1 $(docobjdir)/jcf-dump.1
 	-rm -f $(docobjdir)/gij.1
 	-rm -f $(docobjdir)/jv-convert.1
@@ -288,7 +299,10 @@
   version.h $(GGC_H) intl.h
 java/gjavah.o: $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(JAVA_TREE_H) \
   java/gjavah.c java/jcf-reader.c java/jcf.h java/javaop.h version.h $(GGC_H) \
-  intl.h
+  intl.h java/gjavah.h
+java/gjavah-jni.o: $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(JAVA_TREE_H) \
+  java/gjavah-jni.c java/jcf-reader.c java/jcf.h java/javaop.h version.h $(GGC_H) \
+  intl.h java/gjavah.h
 java/boehm.o: java/boehm.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
   $(TREE_H) $(JAVA_TREE_H) java/parse.h toplev.h
 java/buffer.o: java/buffer.c $(CONFIG_H) java/buffer.h $(SYSTEM_H) coretypes.h \
@@ -390,12 +404,14 @@
 	$(TEXI2HTML) -I $(docdir)/include -I $(srcdir)/java -o $(@D) $<
 
 .INTERMEDIATE: gcj.pod gcjh.pod jv-scan.pod jcf-dump.pod gij.pod \
-  jv-convert.pod grmic.pod grmiregistry.pod gcj-dbtool.pod
+  jv-convert.pod grmic.pod grmiregistry.pod gcj-dbtool.pod gjnih.pod
 
 gcj.pod: java/gcj.texi
 	-$(TEXI2POD) -D gcj < $< > $@
 gcjh.pod: java/gcj.texi
 	-$(TEXI2POD) -D gcjh < $< > $@
+gjnih.pod: java/gcj.texi
+	-$(TEXI2POD) -D gjnih < $< > $@
 jv-scan.pod: java/gcj.texi
 	-$(TEXI2POD) -D jv-scan < $< > $@
 jcf-dump.pod: java/gcj.texi
Index: config-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/config-lang.in,v
retrieving revision 1.16
diff -u -u -r1.16 config-lang.in
--- config-lang.in	22 Jan 2003 20:51:55 -0000	1.16
+++ config-lang.in	28 Apr 2005 23:33:50 -0000
@@ -34,7 +34,7 @@
 
 compilers="jc1\$(exeext) jvgenmain\$(exeext)"
 
-stagestuff="jc1\$(exeext) gcj\$(exeext) jvgenmain\$(exeext) gcjh\$(exeext) jv-scan\$(exeext) jcf-dump\$(exeext)"
+stagestuff="jc1\$(exeext) gcj\$(exeext) jvgenmain\$(exeext) gcjh\$(exeext) gjnih\$(exeext) jv-scan\$(exeext) jcf-dump\$(exeext)"
 
 gtfiles="\$(srcdir)/java/java-tree.h \$(srcdir)/java/jcf.h \$(srcdir)/java/lex.h \$(srcdir)/java/parse.h \$(srcdir)/java/builtins.c \$(srcdir)/java/class.c \$(srcdir)/java/constants.c \$(srcdir)/java/decl.c \$(srcdir)/java/expr.c \$(srcdir)/java/jcf-parse.c \$(srcdir)/java/jcf-write.c \$(srcdir)/java/lang.c \$(srcdir)/java/mangle.c \$(srcdir)/java/parse.y \$(srcdir)/java/resource.c"
 
Index: gcj.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/gcj.texi,v
retrieving revision 1.83
diff -u -u -r1.83 gcj.texi
--- gcj.texi	27 Apr 2005 18:29:27 -0000	1.83
+++ gcj.texi	28 Apr 2005 23:33:50 -0000
@@ -59,6 +59,8 @@
 @direntry
 * gcjh: (gcj)Invoking gcjh.
                             Generate header files from Java class files
+* gjnih: (gcj)Invoking gjnih.
+                            Generate JNI header files from Java class files
 * jv-scan: (gcj)Invoking jv-scan.
                             Print information about Java source files
 * jcf-dump: (gcj)Invoking jcf-dump.
@@ -111,6 +113,7 @@
 * Invoking gcj::	Compiler options supported by @command{gcj}
 * Compatibility::	Compatibility between gcj and other tools for Java
 * Invoking gcjh::       Generate header files from class files
+* Invoking gjnih::      Generate JNI header files from class files
 * Invoking jv-scan::    Print information about source files
 * Invoking jcf-dump::   Print information about class files
 * Invoking gij::	Interpreting Java bytecodes
@@ -145,7 +148,7 @@
     @var{sourcefile}@dots{}
 @c man end
 @c man begin SEEALSO gcj
-gcc(1), gcjh(1), gij(1), jv-scan(1), jcf-dump(1), gfdl(7),
+gcc(1), gcjh(1), gjnih(1), gij(1), jv-scan(1), jcf-dump(1), gfdl(7),
 and the Info entries for @file{gcj} and @file{gcc}.
 @c man end
 @end ignore
@@ -757,6 +760,105 @@
 
 @c man end
 
+@node Invoking gjnih
+@chapter Invoking gjnih
+
+@c man title gjnih generate JNI header files from Java class files
+
+@c man begin DESCRIPTION gjnih
+
+The @code{gjnih} program is used to generate JNI header files from class
+files.  Running it is equivalent to running @code{gcjh -jni}.
+
+@c man end
+
+@ignore
+@c man begin SYNOPSIS gjnih
+gjnih [@option{-stubs}] [@option{-jni}]
+    [@option{-add} @var{text}] [@option{-append} @var{text}] [@option{-friend} @var{text}]
+    [@option{-preprend} @var{text}]
+    [@option{--classpath}=@var{path}] [@option{--CLASSPATH}=@var{path}]
+    [@option{-I}@var{dir}@dots{}] [@option{-d} @var{dir}@dots{}]
+    [@option{-o} @var{file}] [@option{-td} @var{dir}]
+    [@option{-M}] [@option{-MM}] [@option{-MD}] [@option{-MMD}]
+    [@option{--version}] [@option{--help}] [@option{-v}] [@option{--verbose}]
+    @var{classname}@dots{}
+@c man end
+@c man begin SEEALSO gjnih
+gcc(1), gcj(1), gcjh(1), gij(1), jv-scan(1), jcf-dump(1), gfdl(7),
+and the Info entries for @file{gcj} and @file{gcc}.
+@c man end
+@end ignore
+
+@c man begin OPTIONS gjnih
+
+@table @gcctabopt
+@item -stubs
+This causes @code{gjnih} to generate stub files instead of header files.
+By default the stub file will be named after the class, with a suffix of
+@samp{.c}.
+
+@item -jni
+This option is redundant.  It specifies the default behavior which is
+to generate a JNI header or stub.
+
+@item -add @var{text}
+Inserts @var{text} into the class body.  This is ignored in by
+@code{gjnih}.
+
+@item -append @var{text}
+Inserts @var{text} into the header file after the class declaration.
+This is ignored in by @code{gjnih}.
+
+@item -friend @var{text}
+Inserts @var{text} into the class as a @code{friend} declaration.
+This is ignored by @code{gjnih}.
+
+@item -prepend @var{text}
+Inserts @var{text} into the header file before the class declaration.
+This is ignored in by @code{gjnih}.
+
+@item --classpath=@var{path}
+@itemx --CLASSPATH=@var{path}
+@itemx -I@var{directory}
+@itemx -d @var{directory}
+@itemx -o @var{file}
+These options are all identical to the corresponding @command{gcj} options.
+
+@item -o @var{file}
+Sets the output file name.  This cannot be used if there is more than
+one class on the command line.
+
+@item -td @var{directory}
+Sets the name of the directory to use for temporary files.
+
+@item -M
+Print all dependencies to stdout; suppress ordinary output.
+
+@item -MM
+Print non-system dependencies to stdout; suppress ordinary output.
+
+@item -MD
+Print all dependencies to stdout.
+
+@item -MMD
+Print non-system dependencies to stdout.
+
+@item --help
+Print help about @code{gjnih} and exit.  No further processing is done.
+
+@item --version
+Print version information for @code{gjnih} and exit.  No further
+processing is done.
+
+@item -v, --verbose
+Print extra information while running.
+@end table
+
+All remaining options are considered to be names of classes.
+
+@c man end
+
 @node Invoking jv-scan
 @chapter Invoking jv-scan
 
Index: gjavah-jni.c
===================================================================
RCS file: gjavah-jni.c
diff -N gjavah-jni.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gjavah-jni.c	28 Apr 2005 23:33:50 -0000
@@ -0,0 +1,34 @@
+/* Program to write JNI header files from a Java(TM) .class file.
+   gjnih is command-line compatible with SUN's javah.
+
+Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  
+
+Java and all Java-based marks are trademarks or registered trademarks
+of Sun Microsystems, Inc. in the United States and other countries.
+The Free Software Foundation is independent of Sun Microsystems, Inc.  */
+
+#include "gjavah.h"
+
+int
+main (int argc, char** argv)
+{
+  return gjavah_main (argc, argv, 1, "gjnih");
+}
Index: gjavah.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/gjavah.c,v
retrieving revision 1.130
diff -u -u -r1.130 gjavah.c
--- gjavah.c	26 Apr 2005 00:24:00 -0000	1.130
+++ gjavah.c	28 Apr 2005 23:33:50 -0000
@@ -43,6 +43,8 @@
 #include "hashtab.h"
 #include "intl.h"
 
+#include "gjavah.h"
+
 #include <getopt.h>
 
 
@@ -60,6 +62,9 @@
    file.  */
 int flag_newer = 1;
 
+/* The name of the tool.  Either "gcjh" or "gjnih". */
+char *toolname = NULL;
+
 /* Directory to place resulting files in. Set by -d option. */
 static const char *output_directory = "";
 
@@ -266,7 +271,7 @@
 
   va_start (ap, msgid);
 
-  fprintf (stderr, "gcjh: ");
+  fprintf (stderr, "%s: ", toolname);
   vfprintf (stderr, _(msgid), ap);
   va_end (ap);
   fprintf (stderr, "\n");
@@ -2093,18 +2098,19 @@
 		 cstart, mode, cend);
       else
 	{
-	  fprintf (out, "%s This file was created by `gcjh -stubs%s'.%s\n\
+	  fprintf (out, "%s This file was created by `%s -stubs%s'.%s\n\
 %s\n\
 %s This file is intended to give you a head start on implementing native\n\
 %s methods using %s.\n\
-%s Be aware: running `gcjh -stubs %s' once more for this class may\n\
+%s Be aware: running `%s -stubs %s' once more for this class may\n\
 %s overwrite any edits you have made to this file.%s\n\n",
-		   cstart, jflag, mode,
+		   cstart, toolname, jflag, mode,
 		   cstart2,
 		   cstart2,
 		   cstart2,
 		   what,
 		   cstart2,
+		   toolname,
 		   jflag,
 		   cstart2,
 		   cend);
@@ -2327,15 +2333,18 @@
 static void
 usage (void)
 {
-  fprintf (stderr, _("Try 'gcjh --help' for more information.\n"));
+  fprintf (stderr, _("Try '%s --help' for more information.\n"), toolname);
   exit (1);
 }
 
 static void
 help (void)
 {
-  printf (_("Usage: gcjh [OPTION]... CLASS...\n\n"));
-  printf (_("Generate C++ header files from .class files\n\n"));
+  printf (_("Usage: %s [OPTION]... CLASS...\n\n"), toolname);
+  if (! strcmp (toolname, "gjnih"))
+    printf (_("Generate JNI header files from .class files\n\n"));
+  else
+    printf (_("Generate C++ header files from .class files\n\n"));
   printf (_("  -stubs                  Generate an implementation stub file\n"));
   printf (_("  -jni                    Generate a JNI header or stub\n"));
   printf ("\n");
@@ -2372,22 +2381,33 @@
 static void
 version (void)
 {
-  printf ("gcjh (GCC) %s\n\n", version_string);
+  printf ("%s (GCC) %s\n\n", toolname, version_string);
   printf ("Copyright %s 2004 Free Software Foundation, Inc.\n", _("(C)"));
   printf (_("This is free software; see the source for copying conditions.  There is NO\n"
 	    "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"));
   exit (0);
 }
 
+int main (int argc, char** argv) __attribute__((weak));
+
 int
 main (int argc, char** argv)
 {
+  return gjavah_main (argc, argv, 0, "gcjh");
+}
+
+int
+gjavah_main (int argc, char** argv, int jni_mode, char const* which_tool)
+{
   JCF jcf;
   int argi;
   char *output_file = NULL;
   int emit_dependencies = 0, suppress_output = 0;
   int opt;
 
+  flag_jni = jni_mode;
+  toolname = xstrdup (which_tool);
+
   /* Unlock the stdio streams.  */
   unlock_std_streams ();
 
Index: gjavah.h
===================================================================
RCS file: gjavah.h
diff -N gjavah.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gjavah.h	28 Apr 2005 23:33:50 -0000
@@ -0,0 +1,26 @@
+/* Declare gjavah_main.
+
+Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  
+
+Java and all Java-based marks are trademarks or registered trademarks
+of Sun Microsystems, Inc. in the United States and other countries.
+The Free Software Foundation is independent of Sun Microsystems, Inc.  */
+
+int gjavah_main (int argc, char** argv, int jni_mode, char const* which_tool);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]