Re: Example on JNI compilation

2009-04-20 Thread Andreas Otto
Am Samstag 18 April 2009 23:08:58 schrieb LCID Fire:
> I'm currently stuck with compiling a JNI library, which java does not
> recognize. I'm not too sure about what options I have to provide to
> automake and which are already builtin. Does anybody know an example of
> how a jni lib is built using automake?

Hi,

  in my project:   

http://libmsgque.sourceforge.net/
 
  you can find a implementation useable as template

  1. download the sources
  2. go into the "javamsgque" directory
  3. don't forget to add the autoconf macros for JNI
from the "m4" subdirectory and the "acinclude.m4" file


mfg

  Andreas Otto




Re: [PATCH v2 0/3] Improved support for generated Make rules

2009-04-20 Thread Peter Simons
Hi Allan,

a while ago, you submitted a patch and I have to apologize for
responding so late. I'm working on moving the Autoconf Archive to a
public repository at gnu.org. Once that's done, it will be much easier
for everyone to contribute patches. You wrote:

 > The patch series that follows is intended to improve (hopefully
 > replace) the existing macro AX_ADD_AM_MACRO. [...]

Your changes are now on-line at  and
in the GIT repository. I sort of assumed that they are alright with Tom?

Take care,
Peter




Re: Example on JNI compilation

2009-04-20 Thread John Calcote

On 4/20/2009 3:49 PM, Peter O'Gorman wrote:

John Calcote wrote:
   

On 4/18/2009 3:08 PM, LCID Fire wrote:
 

I'm currently stuck with compiling a JNI library, which java does not
recognize. I'm not too sure about what options I have to provide to
automake and which are already builtin. Does anybody know an example
of how a jni lib is built using automake?
   

There are basically two steps to building JNI libraries:
 


Note that on Mac OS X 10.4 and earlier, java will not load modules that
do not have a ".jnilib" extension, so you should add somewhere in
configure.ac, something like:

case $host_os in
*-darwin*)
JNI_EXTRA_LDFLAGS="-shrext .jnilib" ;;
esac
AC_SUBST(JNI_EXTRA_LDFLAGS)

then in your Makefile.am you can have:
mylib_la_LDFLAGS = -module -avoid-version $(JNI_EXTRA_LDFLAGS)

Peter
   
Thanks Peter, I didn't know this. I guess it won't be long before this 
isn't really an issue for newer macs, as 10.6 will probably be released 
in June, thereby bringing 10.4 to end-of-life state. However, there will 
still be plenty of older mac users out there.


I might as well ask this question here: We build a regular C/C++ shared 
library, and link our JNI stubs right into it, exporting the JNI 
interfaces right along side the native library interfaces. It seems to 
work well on the platforms we've tried it out on, and it saves a 
library. In fact, we do the same thing with our C# (mono) interfaces, so 
this library has a hefty exported API.


Besides the issue you pointed out above where JNI libs require a 
specific extension, do you know of any other issues with doing this sort 
of thing?


Thanks in advance,
John


Re: Example on JNI compilation

2009-04-20 Thread Peter O'Gorman
John Calcote wrote:
> On 4/18/2009 3:08 PM, LCID Fire wrote:
>> I'm currently stuck with compiling a JNI library, which java does not
>> recognize. I'm not too sure about what options I have to provide to
>> automake and which are already builtin. Does anybody know an example
>> of how a jni lib is built using automake?
> There are basically two steps to building JNI libraries:

Note that on Mac OS X 10.4 and earlier, java will not load modules that
do not have a ".jnilib" extension, so you should add somewhere in
configure.ac, something like:

case $host_os in
*-darwin*)
   JNI_EXTRA_LDFLAGS="-shrext .jnilib" ;;
esac
AC_SUBST(JNI_EXTRA_LDFLAGS)

then in your Makefile.am you can have:
mylib_la_LDFLAGS = -module -avoid-version $(JNI_EXTRA_LDFLAGS)

Peter
-- 
Peter O'Gorman
http://pogma.com




Re: Example on JNI compilation

2009-04-20 Thread John Calcote

On 4/18/2009 3:08 PM, LCID Fire wrote:
I'm currently stuck with compiling a JNI library, which java does not 
recognize. I'm not too sure about what options I have to provide to 
automake and which are already builtin. Does anybody know an example 
of how a jni lib is built using automake?

There are basically two steps to building JNI libraries:

1. Use the javah utility to generate JNI prototypes in C-language header 
files from your Java source code.
2. Compile the C-language JNI sources (including the headers generated 
in step 1) into a library.


Step 1 above is pure Java-speak, and Automake has little built-in 
functionality for it. Step 2, however is pure gcc, and Automake has no 
trouble with it. For an example of how to integrate javah operations 
into Makefile.am so you can do it all from Automake, see Chapter 6 of 
this online book at freesoftwaremagazine.com:


  http://www.freesoftwaremagazine.com/books/agaal/autotools_example

Search for the text, "Building the JNI C++ sources".

Regards,
John




Re: Example on JNI compilation

2009-04-20 Thread Ralf Wildenhues
* LCID Fire wrote on Mon, Apr 20, 2009 at 07:58:50PM CEST:
> Ralf Wildenhues wrote:
>> * LCID Fire wrote on Sat, Apr 18, 2009 at 11:08:58PM CEST:
>>> I'm currently stuck with compiling a JNI library, which java does not 
>>>  recognize. I'm not too sure about what options I have to provide to  
>>> automake and which are already builtin. Does anybody know an example 
>>> of  how a jni lib is built using automake?
>>
>> How would one go about doing it without automake?

> Like this:
> gcc -c -fPIC myfile.c -o myfile.o
> gcc -shared -lacl -Wl,-soname,mylib.so -o mylib.so myfile.o

I can't see anything JNI'ish or java'ish in the above, so, assuming
mylib.so is destined for $(pkglibdir),

  pkglib_LTLIBRARIES = mylib.la
  mylib_la_SOURCES = myfile.c
  mylib_la_LDFLAGS = -module -avoid-version
  mylib_la_LIBADD = -lacl

or I am still missing something that I haven't understood from your
request.

Cheers,
Ralf




Re: Example on JNI compilation

2009-04-20 Thread LCID Fire

Ralf Wildenhues wrote:

Hello,

* LCID Fire wrote on Sat, Apr 18, 2009 at 11:08:58PM CEST:
I'm currently stuck with compiling a JNI library, which java does not  
recognize. I'm not too sure about what options I have to provide to  
automake and which are already builtin. Does anybody know an example of  
how a jni lib is built using automake?


How would one go about doing it without automake?

Like this:
gcc -c -fPIC myfile.c -o myfile.o
gcc -shared -lacl -Wl,-soname,mylib.so -o mylib.so myfile.o