Java compiler patch: compile resource files into executables
Zack Weinberg
zack@codesourcery.com
Sun Sep 2 21:43:00 GMT 2001
On Sun, Sep 02, 2001 at 09:21:40PM -0700, Anthony Green wrote:
> Zack wrote:
> > This facility will be useful to programs written in other languages.
> > Would you mind documenting the format of the .o file generated by gcj
> > in this mode, so that a C program could make use of it?
>
> Ok. Where would you like to see these docs? Comments in source? Or texinfo?
Texinfo, ideally, since it is a user-useful feature.
> It's basically a couple of unsigned longs followed by the resource
> name and data. The .o also contains a constructor function for
> calling _Jv_RegisterResource with a pointer to this whole mess. I
> plan to add a -z# option to compress the resource data. The java
> runtime change to support this is trivial, and jc1 already links in
> zlib.
Let me give a simple example of the sort of code one would like to be
able to write. The appended shell script generates a self-extracting
archive. What needs to be documented is what the embedded C program
should do instead of declaring and using the arch_length and arch_data
externs.
(There would be less trivial applications that wanted to have access
to the resource name and properties (if any) as well, of course.)
zw
#! /bin/sh
mkdir /tmp/sea$$ || exit 1
tar cf - $2 | gzip > /tmp/sea$$/arch.tar.gz
cat > /tmp/sea$$/code.c <<\EOF
#include <stdio.h>
extern size_t arch_length;
extern unsigned char arch_data[];
int
main(void)
{
/* error checks left out for brevity */
FILE *pipe = popen("zcat | tar xf -", "w");
fwrite(arch_data, 1, arch_length, pipe);
return !!pclose(pipe);
}
EOF
gcj -R arch -o /tmp/sea$$/arch.o /tmp/sea$$/arch.tar.gz
gcc -c -o /tmp/sea$$/code.o /tmp/sea$$/code.c
gcc -o $1 /tmp/sea$$/code.o /tmp/sea$$/arch.o
rm -rf /tmp/sea$$
More information about the Gcc-patches
mailing list