This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch for Review: Build all libjava .class files at once(Updated)
- From: Nic <nferrier at tapsellferrier dot co dot uk>
- To: gnustuff at thisiscool dot com
- Cc: tromey at redhat dot com, GCJ Patches <java-patches at gcc dot gnu dot org>
- Date: 16 Aug 2003 19:52:57 +0100
- Subject: Re: Patch for Review: Build all libjava .class files at once(Updated)
- References: <1ZWT2X754Y21CAQLGEXWD051B9HBKHIF.3f3e7a0d@p733>
Mohan Embar <gnustuff@thisiscool.com> writes:
> Hi Tom,
>
> >Like Alexandre says, you have to use the GNU make trick here to work
> >around systems with command line length limitations. With that change
> >this patch is ok.
>
> Woo hoo! I'll redo, retest and resubmit tomorrow evening.
>
> >Really, we'd like to find a way to write this code so that it doesn't
> >depend on GNU make at all, but still works on these limited systems.
> >Nobody has tried to figure out how to do that yet. We don't even know
> >if it is reasonably possible.
>
> It doesn't seem to me to be possible to get something
> out of a variable to another program other than through
> the command line. Am I missing something?
While you're looking at this have you considered using jarcompiler?
I've attached it and the example Makefile.am we use for paperclips.
#!/bin/bash
# The jar compiler.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# What does it do?
# Builds a jar file by compiling some java source and then jaring up
# the resulting classes.
#
# (C) Tapsell-Ferrier Limited 2003
# Nic Ferrier, <nferrier@tapsellferrier.co.uk>
# Argument 1 MUST contain the name of the JAR file
# Stdin MUST contain the list of the Java source files to compile.
# The following environment variables MUST be present:
# JARCOMPILER_JAVAC the java compiler command
# JARCOMPILER_JAVAC_OPTS options for the java compiler
# JARCOMPILER_CLASSPATH the CLASSPATH for the compile
# JARCOMPILER_JAR the jar command
# About Stdin
# The files passed on stdin need not be JUST java source files, the
# jarcompiler script also recognises META-INF files and a manifest.mf
# file. All META-INF files are added to the META-INF directory in the
# resulting JAR file and the manifest.mf, if present, is used as the
# resulting JAR file's manifest. The first manifest.mf found in the
# input list is used.
# Why BASH specific?
# This is BASH specific because error messages are redirected to
# stderr using the /dev/stderr special form. I've no idea how to do
# this in bourne shell.
# Other requirements.
# grep with -e
# rm
# trap
# tr
# Here's the program source.
# What's the target jar file called?
TARGETJAR=
if [ $1 ]
then
TARGETJAR=$1
else
echo 'No jar file specified.'
exit 1
fi
# Make the filelist from stdin.
FILELIST=filelist-$$
tr ' ' '\012' | tr '\009' '\012' > $FILELIST
# Add the file list to the clean up list
export CLEANUP=${FILELIST}
# Traps cause the CLEANUP to be removed
trap 'rm -rf `echo ${CLEANUP} | tr ":" " "`' 1 2 3 15
# Make the list of source files.
SOURCEFILELIST=sourcefilelist-$$
grep -e '\.java$' ${FILELIST} > $SOURCEFILELIST
# Add the source file list to the clean up list.
CLEANUP=${CLEANUP}:${SOURCEFILELIST}
# Make the list of META-INF files
METAINFCONTENTS=metainf-$$
grep -e '^META-INF/.*$' ${FILELIST} > $METAINFCONTENTS
# Add the meta inf file list to the clean up list.
CLEANUP=${CLEANUP}:${METAINFCONTENTS}
# Find a manifest file.
MANIFESTFILE=`grep -e 'manifest.mf$' ${FILELIST} | head -1`
# Check the directory for temporary storage
TARGETDIR=classes-$$
if [ -f $TARGETDIR ]
then
echo 'The target directory already exists.'
exit 1
else
mkdir $TARGETDIR
# Add the target directory to the clean up list.
CLEANUP=${CLEANUP}:${TARGETDIR}
fi
# Set the current directory.
CURRENT=`pwd`
# Unpack existing target if necessary.
if [ -f $TARGETJAR ]
then
sh -c "cd ${TARGETDIR} ; ${JARCOMPILER_JAR} -xf ${CURRENT}/${TARGETJAR}" 2> /dev/null
fi
# Compile the java source files, quitting if it fails.
FILESTOCOMPILE=`cat ${SOURCEFILELIST} | tr '\012' ' '`
CLASSPATH="$JARCOMPILER_CLASSPATH":${TARGETDIR} ${JARCOMPILER_JAVAC} ${JARCOMPILER_JAVAC_OPTS} -d ${TARGETDIR} @${SOURCEFILELIST} > /dev/null
JAVACEXITVALUE=$?
if [ $JAVACEXITVALUE -gt 0 ]
then
echo Compilation failed. > /dev/stderr
rm -rf `echo ${CLEANUP} | tr ':' ' '`
exit $JAVACEXITVALUE
fi
# Create the jar from the compiled classes, adding manifest if necessary.
JAROPTS=cf
if [ $MANIFESTFILE ]
then
JAROPTS="m${JAROPTS} ${MANIFESTFILE}"
fi
# Now jar the things that need to be jarred.
TOJAR=
for JARTARGET in `ls ${TARGETDIR}`
do
TOJAR="${TOJAR} -C ${TARGETDIR} ${JARTARGET}"
done
${JARCOMPILER_JAR} ${JAROPTS} ${CURRENT}/${TARGETJAR} ${TOJAR} 2> /dev/null
# Now remove all the temporary stuff (including the .class files)
rm -rf `echo ${CLEANUP} | tr ':' ' '`
# End.
# Makefile.am for GNU Paperclips.
# The java source files that make up the project
PAPERCLIPS_JAVASRC = source/gnupaperclips.java \
source/gnu/inet/http/ChunkedOutputStream.java \
source/gnu/inet/mime/base64/Base64InputStream.java \
source/gnu/inet/mime/base64/Base64OutputStream.java \
source/gnu/java/net/protocol/file/FileURLConnection.java \
source/gnu/java/net/protocol/file/Handler.java \
source/gnu/paperclips/AttributeAdapter.java \
source/gnu/paperclips/BadResourceMapping.java \
source/gnu/paperclips/Dispatcher.java \
source/gnu/paperclips/Host.java \
source/gnu/paperclips/HttpSessionManager.java \
source/gnu/paperclips/Int.java \
source/gnu/paperclips/MimeRegistry.java \
source/gnu/paperclips/RequestFilter.java \
source/gnu/paperclips/Requestable.java \
source/gnu/paperclips/RequestableServlet.java \
source/gnu/paperclips/Service.java \
source/gnu/paperclips/ServiceFailure.java \
source/gnu/paperclips/ServiceManager.java \
source/gnu/paperclips/Session.java \
source/gnu/paperclips/URIMap.java \
source/gnu/paperclips/URIMapping.java \
source/gnu/paperclips/URIPattern.java \
source/gnu/paperclips/WebApp.java \
source/gnu/paperclips/paperclips.java \
source/gnu/paperclips/filters/WebLog.java \
source/gnu/paperclips/http/BufferingStream.java \
source/gnu/paperclips/http/ChunkingOutputStream.java \
source/gnu/paperclips/http/ContentLengthOutputStream.java \
source/gnu/paperclips/http/HTTPConnection.java \
source/gnu/paperclips/http/HTTPInStream.java \
source/gnu/paperclips/http/HTTPOutStream.java \
source/gnu/paperclips/http/HTTPRequest.java \
source/gnu/paperclips/http/HTTPResponse.java \
source/gnu/paperclips/http/HTTPUtils.java \
source/gnu/paperclips/http/HttpTimeOutException.java \
source/gnu/paperclips/http/LowImpedanceInputStream.java \
source/gnu/paperclips/http/LowImpedanceOutputStream.java \
source/gnu/paperclips/http/LowImpedanceServletOutputStream.java \
source/gnu/paperclips/http/HTTPServer.java \
source/gnu/paperclips/io/ByteBufferInputStream.java \
source/gnu/paperclips/io/ByteBufferOutputStream.java \
source/gnu/paperclips/io/InputStreamReader.java \
source/gnu/paperclips/loading/ServletLoader.java \
source/gnu/paperclips/loading/WARClassLoader.java \
source/gnu/paperclips/servlets/AutoMapper.java \
source/gnu/paperclips/servlets/CGIServlet.java \
source/gnu/paperclips/servlets/DebugServlet.java \
source/gnu/paperclips/servlets/Test.java \
source/gnu/paperclips/servlets/WWW.java \
source/gnu/paperclips/utils/CleverTokenizer.java \
source/gnu/paperclips/utils/WARUtils.java \
source/gnu/paperclips/utils/DailyLogSink.java \
source/gnu/paperclips/utils/ApacheLogSpecHandler.java \
source/gnu/paperclips/utils/ContinuousLogSink.java \
source/gnu/paperclips/LogWriter.java \
source/gnu/paperclips/LogSink.java \
source/gnu/paperclips/FileServer.java \
source/gnu/paperclips/XmlServer.java
# The META stuff
PAPERCLIPS_META = META-INF/COPYING \
META-INF/LICENSE \
META-INF/mime.types
JARFILE = gnupaperclips.jar
BUILT_SOURCES = $(JARFILE)
META-INF/COPYING: COPYING
cp COPYING META-INF/
META-INF/LICENSE: LICENSE
cp LICENSE META-INF/
PAPERCLIPS_CLASSPATH = lib/servlet.jar:lib/gnujaxp.jar:lib/gnugetopt.jar:lib/gnusocketserv.jar:lib/gnujspengine.jar
$(JARFILE): $(PAPERCLIPS_JAVASRC) $(PAPERCLIPS_META)
echo $? | JARCOMPILER_JAVAC="@JAVAC@" \
JARCOMPILER_JAR=@JAR@ \
JARCOMPILER_CLASSPATH=$(PAPERCLIPS_CLASSPATH) \
./jarcompiler $(JARFILE)
# Remove jar file
clean-local:
rm -f ${JARFILE}
rm META-INF/COPYING
rm META-INF/LICENSE
# End of Makefile.am
It compiles source files in one bound and it does it without messy
command line length problems.
--
Nic Ferrier
http://www.tapsellferrier.co.uk