include ../config

NAME = glibc-2.2.4

PWD := $(shell pwd)

LSRCDIR= $(SRCDIR)/$(NAME)
LBUILDDIR = $(BUILDDIR)/$(NAME)-absolute
LUNPACKDIR = $(UNPACKDIR)/glibc-2.2.4-19.4.src.rpm-unpacked
LTMPDIR = $(BUILDDIR)/$(NAME)-absolute-inst


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

#export AR CC LD NM RANLIB

all: install

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

#unpack: stamp-unpack
#stamp-unpack: stamp-dirs
#	cd $(UNPACKDIR) && tar xfz $(RPMSRCDIR)/glibc-2.2.4-19.4.src.rpm-unpacked.tar.gz
#	touch stamp-unpack

#untar: stamp-untar
#stamp-untar: stamp-unpack
#	cd $(SRCDIR) && tar xfI $(LUNPACKDIR)/glibc-2.2.4.tar.bz2
#	touch stamp-untar

#patch: stamp-patch
#stamp-patch: stamp-untar
#	patchdir=$(LUNPACKDIR) glibcroot=$(LSRCDIR) sh ./patch-glibc
#	cd $(SRCDIR) && patch -p0 <$(PWD)/glibc-softfp.patch
#	touch stamp-patch

# leaving out --enable-threads=posix for now
configure: stamp-configure
stamp-configure: stamp-dirs
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		BUILD_CC=gcc \
		CC='mipsel-linux-gcc -pic-absolute -msoft-float' \
		$(LSRCDIR)/configure --disable-shared --enable-static-nss --disable-profile --without-fp --enable-add-ons=yes --without-cvs --enable-kernel=2.4.0 --with-headers=$(KERNEL_HEADERS) --prefix=/usr --build=$(BUILD_ALIAS) --host=$(HOST_ALIAS)
	touch stamp-configure

build: stamp-build
stamp-build: stamp-configure
	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 install_root=$(LTMPDIR)
	cd $(LTMPDIR) && mipsel-linux-strip -g sbin/* 
	cd $(LTMPDIR)/usr/bin && mipsel-linux-strip -g gencat getconf getent iconv locale localedef pcprofiledump rpcgen sprof
	touch stamp-upstream-install

#fix-temp: stamp-fix-temp
#stamp-fix-temp: stamp-upstream-install
#	cd $(LTMPDIR)/usr/lib && \
#		find . -type l -printf "rm %p; ln -s \`basename %l\` %p\n" | grep " ../../lib" | sh
#	touch stamp-fix-temp

install: stamp-install
stamp-install: stamp-upstream-install
	-mkdir $(INSTALLDIR)/mipsel-linux/lib/soft-float
	-mkdir $(INSTALLDIR)/mipsel-linux/lib/soft-float/pic-absolute
	cd $(LTMPDIR)/usr/lib && \
		find . -print | cpio -pumd $(INSTALLDIR)/mipsel-linux/lib/soft-float/pic-absolute
	touch stamp-install
