This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: static gcj ant
Op do 16-01-2003, om 03:23 schreef Adam Megacz:
> Were you able to get gcj to compile ant? What tweaks did this require?
> I tried a few times about six months ago and couldn't get it to work.
In the end I used the attached script to compile the filtered classes
and performed the linking manually.
(gcj -o ant -static objects/*.o) the binary is compiled -Os, but this is
senseless, if I recompile it with -O0 it cuts down to 9 MB stripped, but
I have to do more testing with the tasks, just not enough time for it.
If you try it out (using the binary I linked) get the 2.2.5 version. The
2.3.1 version won't run on RH73/80.
I had a working directory like work/, with subdirectories work/sources
and work/objects, the work/sources contained toplevel directories for
each package, e.g. work/sources/org.apache.regexp or
work/sources/org.apache.tools , each containing the whole
org/apache/xx/..*.java tree for it's package, every object gets dumped
into the objects/ directory. The static linkage must be specified using
*.o instead of a linkage with .a because some classes won't get resolved
and included into the binary. At first what most bugged me was that the
documentation doesn't make it clear that you have to exclude a
preleading / character from the --resource <resource> parameter. But
after that it all went ok.
Seems to work fine, I am going to test a bigger series of chained xml
scripts this weekend. Currently trying to compile tomcat statically, but
this may not be feasible.
--
Dhek Bhun Kho <bhun@chello.nl>
#!/bin/bash
declare CLASSPATH="" SOURCEPATH="" PACKAGES=""
# main execution
main() {
checkArgs $@
environment $@
compile $@
}
# environment settings
environment() {
unset CLASSPATH
classpath $@
echo Using GCJFLAGS:
echo ---------------
if [ -z GCJFLAGS ];
then
GCJFLAGS="-g0 -pipe -Os -Wno-deprecated -fno-pedantic"
fi
echo $GCJFLAGS
}
# simple usage explanation if arguments fail sanity
printUsage() {
echo SimpleGCJ compile v.0.0.0.1
echo ""
echo This is a simple script, that expects two things:
echo "There exists a directory that contains the sourcetree <src>"
echo "There exists a directory that will contain the objectcode <obj>"
echo ""
echo EXAMPLE:
echo
echo ./compile sources/ objects/
echo
echo ENVIRONMENT:
echo ""
echo GCJFLAGS, e.g.:
echo ""
echo "(bash) export GCJFLAGS=-g0 -pipe -Os -mcpu=athlon -march=athlon"
echo "(csh) set env GCJFLAGS=-ggdb -pipe -falign-jumps=32"
echo ""
echo NOTE:
echo ""
echo In the example above, the sources directories, contain other directories
echo that are not part of any java package namespace. So sources/
echo could contain A/ B/ C/, which are not top level package names, the
echo actual tree for each source starts at sources/A/toppackage/ etc.
echo ""
}
# sanity check for arguments
checkArgs() {
if [ $# != 2 ] || [ ! -d $1 ] || [ ! -d $2 ]
then
printUsage ; exit 1
fi
}
# compile a single package contained in $1/<dir>/
packageCompile() {
local -i count=0; local -i skipped=0; local i j k o;
# sources
F=`find $1 -type f -name "*.java"`
C=`echo $F | wc -w`
echo Package: $1, $C source files
for i in $F
do
j=`echo ${i#$1} | sed "s/^\/*//g" | sed "s/\.java/\.o/g" | sed "s/\//\./g"`
o=${2%%/}/$j
if [ ! -f $o ] || [ $i -nt $o ]
then
gcj $GCJFLAGS -o $o $i $SOURCEPATH --classpath $CLASSPATH -c 2>>ERROR
count=count+1
echo $i
else
skipped=skipped+1
fi
done
echo Compiled $count files, skipped $skipped files
echo ""
# resources
F=`find $1 -type f -name "*[^java$|^diff$]" | sed "s/.*CVS.*//g" | sed "s/.*html$//g"`
C=`echo $F | wc -w` ; count=0; skipped=0;
echo Package: $1, $C resource files
for i in $F
do
j=`echo ${i#$1}`; j=${j##/} ; k=`echo ${j} | sed "s/\//\./g"`
o=${2%/}/${k}_resource.o
if [ ! -f $o ] || [ $i -nt $o ]
then
gcj $GCJFLAGS --resource $j $i -o $o -c -v 2>>ERROR
count=count+1
else
skipped=skipped+1
fi
done
echo Compiled $count files, skipped $skipped files
echo ""
}
# build classpath from all packages in $1/*
classpath() {
for i in `find ${1%%/}/* -type d -maxdepth 0`
do
CLASSPATH=$i:$CLASSPATH
SOURCEPATH="-B$i $SOURCEPATH"
PACKAGES="$i $PACKAGES"
done
echo Using CLASSPATH:
echo ----------------
echo $CLASSPATH
echo ""
echo "Using SOURCEPATH (-Bpath):"
echo --------------------------
echo $SOURCEPATH
echo ""
}
compile() {
echo ""
echo Compiling sourcetree $1 to $2
echo ---------------------`echo $1 | sed "s/./-/g"`----`echo $2 | sed "s/./-/g"`
for i in $PACKAGES
do
echo ""; packageCompile $i $2
done
}
main $@