TAG = R3_8_2
TAG = R4_3_1

cvsroot = :pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse

destination = sources.redhat.com:\~ftp/pub/java

# We don't use dependencies since we want to let the user run steps in
# isolation.
all:
	$(MAKE) checkout
	$(MAKE) compile
	$(MAKE) ecj.jar ecj-source.tar.bz2

checkout:
#	git clone -b R3_8_maintenance git://git.eclipse.org/gitroot/jdt/eclipse.jdt.core.git
#	wget http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/snapshot/$(TAG).tar.gz
	tar xf $(TAG).tar.gz
	rm -rf org.eclipse.jdt.core
	mkdir org.eclipse.jdt.core
	cp $(TAG)/org.eclipse.jdt.core/scripts/about.html \
	  org.eclipse.jdt.core/.
	cp $(TAG)/org.eclipse.jdt.core/scripts/build.xml \
	  org.eclipse.jdt.core/.
	tar -c -f - -C $(TAG)/org.eclipse.jdt.core/compiler org \
	  | tar -x -f - -C org.eclipse.jdt.core/
	find org.eclipse.jdt.core -name CheckDebugAttributes.java | xargs -r rm -f
	find org.eclipse.jdt.core -name BuildJarIndex.java | xargs -r rm -f
	tar -c -f - -C $(TAG)/org.eclipse.jdt.core/batch org \
	  | tar -x -f - -C org.eclipse.jdt.core/
	mkdir -p org.eclipse.jdt.core/META-INF/services
	printf 'org.eclipse.jdt.internal.compiler.tool.EclipseCompiler #Eclipse compiler' \
	  > org.eclipse.jdt.core/META-INF/services/javax.tools.JavaCompiler

SOURCES = org org.eclipse.jdt.core

OUTPUT = bin

ecj.jar:
	cd $(OUTPUT); jar cf ../ecj.jar .

ecj-source.tar.bz2:
	tar -jcf ecj-source.tar.bz2 --exclude '*~' \
		ChangeLog gcc.properties Makefile org org.eclipse.jdt.core

compile:
	@mkdir -p $(OUTPUT)
	find $(SOURCES) -name '*.java' > List
	ecj -d $(OUTPUT) -1.5 -nowarn -g @List
	set -e; \
	here=`pwd`; for dir in $(SOURCES); do \
	  (cd $$dir; find . -name '*.properties' -o -name '*.props' -o -name '*.rsc' | \
	   while read x; do \
	     echo "cp $$x $$here/$(OUTPUT)/$$x"; \
	     mkdir -p $$(dirname $$here/$(OUTPUT)/$$x); \
	     cp $$x $$here/$(OUTPUT)/$$x; \
	   done); \
	done
	cat gcc.properties >> $(OUTPUT)/org/eclipse/jdt/internal/compiler/batch/messages.properties
	mkdir -p $(OUTPUT)/META-INF
#	cp org.eclipse.jdt.core/META-INF/MANIFEST.MF $(OUTPUT)/META-INF

# Once per GCC release you should upload an appropriate jar.
# Don't change these once the release is out.
# You could also upload a 'HEAD' release.
upload:
	@test -n "$(RELEASE)" || ( echo "You must set RELEASE"; exit 1)
	scp ecj.jar $(destination)/ecj-$(RELEASE).jar
	scp ecj-source.tar.bz2 $(destination)/ecj-$(RELEASE)-source.tar.bz2

.PHONY: all login checkout ecj.jar compile upload
