Hi Conor & all,
I worked a bit more on this task, and I think it's getting better! I hope it
will appear in Ant 1.4 :-)
In summary, the <jnicc> task can be used to only create jni headers (like
javah by Richard Beton), or only compile files (or do both).
<jnicc> can include one or more <compiler> sub-task, which can compile
whatever you like! By default, it can run gcc or ms'cl to compile C/C++, but
other compilers could be used... It's far from perfect yet, but I hope to
make it generic enough so that other tasks could use it to compile other
languages on any platform.
Anyway, there's still a lot of work, so I won't pollute this list with the
classes again! (If you want them anyway, drop me an email).
Following are some examples and information for both classes, I hope it's
clear enough to understand how they work and what they can do.
I'd really like to hear your comments and ideas, and if you think this work
is useful...
avagoodweekend,
Gerald.
To create jni headers from all java source files:
<jnicc
src="${src}" desthdir="${build.jni.h}"
classpath="${build.classes}"
>
<patternset includes="**/*.java" />
</jnicc>
To create jni headers from java source files that have a C source file with
the same filename:
<jnicc
src="${src}" desthdir="${build.jni.h}"
classpath="${build.classes}"
>
<patternset includes="**/*.c" />
</jnicc>
To create jni headers from java source files that have a C source file with
the same filename, and compile these C files to a library:
<jnicc
src="${src}" desthdir="${build.jni.h}"
destodir="${build.jni.o}" destdir="${build.lib}"
lib="mylib"
classpath="${build.classes}"
>
<patternset includes="**/*.c" />
<compiler builtin="mscc" />
</jnicc>
To compile all C files to a library with two compilers (no jni):
<jnicc
jni="no"
src="${src}"
destodir="${build.jni.o}" destdir="${build.lib}"
lib="mylib"
>
<patternset includes="**/*.c" />
<compiler builtin="mscc" />
<compiler builtin="gcc" outextradir="gcc" />
</jnicc>
Info from Jnicc.java:
* Task to create jni header files, compile C source files and link
* libraries. This task can take the following arguments:
* <ul>
* <li>src - required (or nested <src>), source directory
* <li>jni - create jni headers? (=true)
* <li>lib - library name without path, prefix or extension
* <li>destdir - library destination directory (=srcdir)
* <li>desthdir - jni header destination directory (=destdir)
* <li>destodir - object files destination directory (=destdir)
* <li>classpath - classpath pointing to the compiler java classes (=srcdir)
* <li>classpathref - reference to an already-defined classpath
* <li>hincludedot - include C headers from the same directory as their
* C source file? (=true)
* </ul>
* <p>
* Nested arguments:
* <ul>
* <li>src - required (or src argument), source directories
* <li>classpath - classpath pointing to the compiler java classes (=srcdir)
* <li>compiler - compiler and linker sub-task
* <li>arg - extra arguments for all compilers and linker
* <li>compilerarg - extra arguments for all compilers
* <li>linkerarg - extra arguments for all linkers
* </ul>
* <p>
* When this task executes, it will recursively scan the <b>src</b>
* looking for the given source files to compile.
* <br>
* If <b>jni</b> is true, if there is a java source file with the same
* filename as the source file in the same directory, javah will create a
* jni header file in desthdir.
* The header filename is the fully-qualified class name, where the class
* separators are replaced by underscore characters '_'
* (e.g. org.fred.foo -> org_fred_foo.h).
* <br>
* If any, the nested compilers will compile the source file to an
* object file in destodir and will link the lib library in destdir.
* The object filename is the relative path of the source filename, where
* the separators are replaced by underscore characters '_'.
* The <b>desthdir</b> directory is given to compilers as their first
include
* directory.
* <br>
* This task and the compilers make the create/compile/link decisions based
* on timestamps.
Info from Compiler.java:
* Task to compile source files and link a library using an external
* compiler/linker. This task can take the following arguments:
* <ul>
* <li>builtin - use built-in compiler settings (=gcc)
* <li>os - OS on which this compiler can run
* <li>outextradir - Extra directory appended to the output directories
* <li>executable - executable filename
* </ul>
* <p>
* Nested arguments:
* <ul>
* <li>arg, extra arguments for both compiler and linker
* <li>compilerarg - extra arguments for the compiler
* <li>linkerarg - extra arguments for the linker
* <li>include - include directories
* </ul>
* <p>
* This task doesn't execute anything! Its parameters are used to
* configure the compiler/linker-dependent settings. Its parent task
* will give task-dependent settings (include directories, destination
* directories for object files and library, and the library name) and
* the list of files to compile. The parent task then asks the compiler
* to do the compilation and linking.
* <br>
* This task makes its compile&link decisions based on source and object
* file timestamps (and the parent task can force compilation of particular
* files if it knows about extra dependencies, like header files).
> -----Original Message-----
> From: Conor MacNeill [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, 13 February, 2001 21:29
> To: [EMAIL PROTECTED]
> Subject: Re: [SUBMISSION] New task to compile jni, c, dll
>
>
> Gerald,
>
> Thanks for posting this. I won't be looking at new tasks
> until I get Ant
> 1.3 out the door so unless someone else has time to pick this
> up, you may
> have to wait a week or two before I can review it. If someone
> else wants to
> comment on it or give Gerald some feedback, please go ahead.
>
> Thanks
> Conor.