Forgot the attachment.

# 'simulate' automake environment
jardir = $(datadir)/java
srcdir=../maktest
MKDIR_P=mkdir -p

VPATH=.:$(srcdir)

all: foo.jar

##
## The makefile.am `equivalent' stuff
##
## This user has chosen to make it gnu-make only.
##
jar_JARS=foo.jar

# sources, all relative to '.'
foo_jar_SOURCES = $(shell cd $(srcdir) ; find src -name '*.java')
# 'generated' sources
foo_jar_SOURCES += stuff.java

# resources all relative to '.'
foo_jar_RESOURCES_PREFIX = src res
foo_jar_RESOURCES = $(shell cd $(srcdir) ; find src res -name '*.txt' -o -name 
'*.jpg' )
# 'generated' resources
foo_jar_RESOURCES += a.txt b.txt c.txt
foo_jar_MANIFEST = manifest
foo_jar_MAIN = au.notzed.stuff.Main

# build classpath
foo_jar_LIBADD = lib/jjmpeg.jar lib/test.jar

# "custom" targets
a.txt b.txt c.txt:
        touch $@

stuff.java:
        echo "class stuff { }" > stuff.java

##
## the jars.am fragment for foo.jar
##

# windows needs ;, of course ...
# automake.in generates this from LIBADD?
foo_jar_CLASSPATH=lib/jjmpeg.jar:lib/test.jar

foo_jar.stamp: $(foo_jar_SOURCES) $(foo_jar_LIBADD)
        rm -rf build/classes/foo_jar
        $(MKDIR_P) build/classes/foo_jar
        clist=""; \
        slist='$(foo_jar_SOURCES)' ; \
        for n in $$slist ; do \
                if test -f $$n ; then \
                        clist="$$clist $$n" ; \
                else \
                        clist="$$clist $(srcdir)/$$n" ; \
                fi ; \
        done; \
        echo compiling: $$clist; \
        javac -cp $(foo_jar_CLASSPATH) -d build/classes/foo_jar $$clist
        touch $@

# the complexity here is due to

# a) having to walk the 'VPATH' manually
# b) having to remap the relative roots of resources to the jar file root
# c) portable shell & tools

foo.jar: foo_jar.stamp $(foo_jar_RESOURCES) $(foo_jar_MANIFEST)
        rlist='$(foo_jar_RESOURCES)'; \
        clist=""; \
        for n in $$rlist ; do \
                found=0; \
                for p in $(foo_jar_RESOURCES_PREFIX) ; do \
                        t=`echo $$n | sed "s@^$$p/@@"` ; \
                        if test $$t != $$n ; then \
                                if test -f $$n ; then \
                                        clist="$$clist -C $$p $$t" ; \
                                else \
                                        clist="$$clist -C $(srcdir)/$$p $$t" ; \
                                fi ;\
                                found=1 ; \
                                break ; \
                        fi ; \
                done ; \
                if test $$found -eq 0 ; then \
                        if test -f $$n ; then \
                                clist="$$clist $$n" ; \
                        else \
                                clist="$$clist $(srcdir)/$$n" ; \
                        fi ;\
                fi ; \
        done ; \
        flags="cf" ; \
        files="$@" ; \
        if test -n "$(foo_jar_MANIFEST)" ; then \
                flags="$${flags}m"; \
                if test -f "$(foo_jar_MANIFEST)" ; then \
                        files="$$files $(foo_jar_MANIFEST)" ; \
                else \
                        files="$$files $(srcdir)/$(foo_jar_MANIFEST)" ; \
                fi; \
        fi ; \
        if test -n "$(foo_jar_MAIN)" ; then \
                flags="$${flags}e" ;\
                files="$$files $(foo_jar_MAIN)" ; \
        fi; \
        echo "jar $$flags $$files $$clist" ; \
        jar $$flags $$files -C build/classes/foo_jar . $$clist || ( rv=$$?; rm 
-f $@ ; exit $$rv )

Reply via email to