include ../config

#	wget $(DEBURL)/b/binutils/binutils_2.12.90.0.1-1.diff.gz
#	wget $(DEBURL)/b/binutils/binutils_2.12.90.0.1-1.dsc
#	wget $(DEBURL)/b/binutils/binutils_2.12.90.0.1.orig.tar.gz

NAME = binutils-2.12.90.0.1

LSRCDIR= $(SRCDIR)/$(NAME)
LBUILDDIR = $(BUILDDIR)/$(NAME)

LUNPACKDIR = $(UNPACKDIR)/binutils-2.12.90.0.1

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)
	touch stamp-dirs

unpack: stamp-unpack
stamp-unpack: stamp-dirs
	cd $(UNPACKDIR) && tar xfz $(DEBSRCDIR)/binutils_2.12.90.0.1.orig.tar.gz
	cd $(UNPACKDIR) && zcat $(DEBSRCDIR)/binutils_2.12.90.0.1-1.diff.gz | patch -p0
	touch stamp-unpack

untar: stamp-untar
stamp-untar: stamp-unpack
	cd $(SRCDIR) && tar xfI $(LUNPACKDIR)/binutils-2.12.90.0.1.tar.bz2
	touch stamp-untar


patch_dir = $(LUNPACKDIR)/debian/patches

all_patches = $(shell (cd $(LUNPACKDIR)/debian/patches/; find -type f ! -name 'chk-*') | sort | sed s,'./',,g)
debian_patches = $(all_patches)

# fixme, ARCH shouldn't be valid
ifneq ($(ARCH),arm)
debian_patches = $(filter-out 011_disable_combreloc_ARM_ONLY.diff,$(all_patches))
endif

list-patches:
	echo $(debian_patches)

patch: stamp-patch
stamp-patch: stamp-untar
	for f in $(debian_patches); do \
	  cd $(LSRCDIR) && patch -p1 <$(patch_dir)/$$f; \
	done
	touch stamp-patch

configure: stamp-configure
stamp-configure: stamp-patch
	cd $(LBUILDDIR) && $(LSRCDIR)/configure --enable-shared --disable-nls --target=$(HOST_ALIAS) --prefix=$(INSTALLDIR)
	touch stamp-configure

build: stamp-build
stamp-build: stamp-configure
	cd $(LBUILDDIR) && make
	touch stamp-build

install: stamp-install
stamp-install: stamp-build
	cd $(LBUILDDIR) && make install
	strip -g $(INSTALLDIR)/bin/*
	touch stamp-install


