include ../config

NAME = gcc-2.96-20000731

PWD := $(shell pwd)

LSRCDIR= $(SRCDIR)/$(NAME)
LBUILDDIR = $(BUILDDIR)/$(NAME)-stage2
LUNPACKDIR = $(UNPACKDIR)/gcc-2.96-99.1.src.rpm-unpacked

#AR=ar
#CC=gcc
#LD=ld
#NM=nm
#RANLIB=ranlib

#export AR CC LD NM RANLIB

all: install

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

#unpack: stamp-unpack
#stamp-unpack: stamp-dirs
#	cd $(UNPACKDIR) && tar xfz $(RPMSRCDIR)/gcc-2.96-99.1.src.rpm-unpacked.tar.gz
#	touch stamp-unpack

#untar: stamp-untar
#stamp-untar: stamp-unpack
#	cd $(SRCDIR) && tar xfI $(LUNPACKDIR)/gcc-2.96-20000731.tar.bz2
#	touch stamp-untar

#patch: stamp-patch
#stamp-patch: stamp-untar
#	patchdir=$(LUNPACKDIR) gccroot=$(LSRCDIR) sh ./patch-gcc
#	cd $(SRCDIR) && patch -p0 <$(PWD)/gcc-init-fini-section.patch
#	touch stamp-patch

# leaving out --enable-threads=posix for now
configure: stamp-configure
stamp-configure: stamp-dirs
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		$(LSRCDIR)/configure --enable-shared --enable-haifa --disable-checking --target=$(HOST_ALIAS) --build=$(BUILD_ALIAS) --host=$(BUILD_ALIAS) --prefix=$(INSTALLDIR) --enable-languages=c,c++
	cd $(LBUILDDIR) && touch gcc/c-gperf.h
	touch stamp-configure

# This bombs out configuring libiberty but who cares
build-gcc: stamp-build-gcc
stamp-build-gcc: stamp-configure
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		make all-gcc
	touch stamp-build-gcc

# We need the absolute libc in order for the config run for libstdc++ to succeed.
build: stamp-build
stamp-build: stamp-build-gcc
	cd $(INSTALLDIR)/mipsel-linux/lib/soft-float/pic-absolute && ln * $(LBUILDDIR)/gcc/pic-absolute/
	cd $(INSTALLDIR)/mipsel-linux/lib/soft-float/pic-absolute && ln * $(LBUILDDIR)/gcc/soft-float/pic-absolute/
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		make
	touch stamp-build

# The .so files for pic-absolute are busted, so nuke them too.
install: stamp-install
stamp-install: stamp-build
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		make install
	cd $(INSTALLDIR)/bin && strip -g gcov *-cpp *-gcc
	cd $(INSTALLDIR)/lib/gcc-lib && strip -g */2.96/cc1 */2.96/cc1plus */2.96/collect2 */2.96/cpp0 */2.96/tradcpp0 
	rm -f $(INSTALLDIR)/mipsel-linux/lib/soft-float/pic-absolute/libstdc++*.so*
	rm -f $(INSTALLDIR)/mipsel-linux/lib/pic-absolute/libstdc++*.so*
	cd $(INSTALLDIR)/lib/gcc-lib && rm mipsel-linux/2.96/pic-absolute/libstdc++.so
	cd $(INSTALLDIR)/lib/gcc-lib && rm mipsel-linux/2.96/soft-float/pic-absolute/libstdc++.so
	touch stamp-install


