NAMEVER=glibc-kernheaders
SPECFILE=$(NAMEVER).spec
VERSION=$(shell grep '^Version:' $(SPECFILE) | awk '{print $$2}' | sed 's/\./_/g')
RELEASE=$(shell grep '^Release:' $(SPECFILE) | awk '{print $$2}' | sed 's/\./_/g')

RPM=$(shell if test -f /usr/bin/rpmbuild ; then echo rpmbuild ; else echo rpm ; fi)

# default target: just make sure we've got the sources
all: sources

i386: sources
	$(RPM) --define "_sourcedir `pwd`" --target i386 -ba $(SPECFILE)

x86_64: sources
	$(RPM) --define "_sourcedir `pwd`" --target x86_64 -ba $(SPECFILE)

alpha: sources
	$(RPM) --define "_sourcedir `pwd`" --target alpha -ba $(SPECFILE)

ia64: sources
	$(RPM) --define "_sourcedir `pwd`" --target ia64 -ba $(SPECFILE)

s390: sources
	$(RPM) --define "_sourcedir `pwd`" --target s390 -ba $(SPECFILE)

s390x: sources
	$(RPM) --define "_sourcedir `pwd`" --target s390x -ba $(SPECFILE)

mac: sources
	$(RPM) --define "_sourcedir `pwd`" --target ppc -ba $(SPECFILE)

ppc: mac

pseries: sources
	$(RPM) --define "_sourcedir `pwd`" --target ppcpseries -ba $(SPECFILE)

ppc64: sources
	$(RPM) --define "_sourcedir `pwd`" --target ppc64 -ba $(SPECFILE)

iseries: sources
	$(RPM) --define "_sourcedir `pwd`" --target ppciseries -ba $(SPECFILE)

prep: rpm-prep

build: srpm 
	vr=`rpm -q --specfile $(SPECFILE) --qf "%{VERSION}-%{RELEASE}\n" | head -1` ;\
	chmod a+r *	; \
	bhc dist-8.0-HEAD  glibc-kernheaders-$$vr.src.rpm

tar: 
	rm -f `find -name "*~"`
	tar --exclude CVS -cvf - usr | bzip2 -9 > glibc-kernheaders.tar.bz2

rpm-prep: sources
	$(RPM) --define "_sourcedir `pwd`" --nodeps -bp $(SPECFILE)

srpm: sources
	$(RPM) --define "_sourcedir `pwd`" --define "_srcrpmdir `pwd`" --nodeps -bs $(SPECFILE)
	echo "Don't forget to make tag if you're building this into the buildsystem!"

# Even uglier.  Make sure the files that are in the current directory
# match whatever was last used by folks to build from CVS.
#
phony:

$(addsuffix .md5,$(FTPFILES)): %.md5: % phony
	@if ! md5sum $< | diff >/dev/null --brief "$@" - ; then echo "md5sum of $< does not match $@" ; exit 1 ; fi

sources: tar


# If you build a new version into the tree, first do "make tag",
# then "make srpm", then build the package.  If the package fails
# to build, fix it, re-run "make tag" without incrementing the
# release number (it will force the tag update), then run "make srpm"
# again and build the package.  Lather, rinse, repeat until the
# package builds successfully.  Use "make check" to check that
# patches apply and make oldconfig works on all arch's, too.
tag:
	cvs tag -F $(NAMEVER)_$(VERSION)-$(RELEASE)

verrel:
	echo $(NAMEVER)_$(VERSION)-$(RELEASE)


# "make new | less" to see what has changed since the last tag was assigned
new:
	@cvs diff -u -r$$(cvs log Makefile 2>/dev/null | awk '/^symbolic names:$$/ {getline; sub(/^[ \t]*/, "") ; sub (/:.*$$/, ""); print; exit 0}')
