# Top level Makefile for DECnet programs

include Makefile.common

#
# ARCH code taken from the Linux kernel sources.
#
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)

#
# PKGNAME determines the .tar.gz file name and also is the directory name
#
PKGNAME=dnprogs

SUBDIRS=libdnet libdap fal dndir dnsubmit dndel dncopy apps dntask mail phone

all: $(SUBDIRS)
	for i in $(SUBDIRS); do make -C $$i $@ ; done

install:
	@if [ $$UID != 0 ]; then echo You must be root to make install; exit 1; fi
	for i in $(SUBDIRS); do make -C $$i $@ ; done

dep depend:	
	for i in $(SUBDIRS); do make -C $$i $@ ; done

tags:	
	etags */*.cc */*.c


backup:
	rm -f /var/tmp/$(PKGNAME).tgz
	tar -czvf /var/tmp/$(PKGNAME).tgz -Xexcludes-backup . 
	cp /var/tmp/$(PKGNAME).tgz /msdos/dev/bosy/

clean:
	for i in $(SUBDIRS); do make -C $$i $@ ; done


dist:	
	for i in $(SUBDIRS); do cd $$i; makedepend; cd ..; done
	if [ -L ../$(PKGNAME)-$(VERSION) ]; then rm ../$(PKGNAME)-$(VERSION); fi
	if [ ! -f ../$(PKGNAME)-$(VERSION) ]; then cd ..; ln -s $(PKGNAME) $(PKGNAME)-$(VERSION); fi
	cd ..; tar -czvhf /var/tmp/$(PKGNAME)-$(VERSION).tar.gz -X$(PKGNAME)-$(VERSION)/excludes-dist $(PKGNAME)-$(VERSION);
	if [ -L ../$(PKGNAME)-$(VERSION) ]; then rm ../$(PKGNAME)-$(VERSION); fi

#
# Make RPM package for RedHat systems.
#
rpm:
	@if [ $$UID != 0 ]; then echo You must be root to make RPMs; exit 1; fi
	sed -e's/%%PACKAGENAME%%/$(PKGNAME)/g' -e's/%%VERSION%%/$(VERSION)/g' -e's@%%PREFIX%%@$(prefix)@g' <rpm.spec >$(PKGNAME).spec
	make install
	make dist
	cp /var/tmp/$(PKGNAME)-$(VERSION).tar.gz /usr/src/redhat/SOURCES
	cp README NEWS Documentation/*.README /usr/src/redhat/BUILD
	rpm -bb -v $(PKGNAME).spec
	rm -f $(PKGNAME).spec

#
# Make Debian package.
#
deb:
	@if [ $$UID != 0 ]; then echo You must be root to make DEBs; exit 1; fi
	rm -f Documentation/*~ Documentation/*.bak
	sed -e's/%%PACKAGENAME%%/$(PKGNAME)/g' -e's/%%VERSION%%/$(VERSION)/g' -e's@%%PREFIX%%@$(prefix)@g' <debian-changelog >debian/changelog
	if [ -L ../$(PKGNAME)-$(VERSION) ]; then rm ../$(PKGNAME)-$(VERSION); fi
	if [ ! -f ../$(PKGNAME)-$(VERSION) ]; then cd ..; ln -s $(PKGNAME) $(PKGNAME)-$(VERSION); fi
	cd ../$(PKGNAME)-$(VERSION); debian/rules binary-arch
	if [ -L ../$(PKGNAME)-$(VERSION) ]; then rm ../$(PKGNAME)-$(VERSION); fi

#
# Copy binaries to the web preload directory.
# Only really works on my Intel machine, hence the check
#
bindist: dist rpm deb
	@if [ `uname -n` != "pandh" ]; then echo Only do this on Patrick's Intel box; exit 1; fi
	cp /usr/src/redhat/SOURCES/$(PKGNAME)-$(VERSION).tar.gz /home/patrick/public_html/decnet
	cp ../$(PKGNAME)_$(VERSION)-1_i386.deb /home/patrick/public_html/decnet
	cp /usr/src/redhat/RPMS/$(ARCH)/$(PKGNAME)-$(VERSION)-1.i386.rpm /home/patrick/public_html/decnet
	cp /scratch/sparclinux/$(PKGNAME)-$(VERSION)-1.sparc.rpm /home/patrick/public_html/decnet
	cp /scratch/sparclinux/$(PKGNAME)_$(VERSION)-1_sparc.deb /home/patrick/public_html/decnet

#
# Dummy rule for sub-directories
#
dummy:


# DO NOT DELETE THIS LINE -- make  depend  depends  on it.
