include ../config

NAME = gcc-20011006

PWD := $(shell pwd)

LSRCDIR= $(SRCDIR)/$(NAME)
LBUILDDIR = $(BUILDDIR)/$(NAME)-stage2
LUNPACKDIR = $(UNPACKDIR)/gcc-2.95-2.95.4.ds8

all: install

dirs: stamp-dirs
stamp-dirs: 
	-mkdir $(LBUILDDIR)
	touch stamp-dirs

configure: stamp-configure
stamp-configure: stamp-dirs
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		$(LSRCDIR)/configure --disable-shared --disable-checking --target=$(HOST_ALIAS) --build=$(BUILD_ALIAS) --host=$(BUILD_ALIAS) --prefix=$(INSTALLDIR) --enable-languages=c,c++
	touch stamp-configure

# In order for libiberty and libstdc++ to configure properly, this
# version of gcc needs working libraries in place.  Well, actually
# they don't have to work; they just have to link such that autoconf
# can find them.

build-gcc: stamp-build-gcc
stamp-build-gcc: stamp-configure
	-mkdir $(LBUILDDIR)/gcc
	-mkdir $(LBUILDDIR)/gcc/soft-float
	-mkdir $(LBUILDDIR)/gcc/snow-model
	-mkdir $(LBUILDDIR)/gcc/soft-float/snow-model
	-ln $(BUILDDIR)/glibc-2.0.7-inst/usr/lib/* $(LBUILDDIR)/gcc/
	-ln $(BUILDDIR)/glibc-2.0.7-inst/usr/lib/* $(LBUILDDIR)/gcc/soft-float/
	-ln $(BUILDDIR)/glibc-2.0.7-absolute-inst/usr/lib/* $(LBUILDDIR)/gcc/snow-model/
	-ln $(BUILDDIR)/glibc-2.0.7-absolute-inst/usr/lib/* $(LBUILDDIR)/gcc/soft-float/snow-model/
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		make all-gcc
	touch stamp-build-gcc

build: stamp-build
stamp-build: stamp-build-gcc
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		make
	touch stamp-build

upstream-install: stamp-upstream-install
stamp-upstream-install: stamp-build
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		make install
	touch stamp-upstream-install

install: stamp-install
stamp-install: stamp-upstream-install
	cd $(INSTALLDIR)/bin && mv gcov mipsel-linux-gcov
	cd $(INSTALLDIR)/bin && mv cpp mipsel-linux-cpp
	cd $(INSTALLDIR)/bin && strip -g mipsel-linux-gcov mipsel-linux-cpp mipsel-linux-gcc mipsel-linux-c++filt mipsel-linux-c++ mipsel-linux-protoize mipsel-linux-unprotoize
	cd $(INSTALLDIR)/lib/gcc-lib && strip */2.95.4/cc1 */2.95.4/cc1plus */2.95.4/collect2 */2.95.4/cpp0
	cd $(INSTALLDIR)/mipsel-linux/lib && rm libiberty.a soft-float/libiberty.a libstdc++.a.2.10.0 soft-float/libstdc++.a.2.10.0
	cd $(INSTALLDIR)/mipsel-linux/lib && rm snow-model/libstdc++.a.2.10.0 snow-model/libiberty.a
	touch stamp-install
