[m-rev.] For review: library predicates for Java using JNI

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Jan 31 12:57:25 AEDT 2004


On 29-Jan-2004, James Goddard <goddardjames at yahoo.com> wrote:
> Implement some library predicates for Java using JNI.
> 
> +#include "../../runtime/mercury_imp.h"
> +#include "../../runtime/mercury_timing.h"

Please don't use relative paths in #include lines;
instead, just include "mercury_imp.h" and add the
appropriate -I option in the Mmakefile.

> Index: java/runtime/Mmakefile
> ===================================================================
> RCS file: java/runtime/Mmakefile
> diff -N java/runtime/Mmakefile
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ java/runtime/Mmakefile	29 Jan 2004 00:21:15 -0000
> @@ -0,0 +1,24 @@
> +
> +# Copyright (C) 2004 The University of Melbourne.
> +# This file may only be copied under the terms of the GNU Library General
> +# Public License - see the file COPYING.LIB in the Mercury distribution.
> +#
> +# This Makefile compiles the shared object for use with mercury.runtime.Native
> +#
> +
> +
> +MAIN_TARGET=Native.so
> +
> +
> +Native.so:	Native.o ../../runtime/mercury_timing.o
> +		gcc -shared Native.o ../../runtime/mercury_timing.o \
> +				-o Native.so
> +
> +Native.o:	Native.c
> +		gcc -c Native.c

Never ever ever use gcc without at _least_ -Wall.

Also, it would be better to avoid hard-coding the name of the
compiler and options, e.g. using $(CC) $(CFLAGS) and setting
CC and CFLAGS appropriately.

Is there any reason why using "mgnuc" won't work?
e.g.

	Native.o:	Native.c
		$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) -c Native.c

Also, shared objects should be compiled with `-fpic', or more
generally with $(CFLAGS_FOR_PIC) -- and then for consistency
with our naming convention used elsewhere it should be Native.pic_o
rather than Native.o.

> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/Mmakefile,v
> retrieving revision 1.128
> diff -u -d -r1.128 Mmakefile
> --- library/Mmakefile	27 Jan 2004 00:20:28 -0000	1.128
> +++ library/Mmakefile	29 Jan 2004 00:42:49 -0000
> @@ -244,12 +244,19 @@
>  # jar file.  At this point we also add the runtime classes to a jar file.
>  # Note that this stage makes use of the symbolic links created earlier to
>  # ensure that the path names are correct within the jar files.
> -JARS = $(STD_LIB_NAME).jar $(STD_LIB_NAME).runtime.jar
> +# We also compile NATIVE_SO here and copy it into the library directory.
> +
> +JARS = $(STD_LIB_NAME).jar $(STD_LIB_NAME).runtime.jar $(NATIVE_SO)
>  
>  .PHONY:	jars
>  jars:	classes
>  	jar cf $(STD_LIB_NAME).jar mercury/*.class
>  	jar cf $(STD_LIB_NAME).runtime.jar mercury/runtime/*.class
> +	+cd mercury/runtime && mmake $(NATIVE_SO)
> +	cp mercury/runtime/$(NATIVE_SO) .

If the building of $(NATIVE_SO) fails, then the whole Mmake should not
fail.  So these last two commands should be prefixed with "-".

> +# This shared object is needed to run some of the standard library methods.
> +NATIVE_SO = Native.so
>  
>  #-----------------------------------------------------------------------------#
>  
> @@ -404,6 +411,7 @@
>  	rm -f liblibrary.$A liblibrary.so library.init
>  	rm -f $($(STD_LIB_NAME).mods:%=%.h)
>  	rm -f tags
> +	rm -f $(JARS)

We should also remove $(NATIVE_SO).

> @@ -485,6 +493,8 @@
>  else
>  
>  ifneq (,$(findstring java,$(GRADE)))
> +
> +# Copy the jars and NATIVE_SO to INSTALL_JAVA_LIBRARY_DIR.

I think the code there doesn't install the NATIVE_SO.

Also, the NATIVE_SO file should not get installed to
INSTALL_JAVA_LIBRARY_DIR (.../lib/mercury/lib/java), because
that directory is for files which are not architecture-dependent.
Instead it should get installed in an architecture-specific directory,
e.g. .../lib/mercury/lib/java/i686-pc-linux-gnu.

Otherwise, that looks good.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list