include ../config

NAME = glibc-2.0.7

PWD := $(shell pwd)

LSRCDIR= $(SRCDIR)/$(NAME)
LBUILDDIR = $(BUILDDIR)/$(NAME)-absolute
LTMPDIR = $(BUILDDIR)/$(NAME)-absolute-inst

all: install

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

untar: stamp-untar
stamp-untar: stamp-dirs
	cd $(SRCDIR) && tar xfz $(DEBSRCDIR)/glibc-2.0.7-snow.tar.gz
	touch stamp-untar

custom_patches = glibc-errno-bss-section glibc-new-softfloat-flag

custom-patch: stamp-custom-patch
stamp-custom-patch: stamp-untar
	set -e; \
	for f in $(custom_patches); do \
	  echo "custom patch $$f:"; \
	  patch -d $(LSRCDIR) -p1 <$(PWD)/$$f.patch; \
	done
	touch stamp-custom-patch

configure: stamp-configure
stamp-configure: stamp-untar stamp-custom-patch
	cd $(LBUILDDIR) && PATH=$(INSTALLDIR)/bin:$$PATH \
		BUILD_CC=gcc \
		CC='mipsel-linux-gcc -snow-model -msoft-float -DDO_STATIC_NSS' \
		$(LSRCDIR)/configure --disable-shared --disable-profile --without-fp --enable-add-ons=yes --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)
	touch stamp-upstream-install

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