where should the .o files end up?
Jeff Sturm
jeff.sturm@appnet.com
Tue Jul 18 13:30:00 GMT 2000
Per Bothner wrote:
> > For compatibility with JDK, I recommend a shell script... you can even
> > call it `javac'. If I can still find the one I used, I'll post it to
> > the list.
>
> My plan was that 'gcj -C' would be more-or-less compatible with javac.
>
> I.e. a javac shell-script should be nothing more than:
> #!/bin/sh
> exec gcj -C "$@"
That's fine for bytecode, but sometimes it would be convenient to have
native compilation mimic bytecode compilation, i.e. instead of
javac f1.java f2.java
jar -cf classes.jar f1.class f2.class
I want:
gcj -c f1.java f2.java
ar -r classes.a f1.o f2.o
Having a command like javac that produces .o files helps a little. I've
attached my javac-like script (warning: I am an infrequent shell
programmer, and it almost certainly has bugs). Note that it cannot
compile from bytecode, since it must extract the package name from the
source.
#!/bin/bash
# Read environment vars
: ${GCJDIR:=/usr/local}
: ${CLASSPATH:=.}
# Set defaults
gcj=$GCJDIR/bin/gcj
gcjargs=
objdir=.
classpath=$GCJDIR/share/libgcj.zip:$CLASSPATH
sources=
# Process command args
while [ $# -gt 0 ]; do
case $1 in
-g*|-O*)
gcjargs="$gcjargs $1" ;;
-classpath)
classpath=$2
shift ;;
-d)
objdir=$2
if [ ! -d "$objdir" ]; then
echo "error: $objdir is not a directory" >&2
exit 1
fi
shift ;;
-*)
echo "warning: unrecognized option: $1" >&2 ;;
*.java)
sources="$sources $1" ;;
esac
shift
done
# Compile each source file in turn, exiting on error
for src in $sources; do
obj=`basename $src .java`.o
pkg=`grep '^package' $src | sed 's/package[ \t]*\(.*\);/\1/'`
if [ "$pkg" ]; then
pkgdir=`echo $pkg | sed 's,\.,/,'`
else
pkgdir=.
fi
# FIXME: don't create target directory if gcj doesn't complete
mkdir -p $objdir/$pkgdir
err=$?
if [ $err -ne 0 ]; then exit $err; fi
$gcj -c $gcjargs --classpath=$classpath $src -o $objdir/$pkgdir/$obj
err=$?
if [ $err -ne 0 ]; then exit $err; fi
done
--
Jeff Sturm
jeff.sturm@appnet.com
More information about the Java
mailing list