GCCVER:=3.3.3
DATE:=20040217-1
MY_DATE:=20040810
REL:=1
CYGWIN_GCCDOTVER:=3.3.3
prefix:=@prefix@
libdir:=@libdir@
sysconfdir:=etc
srcdir:=@srcdir@
VPATH:=$(srcdir)
GCCDOTVER:=${subst _,.,$(GCCVER)}
postinstall:=$(sysconfdir)/postinstall
preremove:=$(sysconfdir)/preremove
tarfile_name:=gcc-mingw-java-$(GCCDOTVER)-$(DATE).tgz
tarfile:=../$(postinstall)/$(tarfile_name)
postinstall_exec:=$(postinstall)/gcc-mingw-java.sh
preremove_exec:=$(preremove)/gcc-mingw-java.sh
NEEDEXE:=jc1.exe\njvgenmain.exe

SRC=gcc-mingw-g++-$(GCCVER)-$(DATE)-src.tar.gz
CORE=gcc-core-$(GCCVER)-$(DATE).tar.gz
GXX=gcc-g++-$(GCCVER)-$(DATE).tar.gz
G77=gcc-g77-$(GCCVER)-$(DATE).tar.gz
GNAT=gcc-ada-$(GCCVER)-$(DATE).tar.gz
GCJ=gcc-java-$(GCCVER)-$(DATE).tar.gz
OBJC=gcc-objc-$(GCCVER)-$(DATE).tar.gz
GPC=gpc-$(DATE).i386-pc-mingw32.tar.gz

.PHONY: all install install-info

all:	usr/i686-pc-mingw32

clean:
	rm -rf usr etc

usr/i686-pc-mingw32: $(GCJ)
	rm -rf usr
	mkdir -p usr/i686-pc-mingw32 usr/lib/gcc-lib
	tar xvzf ${word 1,$^} -C usr/i686-pc-mingw32 lib
	mv usr/i686-pc-mingw32/lib/gcc-lib/mingw32 usr/lib/gcc-lib/i686-pc-mingw32
	[ "$(CYGWIN_GCCDOTVER)" != "$(GCCDOTVER)" ] && \
	mv usr/lib/gcc-lib/i686-pc-mingw32/$(GCCDOTVER) usr/lib/gcc-lib/i686-pc-mingw32/$(CYGWIN_GCCDOTVER) \
	|| :
	cd usr/lib/gcc-lib/i686-pc-mingw32/$(CYGWIN_GCCDOTVER);\
	for f in `/bin/echo -e "$(NEEDEXE)" *.exe specs | sort -u`; do\
	    case "$$f" in\
		*\**)	echo OOPS; exit 1 ;;\
	    esac;\
	    rm -f $$f;\
	    ln -s ../../i686-pc-cygwin/$(CYGWIN_GCCDOTVER)/$$f .;\
	done
	rm -rf usr/i686-pc-mingw32/lib/gcc-lib

install: all $(tarfile) $(postinstall_exec) $(preremove_exec)

$(postinstall):
	@mkdir -p $@

$(preremove):
	@mkdir -p $@

$(tarfile): $(postinstall)
	cd usr; find * \! -type d | sort | tar -T - -czf $@

$(postinstall_exec): $(postinstall)
	(echo '#!/bin/sh';\
	 echo '[ -f /etc/postinstall/$(tarfile_name) ] || exit 0';\
	 echo '[ -d /usr/include ] || exit 0';\
	 echo '/bin/mkdir -p /usr/i686-pc-mingw32 /usr/include/mingw /usr/lib/mingw /usr/i686-pc-cygwin/bin';\
	 echo 'cd /usr/i686-pc-mingw32';\
	 echo '[ ! -e /usr/i686-pc-mingw32/include -a -d "../include/mingw" ] && ln -s "../include/mingw" /usr/i686-pc-mingw32/include';\
	 echo '[ ! -e /usr/i686-pc-mingw32/lib -a -d "../lib/mingw" ] && ln -s "../lib/mingw" /usr/i686-pc-mingw32/lib';\
	 echo '[ ! -e /usr/i686-pc-mingw32/bin -a -d "../i686-pc-cygwin/bin" ] && ln -s "../i686-pc-cygwin/bin" /usr/i686-pc-mingw32/bin';\
	 echo 'echo "*** Unpacking /etc/postinstall/$(tarfile_name).  Please wait. ***"';\
	 echo '/bin/tar -xzvf /etc/postinstall/$(tarfile_name) -C /usr > /etc/preremove/gcc-mingw-java-manifest.lst';\
	) > $@
	chmod a+x $@

$(preremove_exec): $(preremove)
	(echo '#!/bin/sh';\
	 echo '[ -f /etc/preremove/gcc-mingw-java-manifest.lst ] || exit 0';\
	 echo 'echo "*** Removing gcc-mingw-java files.  Please wait. ***"';\
	 echo 'cd /usr';\
	 echo '/bin/rm -rvf `cat /etc/preremove/gcc-mingw-java-manifest.lst` /etc/preremove/gcc-mingw-java-manifest.lst';\
	) > $@
	chmod a+x $@
	
install-info:
	@/bin/echo

Makefile: Makefile.in $(srcdir)/configure.in config.status
	$(SHELL) config.status

config.status: configure
	$(SHELL) config.status --recheck

package: install
	/usr/bin/tar cjf gcc-mingw-java-$(MY_DATE)-$(REL).tar.bz2 etc/

sourcepackage:
	@mkdir -p gcc-mingw-java-$(MY_DATE)-$(REL)
	@cp Makefile.in configure.in configure $(GCJ) gcc-mingw-java-$(MY_DATE)-$(REL)
	@tar cjvf gcc-mingw-java-$(MY_DATE)-$(REL)-src.tar.bz2 gcc-mingw-java-$(MY_DATE)-$(REL)
	@rm -rf gcc-mingw-java-$(MY_DATE)-$(REL)
